You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/08/25 17:15:08 UTC
[groovy] branch GROOVY-9702 created (now cc2c0ad)
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a change to branch GROOVY-9702
in repository https://gitbox.apache.org/repos/asf/groovy.git.
at cc2c0ad GROOVY-9702: source retention for @ASTTest and improved AST modification
This branch includes the following new commits:
new cc2c0ad GROOVY-9702: source retention for @ASTTest and improved AST modification
The 1 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.
[groovy] 01/01: GROOVY-9702: source retention for @ASTTest and
improved AST modification
Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY-9702
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit cc2c0adca6cce2796ab4c35b4a7ec8ec3f4f4d78
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
---
.../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