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 07:07:55 UTC

[1/4] groovy git commit: Trivial refactoring: extract constants

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X e8c404ddf -> 8e93bf91f


Trivial refactoring: extract constants

(cherry picked from commit 2b918f8)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: de0cba894e235b47d44e79fcb7a86bac3e668381
Parents: e8c404d
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Apr 6 14:37:35 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Apr 6 15:07:30 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/de0cba89/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;
             }


[4/4] groovy git commit: Refine the test for GROOVY-8531

Posted by su...@apache.org.
Refine the test for GROOVY-8531

(cherry picked from commit 1b19f68)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 8e93bf91f5a4ad52a40dd9881521c5cd60b606d0
Parents: 75b0625
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Apr 6 15:04:50 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Apr 6 15:07:42 2018 +0800

----------------------------------------------------------------------
 .../groovy/bugs/groovy8531/Groovy8531Bug.groovy | 28 +++++++++++++++++++-
 src/test/groovy/bugs/groovy8531/Reducer.java    | 12 ++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/8e93bf91/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy b/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
index 72dd08b..2369d88 100644
--- a/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
+++ b/src/test/groovy/bugs/groovy8531/Groovy8531Bug.groovy
@@ -25,6 +25,14 @@ class Groovy8531Bug extends GroovyTestCase {
             class Example extends Reducer {
                 public void reduce(PublicContext context) {}
                 public void reduce2(ProtectedContext context) {}
+                public void reduce3(PublicStaticContext context) {}
+                public void reduce4(ProtectedStaticContext context) {}
+                
+                public void reduce5(PublicBaseContext context) {}
+                public void reduce6(ProtectedBaseContext context) {}
+                public void reduce7(PublicStaticBaseContext context) {}
+                public void reduce8(ProtectedStaticBaseContext context) {}
+                
                 public boolean isDynamic(Type type) {
                     return Type.DYNAMIC == type
                 }
@@ -32,6 +40,14 @@ class Groovy8531Bug extends GroovyTestCase {
             
             new Example().reduce(null)
             new Example().reduce2(null)
+            new Example().reduce3(null)
+            new Example().reduce4(null)
+            
+            new Example().reduce5(null)
+            new Example().reduce6(null)
+            new Example().reduce7(null)
+            new Example().reduce8(null)
+            
             assert new Example().isDynamic(Reducer.Type.DYNAMIC)
         '''
     }
@@ -43,6 +59,16 @@ class Groovy8531Bug extends GroovyTestCase {
                 public void reduce3(PrivateContext context) {}
             }
         '''
-        assert errMsg.contains('unable to resolve class')
+        assert errMsg.contains('unable to resolve class PrivateContext')
+    }
+
+    void testPrivateInnerType2() {
+        def errMsg = shouldFail '''
+            package groovy.bugs.groovy8531
+            class Example extends Reducer {
+                public void reduce3(PrivateBaseContext context) {}
+            }
+        '''
+        assert errMsg.contains('unable to resolve class PrivateBaseContext')
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/8e93bf91/src/test/groovy/bugs/groovy8531/Reducer.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/groovy8531/Reducer.java b/src/test/groovy/bugs/groovy8531/Reducer.java
index 95b5b24..6cf865f 100644
--- a/src/test/groovy/bugs/groovy8531/Reducer.java
+++ b/src/test/groovy/bugs/groovy8531/Reducer.java
@@ -18,9 +18,19 @@
  */
 package groovy.bugs.groovy8531;
 
-public class Reducer {
+class BaseReducer {
+    public abstract class PublicBaseContext {}
+    protected abstract class ProtectedBaseContext {}
+    public static abstract class PublicStaticBaseContext {}
+    protected static abstract class ProtectedStaticBaseContext {}
+    private abstract class PrivateBaseContext {}
+}
+
+public class Reducer extends BaseReducer {
     public abstract class PublicContext {}
     protected abstract class ProtectedContext {}
+    public static abstract class PublicStaticContext {}
+    protected static abstract class ProtectedStaticContext {}
     private abstract class PrivateContext {}
 
     public enum Type {


[3/4] groovy git commit: Trivial refactoring: avoid unnecessary `StringBuffer` usage

Posted by su...@apache.org.
Trivial refactoring: avoid unnecessary `StringBuffer` usage

Java compiler will optimize strings concatenation

(cherry picked from commit 79d90ec)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 75b06256e9847925a2ffa5b2f1bbdd0b3507c228
Parents: 09070aa
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Apr 6 14:49:28 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Apr 6 15:07:38 2018 +0800

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/control/ResolveVisitor.java     | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/75b06256/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 bc3630f..20d4f8f 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -460,11 +460,9 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
 
     private static String replaceLastPoint(String name) {
         int lastPoint = name.lastIndexOf('.');
-        name = new StringBuffer()
-                .append(name.substring(0, lastPoint))
-                .append("$")
-                .append(name.substring(lastPoint + 1))
-                .toString();
+        name = name.substring(0, lastPoint) +
+                "$" +
+                name.substring(lastPoint + 1);
         return name;
     }
 


[2/4] groovy git commit: Trivial refactoring: extract variable

Posted by su...@apache.org.
Trivial refactoring: extract variable

(cherry picked from commit ebdfa19)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 09070aa7f3ead44b89b92de8dd29e3fd9274259d
Parents: de0cba8
Author: danielsun1106 <re...@hotmail.com>
Authored: Fri Apr 6 14:46:13 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Fri Apr 6 15:07:34 2018 +0800

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/control/ResolveVisitor.java  | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/09070aa7/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 6065a6d..bc3630f 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -368,15 +368,17 @@ public class ResolveVisitor extends ClassCodeExpressionTransformer {
         // test if vanilla name is current class name
         if (currentClass == type) return true;
 
-        if (genericParameterNames.get(type.getName()) != null) {
-            GenericsType gt = genericParameterNames.get(type.getName());
+        String typeName = type.getName();
+
+        if (genericParameterNames.get(typeName) != null) {
+            GenericsType gt = genericParameterNames.get(typeName);
             type.setRedirect(gt.getType());
-            type.setGenericsTypes(new GenericsType[]{gt});
+            type.setGenericsTypes(new GenericsType[]{ gt });
             type.setGenericsPlaceHolder(true);
             return true;
         }
 
-        if (currentClass.getNameWithoutPackage().equals(type.getName())) {
+        if (currentClass.getNameWithoutPackage().equals(typeName)) {
             type.setRedirect(currentClass);
             return true;
         }