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 Fri, 06 Apr 2018 04:55:23 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 742770d04 -> 24114e01f


Minor refactoring: remove duplicated code of `ResolveVisitor`


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

Branch: refs/heads/master
Commit: 24114e01f8a1fc44b776c9a64c2df50ebc8f7fe9
Parents: 742770d
Author: danielsun1106 <realbluesun@hotmail.com>
Authored: Fri Apr 6 12:54:59 2018 +0800
Committer: danielsun1106 <realbluesun@hotmail.com>
Committed: Fri Apr 6 12:54:59 2018 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/control/ResolveVisitor.java | 50 +++++++++-----------
 1 file changed, 23 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/24114e01/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 43a1dc1..2f82009 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -790,19 +790,8 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
                     return null;
                 }
                 String varName = ve.getName();
-                if (doInitialClassTest) {
-                    // we are at the first name part. This is the right most part.
-                    // If this part is in lower case, then we do not need a class
-                    // check. other parts of the property expression will be tested
-                    // by a different method call to this method, so foo.Bar.bar
-                    // can still be resolved to the class foo.Bar and the static
-                    // field bar.
-                    if (!testVanillaNameForClass(varName)) return null;
-                    doInitialClassTest = false;
-                    name = new StringBuilder(varName);
-                } else {
-                    name.insert(0, varName + ".");
-                }
+                name = getClassName(doInitialClassTest, name, varName);
+                if (name == null) return null;
                 break;
             }
             // anything other than PropertyExpressions or
@@ -816,25 +805,32 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
                 if (propertyPart == null || propertyPart.equals("class")) {
                     return null;
                 }
-                if (doInitialClassTest) {
-                    // we are at the first name part. This is the right most part.
-                    // If this part is in lower case, then we do not need a class
-                    // check. other parts of the property expression will be tested
-                    // by a different method call to this method, so foo.Bar.bar
-                    // can still be resolved to the class foo.Bar and the static
-                    // field bar.
-                    if (!testVanillaNameForClass(propertyPart)) return null;
-                    doInitialClassTest= false;
-                    name = new StringBuilder(propertyPart);
-                } else {
-                    name.insert(0, propertyPart + ".");
-                }
+                name = getClassName(doInitialClassTest, name, propertyPart);
             }
         }
-        if (name.length() == 0) return null;
+
+        if (null == name || name.length() == 0) return null;
+
         return name.toString();
     }
 
+    private static StringBuilder getClassName(boolean doInitialClassTest, StringBuilder name,
String varName) {
+        if (doInitialClassTest) {
+            // we are at the first name part. This is the right most part.
+            // If this part is in lower case, then we do not need a class
+            // check. other parts of the property expression will be tested
+            // by a different method call to this method, so foo.Bar.bar
+            // can still be resolved to the class foo.Bar and the static
+            // field bar.
+            if (!testVanillaNameForClass(varName)) return null;
+            doInitialClassTest = false;
+            name = new StringBuilder(varName);
+        } else {
+            name.insert(0, varName + ".");
+        }
+        return name;
+    }
+
     // iterate from the inner most to the outer and check for classes
     // this check will ignore a .class property, for Example Integer.class will be
     // a PropertyExpression with the ClassExpression of Integer as objectExpression


Mime
View raw message