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 `ResolveVisitor`
Date Wed, 28 Feb 2018 04:08:34 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 8e0ae440e -> 74c21214b


Minor refactoring: remove duplicated code of `ResolveVisitor`

(cherry picked from commit 5030e40)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 74c21214bb6f90cf30e85f0340f6adbbb0f9501f
Parents: 8e0ae44
Author: sunlan <sunlan@apache.org>
Authored: Wed Feb 28 11:35:16 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Wed Feb 28 12:08:26 2018 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/control/ResolveVisitor.java | 47 ++++++++------------
 1 file changed, 19 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/74c21214/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 922c528..a06ad99 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -367,28 +367,14 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         // name in X.
         // GROOVY-4043: Do this check up the hierarchy, if needed
         Map<String, ClassNode> hierClasses = new LinkedHashMap<String, ClassNode>();
-        ClassNode val;
-        for(ClassNode classToCheck = currentClass; classToCheck != ClassHelper.OBJECT_TYPE;

+        for(ClassNode classToCheck = currentClass; classToCheck != ClassHelper.OBJECT_TYPE;
             classToCheck = classToCheck.getSuperClass()) {
             if(classToCheck == null || hierClasses.containsKey(classToCheck.getName())) break;
             hierClasses.put(classToCheck.getName(), classToCheck);
         }
 
         for (ClassNode classToCheck : hierClasses.values()) {
-            val = new ConstructedNestedClass(classToCheck,type.getName());
-            if (resolveFromCompileUnit(val)) {
-                type.setRedirect(val);
-                return true;
-            }
-            // also check interfaces in case we have interfaces with nested classes
-            for (ClassNode next : classToCheck.getAllInterfaces()) {
-                if (type.getName().contains(next.getName())) continue;
-                val = new ConstructedNestedClass(next,type.getName());
-                if (resolve(val, false, false, false)) {
-                    type.setRedirect(val);
-                    return true;
-                }
-            }
+            if (setRedirect(type, classToCheck)) return true;
         }
 
         // another case we want to check here is if we are in a
@@ -416,22 +402,27 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         }
         // most outer class is now element 0
         for (ClassNode testNode : outerClasses) {
-            val = new ConstructedNestedClass(testNode,type.getName());
-            if (resolveFromCompileUnit(val)) {
+            if (setRedirect(type, testNode)) return true;
+        }
+
+        return false;
+    }
+
+    private boolean setRedirect(ClassNode type, ClassNode classToCheck) {
+        ClassNode val = new ConstructedNestedClass(classToCheck, type.getName());
+        if (resolveFromCompileUnit(val)) {
+            type.setRedirect(val);
+            return true;
+        }
+        // also check interfaces in case we have interfaces with nested classes
+        for (ClassNode next : classToCheck.getAllInterfaces()) {
+            if (type.getName().contains(next.getName())) continue;
+            val = new ConstructedNestedClass(next, type.getName());
+            if (resolve(val, false, false, false)) {
                 type.setRedirect(val);
                 return true;
             }
-            // also check interfaces in case we have interfaces with nested classes
-            for (ClassNode next : testNode.getAllInterfaces()) {
-                if (type.getName().contains(next.getName())) continue;
-                val = new ConstructedNestedClass(next,type.getName());
-                if (resolve(val, false, false, false)) {
-                    type.setRedirect(val);
-                    return true;
-                }
-            }
         }
-
         return false;
     }
 


Mime
View raw message