groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 02/03: Refactor code
Date Mon, 04 Nov 2019 16:51:24 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit e760a24a5e2effaef769446cfe76663887ae53a8
Author: mattisonchao <mattisonchao@gmail.com>
AuthorDate: Mon Nov 4 14:43:05 2019 +0800

    Refactor code
    
    Refactored some code about new java version and some performance issue.
    but i'm not sure,Is the file I am modifying correct?
    
    --Make a contribution to groovy every day.
    
    (cherry picked from commit d070a91a635b4f0d8ed88211b954f1df984eaa5d)
---
 src/test/groovy/security/SecurityTest.java         |  9 ++--
 src/test/groovy/security/SecurityTestSupport.java  | 55 ++++++++--------------
 .../classgen/ClassCompletionVerifierTest.java      |  2 +-
 .../org/codehaus/groovy/classgen/TestSupport.java  | 14 +-----
 .../asm/sc/bugs/support/Groovy7133Support.java     |  3 +-
 .../groovy/runtime/memoize/CommonCacheTest.java    |  7 +--
 .../runtime/memoize/ConcurrentCommonCacheTest.java |  7 +--
 .../runtime/memoize/StampedCommonCacheTest.java    |  7 +--
 .../memoize/UnlimitedConcurrentCacheTest.java      |  7 +--
 .../codehaus/groovy/tools/TestDgmConverter.java    |  6 +--
 10 files changed, 32 insertions(+), 85 deletions(-)

diff --git a/src/test/groovy/security/SecurityTest.java b/src/test/groovy/security/SecurityTest.java
index a438994..15f1d00 100644
--- a/src/test/groovy/security/SecurityTest.java
+++ b/src/test/groovy/security/SecurityTest.java
@@ -61,12 +61,9 @@ public class SecurityTest extends SecurityTestSupport {
         // Use our privileged access in order to prevent checks lower in the call stack.
 Otherwise we would have
         // to grant access to IDE unit test runners and unit test libs.  We only care about
testing the call stack
         // higher upstream from this point of execution.
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                Security.setProperty("package.access", "javax.print");
-                return null;
-            }
+        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+            Security.setProperty("package.access", "javax.print");
+            return null;
         });
         //This should throw an ACE because its codeBase does not allow access to javax.print
         assertExecute(script, "/groovy/security/javax/print/deny", new RuntimePermission("accessClassInPackage.javax.print"));
diff --git a/src/test/groovy/security/SecurityTestSupport.java b/src/test/groovy/security/SecurityTestSupport.java
index a4e08c9..0485b82 100644
--- a/src/test/groovy/security/SecurityTestSupport.java
+++ b/src/test/groovy/security/SecurityTestSupport.java
@@ -91,12 +91,7 @@ public abstract class SecurityTestSupport extends GroovyTestCase {
 
     protected GroovyClassLoader loader =
             AccessController.doPrivileged(
-                    new PrivilegedAction<GroovyClassLoader>() {
-                        @Override
-                        public GroovyClassLoader run() {
-                            return new GroovyClassLoader(SecurityTestSupport.class.getClassLoader());
-                        }
-                    }
+                    (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(SecurityTestSupport.class.getClassLoader())
             );
 
     private SecurityManager securityManager;
@@ -135,23 +130,17 @@ public abstract class SecurityTestSupport extends GroovyTestCase {
             }
         }
         currentClassLoader = Thread.currentThread().getContextClassLoader();
-        AccessController.doPrivileged(new PrivilegedAction() {
-            @Override
-            public Object run() {
-                Thread.currentThread().setContextClassLoader(loader);
-                return null;
-            }
+        AccessController.doPrivileged((PrivilegedAction) () -> {
+            Thread.currentThread().setContextClassLoader(loader);
+            return null;
         });
     }
 
     protected void tearDown() {
-        AccessController.doPrivileged(new PrivilegedAction() {
-            @Override
-            public Object run() {
-                System.setSecurityManager(securityManager);
-                Thread.currentThread().setContextClassLoader(currentClassLoader);
-                return null;
-            }
+        AccessController.doPrivileged((PrivilegedAction) () -> {
+            System.setSecurityManager(securityManager);
+            Thread.currentThread().setContextClassLoader(currentClassLoader);
+            return null;
         });
     }
 
@@ -274,18 +263,15 @@ public abstract class SecurityTestSupport extends GroovyTestCase {
         // Use our privileged access in order to prevent checks lower in the call stack.
 Otherwise we would have
         // to grant access to IDE unit test runners and unit test libs.  We only care about
testing the call stack
         // higher upstream from this point of execution.
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                GroovyCodeSource gcs = null;
-                try {
-                    gcs = new GroovyCodeSource(file);
-                } catch (IOException fnfe) {
-                    fail(fnfe.toString());
-                }
-                parseAndExecute(gcs, missingPermission);
-                return null;
+        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+            GroovyCodeSource gcs = null;
+            try {
+                gcs = new GroovyCodeSource(file);
+            } catch (IOException fnfe) {
+                fail(fnfe.toString());
             }
+            parseAndExecute(gcs, missingPermission);
+            return null;
         });
     }
 
@@ -302,12 +288,9 @@ public abstract class SecurityTestSupport extends GroovyTestCase {
         // Use our privileged access in order to prevent checks lower in the call stack.
 Otherwise we would have
         // to grant access to IDE unit test runners and unit test libs.  We only care about
testing the call stack
         // higher upstream from this point of execution.
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            @Override
-            public Void run() {
-                parseAndExecute(new GroovyCodeSource(scriptStr, generateClassName(), effectiveCodeBase),
missingPermission);
-                return null;
-            }
+        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+            parseAndExecute(new GroovyCodeSource(scriptStr, generateClassName(), effectiveCodeBase),
missingPermission);
+            return null;
         });
     }
 }
