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 2023/05/21 22:04:43 UTC
[groovy] branch GROOVY_4_0_X updated (357a3020ba -> 1d53803121)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a change to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
from 357a3020ba GROOVY-10067, GROOVY-11057: better `parameterizeType` result
new d1a37dca68 GROOVY-11062: Annotation collection isn't properly handling enum annotation attribute values
new 1d53803121 GROOVY-11062: Annotation collection isn't properly handling enum annotation attribute values (add test case)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../groovy/tools/javac/JavaStubGenerator.java | 2 ++
.../transform/AnnotationCollectorTransform.java | 11 ++++++++-
.../bugs/{Groovy9238.groovy => Groovy11062.groovy} | 26 +++++++++++-----------
3 files changed, 25 insertions(+), 14 deletions(-)
copy src/test/groovy/bugs/{Groovy9238.groovy => Groovy11062.groovy} (70%)
[groovy] 02/02: GROOVY-11062: Annotation collection isn't properly handling enum annotation attribute values (add test case)
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 1d53803121fc2ca82e493b0e7717717d9abb2899
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed May 17 20:06:45 2023 +1000
GROOVY-11062: Annotation collection isn't properly handling enum annotation attribute values (add test case)
---
src/test/groovy/bugs/Groovy11062.groovy | 53 +++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/src/test/groovy/bugs/Groovy11062.groovy b/src/test/groovy/bugs/Groovy11062.groovy
new file mode 100644
index 0000000000..9105ac6d46
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy11062.groovy
@@ -0,0 +1,53 @@
+/*
+ * 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 groovy.transform.AnnotationCollector
+import groovy.transform.CompileStatic
+import groovy.transform.NullCheck
+import groovy.transform.RecordType
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy11062 {
+
+ @Test
+ void testAnnotationCollectorOfCollectedAnnotations() {
+ assertScript '''
+ import groovy.bugs.Groovy11062.Collector11062
+
+ @Collector11062
+ class Pogo11062 {
+ String x
+ String y = 'y'
+ }
+
+ assert new Pogo11062('A').toString() == 'Pogo11062[x=A, y=y]'
+ assert new Pogo11062('A', 'B').toString() == 'Pogo11062[x=A, y=B]'
+ '''
+ }
+
+ @NullCheck
+ @RecordType
+ @AnnotationCollector
+ @interface Collector11062 {
+ }
+}
[groovy] 01/02: GROOVY-11062: Annotation collection isn't properly handling enum annotation attribute values
Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit d1a37dca68f7c37e2f79a6aa871e330f43381830
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed May 17 19:49:13 2023 +1000
GROOVY-11062: Annotation collection isn't properly handling enum annotation attribute values
---
.../org/codehaus/groovy/tools/javac/JavaStubGenerator.java | 2 ++
.../groovy/transform/AnnotationCollectorTransform.java | 11 ++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 0dd350ec95..0ad3be579e 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -987,6 +987,8 @@ public class JavaStubGenerator {
val = writer.toString();
} else if (constValue instanceof Number || constValue instanceof Boolean) {
val = constValue.toString();
+ } else if (constValue instanceof Enum) {
+ val = constValue.getClass().getName() + "." + constValue.toString();
} else {
val = "\"" + escapeSpecialChars(constValue.toString()) + "\"";
replaceDollars = false;
diff --git a/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java b/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
index 0505a6ae06..2c5e090f30 100644
--- a/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
+++ b/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
@@ -52,6 +52,8 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
import static org.codehaus.groovy.transform.trait.TraitComposer.COMPILESTATIC_CLASSNODE;
import static org.objectweb.asm.Opcodes.ACC_ABSTRACT;
import static org.objectweb.asm.Opcodes.ACC_ANNOTATION;
@@ -158,7 +160,8 @@ public class AnnotationCollectorTransform {
if (e instanceof AnnotationConstantExpression) {
AnnotationConstantExpression ace = (AnnotationConstantExpression) e;
return serialize((AnnotationNode) ace.getValue());
- } else if (e instanceof ListExpression) {
+ }
+ if (e instanceof ListExpression) {
boolean annotationConstant = false;
ListExpression le = (ListExpression) e;
List<Expression> list = le.getExpressions();
@@ -171,6 +174,12 @@ public class AnnotationCollectorTransform {
if (annotationConstant) type = type.makeArray();
return new ArrayExpression(type, newList);
}
+ if (e instanceof ConstantExpression) {
+ Object obj = ((ConstantExpression) e).getValue();
+ if (obj instanceof Enum) {
+ return propX(classX(obj.getClass()), e);
+ }
+ }
return e;
}