groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/06: Minor refactoring: Anonymous type can be replaced with lambda expression
Date Sun, 03 Nov 2019 13:39:07 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

commit be7591e22c9605a9366129ef4c5a184264169922
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sun Nov 3 21:19:58 2019 +0800

    Minor refactoring: Anonymous type can be replaced with lambda expression
---
 src/main/java/groovy/grape/Grape.java              |  29 ++---
 src/main/java/groovy/lang/ExpandoMetaClass.java    | 135 ++++++++++-----------
 src/main/java/groovy/lang/GroovyClassLoader.java   |  71 +++++------
 src/main/java/groovy/lang/GroovyCodeSource.java    |  28 ++---
 src/main/java/groovy/lang/GroovyShell.java         |  36 +-----
 src/main/java/groovy/lang/ProxyMetaClass.java      |  24 +---
 .../java/groovy/util/FactoryBuilderSupport.java    |  12 +-
 src/main/java/groovy/util/GroovyScriptEngine.java  |  40 +++---
 src/main/java/groovy/util/ObjectGraphBuilder.java  |  70 ++++-------
 src/main/java/groovy/util/ProxyGenerator.java      |  14 +--
 .../internal/util/ReevaluatingReference.java       |  13 +-
 .../groovy/ast/tools/WideningCategories.java       |  32 +++--
 .../org/codehaus/groovy/classgen/ReturnAdder.java  |  11 +-
 .../groovy/classgen/asm/InvocationWriter.java      |  14 +--
 .../groovy/classgen/asm/StatementWriter.java       |  20 ++-
 .../asm/sc/StaticCompilationMopWriter.java         |   7 +-
 .../codehaus/groovy/control/ProcessingUnit.java    |  10 +-
 .../org/codehaus/groovy/control/SourceUnit.java    |   6 +-
 .../codehaus/groovy/reflection/SunClassLoader.java |  12 +-
 .../groovy/runtime/ProcessGroovyMethods.java       |  52 ++++----
 .../groovy/runtime/ProxyGeneratorAdapter.java      |   6 +-
 .../groovy/runtime/SocketGroovyMethods.java        |   6 +-
 .../runtime/callsite/GroovySunClassLoader.java     |  16 ++-
 .../runtime/metaclass/MetaClassRegistryImpl.java   |  34 +++---
 .../org/codehaus/groovy/tools/GroovyStarter.java   |   6 +-
 .../transform/SortableASTTransformation.java       |   6 +-
 .../transform/ToStringASTTransformation.java       |   6 +-
 .../TupleConstructorASTTransformation.java         |   6 +-
 .../codehaus/groovy/vmplugin/v7/IndyInterface.java |   8 +-
 .../org/codehaus/groovy/vmplugin/v7/Java7.java     |  18 +--
 30 files changed, 282 insertions(+), 466 deletions(-)

