groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-7014: minor prefactor
Date Fri, 12 Aug 2016 03:27:15 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 8071d118e -> 02ffc25e4


GROOVY-7014: minor prefactor


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

Branch: refs/heads/master
Commit: 02ffc25e4d24498c9822e9432fefc29e39860514
Parents: 8071d11
Author: paulk <paulk@asert.com.au>
Authored: Fri Aug 12 13:27:03 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Fri Aug 12 13:27:03 2016 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/ast/ClassNode.java |  6 +--
 .../groovy/control/StaticImportVisitor.java     | 52 +++++++++++++++-----
 .../codehaus/groovy/control/StaticVerifier.java | 22 ++++++---
 .../groovy/bugs/ConstructorThisCallBug.groovy   | 39 ++++++---------
 4 files changed, 72 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/02ffc25e/src/main/org/codehaus/groovy/ast/ClassNode.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/ast/ClassNode.java b/src/main/org/codehaus/groovy/ast/ClassNode.java
index 221b946..c6e8254 100644
--- a/src/main/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/org/codehaus/groovy/ast/ClassNode.java
@@ -100,8 +100,6 @@ import java.util.Set;
  * by the class are needed, then a call to {@link #redirect()} will help.
  *
  * @see org.codehaus.groovy.ast.ClassHelper
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
- * @author Jochen Theodorou
  */
 public class ClassNode extends AnnotatedNode implements Opcodes {
     private static class MapOfLists {
@@ -1307,10 +1305,10 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
         } else if (arguments instanceof MapExpression) {
             count = 1;
         }
-        
+
         for (MethodNode method : getMethods(name)) {
             if(method.isStatic()) {
-                Parameter[] parameters = method.getParameters(); 
+                Parameter[] parameters = method.getParameters();
                 if (parameters.length == count) return true;
 
                 // handle varargs case

http://git-wip-us.apache.org/repos/asf/groovy/blob/02ffc25e/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/StaticImportVisitor.java b/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
index 84b8156..945cc86 100644
--- a/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
+++ b/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
@@ -18,20 +18,44 @@
  */
 package org.codehaus.groovy.control;
 
-import static org.codehaus.groovy.runtime.MetaClassHelper.capitalize;
-
-import org.codehaus.groovy.ast.*;
-import org.codehaus.groovy.ast.expr.*;
+import org.codehaus.groovy.ast.AnnotatedNode;
+import org.codehaus.groovy.ast.AnnotationNode;
+import org.codehaus.groovy.ast.ClassCodeExpressionTransformer;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.DynamicVariable;
+import org.codehaus.groovy.ast.FieldNode;
+import org.codehaus.groovy.ast.ImportNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.ModuleNode;
+import org.codehaus.groovy.ast.PropertyNode;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.expr.AnnotationConstantExpression;
+import org.codehaus.groovy.ast.expr.ArgumentListExpression;
+import org.codehaus.groovy.ast.expr.BinaryExpression;
+import org.codehaus.groovy.ast.expr.ClassExpression;
+import org.codehaus.groovy.ast.expr.ClosureExpression;
+import org.codehaus.groovy.ast.expr.ConstantExpression;
+import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
+import org.codehaus.groovy.ast.expr.EmptyExpression;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.ListExpression;
+import org.codehaus.groovy.ast.expr.MapEntryExpression;
+import org.codehaus.groovy.ast.expr.MethodCallExpression;
+import org.codehaus.groovy.ast.expr.NamedArgumentListExpression;
+import org.codehaus.groovy.ast.expr.PropertyExpression;
+import org.codehaus.groovy.ast.expr.StaticMethodCallExpression;
+import org.codehaus.groovy.ast.expr.TupleExpression;
+import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.ast.stmt.Statement;
 import org.codehaus.groovy.syntax.Types;
 
-import java.util.*;
+import java.util.List;
+import java.util.Map;
+
+import static org.codehaus.groovy.runtime.MetaClassHelper.capitalize;
 
 /**
  * Visitor to resolve constants and method calls from static Imports
- *
- * @author Jochen Theodorou
- * @author Paul King
  */
 public class StaticImportVisitor extends ClassCodeExpressionTransformer {
     private ClassNode currentClass;
@@ -509,15 +533,19 @@ public class StaticImportVisitor extends ClassCodeExpressionTransformer
{
         return accessor;
     }
 
-    private static boolean hasStaticProperty(ClassNode staticImportType, String propName)
{
-        ClassNode classNode = staticImportType;
+    private static boolean hasStaticProperty(ClassNode cNode, String propName) {
+        return getStaticProperty(cNode, propName) != null;
+    }
+
+    private static PropertyNode getStaticProperty(ClassNode cNode, String propName) {
+        ClassNode classNode = cNode;
         while (classNode != null) {
             for (PropertyNode pn : classNode.getProperties()) {
-                if (pn.getName().equals(propName) && pn.isStatic()) return true;
+                if (pn.getName().equals(propName) && pn.isStatic()) return pn;
             }
             classNode = classNode.getSuperClass();
         }
-        return false;
+        return null;
     }
 
     private Expression findStaticPropertyAccessorByFullName(ClassNode staticImportType, String
accessorMethodName) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/02ffc25e/src/main/org/codehaus/groovy/control/StaticVerifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/control/StaticVerifier.java b/src/main/org/codehaus/groovy/control/StaticVerifier.java
index 1cb8e49..7c70bd4 100644
--- a/src/main/org/codehaus/groovy/control/StaticVerifier.java
+++ b/src/main/org/codehaus/groovy/control/StaticVerifier.java
@@ -18,8 +18,20 @@
  */
 package org.codehaus.groovy.control;
 
-import org.codehaus.groovy.ast.*;
-import org.codehaus.groovy.ast.expr.*;
+import org.codehaus.groovy.ast.ClassCodeVisitorSupport;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.CodeVisitorSupport;
+import org.codehaus.groovy.ast.DynamicVariable;
+import org.codehaus.groovy.ast.FieldNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.Variable;
+import org.codehaus.groovy.ast.expr.ClosureExpression;
+import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.MethodCallExpression;
+import org.codehaus.groovy.ast.expr.PropertyExpression;
+import org.codehaus.groovy.ast.expr.VariableExpression;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -28,14 +40,10 @@ import java.util.List;
 
 /**
  * Verifier to check non-static access in static contexts
- *
- * @author Jochen Theodorou
- * @author Paul King
- * @author <a href="mailto:roshandawrani@codehaus.org">Roshan Dawrani</a>
  */
 public class StaticVerifier extends ClassCodeVisitorSupport {
     private boolean inSpecialConstructorCall;
-    private boolean inPropertyExpression;
+    private boolean inPropertyExpression; // TODO use it or lose it
     private boolean inClosure;
     private MethodNode currentMethod;
     private SourceUnit source;

http://git-wip-us.apache.org/repos/asf/groovy/blob/02ffc25e/src/test/groovy/bugs/ConstructorThisCallBug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/ConstructorThisCallBug.groovy b/src/test/groovy/bugs/ConstructorThisCallBug.groovy
index fd70783..4f5c88b 100644
--- a/src/test/groovy/bugs/ConstructorThisCallBug.groovy
+++ b/src/test/groovy/bugs/ConstructorThisCallBug.groovy
@@ -16,34 +16,25 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-/**
- * ConstructorThisCallBug.groovy
- *
- *     Test Script for the Jira issue: GROOVY-994.
- *
- * @author    Pilho Kim
- * @date      2005.08.05.06.21
- */
-
 package groovy.bugs
 
-public class ConstructorThisCallBug extends GroovyTestCase {
-    public void testCallA() {
-        def a1 = new ConstructorCallA("foo")
-        def a2 = new ConstructorCallA(9) 
-        def a3 = new ConstructorCallA() 
+class ConstructorThisCallBug extends GroovyTestCase {
+    // GROOVY-994
+    void testCallA() {
+        assert new ConstructorCallA("foo").toString() == 'foo'
+        assert new ConstructorCallA(9).toString() == '81'
+        assert new ConstructorCallA().toString() == '100'
     }
-}
 
-public class ConstructorCallA { 
-    public ConstructorCallA() {
-        this(19)               // call another constructor
-    }
+    private static class ConstructorCallA {
+        private String a
 
-    public ConstructorCallA(String a) {
-    }
+        ConstructorCallA(String a) { this.a = a }
+
+        ConstructorCallA(int a) { this("" + (a * a)) } // call another constructor
 
-    public ConstructorCallA(int a) {
-        this("" + (a*a))       // call another constructor
+        ConstructorCallA() { this(10) } // call another constructor
+
+        String toString() { a }
     }
-} 
+}


Mime
View raw message