groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: Refactor code
Date Sun, 03 Nov 2019 05:23:54 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 23097b9  Refactor code
23097b9 is described below

commit 23097b9cdcd5041fedc43c25ab1a1ebc681f310f
Author: mattisonchao <mattisonchao@gmail.com>
AuthorDate: Sun Nov 3 12:43:35 2019 +0800

    Refactor code
    
    Refactored some code about new java version.
    --Make a contribution to groovy every day.
---
 .../codehaus/groovy/ant/CompileTaskSupport.java    |  7 +----
 .../groovy/ant/FileSystemCompilerFacade.java       |  2 +-
 .../main/java/org/codehaus/groovy/ant/Groovy.java  |  7 +----
 .../main/java/org/codehaus/groovy/ant/Groovyc.java | 27 ++++++-------------
 .../java/org/codehaus/groovy/ant/Groovydoc.java    | 30 ++++++++++------------
 .../codehaus/groovy/bsf/CachingGroovyEngine.java   | 14 +++++-----
 .../groovy-bsf/src/spec/test/BSFSpecTest.java      |  2 +-
 .../test/java/org/codehaus/groovy/bsf/BSFTest.java |  2 +-
 8 files changed, 33 insertions(+), 58 deletions(-)

diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
index ecc8f65..85e6ec4 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
@@ -137,12 +137,7 @@ public abstract class CompileTaskSupport
     protected GroovyClassLoader createClassLoader() {
         GroovyClassLoader gcl =
                 AccessController.doPrivileged(
-                        new PrivilegedAction<GroovyClassLoader>() {
-                            @Override
-                            public GroovyClassLoader run() {
-                                return new GroovyClassLoader(ClassLoader.getSystemClassLoader(),
config);
-                            }
-                        });
+                        (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(ClassLoader.getSystemClassLoader(),
config));
 
         Path path = getClasspath();
         if (path != null) {
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/FileSystemCompilerFacade.java
b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/FileSystemCompilerFacade.java
index 88f3041..4ce3920 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/FileSystemCompilerFacade.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/FileSystemCompilerFacade.java
@@ -32,7 +32,7 @@ public class FileSystemCompilerFacade {
     private static final String[] EMPTY_STRING_ARRAY = new String[0];
 
     public static void main(String[] args) {
-        List<String> argList = new ArrayList<String>(Arrays.asList(args));
+        List<String> argList = new ArrayList<>(Arrays.asList(args));
         boolean forceLookupUnnamedFiles = argList.contains("--forceLookupUnnamedFiles");
         if (forceLookupUnnamedFiles) {
             argList.remove("--forceLookupUnnamedFiles");
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
index a0931d0..fb5c467 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
@@ -452,12 +452,7 @@ public class Groovy extends Java {
         final String scriptName = computeScriptName();
         final GroovyClassLoader classLoader =
                 AccessController.doPrivileged(
-                        new PrivilegedAction<GroovyClassLoader>() {
-                            @Override
-                            public GroovyClassLoader run() {
-                                return new GroovyClassLoader(baseClassLoader);
-                            }
-                        });
+                        (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(baseClassLoader));
         addClassPathes(classLoader);
         configureCompiler();
         final GroovyShell groovy = new GroovyShell(classLoader, new Binding(), configuration);
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index 9feb055..f617d8e 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -201,7 +201,7 @@ public class Groovyc extends MatchingTask {
     private Javac javac;
     private boolean jointCompilation;
 
-    private final List<File> temporaryFiles = new ArrayList<File>(2);
+    private final List<File> temporaryFiles = new ArrayList<>(2);
     private File stubDir;
     private boolean keepStubs;
     private boolean forceLookupUnnamedFiles;
@@ -209,7 +209,7 @@ public class Groovyc extends MatchingTask {
     private String scriptBaseClass;
     private String configscript;
 
-    private Set<String> scriptExtensions = new LinkedHashSet<String>();
+    private Set<String> scriptExtensions = new LinkedHashSet<>();
 
     /**
      * If true, generates metadata for reflection on method parameter names (jdk8+ only).
 Defaults to false.
@@ -884,7 +884,7 @@ public class Groovyc extends MatchingTask {
      */
     protected void resetFileLists() {
         compileList = EMPTY_FILE_ARRAY;
-        scriptExtensions = new LinkedHashSet<String>();
+        scriptExtensions = new LinkedHashSet<>();
     }
 
     /**
@@ -961,7 +961,7 @@ public class Groovyc extends MatchingTask {
     }
 
     private List<String> extractJointOptions(Path classpath) {
-        List<String> jointOptions = new ArrayList<String>();
+        List<String> jointOptions = new ArrayList<>();
         if (!jointCompilation) return jointOptions;
 
         // extract joint options, some get pushed up...
@@ -978,9 +978,7 @@ public class Groovyc extends MatchingTask {
                 jointOptions.add("-Fg" + level);
             } else if (key.contains("debugLevel")) {
                 // ignore, taken care of in debug
-            } else if ((key.contains("nowarn"))
-                    || (key.contains("verbose"))
-                    || (key.contains("deprecation"))) {
+            } else if (key.contains("verbose")) {
                 // false is default, so something to do only in true case
                 if ("on".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value))
                     jointOptions.add("-F" + key);
@@ -1268,7 +1266,7 @@ public class Groovyc extends MatchingTask {
             List<String> jointOptions = extractJointOptions(classpath);
 
             String separator = System.getProperty("file.separator");
-            List<String> commandLineList = new ArrayList<String>();
+            List<String> commandLineList = new ArrayList<>();
 
             doForkCommandLineList(commandLineList, classpath, separator);
             doNormalCommandLineList(commandLineList, jointOptions, classpath);
@@ -1372,19 +1370,10 @@ public class Groovyc extends MatchingTask {
 
         GroovyClassLoader loader =
                 AccessController.doPrivileged(
-                        new PrivilegedAction<GroovyClassLoader>() {
-                            @Override
-                            public GroovyClassLoader run() {
-                                return new GroovyClassLoader(parent, configuration);
-                            }
-                        });
+                        (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parent,
configuration));
         if (!forceLookupUnnamedFiles) {
             // in normal case we don't need to do script lookups
-            loader.setResourceLoader(new GroovyResourceLoader() {
-                public URL loadGroovySource(String filename) throws MalformedURLException
{
-                    return null;
-                }
-            });
+            loader.setResourceLoader(filename -> null);
         }
         return loader;
     }
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java
index ccb39ea..b5e408a 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovydoc.java
@@ -66,7 +66,7 @@ public class Groovydoc extends Task {
     private Boolean noVersionStamp;
     private final List<DirSet> packageSets;
     private final List<String> sourceFilesToDoc;
-    private final List<LinkArgument> links = new ArrayList<LinkArgument>();
+    private final List<LinkArgument> links = new ArrayList<>();
     private File overviewFile;
     private File styleSheetFile;
     // dev note: update javadoc comment for #setExtensions(String) if updating below
@@ -76,10 +76,10 @@ public class Groovydoc extends Task {
     private String fileEncoding;
 
     public Groovydoc() {
-        packageNames = new ArrayList<String>();
-        excludePackageNames = new ArrayList<String>();
+        packageNames = new ArrayList<>();
+        excludePackageNames = new ArrayList<>();
         packageSets = new ArrayList<DirSet>();
-        sourceFilesToDoc = new ArrayList<String>();
+        sourceFilesToDoc = new ArrayList<>();
         privateScope = false;
         protectedScope = false;
         publicScope = false;
@@ -335,7 +335,7 @@ public class Groovydoc extends Task {
      * @since 1.5
      */
     private void parsePackages(List<String> resultantPackages, Path sourcePath) {
-        List<String> addedPackages = new ArrayList<String>();
+        List<String> addedPackages = new ArrayList<>();
         List<DirSet> dirSets = new ArrayList<DirSet>(packageSets);
 
         // for each sourcePath entry, add a directoryset with includes
@@ -388,17 +388,15 @@ public class Groovydoc extends Task {
             for (String dir : dirs) {
                 // are there any groovy or java files in this directory?
                 File pd = new File(baseDir, dir);
-                String[] files = pd.list(new FilenameFilter() {
-                    public boolean accept(File dir1, String name) {
-                        if (!includeNoSourcePackages
-                                && name.equals("package.html")) return true;
-                        final StringTokenizer tokenizer = new StringTokenizer(extensions,
":");
-                        while (tokenizer.hasMoreTokens()) {
-                            String ext = tokenizer.nextToken();
-                            if (name.endsWith(ext)) return true;
-                        }
-                        return false;
+                String[] files = pd.list((dir1, name) -> {
+                    if (!includeNoSourcePackages
+                            && name.equals("package.html")) return true;
+                    final StringTokenizer tokenizer = new StringTokenizer(extensions, ":");
+                    while (tokenizer.hasMoreTokens()) {
+                        String ext = tokenizer.nextToken();
+                        if (name.endsWith(ext)) return true;
                     }
+                    return false;
                 });
 
                 for (String filename : files) {
@@ -431,7 +429,7 @@ public class Groovydoc extends Task {
     }
 
     public void execute() throws BuildException {
-        List<String> packagesToDoc = new ArrayList<String>();
+        List<String> packagesToDoc = new ArrayList<>();
         Path sourceDirs = new Path(getProject());
         Properties properties = new Properties();
         properties.setProperty("windowTitle", windowTitle);
diff --git a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/CachingGroovyEngine.java
b/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/CachingGroovyEngine.java
index 9d49673..427e211 100644
--- a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/CachingGroovyEngine.java
+++ b/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/CachingGroovyEngine.java
@@ -100,8 +100,8 @@ public class CachingGroovyEngine extends GroovyEngine {
         if (parent == null)
             parent = GroovyShell.class.getClassLoader();
         setLoader(mgr, parent);
-        execScripts = new HashMap<Object, Class>();
-        evalScripts = new HashMap<Object, Class>();
+        execScripts = new HashMap<>();
+        evalScripts = new HashMap<>();
         context = shell.getContext();
         // create a shell
         // register the mgr with object name "bsf"
@@ -115,12 +115,10 @@ public class CachingGroovyEngine extends GroovyEngine {
     @SuppressWarnings("unchecked")
     private void setLoader(final BSFManager mgr, final ClassLoader finalParent) {
         this.loader =
-                (GroovyClassLoader) AccessController.doPrivileged(new PrivilegedAction()
{
-                    public Object run() {
-                        CompilerConfiguration configuration = new CompilerConfiguration();
-                        configuration.setClasspath(mgr.getClassPath());
-                        return new GroovyClassLoader(finalParent, configuration);
-                    }
+                (GroovyClassLoader) AccessController.doPrivileged((PrivilegedAction) () ->
{
+                    CompilerConfiguration configuration = new CompilerConfiguration();
+                    configuration.setClasspath(mgr.getClassPath());
+                    return new GroovyClassLoader(finalParent, configuration);
                 });
     }
 }
diff --git a/subprojects/groovy-bsf/src/spec/test/BSFSpecTest.java b/subprojects/groovy-bsf/src/spec/test/BSFSpecTest.java
index 7994b4c..d81be0e 100644
--- a/subprojects/groovy-bsf/src/spec/test/BSFSpecTest.java
+++ b/subprojects/groovy-bsf/src/spec/test/BSFSpecTest.java
@@ -52,7 +52,7 @@ public class BSFSpecTest {
         // tag::bsf_apply[]
         BSFManager manager = new BSFManager();
         Vector<String> ignoreParamNames = null;
-        Vector<Integer> args = new Vector<Integer>();
+        Vector<Integer> args = new Vector<>();
         args.add(2);
         args.add(5);
         args.add(1);
diff --git a/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/BSFTest.java b/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/BSFTest.java
index 44bb433..f8c0490 100644
--- a/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/BSFTest.java
+++ b/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/BSFTest.java
@@ -86,7 +86,7 @@ public class BSFTest extends TestCase {
 
     public void testApply() throws Exception {
         Vector ignoreParamNames = null;
-        Vector<Integer> args = new Vector<Integer>();
+        Vector<Integer> args = new Vector<>();
         args.add(2);
         args.add(5);
         args.add(1);


Mime
View raw message