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 2018/09/16 03:49:14 UTC
[1/2] groovy git commit: GROOVY-8797:
VariableScopeVisitor.getPropertyName does not check for isser style methods
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_5_X 1191f058d -> e958c362b
GROOVY-8797: VariableScopeVisitor.getPropertyName does not check for isser style methods
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/11627d90
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/11627d90
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/11627d90
Branch: refs/heads/GROOVY_2_5_X
Commit: 11627d90f16a798067986038cb09b29a1e482ecc
Parents: 1191f05
Author: Eric Milles <er...@thomsonreuters.com>
Authored: Sun Sep 16 12:25:43 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Sun Sep 16 13:48:32 2018 +1000
----------------------------------------------------------------------
.../groovy/ast/tools/MethodNodeUtils.java | 29 +++++++++++++++
.../groovy/classgen/VariableScopeVisitor.java | 27 +++++---------
src/test/groovy/bugs/Groovy8797Bug.groovy | 38 ++++++++++++++++++++
.../stc/FieldsAndPropertiesSTCTest.groovy | 4 +--
4 files changed, 78 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/11627d90/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
index 94427f0..a3597bd 100644
--- a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
@@ -18,9 +18,13 @@
*/
package org.apache.groovy.ast.tools;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
+import static org.apache.groovy.util.BeanUtils.decapitalize;
+
/**
* Utility class for working with MethodNodes
*/
@@ -65,5 +69,30 @@ public class MethodNodeUtils {
return sb.toString();
}
+ /**
+ * For a method node potentially representing a property, returns the name of the property.
+ *
+ * @param mNode a MethodNode
+ * @return the property name without the get/set/is prefix if a property or null
+ */
+ public static String getPropertyName(MethodNode mNode) {
+ String name = mNode.getName();
+ if (name.startsWith("set") || name.startsWith("get") || name.startsWith("is")) {
+ String pname = decapitalize(name.substring(name.startsWith("is") ? 2 : 3));
+ if (!pname.isEmpty()) {
+ if (name.startsWith("set")) {
+ if (mNode.getParameters().length == 1) {
+ return pname;
+ }
+ } else if (mNode.getParameters().length == 0 && !ClassHelper.VOID_TYPE.equals(mNode.getReturnType())) {
+ if (name.startsWith("get") || ClassHelper.boolean_TYPE.equals(mNode.getReturnType())) {
+ return pname;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
private MethodNodeUtils() { }
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/11627d90/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index 088a6d9..1c1366b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -58,6 +58,7 @@ import java.util.List;
import java.util.Map;
import static java.lang.reflect.Modifier.isFinal;
+import static org.apache.groovy.ast.tools.MethodNodeUtils.getPropertyName;
/**
* goes through an AST and initializes the scopes
@@ -187,8 +188,14 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
for (MethodNode mn : cn.getMethods()) {
String pName = getPropertyName(mn);
- if (pName != null && pName.equals(name))
- return new PropertyNode(pName, mn.getModifiers(), ClassHelper.OBJECT_TYPE, cn, null, null, null);
+ if (name.equals(pName)) {
+ PropertyNode property = new PropertyNode(name, mn.getModifiers(), ClassHelper.OBJECT_TYPE, cn, null, null, null);
+ property.getField().setHasNoRealSourcePosition(true);
+ property.getField().setSynthetic(true);
+ property.getField().setDeclaringClass(cn);
+ property.setDeclaringClass(cn);
+ return property;
+ }
}
for (PropertyNode pn : cn.getProperties()) {
@@ -200,22 +207,6 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
return findClassMember(cn.getOuterClass(), name);
}
- private static String getPropertyName(MethodNode m) {
- String name = m.getName();
- if (!(name.startsWith("set") || name.startsWith("get"))) return null;
- String pname = name.substring(3);
- if (pname.length() == 0) return null;
- pname = java.beans.Introspector.decapitalize(pname);
-
- if (name.startsWith("get") && (m.getReturnType() == ClassHelper.VOID_TYPE || m.getParameters().length != 0)) {
- return null;
- }
- if (name.startsWith("set") && m.getParameters().length != 1) {
- return null;
- }
- return pname;
- }
-
// -------------------------------
// different Variable based checks
// -------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/11627d90/src/test/groovy/bugs/Groovy8797Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8797Bug.groovy b/src/test/groovy/bugs/Groovy8797Bug.groovy
new file mode 100644
index 0000000..a5c35be
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8797Bug.groovy
@@ -0,0 +1,38 @@
+/*
+ * 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 gls.CompilableTestSupport
+
+class Groovy8797Bug extends CompilableTestSupport {
+ void testStaticBooleanIsPropertyInStaticContext() {
+ shouldCompile """
+ class C {
+ static Object getFoo() {}
+ static boolean isBar() {}
+ static void setBaz(to) {}
+ static void main(args) {
+ foo
+ bar
+ baz = null
+ }
+ }
+ """
+ }
+}
http://git-wip-us.apache.org/repos/asf/groovy/blob/11627d90/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index a99b27a..91834e1 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -637,7 +637,7 @@ import org.codehaus.groovy.ast.stmt.AssertStatement
void testPropertyAssignmentInSubClassAndMultiSetter() {
10.times {
- assertScript '''import org.codehaus.groovy.ast.PropertyNode
+ assertScript '''
public class Activity {
int debug
@@ -665,7 +665,7 @@ import org.codehaus.groovy.ast.stmt.AssertStatement
void testPropertyAssignmentInSubClassAndMultiSetterThroughDelegation() {
10.times {
- assertScript '''import org.codehaus.groovy.ast.PropertyNode
+ assertScript '''
public class Activity {
int debug
[2/2] groovy git commit: GROOVY-2335: record contributor for StAX
builder
Posted by pa...@apache.org.
GROOVY-2335: record contributor for StAX builder
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e958c362
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e958c362
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e958c362
Branch: refs/heads/GROOVY_2_5_X
Commit: e958c362b7318e9dcd6363b6f990b3982184b77f
Parents: 11627d9
Author: Paul King <pa...@asert.com.au>
Authored: Sun Sep 16 13:04:27 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Sun Sep 16 13:48:34 2018 +1000
----------------------------------------------------------------------
gradle/pomconfigurer.gradle | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/e958c362/gradle/pomconfigurer.gradle
----------------------------------------------------------------------
diff --git a/gradle/pomconfigurer.gradle b/gradle/pomconfigurer.gradle
index 681b012..0a54ebf 100644
--- a/gradle/pomconfigurer.gradle
+++ b/gradle/pomconfigurer.gradle
@@ -639,6 +639,9 @@ project.ext.pomConfigureClosureWithoutTweaks = {
contributor {
name 'Ben Yu'
}
+ contributor {
+ name 'Dejan Bosanac'
+ }
}
mailingLists {
mailingList {