groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch GROOVY_3_0_X updated: GROOVY-9323: AST for precompiled classes loaded from the classpath does not contain constructor annotation information
Date Tue, 03 Dec 2019 21:53:43 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 47d72e2  GROOVY-9323: AST for precompiled classes loaded from the classpath does
not contain constructor annotation information
47d72e2 is described below

commit 47d72e2fdbb84cd5dffc2e423502093549a298e1
Author: Paul King <paulk@asert.com.au>
AuthorDate: Tue Dec 3 22:53:30 2019 +1000

    GROOVY-9323: AST for precompiled classes loaded from the classpath does not contain constructor
annotation information
---
 .../transform/InheritConstructorsASTTransformation.java |  2 +-
 .../java/org/codehaus/groovy/vmplugin/v5/Java5.java     |  4 +++-
 .../transform/InheritConstructorsTransformTest.groovy   | 17 ++++++++++++++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
index 254b087..d9cd063 100644
--- a/src/main/java/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/InheritConstructorsASTTransformation.java
@@ -96,7 +96,7 @@ public class InheritConstructorsASTTransformation extends AbstractASTTransformat
         if (isExisting(classNode, params)) return;
         ConstructorNode added = addGeneratedConstructor(classNode, consNode.getModifiers(),
params, consNode.getExceptions(), block(ctorSuperS(args(theArgs))));
         if (copyConstructorAnnotations) {
-            added.addAnnotations(copyAnnotatedNodeAnnotations(consNode, ANNOTATION));
+            added.addAnnotations(copyAnnotatedNodeAnnotations(consNode, ANNOTATION, false));
         }
     }
 
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index 0f3b668..db0fc3f 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -26,6 +26,7 @@ import org.codehaus.groovy.ast.AnnotationNode;
 import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.CompileUnit;
+import org.codehaus.groovy.ast.ConstructorNode;
 import org.codehaus.groovy.ast.FieldNode;
 import org.codehaus.groovy.ast.GenericsType;
 import org.codehaus.groovy.ast.MethodNode;
@@ -396,7 +397,8 @@ public class Java5 implements VMPlugin {
                 }
                 Parameter[] params = params1;
                 ClassNode[] exceptions = makeClassNodes(compileUnit, ctor.getGenericExceptionTypes(),
ctor.getExceptionTypes());
-                classNode.addConstructor(ctor.getModifiers(), params, exceptions, null);
+                ConstructorNode cn = classNode.addConstructor(ctor.getModifiers(), params,
exceptions, null);
+                setAnnotationMetaData(ctor.getAnnotations(), cn);
             }
 
             Class sc = clazz.getSuperclass();
diff --git a/src/test/org/codehaus/groovy/transform/InheritConstructorsTransformTest.groovy
b/src/test/org/codehaus/groovy/transform/InheritConstructorsTransformTest.groovy
index 03230ff..c3f1aea 100644
--- a/src/test/org/codehaus/groovy/transform/InheritConstructorsTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/InheritConstructorsTransformTest.groovy
@@ -224,4 +224,19 @@ class InheritConstructorsTransformTest extends GroovyShellTestCase {
         assert message.contains('Cannot call OrderPublisher <RoundingMode>#<init>(java.util.Set
<RoundingMode>) with arguments [java.util.HashSet <Date>]')
     }
 
-}
\ No newline at end of file
+    // GROOVY-9323
+    void testAnnotationsCopiedForConstructorsFromPrecompiledClass() {
+        assertScript '''
+            @groovy.transform.InheritConstructors(constructorAnnotations=true)
+            class MyChildException extends org.codehaus.groovy.transform.MyException9323
{}
+
+            def annos = MyChildException.constructors[0].annotations*.annotationType().simpleName
+            assert annos.contains('Generated') && annos.contains('Deprecated')
+        '''
+    }
+}
+
+class MyException9323 extends RuntimeException {
+    @Deprecated
+    MyException9323() {}
+}


Mime
View raw message