minor refactor

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

Branch: refs/heads/master
Commit: 3d60dbd796c6b362c8c590b14c247b9769a8edbf
Parents: 973197f
Author: paulk <pa...@asert.com.au>
Authored: Wed Jun 1 13:35:39 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Wed Jun 1 13:35:39 2016 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/ast/ClassNode.java | 29 ++------------
 .../groovy/ast/tools/ClassNodeUtils.java        | 41 ++++++++++++++++++++
 .../groovy/ast/tools/ParameterUtils.java        | 39 +++++++++++++++++++
 .../classgen/ClassCompletionVerifier.java       |  3 +-
 .../groovy/classgen/ExtendedVerifier.java       | 19 +--------
 .../classgen/asm/OptimizingStatementWriter.java | 18 +--------
 6 files changed, 90 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/3d60dbd7/src/main/org/codehaus/groovy/ast/ClassNode.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/ClassNode.java 
b/src/main/org/codehaus/groovy/ast/ClassNode.java
index 68ac22d..37ad787 100644
--- a/src/main/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/org/codehaus/groovy/ast/ClassNode.java
@@ -23,6 +23,8 @@ import org.codehaus.groovy.ast.expr.*;
 import org.codehaus.groovy.ast.stmt.BlockStatement;
 import org.codehaus.groovy.ast.stmt.ExpressionStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
+import org.codehaus.groovy.ast.tools.ClassNodeUtils;
+import org.codehaus.groovy.ast.tools.ParameterUtils;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.transform.ASTTransformation;
 import org.codehaus.groovy.transform.GroovyASTTransformation;
@@ -431,7 +433,7 @@ public class ClassNode extends AnnotatedNode implements 
Opcodes {
         } else {
             result = new HashMap<String, MethodNode>();
         }
