groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 02/02: Minor refactoring: Convert `ClassgenCallback` to functional interface
Date Mon, 26 Aug 2019 05:50:21 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 5a7fa7357bf587c317825df0de907e0d512e8b5d
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Sat Aug 24 01:53:39 2019 +0800

    Minor refactoring: Convert `ClassgenCallback` to functional interface
---
 src/main/java/groovy/lang/GroovyClassLoader.java               | 2 +-
 src/main/java/groovy/lang/MetaClassImpl.java                   | 9 +++------
 src/main/java/org/codehaus/groovy/control/CompilationUnit.java | 6 +++---
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java b/src/main/java/groovy/lang/GroovyClassLoader.java
index 2d726d9..726c5d4 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/groovy/lang/GroovyClassLoader.java
@@ -684,7 +684,7 @@ public class GroovyClassLoader extends URLClassLoader {
         return new ClassCollector(loader, unit, su);
     }
 
-    public static class ClassCollector extends CompilationUnit.ClassgenCallback {
+    public static class ClassCollector implements CompilationUnit.ClassgenCallback {
         private Class generatedClass;
         private final GroovyClassLoader cl;
         private final SourceUnit su;
diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index c7ad553..8f7a723 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -79,7 +79,6 @@ import org.codehaus.groovy.util.FastArray;
 import org.codehaus.groovy.util.SingleKeyHashMap;
 import org.codehaus.groovy.vmplugin.VMPlugin;
 import org.codehaus.groovy.vmplugin.VMPluginFactory;
-import org.objectweb.asm.ClassVisitor;
 
 import java.beans.BeanInfo;
 import java.beans.EventSetDescriptor;
@@ -3035,11 +3034,9 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                      * checking won't work but that mostly affects the bytecode
                      * generation rather than viewing the AST
                      */
-                    CompilationUnit.ClassgenCallback search = new CompilationUnit.ClassgenCallback()
{
-                        public void call(ClassVisitor writer, ClassNode node) {
-                            if (node.getName().equals(theClass.getName())) {
-                                MetaClassImpl.this.classNode = node;
-                            }
+                    CompilationUnit.ClassgenCallback search = (writer, node) -> {
+                        if (node.getName().equals(theClass.getName())) {
+                            MetaClassImpl.this.classNode = node;
                         }
                     };
 
diff --git a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
index 8e71645..1aa5221 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
@@ -514,9 +514,9 @@ public class CompilationUnit extends ProcessingUnit {
      * for each primary and inner class.  Use setClassgenCallback() before
      * running compile() to set your callback.
      */
-    // TODO: Convert to functional interface?
-    public abstract static class ClassgenCallback {
-        public abstract void call(ClassVisitor writer, ClassNode node) throws CompilationFailedException;
+    @FunctionalInterface
+    public interface ClassgenCallback {
+        void call(ClassVisitor writer, ClassNode node) throws CompilationFailedException;
     }
 
     /**


Mime
View raw message