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/08/08 04:32:46 UTC

[groovy] 01/02: GROOVY-10121: @AnnotationCollector does not work with JUnit 5

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

commit 6b8519c46e0b5aace734c8f90c1633f3424e2931
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Aug 7 01:34:07 2021 +1000

    GROOVY-10121: @AnnotationCollector does not work with JUnit 5
---
 .../transform/AnnotationCollectorTransform.java    |  2 +-
 .../AnnotationCollectorReflectionTest.groovy       | 29 ++++++++++++++++++++++
 .../groovy10121/SomeCollectedAnnotations.groovy    | 24 ++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java b/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
index e256fc0..6f39a70 100644
--- a/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
+++ b/src/main/java/org/codehaus/groovy/transform/AnnotationCollectorTransform.java
@@ -122,7 +122,7 @@ public class AnnotationCollectorTransform {
                 // force no interfaces implemented
                 helper.setInterfaces(ClassNode.EMPTY_ARRAY);
             } else {
-                helper = new InnerClassNode(cn.getPlainNodeReference(), cn.getName() + "$CollectorHelper",
+                helper = new InnerClassNode(cn, cn.getName() + "$CollectorHelper",
                         ACC_PUBLIC | ACC_STATIC | ACC_FINAL, ClassHelper.OBJECT_TYPE.getPlainNodeReference());
                 cn.getModule().addClass(helper);
                 helper.addAnnotation(new AnnotationNode(COMPILESTATIC_CLASSNODE));
diff --git a/src/test/groovy/bugs/groovy10121/AnnotationCollectorReflectionTest.groovy b/src/test/groovy/bugs/groovy10121/AnnotationCollectorReflectionTest.groovy
new file mode 100644
index 0000000..505279a
--- /dev/null
+++ b/src/test/groovy/bugs/groovy10121/AnnotationCollectorReflectionTest.groovy
@@ -0,0 +1,29 @@
+/*
+ *  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.groovy10121
+
+import org.junit.Test
+
+final class AnnotationCollectorReflectionTest {
+    @Test
+    void testHelperIsVisibleAsInnerClass() {
+        def innerNames = SomeCollectedAnnotations.classes*.name
+        assert innerNames.contains('groovy.bugs.groovy10121.SomeCollectedAnnotations$CollectorHelper')
+    }
+}
diff --git a/src/test/groovy/bugs/groovy10121/SomeCollectedAnnotations.groovy b/src/test/groovy/bugs/groovy10121/SomeCollectedAnnotations.groovy
new file mode 100644
index 0000000..d7dd5cc
--- /dev/null
+++ b/src/test/groovy/bugs/groovy10121/SomeCollectedAnnotations.groovy
@@ -0,0 +1,24 @@
+/*
+ *  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.groovy10121
+
+import groovy.transform.AnnotationCollector
+
+@AnnotationCollector
+@interface SomeCollectedAnnotations { }