-        addInterfaceMethods(result);
+        ClassNodeUtils.addInterfaceMethods(this, result);
 
         // And add in the methods implemented in this class.
         for (MethodNode method : getMethods()) {
@@ -441,19 +443,6 @@ public class ClassNode extends AnnotatedNode implements 
Opcodes {
         return result;
     }
 
-    public void addInterfaceMethods(Map<String, MethodNode> methodsMap) {
-        // add in unimplemented abstract methods from the interfaces
-        for (ClassNode iface : getInterfaces()) {
-            Map<String, MethodNode> ifaceMethodsMap = 
iface.getDeclaredMethodsMap();
-            for (String methSig : ifaceMethodsMap.keySet()) {
-                if (!methodsMap.containsKey(methSig)) {
-                    MethodNode methNode = ifaceMethodsMap.get(methSig);
-                    methodsMap.put(methSig, methNode);
-                }
-            }
-        }
-    }
-
     public String getName() {
         return redirect().name;
     }
@@ -1047,17 +1036,7 @@ public class ClassNode extends AnnotatedNode implements 
Opcodes {
      * @return true if the two arrays are of the same size and have the same 
contents
      */
     protected boolean parametersEqual(Parameter[] a, Parameter[] b) {
-        if (a.length == b.length) {
-            boolean answer = true;
-            for (int i = 0; i < a.length; i++) {
-                if (!a[i].getType().equals(b[i].getType())) {
-                    answer = false;
-                    break;
-                }
-            }
-            return answer;
-        }
-        return false;
+        return ParameterUtils.parametersEqual(a, b);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/3d60dbd7/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
new file mode 100644
index 0000000..f3eec90
--- /dev/null
+++ b/src/main/org/codehaus/groovy/ast/tools/ClassNodeUtils.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.codehaus.groovy.ast.tools;
+
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.MethodNode;
+
+import java.util.Map;
+
+public class ClassNodeUtils {
+    public static void addInterfaceMethods(ClassNode cnode, Map<String, 
MethodNode> methodsMap) {
+        // add in unimplemented abstract methods from the interfaces
+        for (ClassNode iface : cnode.getInterfaces()) {
+            Map<String, MethodNode> ifaceMethodsMap = 
iface.getDeclaredMethodsMap();
+            for (String methSig : ifaceMethodsMap.keySet()) {
+                if (!methodsMap.containsKey(methSig)) {
+                    MethodNode methNode = ifaceMethodsMap.get(methSig);
+                    methodsMap.put(methSig, methNode);
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/3d60dbd7/src/main/org/codehaus/groovy/ast/tools/ParameterUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/tools/ParameterUtils.java 
b/src/main/org/codehaus/groovy/ast/tools/ParameterUtils.java
new file mode 100644
index 0000000..4edf92e
--- /dev/null
+++ b/src/main/org/codehaus/groovy/ast/tools/ParameterUtils.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.codehaus.groovy.ast.tools;
+
+import org.codehaus.groovy.ast.Parameter;
+
+public class ParameterUtils {
+    public static boolean parametersEqual(Parameter[] a, Parameter[] b) {
+        if (a.length == b.length) {
+            boolean answer = true;
+            for (int i = 0; i < a.length; i++) {
+                if (!a[i].getType().equals(b[i].getType())) {
+                    answer = false;
+                    break;
+                }
+            }
+            return answer;
+        }
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/3d60dbd7/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java 
b/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
index c29c705..9fe13cf 100644
--- a/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
+++ b/src/main/org/codehaus/groovy/classgen/ClassCompletionVerifier.java
@@ -35,6 +35,7 @@ import org.codehaus.groovy.ast.expr.PropertyExpression;
 import org.codehaus.groovy.ast.expr.TupleExpression;
 import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.ast.stmt.CatchStatement;
+import org.codehaus.groovy.ast.tools.ClassNodeUtils;
 import org.codehaus.groovy.ast.tools.GeneralUtils;
 import org.codehaus.groovy.control.SourceUnit;
 import org.codehaus.groovy.runtime.MetaClassHelper;
@@ -93,7 +94,7 @@ public class ClassCompletionVerifier extends 
ClassCodeVisitorSupport {
             result = new HashMap<String, MethodNode>();
         }
         // add in unimplemented abstract methods from the interfaces
-        node.addInterfaceMethods(result);
+        ClassNodeUtils.addInterfaceMethods(node, result);
         for (MethodNode methodNode : node.getMethods()) {
             MethodNode mn = result.get(methodNode.getTypeDescriptor());
             if (mn != null && (mn.isStatic() ^ methodNode.isStatic()) && 
!methodNode.isStaticConstructor()) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/3d60dbd7/src/main/org/codehaus/groovy/classgen/ExtendedVerifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/ExtendedVerifier.java 
b/src/main/org/codehaus/groovy/classgen/ExtendedVerifier.java
index 57cfbfa..f66a95a 100644
--- a/src/main/org/codehaus/groovy/classgen/ExtendedVerifier.java
+++ b/src/main/org/codehaus/groovy/classgen/ExtendedVerifier.java
@@ -22,6 +22,7 @@ import org.codehaus.groovy.ast.*;
 import org.codehaus.groovy.ast.expr.DeclarationExpression;
 import org.codehaus.groovy.ast.stmt.ReturnStatement;
 import org.codehaus.groovy.ast.stmt.Statement;
+import org.codehaus.groovy.ast.tools.ParameterUtils;
 import org.codehaus.groovy.control.AnnotationConstantsVisitor;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.codehaus.groovy.control.ErrorCollector;
@@ -46,8 +47,6 @@ import static 
org.codehaus.groovy.ast.tools.GenericsUtils.createGenericsSpec;
  * <p>
  * Current limitations:
  * - annotations on local variables are not supported
- *
- * @author <a href='mailto:the[dot]mindstorm[at]gmail[dot]com'>Alex Popescu</a>
  */
 public class ExtendedVerifier extends ClassCodeVisitorSupport {
     public static final String JVM_ERROR_MESSAGE = "Please make sure you are 
running on a JVM >= 1.5";
@@ -234,27 +233,13 @@ public class ExtendedVerifier extends 
ClassCodeVisitorSupport {
     private static MethodNode getDeclaredMethodCorrected(Map genericsSpec, 
MethodNode mn, ClassNode correctedNext) {
         for (MethodNode orig :  
correctedNext.getDeclaredMethods(mn.getName())) {
             MethodNode method = correctToGenericsSpec(genericsSpec, orig);
-            if (parametersEqual(method.getParameters(), mn.getParameters())) {
+            if (ParameterUtils.parametersEqual(method.getParameters(), 
mn.getParameters())) {
                 return method;
             }
         }
         return null;
     }
 
-    private static boolean parametersEqual(Parameter[] a, Parameter[] b) {
-        if (a.length == b.length) {
-            boolean answer = true;
-            for (int i = 0; i < a.length; i++) {
-                if (!a[i].getType().equals(b[i].getType())) {
-                    answer = false;
-                    break;
-                }
-            }
-            return answer;
-        }
-        return false;
-    }
-
     /**
      * Resolve metadata and details of the annotation.
      *

http://git-wip-us.apache.org/repos/asf/groovy/blob/3d60dbd7/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
----------------------------------------------------------------------
diff --git 
a/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java 
b/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
index 104eb1f..9e660fa 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
@@ -25,6 +25,7 @@ import org.codehaus.groovy.ast.*;
 import org.codehaus.groovy.ast.expr.*;
 import org.codehaus.groovy.ast.stmt.*;
 import org.codehaus.groovy.GroovyBugError;
+import org.codehaus.groovy.ast.tools.ParameterUtils;
 import org.codehaus.groovy.classgen.AsmClassGenerator;
 import org.codehaus.groovy.classgen.Verifier;
 import org.codehaus.groovy.control.SourceUnit;
@@ -40,7 +41,6 @@ import static 
org.codehaus.groovy.ast.tools.WideningCategories.*;
 
 /**
  * A class to write out the optimized statements
- * @author <a href="mailto:blackd...@gmx.org";>Jochen "blackdrag" Theodorou</a>
  */
 public class OptimizingStatementWriter extends StatementWriter {
     
@@ -850,7 +850,7 @@ public class OptimizingStatementWriter extends 
StatementWriter {
             List<ConstructorNode> cl = node.getDeclaredConstructors();
             MethodNode res = null;
             for (ConstructorNode cn : cl) {
-                if (parametersEqual(cn.getParameters(), paraTypes)) {
+                if (ParameterUtils.parametersEqual(cn.getParameters(), 
paraTypes)) {
                     res = cn;
                     break;
                 }
@@ -859,20 +859,6 @@ public class OptimizingStatementWriter extends 
StatementWriter {
             return null;
         }
 
-        private static boolean parametersEqual(Parameter[] a, Parameter[] b) {
-            if (a.length == b.length) {
-                boolean answer = true;
-                for (int i = 0; i < a.length; i++) {
-                    if (!a[i].getType().equals(b[i].getType())) {
-                        answer = false;
-                        break;
-                    }
-                }
-                return answer;
-            }
-            return false;
-        }
-        
         private static boolean validTypeForCall(ClassNode type) {
             // do call only for final classes and primitive types
             if (isPrimitiveType(type)) return true;

Reply via email to