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 2021/04/01 04:30:38 UTC
[groovy] 01/10: GROOVY-9993: Field and a property with the same
name: clarification of boundary cases (package scope should know about
split properties)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 33d033a39cf91c39359c1afab92d7e4ea19fbec4
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Mar 30 20:57:03 2021 +1000
GROOVY-9993: Field and a property with the same name: clarification of boundary cases (package scope should know about split properties)
---
.../transform/PackageScopeASTTransformation.java | 25 ++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/PackageScopeASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/PackageScopeASTTransformation.java
index 9a9bc9f..22ac1a3 100644
--- a/src/main/java/org/codehaus/groovy/transform/PackageScopeASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/PackageScopeASTTransformation.java
@@ -136,12 +136,13 @@ public class PackageScopeASTTransformation extends AbstractASTTransformation {
}
}
- private static void visitFieldNode(FieldNode fNode) {
+ private void visitFieldNode(FieldNode fNode) {
final ClassNode cNode = fNode.getDeclaringClass();
final List<PropertyNode> pList = cNode.getProperties();
PropertyNode foundProp = null;
+ String fName = fNode.getName();
for (PropertyNode pNode : pList) {
- if (pNode.getName().equals(fNode.getName())) {
+ if (pNode.getName().equals(fName) && pNode.getAnnotations(MY_TYPE) != null) {
foundProp = pNode;
break;
}
@@ -149,6 +150,26 @@ public class PackageScopeASTTransformation extends AbstractASTTransformation {
if (foundProp != null) {
revertVisibility(fNode);
pList.remove(foundProp);
+ // now check for split property
+ foundProp = null;
+ for (PropertyNode pNode : pList) {
+ if (pNode.getName().equals(fName)) {
+ foundProp = pNode;
+ break;
+ }
+ }
+ if (foundProp != null) {
+ FieldNode oldField = foundProp.getField();
+ cNode.getFields().remove(oldField);
+ cNode.getFieldIndex().put(fName, fNode);
+ if (foundProp.hasInitialExpression()) {
+ if (fNode.hasInitialExpression()) {
+ addError("The split property definition named '" + fName + "' must not have an initial value for both the field and the property", fNode);
+ }
+ fNode.setInitialValueExpression(foundProp.getInitialExpression());
+ }
+ foundProp.setField(fNode);
+ }
}
}