groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] 03/06: GROOVY-9053: Missing @Generated annotation on @Bindable
Date Fri, 22 Mar 2019 01:33:38 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 4e8cc154772537e06d7817203ce8bc60292f47a4
Author: Paul King <paulk@asert.com.au>
AuthorDate: Fri Mar 22 09:56:49 2019 +1000

    GROOVY-9053: Missing @Generated annotation on @Bindable
---
 .../groovy/beans/BindableASTTransformation.java    | 19 ++++++-------
 ...bleTest.groovy => BindableTransformTest.groovy} | 31 ++++++++++++++++++++--
 2 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/src/main/groovy/groovy/beans/BindableASTTransformation.java b/src/main/groovy/groovy/beans/BindableASTTransformation.java
index 037ee2f..60474f9 100644
--- a/src/main/groovy/groovy/beans/BindableASTTransformation.java
+++ b/src/main/groovy/groovy/beans/BindableASTTransformation.java
@@ -43,6 +43,7 @@ import org.objectweb.asm.Opcodes;
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
 
+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.assignX;
@@ -73,7 +74,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
  * If a {@link Vetoable} annotation is detected it does nothing and
  * lets the {@link VetoableASTTransformation} handle all the changes.
  */
-@GroovyASTTransformation(phase= CompilePhase.CANONICALIZATION)
+@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
 public class BindableASTTransformation implements ASTTransformation, Opcodes {
 
     protected static final ClassNode boundClassNode = ClassHelper.make(Bindable.class);
@@ -253,7 +254,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
                 setterBlock);
         setter.setSynthetic(true);
         // add it to the class
-        declaringClass.addMethod(setter);
+        addGeneratedMethod(declaringClass, setter);
     }
 
     /**
@@ -339,7 +340,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
         // void addPropertyChangeListener(listener) {
         //     this$propertyChangeSupport.addPropertyChangeListener(listener)
         //  }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "addPropertyChangeListener",
                         ACC_PUBLIC,
@@ -352,7 +353,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
         // void addPropertyChangeListener(name, listener) {
         //     this$propertyChangeSupport.addPropertyChangeListener(name, listener)
         //  }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "addPropertyChangeListener",
                         ACC_PUBLIC,
@@ -365,7 +366,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
         // boolean removePropertyChangeListener(listener) {
         //    return this$propertyChangeSupport.removePropertyChangeListener(listener);
         // }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "removePropertyChangeListener",
                         ACC_PUBLIC,
@@ -375,7 +376,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
                         stmt(callX(fieldX(pcsField), "removePropertyChangeListener", args(varX("listener",
pclClassNode))))));
 
         // add method: void removePropertyChangeListener(name, listener)
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "removePropertyChangeListener",
                         ACC_PUBLIC,
@@ -388,7 +389,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
         // void firePropertyChange(String name, Object oldValue, Object newValue) {
         //     this$propertyChangeSupport.firePropertyChange(name, oldValue, newValue)
         //  }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "firePropertyChange",
                         ACC_PUBLIC,
@@ -401,7 +402,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
         // PropertyChangeListener[] getPropertyChangeListeners() {
         //   return this$propertyChangeSupport.getPropertyChangeListeners
         // }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "getPropertyChangeListeners",
                         ACC_PUBLIC,
@@ -414,7 +415,7 @@ public class BindableASTTransformation implements ASTTransformation, Opcodes
{
         // PropertyChangeListener[] getPropertyChangeListeners(String name) {
         //   return this$propertyChangeSupport.getPropertyChangeListeners(name)
         // }
-        declaringClass.addMethod(
+        addGeneratedMethod(declaringClass,
                 new MethodNode(
                         "getPropertyChangeListeners",
                         ACC_PUBLIC,
diff --git a/src/test/groovy/beans/BindableTest.groovy b/src/test/groovy/beans/BindableTransformTest.groovy
similarity index 92%
rename from src/test/groovy/beans/BindableTest.groovy
rename to src/test/groovy/beans/BindableTransformTest.groovy
index 1b88758..9424450 100644
--- a/src/test/groovy/beans/BindableTest.groovy
+++ b/src/test/groovy/beans/BindableTransformTest.groovy
@@ -25,7 +25,7 @@ import java.beans.PropertyChangeListener
 import static java.lang.reflect.Modifier.isPublic
 import static java.lang.reflect.Modifier.isSynthetic
 
-class BindableTest extends GroovyTestCase {
+class BindableTransformTest extends GroovyShellTestCase {
 
     void testSimpleBindableProperty() {
         assertScript """
@@ -369,4 +369,31 @@ class BindableTest extends GroovyTestCase {
             assert new MyBean()
         """
     }
-}
\ No newline at end of file
+
+    void testBindableGeneratedMethodsAreAnnotatedWithGenerated_GROOVY9053() {
+        def person = evaluate('''
+            class Person {
+                @groovy.beans.Bindable
+                String firstName
+
+                void setFirstName(String fn) {
+                    this.firstName = fn.toUpperCase()
+                }
+
+                @groovy.beans.Bindable
+                def zipCode
+             }
+             new Person()
+        ''')
+
+        person.class.declaredMethods.each { m ->
+            if (m.name.contains('PropertyChange') || m.name in ['setZipCode']) {
+                assert m.annotations*.annotationType().name.contains('groovy.transform.Generated')
+            }
+            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