You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/08/25 23:55:19 UTC

[1/2] groovy git commit: GROOVY-7917: Sub class can't override final static property (closes #394)

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X fe2a2d655 -> 24f432860


GROOVY-7917: Sub class can't override final static property (closes #394)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 9696abeae11d6eaa9e2c629861b6b6e52785288e
Parents: fe2a2d6
Author: paulk <pa...@asert.com.au>
Authored: Thu Aug 25 10:47:47 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Aug 25 16:46:24 2016 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/ast/ClassNode.java | 10 ++++--
 .../org/codehaus/groovy/classgen/Verifier.java  | 15 +++++---
 src/test/groovy/bugs/Groovy7917Bug.groovy       | 36 ++++++++++++++++++++
 3 files changed, 54 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9696abea/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 12994ed..8c53441 100644
--- a/src/main/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/org/codehaus/groovy/ast/ClassNode.java
@@ -1078,6 +1078,10 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     }
 
     public MethodNode getGetterMethod(String getterName) {
+        return getGetterMethod(getterName, true);
+    }
+
+    public MethodNode getGetterMethod(String getterName, boolean searchSuperClasses) {
         MethodNode getterMethod = null;
         for (MethodNode method : getDeclaredMethods(getterName)) {
             if (getterName.equals(method.getName())
@@ -1093,8 +1097,10 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
             }
         }
         if (getterMethod != null) return getterMethod;
-        ClassNode parent = getSuperClass();
-        if (parent!=null) return parent.getGetterMethod(getterName);
+        if (searchSuperClasses) {
+            ClassNode parent = getSuperClass();
+            if (parent != null) return parent.getGetterMethod(getterName);
+        }
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/9696abea/src/main/org/codehaus/groovy/classgen/Verifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/Verifier.java b/src/main/org/codehaus/groovy/classgen/Verifier.java
index 067cbfc..c3d01e6 100644
--- a/src/main/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/org/codehaus/groovy/classgen/Verifier.java
@@ -610,15 +610,15 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
 
         // GROOVY-3726: clear volatile, transient modifiers so that they don't get applied to methods
         if ((propNodeModifiers & Modifier.VOLATILE) != 0) {
-            propNodeModifiers = propNodeModifiers - Modifier.VOLATILE;
+            propNodeModifiers -= Modifier.VOLATILE;
         }
         if ((propNodeModifiers & Modifier.TRANSIENT) != 0) {
-            propNodeModifiers = propNodeModifiers - Modifier.TRANSIENT;
+            propNodeModifiers -= Modifier.TRANSIENT;
         }
 
         Statement getterBlock = node.getGetterBlock();
         if (getterBlock == null) {
-            MethodNode getter = classNode.getGetterMethod(getterName);
+            MethodNode getter = classNode.getGetterMethod(getterName, !node.isStatic());
             if (getter == null && ClassHelper.boolean_TYPE == node.getType()) {
                 String secondGetterName = "is" + capitalize(name);
                 getter = classNode.getGetterMethod(secondGetterName);
@@ -638,9 +638,14 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
             }
         }
 
+        int getterModifiers = propNodeModifiers;
+        // don't make static accessors final
+        if (node.isStatic() && (propNodeModifiers & Modifier.FINAL) != 0) {
+            getterModifiers -= Modifier.FINAL;
+        }
         if (getterBlock != null) {
             MethodNode getter =
-                    new MethodNode(getterName, propNodeModifiers, node.getType(), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock);
+                    new MethodNode(getterName, getterModifiers, node.getType(), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock);
             getter.setSynthetic(true);
             addPropertyMethod(getter);
             visitMethod(getter);
@@ -648,7 +653,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
             if (ClassHelper.boolean_TYPE == node.getType() || ClassHelper.Boolean_TYPE == node.getType()) {
                 String secondGetterName = "is" + capitalize(name);
                 MethodNode secondGetter =
-                        new MethodNode(secondGetterName, propNodeModifiers, node.getType(), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock);
+                        new MethodNode(secondGetterName, getterModifiers, node.getType(), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock);
                 secondGetter.setSynthetic(true);
                 addPropertyMethod(secondGetter);
                 visitMethod(secondGetter);

http://git-wip-us.apache.org/repos/asf/groovy/blob/9696abea/src/test/groovy/bugs/Groovy7917Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7917Bug.groovy b/src/test/groovy/bugs/Groovy7917Bug.groovy
new file mode 100644
index 0000000..7016cd3
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7917Bug.groovy
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+class Groovy7917Bug extends GroovyTestCase {
+    void testShouldBeAbleToOverrideStaticConstantProperties() {
+        assertScript '''
+            class Base {
+                static final String CONST = "Base Class"
+            }
+
+            class Derived extends Base {
+                static final String CONST = "Derived Class"
+            }
+
+            assert Base.CONST == 'Base Class'
+            assert Derived.CONST == 'Derived Class'
+        '''
+    }
+}


[2/2] groovy git commit: GROOVY-7912: MissingPropertyException when referencing a static import in a closure's optional parameters

Posted by pa...@apache.org.
GROOVY-7912: MissingPropertyException when referencing a static import in a closure's optional parameters


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 24f432860b5b9699ae80d745d62f80be377273bd
Parents: 9696abe
Author: paulk <pa...@asert.com.au>
Authored: Tue Aug 23 13:26:54 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri Aug 26 09:54:32 2016 +1000

----------------------------------------------------------------------
 .../groovy/control/StaticImportVisitor.java     |  8 +++++
 src/test/groovy/bugs/Groovy7912Bug.groovy       | 34 ++++++++++++++++++++
 2 files changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/24f43286/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 945cc86..2841d7a 100644
--- a/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
+++ b/src/main/org/codehaus/groovy/control/StaticImportVisitor.java
@@ -27,6 +27,7 @@ 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.Parameter;
 import org.codehaus.groovy.ast.PropertyNode;
 import org.codehaus.groovy.ast.Variable;
 import org.codehaus.groovy.ast.expr.AnnotationConstantExpression;
@@ -341,6 +342,13 @@ public class StaticImportVisitor extends ClassCodeExpressionTransformer {
     protected Expression transformClosureExpression(ClosureExpression ce) {
         boolean oldInClosure = inClosure;
         inClosure = true;
+        if (ce.getParameters() != null) {
+            for (Parameter p : ce.getParameters()) {
+                if (p.hasInitialExpression()) {
+                    p.setInitialExpression(transform(p.getInitialExpression()));
+                }
+            }
+        }
         Statement code = ce.getCode();
         if (code != null) code.visit(this);
         inClosure = oldInClosure;

http://git-wip-us.apache.org/repos/asf/groovy/blob/24f43286/src/test/groovy/bugs/Groovy7912Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7912Bug.groovy b/src/test/groovy/bugs/Groovy7912Bug.groovy
new file mode 100644
index 0000000..005974c
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7912Bug.groovy
@@ -0,0 +1,34 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import static java.util.Collections.EMPTY_LIST
+import static java.util.Collections.emptyList
+
+class Groovy7912Bug extends GroovyTestCase {
+    void testClosureWithStaticImportProperty() {
+        Closure closure = { List list = EMPTY_LIST -> list.size() }
+        assert closure() == 0
+    }
+
+    void testClosureWithStaticImportMethod() {
+        Closure closure = { List list = emptyList() -> list.size() }
+        assert closure() == 0
+    }
+}
\ No newline at end of file