groovy-commits mailing list archives

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

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


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

commit f077909b0c125c6d95d5b5c33cb1be569a9f3e67
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 1c4837c..b52185f 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 2075e00..aa5a7d9 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -24,6 +24,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;
@@ -394,7 +395,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 263d370..b96be1d 100644
--- a/src/test/org/codehaus/groovy/transform/InheritConstructorsTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/InheritConstructorsTransformTest.groovy
@@ -222,4 +222,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