You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/04/06 06:38:45 UTC

groovy git commit: Trivial refactoring: extract constants

Repository: groovy
Updated Branches:
  refs/heads/master 10cdf235d -> 2b918f8e6


Trivial refactoring: extract constants


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

Branch: refs/heads/master
Commit: 2b918f8e6e5e2735fc5835b7c68f1e859de540b0
Parents: 10cdf23
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Apr 6 14:37:35 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Apr 6 14:38:38 2018 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/control/ResolveVisitor.java | 21 +++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2b918f8e/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 653e11c..6065a6d 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -87,9 +87,12 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.isDefaultVisibility;
  * Note: the method to start the resolving is  startResolving(ClassNode, SourceUnit).
  */
 public class ResolveVisitor extends ClassCodeExpressionTransformer {
-    private ClassNode currentClass;
     // note: BigInteger and BigDecimal are also imported by default
     public static final String[] DEFAULT_IMPORTS = {"java.lang.", "java.io.", "java.net.", "java.util.", "groovy.lang.", "groovy.util."};
+    private static final String BIGINTEGER_STR = "BigInteger";
+    private static final String BIGDECIMAL_STR = "BigDecimal";
+
+    private ClassNode currentClass;
     private final CompilationUnit compilationUnit;
     private SourceUnit source;
     private VariableScope currentScope;
@@ -497,34 +500,34 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         return false;
     }
 
-    private boolean resolveFromDefaultImports(ClassNode type, boolean testDefaultImports) {
+    private boolean resolveFromDefaultImports(final ClassNode type, boolean testDefaultImports) {
         // test default imports
         testDefaultImports &= !type.hasPackageName();
         // we do not resolve a vanilla name starting with a lower case letter
         // try to resolve against a default import, because we know that the
         // default packages do not contain classes like these
         testDefaultImports &= !(type instanceof LowerCaseClass);
+        final String typeName = type.getName();
+
         if (testDefaultImports) {
-            for (int i = 0, size = DEFAULT_IMPORTS.length; i < size; i++) {
-                String packagePrefix = DEFAULT_IMPORTS[i];
-                String name = type.getName();
+            for (String packagePrefix : DEFAULT_IMPORTS) {
                 // We limit the inner class lookups here by using ConstructedClassWithPackage.
                 // This way only the name will change, the packagePrefix will
                 // not be included in the lookup. The case where the
                 // packagePrefix is really a class is handled elsewhere.
                 // WARNING: This code does not expect a class that has a static
                 //          inner class in DEFAULT_IMPORTS
-                ConstructedClassWithPackage tmp =  new ConstructedClassWithPackage(packagePrefix,name);
+                ConstructedClassWithPackage tmp = new ConstructedClassWithPackage(packagePrefix, typeName);
                 if (resolve(tmp, false, false, false)) {
                     type.setRedirect(tmp.redirect());
                     return true;
                 }
             }
-            String name = type.getName();
-            if (name.equals("BigInteger")) {
+
+            if (BIGINTEGER_STR.equals(typeName)) {
                 type.setRedirect(ClassHelper.BigInteger_TYPE);
                 return true;
-            } else if (name.equals("BigDecimal")) {
+            } else if (BIGDECIMAL_STR.equals(typeName)) {
                 type.setRedirect(ClassHelper.BigDecimal_TYPE);
                 return true;
             }