Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X bb3daa2c0 -> d84193c2a


minor refactor


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/77f9b9ba
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/77f9b9ba
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/77f9b9ba

Branch: refs/heads/GROOVY_2_4_X
Commit: 77f9b9bac184f788f544f40585a796a0bdbef69e
Parents: 984173f
Author: paulk <pa...@asert.com.au>
Authored: Tue Jun 7 21:46:11 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Tue Jun 14 23:15:57 2016 +1000

----------------------------------------------------------------------
 .../groovy/ast/tools/ClassNodeUtils.java        | 27 ++++++++++++++++++
 .../org/codehaus/groovy/classgen/Verifier.java  | 29 +++-----------------
 2 files changed, 31 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/77f9b9ba/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java 
b/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
index f3eec90..82cc190 100644
--- a/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
+++ b/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
@@ -20,9 +20,13 @@
 
 package org.codehaus.groovy.ast.tools;
 
+import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.MethodNode;
 
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 public class ClassNodeUtils {
@@ -38,4 +42,27 @@ public class ClassNodeUtils {
             }
         }
     }
+
+    public static Map<String, MethodNode> 
getDeclaredMethodMapsFromInterfaces(ClassNode classNode) {
+        Map<String, MethodNode> result = new HashMap<String, MethodNode>();
+        ClassNode[] interfaces = classNode.getInterfaces();
+        for (ClassNode iface : interfaces) {
+            result.putAll(iface.getDeclaredMethodsMap());
+        }
+        return result;
+    }
+
+    public static void addDeclaredMethodMapsFromSuperInterfaces(ClassNode cn, 
Map<String, MethodNode> allInterfaceMethods) {
+        List cnInterfaces = Arrays.asList(cn.getInterfaces());
+        ClassNode sn = cn.getSuperClass();
+        while (sn != null && !sn.equals(ClassHelper.OBJECT_TYPE)) {
+            ClassNode[] interfaces = sn.getInterfaces();
+            for (ClassNode iface : interfaces) {
+                if (!cnInterfaces.contains(iface)) {
+                    allInterfaceMethods.putAll(iface.getDeclaredMethodsMap());
+                }
+            }
+            sn = sn.getSuperClass();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/77f9b9ba/src/main/org/codehaus/groovy/classgen/Verifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/Verifier.java 
b/src/main/org/codehaus/groovy/classgen/Verifier.java
index 1e390a9..d65a755 100644
--- a/src/main/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/org/codehaus/groovy/classgen/Verifier.java
@@ -37,6 +37,7 @@ import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.ExpressionStatement;
 import org.codehaus.groovy.ast.stmt.ReturnStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
+import org.codehaus.groovy.ast.tools.ClassNodeUtils;
 import org.codehaus.groovy.ast.tools.GenericsUtils;
 import org.codehaus.groovy.classgen.asm.BytecodeHelper;
 import org.codehaus.groovy.classgen.asm.MopWriter;
@@ -1135,16 +1136,9 @@ public class Verifier implements GroovyClassVisitor, 
Opcodes {
         Map genericsSpec = new HashMap();
 
         // unimplemented abstract methods from interfaces
-        Map abstractMethods = new HashMap();
-        Map<String, MethodNode> allInterfaceMethods = new HashMap<String, 
MethodNode>();
-        ClassNode[] interfaces = classNode.getInterfaces();
-        for (ClassNode iface : interfaces) {
-            Map ifaceMethodsMap = iface.getDeclaredMethodsMap();
-            abstractMethods.putAll(ifaceMethodsMap);
-            allInterfaceMethods.putAll(ifaceMethodsMap);
-        }
-
-        collectSuperInterfaceMethods(classNode, allInterfaceMethods);
+        Map<String, MethodNode> abstractMethods = 
ClassNodeUtils.getDeclaredMethodMapsFromInterfaces(classNode);
+        Map<String, MethodNode> allInterfaceMethods = new HashMap<String, 
MethodNode>(abstractMethods);
+        ClassNodeUtils.addDeclaredMethodMapsFromSuperInterfaces(classNode, 
allInterfaceMethods);
 
         List<MethodNode> declaredMethods = new 
ArrayList<MethodNode>(classNode.getMethods());
         // remove all static, private and package private methods
@@ -1183,21 +1177,6 @@ public class Verifier implements GroovyClassVisitor, 
Opcodes {
         }
     }
 
-    private static void collectSuperInterfaceMethods(ClassNode cn, Map<String, 
MethodNode> allInterfaceMethods) {
-        List cnInterfaces = Arrays.asList(cn.getInterfaces());
-        ClassNode sn = cn.getSuperClass();
-        while (sn != null && !sn.equals(ClassHelper.OBJECT_TYPE)) {
-            ClassNode[] interfaces = sn.getInterfaces();
-            for (ClassNode iface : interfaces) {
-                if (!cnInterfaces.contains(iface)) {
-                    Map<String, MethodNode> ifaceMethodsMap = 
iface.getDeclaredMethodsMap();
-                    allInterfaceMethods.putAll(ifaceMethodsMap);
-                }
-            }
-            sn = sn.getSuperClass();
-        }
-    }
-
     private void addCovariantMethods(ClassNode classNode, List 
declaredMethods, Map abstractMethods, Map methodsToAdd, Map oldGenericsSpec) {
         ClassNode sn = classNode.getUnresolvedSuperClass(false);
 

Reply via email to