diff --git a/src/main/java/groovy/grape/Grape.java b/src/main/java/groovy/grape/Grape.java
index 7ab4328..dfe7a37 100644
--- a/src/main/java/groovy/grape/Grape.java
+++ b/src/main/java/groovy/grape/Grape.java
@@ -157,24 +157,21 @@ public class Grape {
 
     public static void grab(final Map<String, Object> args, final Map... dependencies) {
         if (enableGrapes) {
-            AccessController.doPrivileged(new PrivilegedAction<Void>() {
-                @Override
-                public Void run() {
-                    GrapeEngine instance = getInstance();
-                    if (instance != null) {
-                        if (!args.containsKey(AUTO_DOWNLOAD_SETTING)) {
-                            args.put(AUTO_DOWNLOAD_SETTING, enableAutoDownload);
-                        }
-                        if (!args.containsKey(DISABLE_CHECKSUMS_SETTING)) {
-                            args.put(DISABLE_CHECKSUMS_SETTING, disableChecksums);
-                        }
-                        if (!args.containsKey(GrapeEngine.CALLEE_DEPTH)) {
-                            args.put(GrapeEngine.CALLEE_DEPTH, GrapeEngine.DEFAULT_CALLEE_DEPTH + 2);
-                        }
-                        instance.grab(args, dependencies);
+            AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                GrapeEngine instance = getInstance();
+                if (instance != null) {
+                    if (!args.containsKey(AUTO_DOWNLOAD_SETTING)) {
+                        args.put(AUTO_DOWNLOAD_SETTING, enableAutoDownload);
                     }
-                    return null;
+                    if (!args.containsKey(DISABLE_CHECKSUMS_SETTING)) {
+                        args.put(DISABLE_CHECKSUMS_SETTING, disableChecksums);
+                    }
+                    if (!args.containsKey(GrapeEngine.CALLEE_DEPTH)) {
+                        args.put(GrapeEngine.CALLEE_DEPTH, GrapeEngine.DEFAULT_CALLEE_DEPTH + 2);
+                    }
+                    instance.grab(args, dependencies);
                 }
+                return null;
             });
         }
     }
diff --git a/src/main/java/groovy/lang/ExpandoMetaClass.java b/src/main/java/groovy/lang/ExpandoMetaClass.java
index 578fad1..42abd56 100644
--- a/src/main/java/groovy/lang/ExpandoMetaClass.java
+++ b/src/main/java/groovy/lang/ExpandoMetaClass.java
@@ -846,27 +846,24 @@ public class ExpandoMetaClass extends MetaClassImpl implements GroovyObject {
      * @param newValue The properties initial value
      */
     public void registerBeanProperty(final String property, final Object newValue) {
-        performOperationOnMetaClass(new Callable() {
-            public void call() {
-                Class type = newValue == null ? Object.class : newValue.getClass();
-
-                MetaBeanProperty mbp = newValue instanceof MetaBeanProperty ? (MetaBeanProperty) newValue : new ThreadManagedMetaBeanProperty(theClass, property, type, newValue);
+        performOperationOnMetaClass(() -> {
+            Class type = newValue == null ? Object.class : newValue.getClass();
 
-                final MetaMethod getter = mbp.getGetter();
-                final MethodKey getterKey = new DefaultCachedMethodKey(theClass, getter.getName(), CachedClass.EMPTY_ARRAY, false);
-                final MetaMethod setter = mbp.getSetter();
-                final MethodKey setterKey = new DefaultCachedMethodKey(theClass, setter.getName(), setter.getParameterTypes(), false);
-                addMetaMethod(getter);
-                addMetaMethod(setter);
+            MetaBeanProperty mbp = newValue instanceof MetaBeanProperty ? (MetaBeanProperty) newValue : new ThreadManagedMetaBeanProperty(theClass, property, type, newValue);
 
-                expandoMethods.put(setterKey, setter);
-                expandoMethods.put(getterKey, getter);
-                expandoProperties.put(mbp.getName(), mbp);
+            final MetaMethod getter = mbp.getGetter();
+            final MethodKey getterKey = new DefaultCachedMethodKey(theClass, getter.getName(), CachedClass.EMPTY_ARRAY, false);
+            final MetaMethod setter = mbp.getSetter();
+            final MethodKey setterKey = new DefaultCachedMethodKey(theClass, setter.getName(), setter.getParameterTypes(), false);
+            addMetaMethod(getter);
+            addMetaMethod(setter);
 
-                addMetaBeanProperty(mbp);
-                performRegistryCallbacks();
-            }
+            expandoMethods.put(setterKey, setter);
+            expandoMethods.put(getterKey, getter);
+            expandoProperties.put(mbp.getName(), mbp);
 
+            addMetaBeanProperty(mbp);
+            performRegistryCallbacks();
         });
     }
 
@@ -877,32 +874,29 @@ public class ExpandoMetaClass extends MetaClassImpl implements GroovyObject {
      */
     public void registerInstanceMethod(final MetaMethod metaMethod) {
         final boolean inited = this.initCalled;
-        performOperationOnMetaClass(new Callable() {
-            public void call() {
-                String methodName = metaMethod.getName();
-                checkIfGroovyObjectMethod(metaMethod);
-                MethodKey key = new DefaultCachedMethodKey(theClass, methodName, metaMethod.getParameterTypes(), false);
+        performOperationOnMetaClass(() -> {
+            String methodName = metaMethod.getName();
+            checkIfGroovyObjectMethod(metaMethod);
+            MethodKey key = new DefaultCachedMethodKey(theClass, methodName, metaMethod.getParameterTypes(), false);
 
-                if (isInitialized()) {
-                    throw new RuntimeException("Already initialized, cannot add new method: " + metaMethod);
-                }
-                // we always adds meta methods to class itself
-                addMetaMethodToIndex(metaMethod, metaMethodIndex.getHeader(theClass));
+            if (isInitialized()) {
+                throw new RuntimeException("Already initialized, cannot add new method: " + metaMethod);
+            }
+            // we always adds meta methods to class itself
+            addMetaMethodToIndex(metaMethod, metaMethodIndex.getHeader(theClass));
 
-                dropMethodCache(methodName);
-                expandoMethods.put(key, metaMethod);
+            dropMethodCache(methodName);
+            expandoMethods.put(key, metaMethod);
 
-                if (inited && isGetter(methodName, metaMethod.getParameterTypes())) {
-                    String propertyName = getPropertyForGetter(methodName);
-                    registerBeanPropertyForMethod(metaMethod, propertyName, true, false);
+            if (inited && isGetter(methodName, metaMethod.getParameterTypes())) {
+                String propertyName = getPropertyForGetter(methodName);
+                registerBeanPropertyForMethod(metaMethod, propertyName, true, false);
 
-                } else if (inited && isSetter(methodName, metaMethod.getParameterTypes())) {
-                    String propertyName = getPropertyForSetter(methodName);
-                    registerBeanPropertyForMethod(metaMethod, propertyName, false, false);
-                }
-                performRegistryCallbacks();
+            } else if (inited && isSetter(methodName, metaMethod.getParameterTypes())) {
+                String propertyName = getPropertyForSetter(methodName);
+                registerBeanPropertyForMethod(metaMethod, propertyName, false, false);
             }
-
+            performRegistryCallbacks();
         });
     }
 
@@ -1002,49 +996,46 @@ public class ExpandoMetaClass extends MetaClassImpl implements GroovyObject {
      * @param callable The callable Closure
      */
     protected void registerStaticMethod(final String name, final Closure callable, final Class[] paramTypes) {
-        performOperationOnMetaClass(new Callable() {
-            public void call() {
-                String methodName;
-                if (name.equals(METHOD_MISSING))
-                    methodName = STATIC_METHOD_MISSING;
-                else if (name.equals(PROPERTY_MISSING))
-                    methodName = STATIC_PROPERTY_MISSING;
-                else
-                    methodName = name;
+        performOperationOnMetaClass(() -> {
+            String methodName;
+            if (name.equals(METHOD_MISSING))
+                methodName = STATIC_METHOD_MISSING;
+            else if (name.equals(PROPERTY_MISSING))
+                methodName = STATIC_PROPERTY_MISSING;
+            else
+                methodName = name;
 
-                ClosureStaticMetaMethod metaMethod = null;
+            ClosureStaticMetaMethod metaMethod = null;
 
-                if (paramTypes != null) {
-                    metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable, paramTypes);
-                } else {
-                    metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable);
-                }
+            if (paramTypes != null) {
+                metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable, paramTypes);
+            } else {
+                metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable);
+            }
 
-                if (methodName.equals(INVOKE_METHOD_METHOD) && callable.getParameterTypes().length == 2) {
-                    invokeStaticMethodMethod = metaMethod;
-                } else {
-                    if (methodName.equals(METHOD_MISSING)) {
-                        methodName = STATIC_METHOD_MISSING;
-                    }
-                    MethodKey key = new DefaultCachedMethodKey(theClass, methodName, metaMethod.getParameterTypes(), false);
+            if (methodName.equals(INVOKE_METHOD_METHOD) && callable.getParameterTypes().length == 2) {
+                invokeStaticMethodMethod = metaMethod;
+            } else {
+                if (methodName.equals(METHOD_MISSING)) {
+                    methodName = STATIC_METHOD_MISSING;
+                }
+                MethodKey key = new DefaultCachedMethodKey(theClass, methodName, metaMethod.getParameterTypes(), false);
 
-                    addMetaMethod(metaMethod);
-                    dropStaticMethodCache(methodName);
+                addMetaMethod(metaMethod);
+                dropStaticMethodCache(methodName);
 //                    cacheStaticMethod(key,metaMethod);
 
-                    if (isGetter(methodName, metaMethod.getParameterTypes())) {
-                        String propertyName = getPropertyForGetter(methodName);
-                        registerBeanPropertyForMethod(metaMethod, propertyName, true, true);
+                if (isGetter(methodName, metaMethod.getParameterTypes())) {
+                    String propertyName = getPropertyForGetter(methodName);
+                    registerBeanPropertyForMethod(metaMethod, propertyName, true, true);
 
-                    } else if (isSetter(methodName, metaMethod.getParameterTypes())) {
-                        String propertyName = getPropertyForSetter(methodName);
-                        registerBeanPropertyForMethod(metaMethod, propertyName, false, true);
-                    }
-                    performRegistryCallbacks();
-                    expandoMethods.put(key, metaMethod);
+                } else if (isSetter(methodName, metaMethod.getParameterTypes())) {
+                    String propertyName = getPropertyForSetter(methodName);
+                    registerBeanPropertyForMethod(metaMethod, propertyName, false, true);
                 }
+                performRegistryCallbacks();
+                expandoMethods.put(key, metaMethod);
             }
-
         });
     }
 
diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java b/src/main/java/groovy/lang/GroovyClassLoader.java
index 59741fb..afc52ff 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/groovy/lang/GroovyClassLoader.java
@@ -325,12 +325,7 @@ public class GroovyClassLoader extends URLClassLoader {
 
         return sourceCache.getAndPut(
                 cacheKey,
-                new EvictableCache.ValueProvider<String, Class>() {
-                    @Override
-                    public Class provide(String key) {
-                        return doParseClass(codeSource);
-                    }
-                },
+                key -> doParseClass(codeSource),
                 shouldCacheSource
         );
     }
@@ -666,11 +661,7 @@ public class GroovyClassLoader extends URLClassLoader {
      * @return the ClassCollector
      */
     protected ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
-        InnerLoader loader = AccessController.doPrivileged(new PrivilegedAction<InnerLoader>() {
-            public InnerLoader run() {
-                return new InnerLoader(GroovyClassLoader.this);
-            }
-        });
+        InnerLoader loader = AccessController.doPrivileged((PrivilegedAction<InnerLoader>) () -> new InnerLoader(GroovyClassLoader.this));
         return new ClassCollector(loader, unit, su);
     }
 
@@ -1098,42 +1089,40 @@ public class GroovyClassLoader extends URLClassLoader {
      * @see #addURL(URL)
      */
     public void addClasspath(final String path) {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            public Void run() {
+        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 
-                URI newURI;
-                try {
-                    newURI = new URI(path);
-                    // check if we can create a URL from that URI
-                    newURI.toURL();
-                } catch (URISyntaxException | IllegalArgumentException | MalformedURLException e) {
-                    // the URI has a false format, so lets try it with files ...
-                    newURI=new File(path).toURI();
-                }
+            URI newURI;
+            try {
+                newURI = new URI(path);
+                // check if we can create a URL from that URI
+                newURI.toURL();
+            } catch (URISyntaxException | IllegalArgumentException | MalformedURLException e) {
+                // the URI has a false format, so lets try it with files ...
+                newURI=new File(path).toURI();
+            }
 
-                URL[] urls = getURLs();
-                for (URL url : urls) {
-                    // Do not use URL.equals.  It uses the network to resolve names and compares ip addresses!
-                    // That is a violation of RFC and just plain evil.
-                    // http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html
-                    // http://docs.oracle.com/javase/7/docs/api/java/net/URL.html#equals(java.lang.Object)
-                    // "Since hosts comparison requires name resolution, this operation is a blocking operation.
-                    // Note: The defined behavior for equals is known to be inconsistent with virtual hosting in HTTP."
-                    try {
-                        if (newURI.equals(url.toURI())) return null;
-                    } catch (URISyntaxException e) {
-                        // fail fast! if we got a malformed URI the Classloader has to tell it
-                        throw new RuntimeException( e );
-                    }
-                }
+            URL[] urls = getURLs();
+            for (URL url : urls) {
+                // Do not use URL.equals.  It uses the network to resolve names and compares ip addresses!
+                // That is a violation of RFC and just plain evil.
+                // http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html
+                // http://docs.oracle.com/javase/7/docs/api/java/net/URL.html#equals(java.lang.Object)
+                // "Since hosts comparison requires name resolution, this operation is a blocking operation.
+                // Note: The defined behavior for equals is known to be inconsistent with virtual hosting in HTTP."
                 try {
-                    addURL(newURI.toURL());
-                } catch (MalformedURLException e) {
-                    // fail fast! if we got a malformed URL the Classloader has to tell it
+                    if (newURI.equals(url.toURI())) return null;
+                } catch (URISyntaxException e) {
+                    // fail fast! if we got a malformed URI the Classloader has to tell it
                     throw new RuntimeException( e );
                 }
-                return null;
             }
+            try {
+                addURL(newURI.toURL());
+            } catch (MalformedURLException e) {
+                // fail fast! if we got a malformed URL the Classloader has to tell it
+                throw new RuntimeException( e );
+            }
+            return null;
         });
     }
 
diff --git a/src/main/java/groovy/lang/GroovyCodeSource.java b/src/main/java/groovy/lang/GroovyCodeSource.java
index 6acd292..2cd6fa2 100644
--- a/src/main/java/groovy/lang/GroovyCodeSource.java
+++ b/src/main/java/groovy/lang/GroovyCodeSource.java
@@ -123,22 +123,20 @@ public class GroovyCodeSource {
         //The calls below require access to user.dir - allow here since getName() and getCodeSource() are
         //package private and used only by the GroovyClassLoader.
         try {
-            Object[] info = AccessController.doPrivileged(new PrivilegedExceptionAction<Object[]>() {
-                public Object[] run() throws IOException {
-                    // retrieve the content of the file using the provided encoding
-                    if (encoding != null) {
-                        scriptText = ResourceGroovyMethods.getText(infile, encoding);
-                    } else {
-                        scriptText = ResourceGroovyMethods.getText(infile);
-                    }
-
-                    Object[] info = new Object[2];
-                    URL url = file.toURI().toURL();
-                    info[0] = url.toExternalForm();
-                    //toURI().toURL() will encode, but toURL() will not.
-                    info[1] = new CodeSource(url, (Certificate[]) null);
-                    return info;
+            Object[] info = AccessController.doPrivileged((PrivilegedExceptionAction<Object[]>) () -> {
+                // retrieve the content of the file using the provided encoding
+                if (encoding != null) {
+                    scriptText = ResourceGroovyMethods.getText(infile, encoding);
+                } else {
+                    scriptText = ResourceGroovyMethods.getText(infile);
                 }
+
+                Object[] info1 = new Object[2];
+                URL url = file.toURI().toURL();
+                info1[0] = url.toExternalForm();
+                //toURI().toURL() will encode, but toURL() will not.
+                info1[1] = new CodeSource(url, (Certificate[]) null);
+                return info1;
             });
 
             this.name = (String) info[0];
diff --git a/src/main/java/groovy/lang/GroovyShell.java b/src/main/java/groovy/lang/GroovyShell.java
index 6f32a3c..3255fa1 100644
--- a/src/main/java/groovy/lang/GroovyShell.java
+++ b/src/main/java/groovy/lang/GroovyShell.java
@@ -100,11 +100,7 @@ public class GroovyShell extends GroovyObjectSupport {
             && ((GroovyClassLoader) parentLoader).hasCompatibleConfiguration(config)) {
           this.loader = (GroovyClassLoader) parentLoader;
         } else {
-          this.loader = AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
-              public GroovyClassLoader run() {
-                  return new GroovyClassLoader(parentLoader,config);
-              }
-          });
+          this.loader = AccessController.doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> new GroovyClassLoader(parentLoader,config));
         }
         this.context = binding;
         this.config = config;
@@ -212,11 +208,7 @@ public class GroovyShell extends GroovyObjectSupport {
         // if you are compiling the script because the JVM isn't executing the main method.
         Class scriptClass;
         try {
-            scriptClass = AccessController.doPrivileged(new PrivilegedExceptionAction<Class>() {
-                public Class run() throws CompilationFailedException, IOException {
-                    return loader.parseClass(scriptFile);
-                }
-            });
+            scriptClass = AccessController.doPrivileged((PrivilegedExceptionAction<Class>) () -> loader.parseClass(scriptFile));
         } catch (PrivilegedActionException pae) {
             Exception e = pae.getException();
             if (e instanceof CompilationFailedException) {
@@ -347,11 +339,7 @@ public class GroovyShell extends GroovyObjectSupport {
      * @param args       the command line arguments to pass in
      */
     public Object run(final String scriptText, final String fileName, String[] args) throws CompilationFailedException {
-        GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
-            public GroovyCodeSource run() {
-                return new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE);
-            }
-        });
+        GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE));
         return run(gcs, args);
     }
 
@@ -415,11 +403,7 @@ public class GroovyShell extends GroovyObjectSupport {
      * @param args     the command line arguments to pass in
      */
     public Object run(final Reader in, final String fileName, String[] args) throws CompilationFailedException {
-        GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
-                    public GroovyCodeSource run() {
-                        return new GroovyCodeSource(in, fileName, DEFAULT_CODE_BASE);
-                    }
-        });
+        GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(in, fileName, DEFAULT_CODE_BASE));
         Class scriptClass = parseClass(gcs);
         return runScriptOrMainOrTestOrRunnable(scriptClass, args);
     }
@@ -476,11 +460,7 @@ public class GroovyShell extends GroovyObjectSupport {
             sm.checkPermission(new GroovyCodeSourcePermission(codeBase));
         }
 
-        GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
-            public GroovyCodeSource run() {
-                return new GroovyCodeSource(scriptText, fileName, codeBase);
-            }
-        });
+        GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, codeBase));
 
         return evaluate(gcs);
     }
@@ -590,11 +570,7 @@ public class GroovyShell extends GroovyObjectSupport {
     }
 
     public Script parse(final String scriptText, final String fileName) throws CompilationFailedException {
-        GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
-            public GroovyCodeSource run() {
-                return new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE);
-            }
-        });
+        GroovyCodeSource gcs = AccessController.doPrivileged((PrivilegedAction<GroovyCodeSource>) () -> new GroovyCodeSource(scriptText, fileName, DEFAULT_CODE_BASE));
         return parse(gcs);
     }
 
diff --git a/src/main/java/groovy/lang/ProxyMetaClass.java b/src/main/java/groovy/lang/ProxyMetaClass.java
index 06c8d96..ed1d8dd 100644
--- a/src/main/java/groovy/lang/ProxyMetaClass.java
+++ b/src/main/java/groovy/lang/ProxyMetaClass.java
@@ -115,11 +115,7 @@ public class ProxyMetaClass extends MetaClassImpl implements AdaptingMetaClass {
      * See Interceptor for details.
      */
     public Object invokeMethod(final Object object, final String methodName, final Object[] arguments) {
-        return doCall(object, methodName, arguments, interceptor, new Callable() {
-            public Object call() {
-                return adaptee.invokeMethod(object, methodName, arguments);
-            }
-        });
+        return doCall(object, methodName, arguments, interceptor, () -> adaptee.invokeMethod(object, methodName, arguments));
     }
 
     /**
@@ -130,11 +126,7 @@ public class ProxyMetaClass extends MetaClassImpl implements AdaptingMetaClass {
      */
     @Override
     public Object invokeMethod(final Class sender, final Object object, final String methodName, final Object[] arguments, final boolean isCallToSuper, final boolean fromInsideClass) {
-        return doCall(object, methodName, arguments, interceptor, new Callable() {
-            public Object call() {
-                return adaptee.invokeMethod(sender, object, methodName, arguments, isCallToSuper, fromInsideClass);
-            }
-        });
+        return doCall(object, methodName, arguments, interceptor, () -> adaptee.invokeMethod(sender, object, methodName, arguments, isCallToSuper, fromInsideClass));
     }
 
     /**
@@ -144,11 +136,7 @@ public class ProxyMetaClass extends MetaClassImpl implements AdaptingMetaClass {
      * See Interceptor for details.
      */
     public Object invokeStaticMethod(final Object object, final String methodName, final Object[] arguments) {
-        return doCall(object, methodName, arguments, interceptor, new Callable() {
-            public Object call() {
-                return adaptee.invokeStaticMethod(object, methodName, arguments);
-            }
-        });
+        return doCall(object, methodName, arguments, interceptor, () -> adaptee.invokeStaticMethod(object, methodName, arguments));
     }
 
     /**
@@ -158,11 +146,7 @@ public class ProxyMetaClass extends MetaClassImpl implements AdaptingMetaClass {
      * See Interceptor for details.
      */
     public Object invokeConstructor(final Object[] arguments) {
-        return doCall(theClass, "ctor", arguments, interceptor, new Callable() {
-            public Object call() {
-                return adaptee.invokeConstructor(arguments);
-            }
-        });
+        return doCall(theClass, "ctor", arguments, interceptor, () -> adaptee.invokeConstructor(arguments));
     }
 
     /**
diff --git a/src/main/java/groovy/util/FactoryBuilderSupport.java b/src/main/java/groovy/util/FactoryBuilderSupport.java
index 7316433..aeffa68 100644
--- a/src/main/java/groovy/util/FactoryBuilderSupport.java
+++ b/src/main/java/groovy/util/FactoryBuilderSupport.java
@@ -71,13 +71,11 @@ public abstract class FactoryBuilderSupport extends Binding {
     public static final String CHILD_BUILDER = "_CHILD_BUILDER_";
     public static final String SCRIPT_CLASS_NAME = "_SCRIPT_CLASS_NAME_";
     private static final Logger LOG = Logger.getLogger(FactoryBuilderSupport.class.getName());
-    private static final Comparator<Method> METHOD_COMPARATOR = new Comparator<Method>() {
-        public int compare(final Method o1, final Method o2) {
-            int cmp = o1.getName().compareTo(o2.getName());
-            if (cmp != 0) return cmp;
-            cmp = o1.getParameterTypes().length - o2.getParameterTypes().length;
-            return cmp;
-        }
+    private static final Comparator<Method> METHOD_COMPARATOR = (o1, o2) -> {
+        int cmp = o1.getName().compareTo(o2.getName());
+        if (cmp != 0) return cmp;
+        cmp = o1.getParameterTypes().length - o2.getParameterTypes().length;
+        return cmp;
     };
 
     /**
diff --git a/src/main/java/groovy/util/GroovyScriptEngine.java b/src/main/java/groovy/util/GroovyScriptEngine.java
index eede5cb..fa813a6 100644
--- a/src/main/java/groovy/util/GroovyScriptEngine.java
+++ b/src/main/java/groovy/util/GroovyScriptEngine.java
@@ -61,11 +61,7 @@ import java.util.concurrent.ConcurrentHashMap;
  * with dependent scripts.
  */
 public class GroovyScriptEngine implements ResourceConnector {
-    private static final ClassLoader CL_STUB = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
-        public ClassLoader run() {
-            return new ClassLoader() {};
-        }
-    });
+    private static final ClassLoader CL_STUB = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> new ClassLoader() {});
 
     private static final URL[] EMPTY_URL_ARRAY = new URL[0];
 
@@ -133,20 +129,18 @@ public class GroovyScriptEngine implements ResourceConnector {
 
         private void setResLoader() {
             final GroovyResourceLoader rl = getResourceLoader();
-            setResourceLoader(new GroovyResourceLoader() {
-                public URL loadGroovySource(String className) throws MalformedURLException {
-                    String filename;
-                    for (String extension : getConfig().getScriptExtensions()) {
-                        filename = className.replace('.', File.separatorChar) + "." + extension;
-                        try {
-                            URLConnection dependentScriptConn = rc.getResourceConnection(filename);
-                            return dependentScriptConn.getURL();
-                        } catch (ResourceException e) {
-                            //TODO: maybe do something here?
-                        }
+            setResourceLoader(className -> {
+                String filename;
+                for (String extension : getConfig().getScriptExtensions()) {
+                    filename = className.replace('.', File.separatorChar) + "." + extension;
+                    try {
+                        URLConnection dependentScriptConn = rc.getResourceConnection(filename);
+                        return dependentScriptConn.getURL();
+                    } catch (ResourceException e) {
+                        //TODO: maybe do something here?
                     }
-                    return rl.loadGroovySource(className);
                 }
+                return rl.loadGroovySource(className);
             });
         }
 
@@ -349,13 +343,11 @@ public class GroovyScriptEngine implements ResourceConnector {
      */
     private GroovyClassLoader initGroovyLoader() {
         GroovyClassLoader groovyClassLoader =
-                AccessController.doPrivileged(new PrivilegedAction<ScriptClassLoader>() {
-                    public ScriptClassLoader run() {
-                        if (parentLoader instanceof GroovyClassLoader) {
-                            return new ScriptClassLoader((GroovyClassLoader) parentLoader);
-                        } else {
-                            return new ScriptClassLoader(parentLoader, config);
-                        }
+                AccessController.doPrivileged((PrivilegedAction<ScriptClassLoader>) () -> {
+                    if (parentLoader instanceof GroovyClassLoader) {
+                        return new ScriptClassLoader((GroovyClassLoader) parentLoader);
+                    } else {
+                        return new ScriptClassLoader(parentLoader, config);
                     }
                 });
         for (URL root : roots) groovyClassLoader.addURL(root);
diff --git a/src/main/java/groovy/util/ObjectGraphBuilder.java b/src/main/java/groovy/util/ObjectGraphBuilder.java
index b6b6b48..5a10b26 100644
--- a/src/main/java/groovy/util/ObjectGraphBuilder.java
+++ b/src/main/java/groovy/util/ObjectGraphBuilder.java
@@ -152,13 +152,10 @@ public class ObjectGraphBuilder extends FactoryBuilderSupport {
             this.childPropertySetter = (ChildPropertySetter) childPropertySetter;
         } else if (childPropertySetter instanceof Closure) {
             final ObjectGraphBuilder self = this;
-            this.childPropertySetter = new ChildPropertySetter() {
-                public void setChild(Object parent, Object child, String parentName,
-                                     String propertyName) {
-                    Closure cls = (Closure) childPropertySetter;
-                    cls.setDelegate(self);
-                    cls.call(parent, child, parentName, propertyName);
-                }
+            this.childPropertySetter = (parent, child, parentName, propertyName) -> {
+                Closure cls = (Closure) childPropertySetter;
+                cls.setDelegate(self);
+                cls.call(parent, child, parentName, propertyName);
             };
         } else {
             this.childPropertySetter = new DefaultChildPropertySetter();
@@ -181,19 +178,13 @@ public class ObjectGraphBuilder extends FactoryBuilderSupport {
         if (classNameResolver instanceof ClassNameResolver) {
             this.classNameResolver = (ClassNameResolver) classNameResolver;
         } else if (classNameResolver instanceof String) {
-            this.classNameResolver = new ClassNameResolver() {
-                public String resolveClassname(String classname) {
-                    return makeClassName((String) classNameResolver, classname);
-                }
-            };
+            this.classNameResolver = classname -> makeClassName((String) classNameResolver, classname);
         } else if (classNameResolver instanceof Closure) {
             final ObjectGraphBuilder self = this;
-            this.classNameResolver = new ClassNameResolver() {
-                public String resolveClassname(String classname) {
-                    Closure cls = (Closure) classNameResolver;
-                    cls.setDelegate(self);
-                    return (String) cls.call(new Object[]{classname});
-                }
+            this.classNameResolver = classname -> {
+                Closure cls = (Closure) classNameResolver;
+                cls.setDelegate(self);
+                return (String) cls.call(new Object[]{classname});
             };
         } else if (classNameResolver instanceof Map) {
             Map classNameResolverOptions = (Map) classNameResolver;
@@ -229,19 +220,13 @@ public class ObjectGraphBuilder extends FactoryBuilderSupport {
         if (identifierResolver instanceof IdentifierResolver) {
             this.identifierResolver = (IdentifierResolver) identifierResolver;
         } else if (identifierResolver instanceof String) {
-            this.identifierResolver = new IdentifierResolver() {
-                public String getIdentifierFor(String nodeName) {
-                    return (String) identifierResolver;
-                }
-            };
+            this.identifierResolver = nodeName -> (String) identifierResolver;
         } else if (identifierResolver instanceof Closure) {
             final ObjectGraphBuilder self = this;
-            this.identifierResolver = new IdentifierResolver() {
-                public String getIdentifierFor(String nodeName) {
-                    Closure cls = (Closure) identifierResolver;
-                    cls.setDelegate(self);
-                    return (String) cls.call(new Object[]{nodeName});
-                }
+            this.identifierResolver = nodeName -> {
+                Closure cls = (Closure) identifierResolver;
+                cls.setDelegate(self);
+                return (String) cls.call(new Object[]{nodeName});
             };
         } else {
             this.identifierResolver = new DefaultIdentifierResolver();
@@ -265,13 +250,10 @@ public class ObjectGraphBuilder extends FactoryBuilderSupport {
             this.newInstanceResolver = (NewInstanceResolver) newInstanceResolver;
         } else if (newInstanceResolver instanceof Closure) {
             final ObjectGraphBuilder self = this;
-            this.newInstanceResolver = new NewInstanceResolver() {
-                public Object newInstance(Class klass, Map attributes)
-                        throws InstantiationException, IllegalAccessException {
-                    Closure cls = (Closure) newInstanceResolver;
-                    cls.setDelegate(self);
-                    return cls.call(klass, attributes);
-                }
+            this.newInstanceResolver = (klass, attributes) -> {
+                Closure cls = (Closure) newInstanceResolver;
+                cls.setDelegate(self);
+                return cls.call(klass, attributes);
             };
         } else {
             this.newInstanceResolver = new DefaultNewInstanceResolver();
@@ -287,19 +269,13 @@ public class ObjectGraphBuilder extends FactoryBuilderSupport {
         if (referenceResolver instanceof ReferenceResolver) {
             this.referenceResolver = (ReferenceResolver) referenceResolver;
         } else if (referenceResolver instanceof String) {
-            this.referenceResolver = new ReferenceResolver() {
-                public String getReferenceFor(String nodeName) {
-                    return (String) referenceResolver;
-                }
-            };
+            this.referenceResolver = nodeName -> (String) referenceResolver;
         } else if (referenceResolver instanceof Closure) {
             final ObjectGraphBuilder self = this;
-            this.referenceResolver = new ReferenceResolver() {
-                public String getReferenceFor(String nodeName) {
-                    Closure cls = (Closure) referenceResolver;
-                    cls.setDelegate(self);
-                    return (String) cls.call(new Object[]{nodeName});
-                }
+            this.referenceResolver = nodeName -> {
+                Closure cls = (Closure) referenceResolver;
+                cls.setDelegate(self);
+                return (String) cls.call(new Object[]{nodeName});
             };
         } else {
             this.referenceResolver = new DefaultReferenceResolver();
diff --git a/src/main/java/groovy/util/ProxyGenerator.java b/src/main/java/groovy/util/ProxyGenerator.java
index 3fd5ff2..06d6a2a 100644
--- a/src/main/java/groovy/util/ProxyGenerator.java
+++ b/src/main/java/groovy/util/ProxyGenerator.java
@@ -247,14 +247,12 @@ public class ProxyGenerator {
     }
     
     private static final class CacheKey {
-        private static final Comparator<Class> INTERFACE_COMPARATOR = new Comparator<Class>() {
-            public int compare(final Class o1, final Class o2) {
-                // Traits order *must* be preserved
-                // See GROOVY-7285
-                if (Traits.isTrait(o1)) return -1;
-                if (Traits.isTrait(o2)) return 1;
-                return o1.getName().compareTo(o2.getName());
-            }
+        private static final Comparator<Class> INTERFACE_COMPARATOR = (o1, o2) -> {
+            // Traits order *must* be preserved
+            // See GROOVY-7285
+            if (Traits.isTrait(o1)) return -1;
+            if (Traits.isTrait(o2)) return 1;
+            return o1.getName().compareTo(o2.getName());
         };
         private final boolean emptyMethods;
         private final boolean useDelegate;
diff --git a/src/main/java/org/apache/groovy/internal/util/ReevaluatingReference.java b/src/main/java/org/apache/groovy/internal/util/ReevaluatingReference.java
index feeeea8..255e97b 100644
--- a/src/main/java/org/apache/groovy/internal/util/ReevaluatingReference.java
+++ b/src/main/java/org/apache/groovy/internal/util/ReevaluatingReference.java
@@ -41,15 +41,10 @@ public class ReevaluatingReference<T> {
     static {
         try {
             //TODO Jochen: move the findSpecial to a central place together with others to easy security configuration
-            FALLBACK_HANDLE = AccessController.doPrivileged(new PrivilegedExceptionAction<MethodHandle>() {
-                @Override
-                public MethodHandle run() throws Exception {
-                    return  MethodHandles.lookup().findSpecial(
-                            ReevaluatingReference.class, "replacePayLoad",
-                            MethodType.methodType(Object.class),
-                            ReevaluatingReference.class);
-                }
-            });
+            FALLBACK_HANDLE = AccessController.doPrivileged((PrivilegedExceptionAction<MethodHandle>) () -> MethodHandles.lookup().findSpecial(
+                    ReevaluatingReference.class, "replacePayLoad",
+                    MethodType.methodType(Object.class),
+                    ReevaluatingReference.class));
         } catch (PrivilegedActionException e) {
             throw new GroovyBugError(e);
         }
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
index 374239c..85cdd76 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
@@ -89,18 +89,16 @@ public class WideningCategories {
      * since a concrete implementation should be used at compile time, we must ensure that interfaces are
      * always sorted. It is not important what sort is used, as long as the result is constant.
      */
-    private static final Comparator<ClassNode> INTERFACE_CLASSNODE_COMPARATOR = new Comparator<ClassNode>() {
-        public int compare(final ClassNode o1, final ClassNode o2) {
-            int interfaceCountForO1 = o1.getInterfaces().length;
-            int interfaceCountForO2 = o2.getInterfaces().length;
-            if (interfaceCountForO1 > interfaceCountForO2) return -1;
-            if (interfaceCountForO1 < interfaceCountForO2) return 1;
-            int methodCountForO1 = o1.getMethods().size();
-            int methodCountForO2 = o2.getMethods().size();
-            if (methodCountForO1 > methodCountForO2) return -1;
-            if (methodCountForO1 < methodCountForO2) return 1;
-            return o1.getName().compareTo(o2.getName());
-        }
+    private static final Comparator<ClassNode> INTERFACE_CLASSNODE_COMPARATOR = (o1, o2) -> {
+        int interfaceCountForO1 = o1.getInterfaces().length;
+        int interfaceCountForO2 = o2.getInterfaces().length;
+        if (interfaceCountForO1 > interfaceCountForO2) return -1;
+        if (interfaceCountForO1 < interfaceCountForO2) return 1;
+        int methodCountForO1 = o1.getMethods().size();
+        int methodCountForO2 = o2.getMethods().size();
+        if (methodCountForO1 > methodCountForO2) return -1;
+        if (methodCountForO1 < methodCountForO2) return 1;
+        return o1.getName().compareTo(o2.getName());
     };
 
     /**
@@ -592,12 +590,10 @@ public class WideningCategories {
      *
      */
     public static class LowestUpperBoundClassNode extends ClassNode {
-        private static final Comparator<ClassNode> CLASS_NODE_COMPARATOR = new Comparator<ClassNode>() {
-            public int compare(final ClassNode o1, final ClassNode o2) {
-                String n1 = o1 instanceof LowestUpperBoundClassNode?((LowestUpperBoundClassNode)o1).name:o1.getName();
-                String n2 = o2 instanceof LowestUpperBoundClassNode?((LowestUpperBoundClassNode)o2).name:o2.getName();
-                return n1.compareTo(n2);
-            }
+        private static final Comparator<ClassNode> CLASS_NODE_COMPARATOR = (o1, o2) -> {
+            String n1 = o1 instanceof LowestUpperBoundClassNode?((LowestUpperBoundClassNode)o1).name:o1.getName();
+            String n2 = o2 instanceof LowestUpperBoundClassNode?((LowestUpperBoundClassNode)o2).name:o2.getName();
+            return n1.compareTo(n2);
         };
         private final ClassNode compileTimeClassNode;
         private final String name;
diff --git a/src/main/java/org/codehaus/groovy/classgen/ReturnAdder.java b/src/main/java/org/codehaus/groovy/classgen/ReturnAdder.java
index 22f3059..110cb99 100644
--- a/src/main/java/org/codehaus/groovy/classgen/ReturnAdder.java
+++ b/src/main/java/org/codehaus/groovy/classgen/ReturnAdder.java
@@ -46,9 +46,7 @@ import java.util.List;
  */
 public class ReturnAdder {
 
-    private static final ReturnStatementListener DEFAULT_LISTENER = new ReturnStatementListener() {
-        public void returnStatementAdded(final ReturnStatement returnStatement) {
-        }
+    private static final ReturnStatementListener DEFAULT_LISTENER = returnStatement -> {
     };
 
     /**
@@ -165,12 +163,7 @@ public class ReturnAdder {
         if (statement instanceof TryCatchStatement) {
             TryCatchStatement trys = (TryCatchStatement) statement;
             final boolean[] missesReturn = new boolean[1];
-            new ReturnAdder(new ReturnStatementListener() {
-                @Override
-                public void returnStatementAdded(ReturnStatement returnStatement) {
-                    missesReturn[0] = true;
-                }
-            }).addReturnsIfNeeded(trys.getFinallyStatement(), scope);
+            new ReturnAdder(returnStatement -> missesReturn[0] = true).addReturnsIfNeeded(trys.getFinallyStatement(), scope);
             boolean hasFinally = !(trys.getFinallyStatement() instanceof EmptyStatement);
 
             // if there is no missing return in the finally block and the block exists
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
index 3287481..c4a40ad 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/InvocationWriter.java
@@ -718,14 +718,12 @@ public class InvocationWriter {
     private static List<ConstructorNode> sortConstructors(ConstructorCallExpression call, ClassNode callNode) {
         // sort in a new list to prevent side effects
         List<ConstructorNode> constructors = new ArrayList<ConstructorNode>(callNode.getDeclaredConstructors());
-        Comparator comp = new Comparator() {
-            public int compare(Object arg0, Object arg1) {
-                ConstructorNode c0 = (ConstructorNode) arg0;
-                ConstructorNode c1 = (ConstructorNode) arg1;
-                String descriptor0 = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, c0.getParameters());
-                String descriptor1 = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, c1.getParameters());
-                return descriptor0.compareTo(descriptor1);
-            }
+        Comparator comp = (arg0, arg1) -> {
+            ConstructorNode c0 = (ConstructorNode) arg0;
+            ConstructorNode c1 = (ConstructorNode) arg1;
+            String descriptor0 = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, c0.getParameters());
+            String descriptor1 = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, c1.getParameters());
+            return descriptor0.compareTo(descriptor1);
         };
         Collections.sort(constructors, comp);
         return constructors;
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java
index 3a1f712..ad37efb 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java
@@ -437,13 +437,10 @@ public class StatementWriter {
 
     private BlockRecorder makeBlockRecorder(Statement finallyStatement) {
         final BlockRecorder block = new BlockRecorder();
-        block.excludedStatement = new Runnable() {
-            @Override
-            public void run() {
-                controller.getCompileStack().pushBlockRecorderVisit(block);
-                finallyStatement.visit(controller.getAcg());
-                controller.getCompileStack().popBlockRecorderVisit(block);
-            }
+        block.excludedStatement = () -> {
+            controller.getCompileStack().pushBlockRecorderVisit(block);
+            finallyStatement.visit(controller.getAcg());
+            controller.getCompileStack().popBlockRecorderVisit(block);
         };
         controller.getCompileStack().pushBlockRecorder(block);
         return block;
@@ -553,12 +550,9 @@ public class StatementWriter {
         // if there is only a break/continue.
         mv.visitInsn(NOP);
 
-        Runnable finallyPart = new Runnable() {
-            @Override
-            public void run() {
-                mv.visitVarInsn(ALOAD, index);
-                mv.visitInsn(MONITOREXIT);
-            }
+        Runnable finallyPart = () -> {
+            mv.visitVarInsn(ALOAD, index);
+            mv.visitInsn(MONITOREXIT);
         };
         BlockRecorder fb = new BlockRecorder(finallyPart);
         fb.startRange(synchronizedStart);
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticCompilationMopWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticCompilationMopWriter.java
index c30040d..781ebe1 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticCompilationMopWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticCompilationMopWriter.java
@@ -35,12 +35,7 @@ import java.util.LinkedList;
  */
 public class StaticCompilationMopWriter extends MopWriter {
 
-    public static final MopWriter.Factory FACTORY = new MopWriter.Factory() {
-        @Override
-        public MopWriter create(final WriterController controller) {
-            return new StaticCompilationMopWriter(controller);
-        }
-    };
+    public static final MopWriter.Factory FACTORY = controller -> new StaticCompilationMopWriter(controller);
 
     private final StaticTypesWriterController controller;
 
diff --git a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
index a16c826..83146cf 100644
--- a/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/ProcessingUnit.java
@@ -98,12 +98,10 @@ public abstract class ProcessingUnit {
     public void setClassLoader(final GroovyClassLoader loader) {
         // ClassLoaders should only be created inside a doPrivileged block in case
         // this method is invoked by code that does not have security permissions.
-        this.classLoader = loader != null ? loader : AccessController.doPrivileged(new PrivilegedAction<GroovyClassLoader>() {
-            public GroovyClassLoader run() {
-                ClassLoader parent = Thread.currentThread().getContextClassLoader();
-                if (parent == null) parent = ProcessingUnit.class.getClassLoader();
-                return new GroovyClassLoader(parent, getConfiguration());
-            }
+        this.classLoader = loader != null ? loader : AccessController.doPrivileged((PrivilegedAction<GroovyClassLoader>) () -> {
+            ClassLoader parent = Thread.currentThread().getContextClassLoader();
+            if (parent == null) parent = ProcessingUnit.class.getClassLoader();
+            return new GroovyClassLoader(parent, getConfiguration());
         });
     }
 
diff --git a/src/main/java/org/codehaus/groovy/control/SourceUnit.java b/src/main/java/org/codehaus/groovy/control/SourceUnit.java
index 5188611..561f42d 100644
--- a/src/main/java/org/codehaus/groovy/control/SourceUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/SourceUnit.java
@@ -256,11 +256,7 @@ public class SourceUnit extends ProcessingUnit {
             getErrorCollector().addError(new SyntaxErrorMessage(e, this));
         }
 
-        String property = (String) AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                return System.getProperty("groovy.ast");
-            }
-        });
+        String property = (String) AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("groovy.ast"));
 
         if ("xml".equals(property)) {
             saveAsXML(name, ast);
diff --git a/src/main/java/org/codehaus/groovy/reflection/SunClassLoader.java b/src/main/java/org/codehaus/groovy/reflection/SunClassLoader.java
index 0a6a082..6914585 100644
--- a/src/main/java/org/codehaus/groovy/reflection/SunClassLoader.java
+++ b/src/main/java/org/codehaus/groovy/reflection/SunClassLoader.java
@@ -41,13 +41,11 @@ public class SunClassLoader extends ClassLoader implements Opcodes {
     static {
         SunClassLoader res;
         try {
-            res = AccessController.doPrivileged(new PrivilegedAction<SunClassLoader>() {
-                public SunClassLoader run() {
-                    try {
-                        return new SunClassLoader();
-                    } catch (Throwable e) {
-                        return null;
-                    }
+            res = AccessController.doPrivileged((PrivilegedAction<SunClassLoader>) () -> {
+                try {
+                    return new SunClassLoader();
+                } catch (Throwable e) {
+                    return null;
                 }
             });
         }
diff --git a/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
index 7348d3f..fc82dc9 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
@@ -348,13 +348,11 @@ public class ProcessGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.2
      */
     public static void withWriter(final Process self, final Closure closure) {
-        new Thread(new Runnable() {
-            public void run() {
-                try {
-                    IOGroovyMethods.withWriter(new BufferedOutputStream(getOut(self)), closure);
-                } catch (IOException e) {
-                    throw new GroovyRuntimeException("exception while reading process stream", e);
-                }
+        new Thread(() -> {
+            try {
+                IOGroovyMethods.withWriter(new BufferedOutputStream(getOut(self)), closure);
+            } catch (IOException e) {
+                throw new GroovyRuntimeException("exception while reading process stream", e);
             }
         }).start();
     }
@@ -370,13 +368,11 @@ public class ProcessGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.2
      */
     public static void withOutputStream(final Process self, final Closure closure) {
-        new Thread(new Runnable() {
-            public void run() {
-                try {
-                    IOGroovyMethods.withStream(new BufferedOutputStream(getOut(self)), closure);
-                } catch (IOException e) {
-                    throw new GroovyRuntimeException("exception while reading process stream", e);
-                }
+        new Thread(() -> {
+            try {
+                IOGroovyMethods.withStream(new BufferedOutputStream(getOut(self)), closure);
+            } catch (IOException e) {
+                throw new GroovyRuntimeException("exception while reading process stream", e);
             }
         }).start();
     }
@@ -391,22 +387,20 @@ public class ProcessGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.5.2
      */
     public static Process pipeTo(final Process left, final Process right) throws IOException {
-        new Thread(new Runnable() {
-            public void run() {
-                InputStream in = new BufferedInputStream(getIn(left));
-                OutputStream out = new BufferedOutputStream(getOut(right));
-                byte[] buf = new byte[8192];
-                int next;
-                try {
-                    while ((next = in.read(buf)) != -1) {
-                        out.write(buf, 0, next);
-                    }
-                } catch (IOException e) {
-                    throw new GroovyRuntimeException("exception while reading process stream", e);
-                } finally {
-                    closeWithWarning(out);
-                    closeWithWarning(in);
+        new Thread(() -> {
+            InputStream in = new BufferedInputStream(getIn(left));
+            OutputStream out = new BufferedOutputStream(getOut(right));
+            byte[] buf = new byte[8192];
+            int next;
+            try {
+                while ((next = in.read(buf)) != -1) {
+                    out.write(buf, 0, next);
                 }
+            } catch (IOException e) {
+                throw new GroovyRuntimeException("exception while reading process stream", e);
+            } finally {
+                closeWithWarning(out);
+                closeWithWarning(in);
             }
         }).start();
         return right;
diff --git a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
index 8f688cb..23c4017 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
@@ -252,11 +252,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes {
     }
 
     private static InnerLoader createInnerLoader(final ClassLoader parent, final Class[] interfaces) {
-        return AccessController.doPrivileged(new PrivilegedAction<InnerLoader>() {
-            public InnerLoader run() {
-                return new InnerLoader(parent, interfaces);
-            }
-        });
+        return AccessController.doPrivileged((PrivilegedAction<InnerLoader>) () -> new InnerLoader(parent, interfaces));
     }
 
     private InnerLoader findClassLoader(Class clazz, Class[] interfaces) {
diff --git a/src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java
index ded99e5..38a9053 100644
--- a/src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/SocketGroovyMethods.java
@@ -178,11 +178,7 @@ public class SocketGroovyMethods extends DefaultGroovyMethodsSupport {
                                 @ClosureParams(value=SimpleType.class, options="java.net.Socket") final Closure closure) throws IOException {
         final Socket socket = serverSocket.accept();
         if (runInANewThread) {
-            new Thread(new Runnable() {
-                public void run() {
-                    invokeClosureWithSocket(socket, closure);
-                }
-            }).start();
+            new Thread(() -> invokeClosureWithSocket(socket, closure)).start();
         } else {
             invokeClosureWithSocket(socket, closure);
         }
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/GroovySunClassLoader.java b/src/main/java/org/codehaus/groovy/runtime/callsite/GroovySunClassLoader.java
index 71fd21e..1462825 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/GroovySunClassLoader.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/GroovySunClassLoader.java
@@ -33,17 +33,15 @@ public class GroovySunClassLoader extends SunClassLoader {
     public static final SunClassLoader sunVM;
 
     static {
-            sunVM = AccessController.doPrivileged(new PrivilegedAction<SunClassLoader>() {
-                public SunClassLoader run() {
-                    try {
-                        if (SunClassLoader.sunVM != null) {
-                            return new GroovySunClassLoader();
-                        }
+            sunVM = AccessController.doPrivileged((PrivilegedAction<SunClassLoader>) () -> {
+                try {
+                    if (SunClassLoader.sunVM != null) {
+                        return new GroovySunClassLoader();
                     }
-                    catch (Throwable t) {//
-                    }
-                    return null;
                 }
+                catch (Throwable t) {//
+                }
+                return null;
             });
     }
 
diff --git a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
index 5495b9a..ec9fe1b 100644
--- a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
+++ b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
@@ -135,25 +135,23 @@ public class MetaClassRegistryImpl implements MetaClassRegistry{
         ClassInfo.getClassInfo(ExpandoMetaClass.class).setStrongMetaClass(emcMetaClass);
 
 
-        addNonRemovableMetaClassRegistryChangeEventListener(new MetaClassRegistryChangeEventListener(){
-            public void updateConstantMetaClass(MetaClassRegistryChangeEvent cmcu) {
-                // The calls to DefaultMetaClassInfo.setPrimitiveMeta and sdyn.setBoolean need to be
-                // ordered. Even though metaClassInfo is thread-safe, it is included in the block
-                // so the meta classes are added to the queue in the same order.
-                synchronized (metaClassInfo) {
-                   metaClassInfo.add(cmcu.getNewMetaClass());
-                   DefaultMetaClassInfo.getNewConstantMetaClassVersioning();
-                   Class c = cmcu.getClassToUpdate();
-                   DefaultMetaClassInfo.setPrimitiveMeta(c, cmcu.getNewMetaClass()==null);
-                   Field sdyn;
-                   try {
-                       sdyn = c.getDeclaredField(Verifier.STATIC_METACLASS_BOOL);
-                       sdyn.setBoolean(null, cmcu.getNewMetaClass()!=null);
-                   } catch (Throwable e) {
-                       //DO NOTHING
-                   }
+        addNonRemovableMetaClassRegistryChangeEventListener(cmcu -> {
+            // The calls to DefaultMetaClassInfo.setPrimitiveMeta and sdyn.setBoolean need to be
+            // ordered. Even though metaClassInfo is thread-safe, it is included in the block
+            // so the meta classes are added to the queue in the same order.
+            synchronized (metaClassInfo) {
+               metaClassInfo.add(cmcu.getNewMetaClass());
+               DefaultMetaClassInfo.getNewConstantMetaClassVersioning();
+               Class c = cmcu.getClassToUpdate();
+               DefaultMetaClassInfo.setPrimitiveMeta(c, cmcu.getNewMetaClass()==null);
+               Field sdyn;
+               try {
+                   sdyn = c.getDeclaredField(Verifier.STATIC_METACLASS_BOOL);
+                   sdyn.setBoolean(null, cmcu.getNewMetaClass()!=null);
+               } catch (Throwable e) {
+                   //DO NOTHING
+               }
 
-                }
             }
         });
    }
diff --git a/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java b/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java
index 08f8f1c..c745510 100644
--- a/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java
+++ b/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java
@@ -94,11 +94,7 @@ public class GroovyStarter {
             }
         }
         // create loader and execute main class
-        ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<RootLoader>() {
-            public RootLoader run() {
-                return new RootLoader(lc);
-            }
-        });
+        ClassLoader loader = AccessController.doPrivileged((PrivilegedAction<RootLoader>) () -> new RootLoader(lc));
         Method m=null;
         try {
             Class c = loader.loadClass(lc.getMainClass());
diff --git a/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java
index e45772c..7acd487 100644
--- a/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/SortableASTTransformation.java
@@ -236,11 +236,7 @@ public class SortableASTTransformation extends AbstractASTTransformation {
             checkComparable(pNode);
         }
         if (includes != null) {
-            Comparator<PropertyNode> includeComparator = new Comparator<PropertyNode>() {
-                public int compare(PropertyNode o1, PropertyNode o2) {
-                    return Integer.compare(includes.indexOf(o1.getName()), includes.indexOf(o2.getName()));
-                }
-            };
+            Comparator<PropertyNode> includeComparator = (o1, o2) -> Integer.compare(includes.indexOf(o1.getName()), includes.indexOf(o2.getName()));
             Collections.sort(properties, includeComparator);
         }
         return properties;
diff --git a/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java
index eff7aa6..7de6e13 100644
--- a/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/ToStringASTTransformation.java
@@ -218,11 +218,7 @@ public class ToStringASTTransformation extends AbstractASTTransformation {
         }
 
         if (includes != null) {
-            Comparator<ToStringElement> includeComparator = new Comparator<ToStringElement>() {
-                public int compare(ToStringElement tse1, ToStringElement tse2) {
-                    return Integer.compare(includes.indexOf(tse1.name), includes.indexOf(tse2.name));
-                }
-            };
+            Comparator<ToStringElement> includeComparator = (tse1, tse2) -> Integer.compare(includes.indexOf(tse1.name), includes.indexOf(tse2.name));
             Collections.sort(elements, includeComparator);
         }
 
diff --git a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
index 65cd26d..def9095 100644
--- a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
@@ -248,11 +248,7 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation
         }
 
         if (includes != null) {
-            Comparator<Parameter> includeComparator = new Comparator<Parameter>() {
-                public int compare(Parameter p1, Parameter p2) {
-                    return Integer.compare(includes.indexOf(p1.getName()), includes.indexOf(p2.getName()));
-                }
-            };
+            Comparator<Parameter> includeComparator = (p1, p2) -> Integer.compare(includes.indexOf(p1.getName()), includes.indexOf(p2.getName()));
             Collections.sort(params, includeComparator);
         }
 
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
index 6057476..3cbfad3 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
@@ -19,8 +19,6 @@
 package org.codehaus.groovy.vmplugin.v7;
 
 import groovy.lang.GroovySystem;
-import groovy.lang.MetaClassRegistryChangeEvent;
-import groovy.lang.MetaClassRegistryChangeEventListener;
 import org.codehaus.groovy.GroovyBugError;
 
 import java.lang.invoke.CallSite;
@@ -104,11 +102,7 @@ public class IndyInterface {
 
         protected static SwitchPoint switchPoint = new SwitchPoint();
         static {
-            GroovySystem.getMetaClassRegistry().addMetaClassRegistryChangeEventListener(new MetaClassRegistryChangeEventListener() {
-                public void updateConstantMetaClass(MetaClassRegistryChangeEvent cmcu) {
-                	invalidateSwitchPoints();
-                }
-            });
+            GroovySystem.getMetaClassRegistry().addMetaClassRegistryChangeEventListener(cmcu -> invalidateSwitchPoints());
         }
 
         /**
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/Java7.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/Java7.java
index 071e71e..bc93bbd 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/Java7.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/Java7.java
@@ -47,12 +47,9 @@ public class Java7 extends Java6 {
             try {
                 if (!con.isAccessible()) {
                     final Constructor tmp = con;
-                    AccessController.doPrivileged(new PrivilegedAction<Object>() {
-                        @Override
-                        public Object run() {
-                            ReflectionUtils.trySetAccessible(tmp);
-                            return null;
-                        }
+                    AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
+                        ReflectionUtils.trySetAccessible(tmp);
+                        return null;
                     });
                 }
             } catch (SecurityException se) {
@@ -86,12 +83,9 @@ public class Java7 extends Java6 {
             return super.getInvokeSpecialHandle(method, receiver);
         }
         if (!method.isAccessible()) {
-            AccessController.doPrivileged(new PrivilegedAction<Object>() {
-                @Override
-                public Object run() {
-                    ReflectionUtils.trySetAccessible(method);
-                    return null;
-                }
+            AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
+                ReflectionUtils.trySetAccessible(method);
+                return null;
             });
         }
         Class declaringClass = method.getDeclaringClass();


Mime
View raw message