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 2020/08/27 01:04:11 UTC

[groovy] branch master updated: GROOVY-9702: source retention for @ASTTest and improved AST modification (closes #1352)

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


The following commit(s) were added to refs/heads/master by this push:
     new 74c37bd  GROOVY-9702: source retention for @ASTTest and improved AST modification (closes #1352)
74c37bd is described below

commit 74c37bdd7979c4461862e14c2016e74679dbd3d2
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Aug 25 12:14:50 2020 -0500

    GROOVY-9702: source retention for @ASTTest and improved AST modification (closes #1352)
---
 .../org/codehaus/groovy/transform/ASTTestTransformation.groovy      | 6 +++++-
 src/main/java/groovy/transform/ASTTest.java                         | 5 +++--
 src/test/groovy/transform/AnnotationCollectorLegacyTest.groovy      | 6 +++---
 src/test/groovy/transform/AnnotationCollectorTest.groovy            | 2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy b/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy
index 15ca578..e14a8fe 100644
--- a/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy
+++ b/src/main/groovy/org/codehaus/groovy/transform/ASTTestTransformation.groovy
@@ -25,9 +25,11 @@ import org.codehaus.groovy.ast.ClassCodeVisitorSupport
 import org.codehaus.groovy.ast.ClassHelper
 import org.codehaus.groovy.ast.ClassNode
 import org.codehaus.groovy.ast.MethodNode
+import org.codehaus.groovy.ast.Parameter
 import org.codehaus.groovy.ast.expr.ClosureExpression
 import org.codehaus.groovy.ast.expr.PropertyExpression
 import org.codehaus.groovy.ast.expr.VariableExpression
+import org.codehaus.groovy.ast.stmt.EmptyStatement
 import org.codehaus.groovy.ast.stmt.Statement
 import org.codehaus.groovy.control.CompilationUnit
 import org.codehaus.groovy.control.CompilePhase
@@ -72,7 +74,9 @@ class ASTTestTransformation implements ASTTransformation, CompilationUnitAware {
         }
         // convert value into node metadata so that the expression doesn't mix up with other AST xforms like STC
         annotationNode.setNodeMetaData(ASTTestTransformation, member)
-        annotationNode.members.remove('value')
+        annotationNode.setMember('value', new ClosureExpression(
+            Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE))
+        member.variableScope.@parent = null
 
         def pcallback = compilationUnit.progressCallback
         def callback = new CompilationUnit.ProgressCallback() {
diff --git a/src/main/java/groovy/transform/ASTTest.java b/src/main/java/groovy/transform/ASTTest.java
index 1779161..1c144a8 100644
--- a/src/main/java/groovy/transform/ASTTest.java
+++ b/src/main/java/groovy/transform/ASTTest.java
@@ -18,6 +18,7 @@
  */
 package groovy.transform;
 
+import groovy.lang.Closure;
 import org.codehaus.groovy.control.CompilePhase;
 import org.codehaus.groovy.transform.GroovyASTTransformationClass;
 
@@ -52,7 +53,7 @@ import java.lang.annotation.Target;
  * @since 2.0.0
  */
 @Documented
-@Retention(RetentionPolicy.RUNTIME)
+@Retention(RetentionPolicy.SOURCE)
 @Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
 @GroovyASTTransformationClass("org.codehaus.groovy.transform.ASTTestTransformation")
 public @interface ASTTest {
@@ -64,5 +65,5 @@ public @interface ASTTest {
     /**
      * A closure which is executed against the annotated node after the specified phase has completed.
      */
-    Class value();
+    Class<? extends /*@ClosureParams(value=FromString.class,options="")*/ Closure<?>> value();
 }
diff --git a/src/test/groovy/transform/AnnotationCollectorLegacyTest.groovy b/src/test/groovy/transform/AnnotationCollectorLegacyTest.groovy
index 0268602..304c03c 100644
--- a/src/test/groovy/transform/AnnotationCollectorLegacyTest.groovy
+++ b/src/test/groovy/transform/AnnotationCollectorLegacyTest.groovy
@@ -162,7 +162,7 @@ class AnnotationCollectorLegacyTest extends GroovyTestCase {
     }
 
     void testAST() {
-        assertScript """
+        assertScript '''
             import groovy.transform.*
             @AnnotationCollector(value = [ToString, EqualsAndHashCode, Sortable], serializeClass = Alias)
             @interface Alias {}
@@ -178,11 +178,11 @@ class AnnotationCollectorLegacyTest extends GroovyTestCase {
             class Foo {
                 Integer a, b
             }
-            assert Foo.class.annotations.size() == 4
+            assert Foo.class.annotations.size() == 3
             assert new Foo(a: 1, b: 2).toString() == "Foo(2)"
             assert Alias.value().length == 0
             assert Alias.value() instanceof Object[][]
-        """
+        '''
     }
 
     void testConflictingAnnotations() {
diff --git a/src/test/groovy/transform/AnnotationCollectorTest.groovy b/src/test/groovy/transform/AnnotationCollectorTest.groovy
index 6f519a5..f78235b 100644
--- a/src/test/groovy/transform/AnnotationCollectorTest.groovy
+++ b/src/test/groovy/transform/AnnotationCollectorTest.groovy
@@ -185,7 +185,7 @@ class AnnotationCollectorTest extends GroovyTestCase {
             class Foo {
                 Integer a, b
             }
-            assert Foo.class.annotations.size() == 4
+            assert Foo.class.annotations.size() == 3
             assert new Foo(a: 1, b: 2).toString() == "Foo(2)"
             def data = Alias.getAnnotation(AnnotationCollector).serializeClass().value()
             assert data.length == 0