diff --git a/src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java b/src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java
index 4de5012..41be14e 100644
--- a/src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java
+++ b/src/test/org/codehaus/groovy/classgen/ClassCompletionVerifierTest.java
@@ -81,7 +81,7 @@ public class ClassCompletionVerifierTest extends TestSupport {
 
     public void testDetectsAbstractPrivateMethod() throws Exception {
         ClassNode node = new ClassNode("X", ACC_ABSTRACT, ClassHelper.OBJECT_TYPE);
-        node.addMethod(new MethodNode("y", ACC_PRIVATE | ACC_ABSTRACT, ClassHelper.VOID_TYPE,
new Parameter[0], ClassNode.EMPTY_ARRAY, null));
+        node.addMethod(new MethodNode("y", ACC_PRIVATE | ACC_ABSTRACT, ClassHelper.VOID_TYPE,
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, null));
         verifier.visitClass(node);
         checkErrorMessage(EXPECTED_ABSTRACT_PRIVATE_METHOD_ERROR_MESSAGE);
     }
diff --git a/src/test/org/codehaus/groovy/classgen/TestSupport.java b/src/test/org/codehaus/groovy/classgen/TestSupport.java
index a6f19c8..8157ef8 100644
--- a/src/test/org/codehaus/groovy/classgen/TestSupport.java
+++ b/src/test/org/codehaus/groovy/classgen/TestSupport.java
@@ -59,12 +59,7 @@ public class TestSupport extends GroovyTestCase implements Opcodes {
     final ClassLoader parentLoader = getClass().getClassLoader();
     protected final GroovyClassLoader loader =
             AccessController.doPrivileged(
-                    new PrivilegedAction<GroovyClassLoader>() {
-                        @Override
-                        public GroovyClassLoader run() {
-                            return new GroovyClassLoader(parentLoader);
-                        }
-                    }
+                    (PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parentLoader)
             );
     final CompileUnit unit = new CompileUnit(loader, new CompilerConfiguration());
     final ModuleNode module = new ModuleNode(unit);
@@ -153,12 +148,7 @@ public class TestSupport extends GroovyTestCase implements Opcodes {
         log.info("About to execute script");
         log.info(text);
         GroovyCodeSource gcs = AccessController.doPrivileged(
-                new PrivilegedAction<GroovyCodeSource>() {
-                    @Override
-                    public GroovyCodeSource run() {
-                        return new GroovyCodeSource(text, scriptName, "/groovy/testSupport");
-                    }
-                }
+                (PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(text,
scriptName, "/groovy/testSupport")
         );
         Class groovyClass = loader.parseClass(gcs);
         Script script = InvokerHelper.createScript(groovyClass, new Binding());
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7133Support.java
b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7133Support.java
index d27271d..742484b 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7133Support.java
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/bugs/support/Groovy7133Support.java
@@ -19,10 +19,11 @@
 package org.codehaus.groovy.classgen.asm.sc.bugs.support;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 public class Groovy7133Support {
     public static List<int[]> list() {
-        return Arrays.asList(new int[1]);
+        return Collections.singletonList(new int[1]);
     }
 }
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java b/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java
index bd2c7e9..b7ed91a 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java
+++ b/src/test/org/codehaus/groovy/runtime/memoize/CommonCacheTest.java
@@ -60,12 +60,7 @@ public class CommonCacheTest {
         CommonCache<String, String> sc = new CommonCache<>();
 
         EvictableCache.ValueProvider vp =
-                new EvictableCache.ValueProvider<String, String>() {
-                    @Override
-                    public String provide(String key) {
-                        return "Chinese";
-                    }
-                };
+                (EvictableCache.ValueProvider<String, String>) key -> "Chinese";
 
         Assert.assertEquals("Chinese", sc.getAndPut("language", vp,false));
         Assert.assertNull(sc.get("language"));
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java b/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java
index 967685b..97ecadc 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java
+++ b/src/test/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCacheTest.java
@@ -61,12 +61,7 @@ public class ConcurrentCommonCacheTest {
         ConcurrentCommonCache<String, String> sc = new ConcurrentCommonCache<>();
 
         EvictableCache.ValueProvider vp =
-                new EvictableCache.ValueProvider<String, String>() {
-            @Override
-            public String provide(String key) {
-                return "Chinese";
-            }
-        };
+                (EvictableCache.ValueProvider<String, String>) key -> "Chinese";
 
         Assert.assertEquals("Chinese", sc.getAndPut("language", vp,false));
         Assert.assertNull(sc.get("language"));
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java b/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java
index 7b8b071..072492f 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java
+++ b/src/test/org/codehaus/groovy/runtime/memoize/StampedCommonCacheTest.java
@@ -61,12 +61,7 @@ public class StampedCommonCacheTest {
         StampedCommonCache<String, String> sc = new StampedCommonCache<>();
 
         EvictableCache.ValueProvider vp =
-                new EvictableCache.ValueProvider<String, String>() {
-            @Override
-            public String provide(String key) {
-                return "Chinese";
-            }
-        };
+                (EvictableCache.ValueProvider<String, String>) key -> "Chinese";
 
         Assert.assertEquals("Chinese", sc.getAndPut("language", vp,false));
         Assert.assertNull(sc.get("language"));
diff --git a/src/test/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCacheTest.java
b/src/test/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCacheTest.java
index d0e2a5a..ab5d4ad 100644
--- a/src/test/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCacheTest.java
+++ b/src/test/org/codehaus/groovy/runtime/memoize/UnlimitedConcurrentCacheTest.java
@@ -62,12 +62,7 @@ public class UnlimitedConcurrentCacheTest {
         UnlimitedConcurrentCache<String, String> sc = new UnlimitedConcurrentCache<>();
 
         EvictableCache.ValueProvider vp =
-                new EvictableCache.ValueProvider<String, String>() {
-            @Override
-            public String provide(String key) {
-                return "Chinese";
-            }
-        };
+                (EvictableCache.ValueProvider<String, String>) key -> "Chinese";
 
         Assert.assertEquals("Chinese", sc.getAndPut("language", vp));
         Assert.assertEquals("Chinese", sc.get("language"));
diff --git a/src/test/org/codehaus/groovy/tools/TestDgmConverter.java b/src/test/org/codehaus/groovy/tools/TestDgmConverter.java
index 575ed03..393d7d6 100644
--- a/src/test/org/codehaus/groovy/tools/TestDgmConverter.java
+++ b/src/test/org/codehaus/groovy/tools/TestDgmConverter.java
@@ -38,11 +38,7 @@ public class TestDgmConverter extends TestCase {
         File dgmClassDirectory = new File(TestDgmConverter.class.getResource(REFERENCE_CLASS).toURI()).getParentFile();
 
         final File[] files = dgmClassDirectory.listFiles();
-        Arrays.sort(files, new Comparator<File>() {
-            public int compare(final File o1, final File o2) {
-                return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
-            }
-        });
+        Arrays.sort(files, (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(),
o2.getName()));
         for (int i = 0; i < files.length; i++) {
             File file = files[i];
             final String name = file.getName();


Mime
View raw message