You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2019/11/02 21:47:04 UTC

[groovy] 07/08: Java 8 refactor

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 0fdf71e23e812ed161d13bb28181ca966d4228e0
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 04:28:53 2019 +0800

    Java 8 refactor
    
    (cherry picked from commit 2042f6c2cc38114acf7e27d7dfda3b34389d5903)
---
 src/main/java/groovy/lang/MetaClassImpl.java | 45 +++++++++-------------------
 1 file changed, 14 insertions(+), 31 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index e1b00eb..8cee0f2 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -82,7 +82,6 @@ import org.codehaus.groovy.vmplugin.VMPluginFactory;
 import javax.annotation.Nullable;
 import java.beans.BeanInfo;
 import java.beans.EventSetDescriptor;
-import java.beans.IntrospectionException;
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Array;
@@ -1626,14 +1625,12 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
 
         CachedConstructor constructor = createCachedConstructor(arguments);
         List l = new ArrayList(constructors.toList());
-        Comparator comp = new Comparator() {
-            public int compare(Object arg0, Object arg1) {
-                CachedConstructor c0 = (CachedConstructor) arg0;
-                CachedConstructor c1 = (CachedConstructor) arg1;
-                String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes());
-                String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes());
-                return descriptor0.compareTo(descriptor1);
-            }
+        Comparator comp = (arg0, arg1) -> {
+            CachedConstructor c0 = (CachedConstructor) arg0;
+            CachedConstructor c1 = (CachedConstructor) arg1;
+            String descriptor0 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c0.getNativeParameterTypes());
+            String descriptor1 = BytecodeHelper.getMethodDescriptor(Void.TYPE, c1.getNativeParameterTypes());
+            return descriptor0.compareTo(descriptor1);
         };
         Collections.sort(l, comp);
         int found = -1;
@@ -3404,17 +3401,9 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         //     introspect
         try {
             if (isBeanDerivative(theClass)) {
-                info = (BeanInfo) AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws IntrospectionException {
-                        return Introspector.getBeanInfo(theClass, Introspector.IGNORE_ALL_BEANINFO);
-                    }
-                });
+                info = (BeanInfo) AccessController.doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass, Introspector.IGNORE_ALL_BEANINFO));
             } else {
-                info = (BeanInfo) AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws IntrospectionException {
-                        return Introspector.getBeanInfo(theClass);
-                    }
-                });
+                info = (BeanInfo) AccessController.doPrivileged((PrivilegedExceptionAction) () -> Introspector.getBeanInfo(theClass));
             }
         } catch (PrivilegedActionException pae) {
             throw new GroovyRuntimeException("exception during bean introspection", pae.getException());
@@ -3914,21 +3903,15 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         metaMethodIndex.clearCaches();
     }
 
-    private static final SingleKeyHashMap.Copier NAME_INDEX_COPIER = new SingleKeyHashMap.Copier() {
-        public Object copy(Object value) {
-            if (value instanceof FastArray) {
-                return ((FastArray) value).copy();
-            } else {
-                return value;
-            }
+    private static final SingleKeyHashMap.Copier NAME_INDEX_COPIER = value -> {
+        if (value instanceof FastArray) {
+            return ((FastArray) value).copy();
+        } else {
+            return value;
         }
     };
 
-    private static final SingleKeyHashMap.Copier METHOD_INDEX_COPIER = new SingleKeyHashMap.Copier() {
-        public Object copy(Object value) {
-            return SingleKeyHashMap.copy(new SingleKeyHashMap(false), (SingleKeyHashMap) value, NAME_INDEX_COPIER);
-        }
-    };
+    private static final SingleKeyHashMap.Copier METHOD_INDEX_COPIER = value -> SingleKeyHashMap.copy(new SingleKeyHashMap(false), (SingleKeyHashMap) value, NAME_INDEX_COPIER);
 
     static class MethodIndex extends Index {
         public MethodIndex(boolean b) {