groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring: remove duplicated code of `Verifier`
Date Thu, 01 Mar 2018 00:03:28 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 4e1ad1fb8 -> 4d7884edc


Minor refactoring: remove duplicated code of `Verifier`


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

Branch: refs/heads/master
Commit: 4d7884edc7f09f4315633bf5afd5e53b906f190a
Parents: 4e1ad1f
Author: sunlan <sunlan@apache.org>
Authored: Thu Mar 1 07:54:27 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Mar 1 08:00:33 2018 +0800

----------------------------------------------------------------------
 .../org/codehaus/groovy/classgen/Verifier.java  | 67 ++++++++++----------
 1 file changed, 33 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/4d7884ed/src/main/java/org/codehaus/groovy/classgen/Verifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index 2e5c851..923d228 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -713,19 +713,11 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
             getterModifiers = ~Modifier.FINAL & getterModifiers;
         }
         if (getterBlock != null) {
-            MethodNode getter =
-                    new MethodNode(getterName, getterModifiers, node.getType(), Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY, getterBlock);
-            getter.setSynthetic(true);
-            addPropertyMethod(getter);
-            visitMethod(getter);
+            visitGetter(node, getterBlock, getterModifiers, getterName);
 
             if (ClassHelper.boolean_TYPE == node.getType() || ClassHelper.Boolean_TYPE ==
node.getType()) {
                 String secondGetterName = "is" + capitalize(name);
-                MethodNode secondGetter =
-                        new MethodNode(secondGetterName, getterModifiers, node.getType(),
Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock);
-                secondGetter.setSynthetic(true);
-                addPropertyMethod(secondGetter);
-                visitMethod(secondGetter);
+                visitGetter(node, getterBlock, getterModifiers, secondGetterName);
             }
         }
         if (setterBlock != null) {
@@ -738,6 +730,14 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
         }
     }
 
+    private void visitGetter(PropertyNode node, Statement getterBlock, int getterModifiers,
String secondGetterName) {
+        MethodNode secondGetter =
+                new MethodNode(secondGetterName, getterModifiers, node.getType(), Parameter.EMPTY_ARRAY,
ClassNode.EMPTY_ARRAY, getterBlock);
+        secondGetter.setSynthetic(true);
+        addPropertyMethod(secondGetter);
+        visitMethod(secondGetter);
+    }
+
     protected void addPropertyMethod(MethodNode method) {
         classNode.addMethod(method);
         // GROOVY-4415 / GROOVY-4645: check that there's no abstract method which corresponds
to this one
@@ -915,22 +915,10 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                         );
                         k++;
                     } else if (parameter.hasInitialExpression()) {
-                        newParams[index++] = parameter;
-                        arguments.addExpression(
-                                new CastExpression(
-                                        parameter.getType(),
-                                        new VariableExpression(parameter.getName())
-                                )
-                        );
+                        index = addExpression(newParams, arguments, index, parameter);
                         k++;
                     } else {
-                        newParams[index++] = parameter;
-                        arguments.addExpression(
-                                new CastExpression(
-                                        parameter.getType(),
-                                        new VariableExpression(parameter.getName())
-                                )
-                        );
+                        index = addExpression(newParams, arguments, index, parameter);
                     }
                 }
             }
@@ -944,6 +932,17 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
         }
     }
 
+    private int addExpression(Parameter[] newParams, ArgumentListExpression arguments, int
index, Parameter parameter) {
+        newParams[index++] = parameter;
+        arguments.addExpression(
+                new CastExpression(
+                        parameter.getType(),
+                        new VariableExpression(parameter.getName())
+                )
+        );
+        return index;
+    }
+
     protected void addClosureCode(InnerClassNode node) {
         // add a new invoke
     }
@@ -1264,11 +1263,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
             Map genericsSpec = createGenericsSpec(sn, oldGenericsSpec);
             List<MethodNode> classMethods = sn.getMethods();
             // original class causing bridge methods for methods in super class
-            for (Object declaredMethod : declaredMethods) {
-                MethodNode method = (MethodNode) declaredMethod;
-                if (method.isStatic()) continue;
-                storeMissingCovariantMethods(classMethods, method, methodsToAdd, genericsSpec,
false);
-            }
+            storeMissingCovariantMethods(declaredMethods, methodsToAdd, genericsSpec, classMethods);
             // super class causing bridge methods for abstract methods in original class
             if (!abstractMethods.isEmpty()) {
                 for (Object classMethod : classMethods) {
@@ -1285,16 +1280,20 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
         for (ClassNode anInterface : interfaces) {
             List interfacesMethods = anInterface.getMethods();
             Map genericsSpec = createGenericsSpec(anInterface, oldGenericsSpec);
-            for (Object declaredMethod : declaredMethods) {
-                MethodNode method = (MethodNode) declaredMethod;
-                if (method.isStatic()) continue;
-                storeMissingCovariantMethods(interfacesMethods, method, methodsToAdd, genericsSpec,
false);
-            }
+            storeMissingCovariantMethods(declaredMethods, methodsToAdd, genericsSpec, interfacesMethods);
             addCovariantMethods(anInterface, declaredMethods, abstractMethods, methodsToAdd,
genericsSpec);
         }
 
     }
 
+    private void storeMissingCovariantMethods(List declaredMethods, Map methodsToAdd, Map
genericsSpec, List<MethodNode> methodNodeList) {
+        for (Object declaredMethod : declaredMethods) {
+            MethodNode method = (MethodNode) declaredMethod;
+            if (method.isStatic()) continue;
+            storeMissingCovariantMethods(methodNodeList, method, methodsToAdd, genericsSpec,
false);
+        }
+    }
+
     private MethodNode getCovariantImplementation(final MethodNode oldMethod, final MethodNode
overridingMethod, Map genericsSpec, boolean ignoreError) {
         // method name
         if (!oldMethod.getName().equals(overridingMethod.getName())) return null;


Mime
View raw message