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:20 UTC
[2/2] groovy git commit: GROOVY-7912: MissingPropertyException when
referencing a static import in a closure's optional parameters
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