Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X e51be18e9 -> 9dfb757ec


Trivial refactoring: reuse the helper method `replaceLastPointWithDollar`

(cherry picked from commit 3282a51)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 9dfb757ecf2fb10f1d152cf5ca9eb8e89686894f
Parents: e51be18
Author: danielsun1106 <realblue...@hotmail.com>
Authored: Fri Apr 6 16:22:47 2018 +0800
Committer: danielsun1106 <realblue...@hotmail.com>
Committed: Fri Apr 6 16:24:50 2018 +0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/9dfb757e/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 20d4f8f..1bdf9b8 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -270,7 +270,7 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
         genericParameterNames = oldPNames;
     }
 
-    private boolean resolveToInner (ClassNode type) {
+    private boolean resolveToInner(ClassNode type) {
         // we do not do our name mangling to find an inner class
         // if the type is a ConstructedClassWithPackage, because in this case 
we
         // are resolving the name at a different place already
@@ -279,9 +279,8 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
         String name = type.getName();
         String saved = name;
         while (true) {
-            int len = name.lastIndexOf('.');
-            if (len == -1) break;
-            name = name.substring(0,len) + "$" + name.substring(len+1);
+            if (-1 == name.lastIndexOf('.')) break;
+            name = replaceLastPointWithDollar(name);
             type.setName(name);
             if (resolve(type)) return true;
         }
@@ -315,8 +314,8 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
                 return true;
             }
         }
-        return false;
 
+        return false;
     }
 
     private boolean checkInnerTypeVisibility(ClassNode enclosingType, 
ClassNode innerClassNode) {
@@ -458,12 +457,10 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
         return false;
     }
 
-    private static String replaceLastPoint(String name) {
-        int lastPoint = name.lastIndexOf('.');
-        name = name.substring(0, lastPoint) +
-                "$" +
-                name.substring(lastPoint + 1);
-        return name;
+    private static String replaceLastPointWithDollar(String name) {
+        int lastPointIndex = name.lastIndexOf('.');
+
+        return name.substring(0, lastPointIndex) + "$" + 
name.substring(lastPointIndex + 1);
     }
 
     private boolean resolveFromStaticInnerClasses(ClassNode type, boolean 
testStaticInnerClasses) {
@@ -483,7 +480,7 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
                 // the package is really a class is handled elsewhere
                 ConstructedClassWithPackage tmp = 
(ConstructedClassWithPackage) type;
                 String savedName = tmp.className;
-                tmp.className = replaceLastPoint(savedName);
+                tmp.className = replaceLastPointWithDollar(savedName);
                 if (resolve(tmp, false, true, true)) {
                     type.setRedirect(tmp.redirect());
                     return true;
@@ -491,7 +488,7 @@ public class ResolveVisitor extends 
ClassCodeExpressionTransformer {
                 tmp.className = savedName;
             }   else {
                 String savedName = type.getName();
-                String replacedPointType = replaceLastPoint(savedName);
+                String replacedPointType = 
replaceLastPointWithDollar(savedName);
                 type.setName(replacedPointType);
                 if (resolve(type, false, true, true)) return true;
                 type.setName(savedName);

Reply via email to