groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 04/06: GROOVY-9052: Missing @Generated annotation on @Vetoable
Date Fri, 22 Mar 2019 01:33:39 GMT
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

commit 5b196536a742a3e799393c21cd3b9998f9de2900
Author: Paul King <paulk@asert.com.au>
AuthorDate: Fri Mar 22 10:15:24 2019 +1000

    GROOVY-9052: Missing @Generated annotation on @Vetoable
---
 .../groovy/beans/VetoableASTTransformation.java    | 17 +++++++------
 ...bleTest.groovy => VetoableTransformTest.groovy} | 29 ++++++++++++++++++++--
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/src/main/groovy/groovy/beans/VetoableASTTransformation.java b/src/main/groovy/groovy/beans/VetoableASTTransformation.java
index b574ca1..315c014 100644
--- a/src/main/groovy/groovy/beans/VetoableASTTransformation.java
+++ b/src/main/groovy/groovy/beans/VetoableASTTransformation.java
@@ -43,6 +43,7 @@ import java.beans.PropertyVetoException;
 import java.beans.VetoableChangeListener;
 import java.beans.VetoableChangeSupport;
 
+import static org.apache.groovy.ast.tools.ClassNodeUtils.addGeneratedMethod;
 import static org.apache.groovy.util.BeanUtils.capitalize;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.assignS;
@@ -318,7 +319,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
                 setterBlock);
         setter.setSynthetic(true);
         // add it to the class
-        declaringClass.addMethod(setter);
+        addGeneratedMethod(declaringClass, setter);
     }
 
     /**
@@ -352,7 +353,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
         // void addVetoableChangeListener(listener) {
         //     this$vetoableChangeSupport.addVetoableChangeListener(listener)
         //  }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "addVetoableChangeListener",
                         ACC_PUBLIC,
@@ -365,7 +366,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
         // void addVetoableChangeListener(name, listener) {
         //     this$vetoableChangeSupport.addVetoableChangeListener(name, listener)
         //  }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "addVetoableChangeListener",
                         ACC_PUBLIC,
@@ -378,7 +379,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
         // boolean removeVetoableChangeListener(listener) {
         //    return this$vetoableChangeSupport.removeVetoableChangeListener(listener);
         // }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "removeVetoableChangeListener",
                         ACC_PUBLIC,
@@ -388,7 +389,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
                         stmt(callX(fieldX(vcsField), "removeVetoableChangeListener", args(varX("listener",
vclClassNode))))));
 
         // add method: void removeVetoableChangeListener(name, listener)
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "removeVetoableChangeListener",
                         ACC_PUBLIC,
@@ -403,7 +404,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
         // {
         //     this$vetoableChangeSupport.fireVetoableChange(name, oldValue, newValue)
         //  }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "fireVetoableChange",
                         ACC_PUBLIC,
@@ -416,7 +417,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
         // VetoableChangeListener[] getVetoableChangeListeners() {
         //   return this$vetoableChangeSupport.getVetoableChangeListeners
         // }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "getVetoableChangeListeners",
                         ACC_PUBLIC,
@@ -429,7 +430,7 @@ public class VetoableASTTransformation extends BindableASTTransformation
{
         // VetoableChangeListener[] getVetoableChangeListeners(String name) {
         //   return this$vetoableChangeSupport.getVetoableChangeListeners(name)
         // }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "getVetoableChangeListeners",
                         ACC_PUBLIC,
diff --git a/src/test/groovy/beans/VetoableTest.groovy b/src/test/groovy/beans/VetoableTransformTest.groovy
similarity index 93%
rename from src/test/groovy/beans/VetoableTest.groovy
rename to src/test/groovy/beans/VetoableTransformTest.groovy
index 2a8519a..3fce996 100644
--- a/src/test/groovy/beans/VetoableTest.groovy
+++ b/src/test/groovy/beans/VetoableTransformTest.groovy
@@ -20,7 +20,7 @@ package groovy.beans
 
 import org.codehaus.groovy.control.CompilationFailedException
 
-class VetoableTest extends GroovyTestCase {
+class VetoableTransformTest extends GroovyShellTestCase {
 
     void testSimpleConstrainedProperty() {
         GroovyShell shell = new GroovyShell()
@@ -456,4 +456,29 @@ class VetoableTest extends GroovyTestCase {
             assert new MyBean()
         """
     }
-}
\ No newline at end of file
+
+    void testVetoableGeneratedMethodsAreAnnotatedWithGenerated_GROOVY9052() {
+        def person = evaluate('''
+            @groovy.beans.Vetoable
+            class Person {
+                String firstName
+
+                void setFirstName(String fn) {
+                    this.firstName = fn.toUpperCase()
+                }
+
+                def zipCode
+             }
+             new Person()
+        ''')
+
+        person.class.declaredMethods.each { m ->
+            if (m.name.contains('VetoableChange') || m.name in ['setZipCode']) {
+                assert m.annotations*.annotationType().name.contains('groovy.transform.Generated')
+            } else if (m.name in ['setFirstName']) {
+                // wrapped methods should not be marked since they contain non-generated
logic
+                assert !m.annotations*.annotationType().name.contains('groovy.transform.Generated')
+            }
+        }
+    }
+}


Mime
View raw message