groovy git commit: GROOVY-8495: GroovyObject method implementations are marked with ACC_SYNTHETIC

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: GROOVY-8495: GroovyObject method implementations are marked with ACC_SYNTHETIC

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 7e72d3674 -> 406ffc12a


GROOVY-8495: GroovyObject method implementations are marked with ACC_SYNTHETIC


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/406ffc12
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/406ffc12
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/406ffc12

Branch: refs/heads/master
Commit: 406ffc12a32858db879443ae36e333f151ca2a08
Parents: 7e72d36
Author: Paul King <[hidden email]>
Authored: Fri Sep 14 22:40:57 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Fri Sep 14 22:41:20 2018 +1000

----------------------------------------------------------------------
 src/main/java/org/codehaus/groovy/classgen/Verifier.java  | 10 +++++-----
 .../org/codehaus/groovy/reflection/MixinInMetaClass.java  |  4 ++++
 .../groovy/runtime/callsite/AbstractCallSite.java         |  3 ++-
 .../java/org/codehaus/groovy/vmplugin/v7/Selector.java    |  3 ++-
 src/test/groovy/bugs/Groovy3175_Bug.groovy                | 10 +++++++---
 5 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/406ffc12/src/main/java/org/codehaus/groovy/classgen/Verifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index cd234f0..35f40aa 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -408,7 +408,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
 
         if (!node.hasMethod("getMetaClass", Parameter.EMPTY_ARRAY)) {
             metaClassField = setMetaClassFieldIfNotExists(node, metaClassField);
-            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !shouldAnnotate,
                     "getMetaClass",
                     ACC_PUBLIC,
                     ClassHelper.METACLASS_TYPE,
@@ -476,7 +476,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                 setMetaClassCode = new BytecodeSequence(list);
             }
 
-            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !shouldAnnotate,
                     "setMetaClass",
                     ACC_PUBLIC, ClassHelper.VOID_TYPE,
                     SET_METACLASS_PARAMS, ClassNode.EMPTY_ARRAY,
@@ -492,7 +492,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
             blockScope.putReferencedLocalVariable(vMethods);
             blockScope.putReferencedLocalVariable(vArguments);
 
-            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !shouldAnnotate,
                     "invokeMethod",
                     ACC_PUBLIC,
                     ClassHelper.OBJECT_TYPE, INVOKE_METHOD_PARAMS,
@@ -513,7 +513,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
         }
 
         if (!node.hasMethod("getProperty", GET_PROPERTY_PARAMS)) {
-            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !shouldAnnotate,
                     "getProperty",
                     ACC_PUBLIC,
                     ClassHelper.OBJECT_TYPE,
@@ -534,7 +534,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
         }
 
         if (!node.hasMethod("setProperty", SET_PROPERTY_PARAMS)) {
-            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !shouldAnnotate,
                     "setProperty",
                     ACC_PUBLIC,
                     ClassHelper.VOID_TYPE,

http://git-wip-us.apache.org/repos/asf/groovy/blob/406ffc12/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java b/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
index 4dfa083..727cb89 100644
--- a/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
+++ b/src/main/java/org/codehaus/groovy/reflection/MixinInMetaClass.java
@@ -25,6 +25,7 @@ import groovy.lang.GroovySystem;
 import groovy.lang.MetaClass;
 import groovy.lang.MetaMethod;
 import groovy.lang.MetaProperty;
+import groovy.transform.Generated;
 import org.codehaus.groovy.runtime.HandleMetaClass;
 import org.codehaus.groovy.runtime.MetaClassHelper;
 import org.codehaus.groovy.runtime.metaclass.MixedInMetaClass;
@@ -137,6 +138,9 @@ public class MixinInMetaClass extends ManagedConcurrentMap {
                 if (method instanceof CachedMethod && ((CachedMethod) method).getCachedMethod().isSynthetic())
                     continue;
 
+                if (method instanceof CachedMethod && ((CachedMethod) method).getCachedMethod().getAnnotation(Generated.class) != null)
+                    continue;
+
                 if (Modifier.isStatic(mod)) {
                     if (method instanceof CachedMethod)
                         staticMethod(self, arr, (CachedMethod) method);

http://git-wip-us.apache.org/repos/asf/groovy/blob/406ffc12/src/main/java/org/codehaus/groovy/runtime/callsite/AbstractCallSite.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/AbstractCallSite.java b/src/main/java/org/codehaus/groovy/runtime/callsite/AbstractCallSite.java
index d85e445..758f880 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/AbstractCallSite.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/AbstractCallSite.java
@@ -23,6 +23,7 @@ import groovy.lang.GroovyRuntimeException;
 import groovy.lang.MetaClass;
 import groovy.lang.MetaClassImpl;
 import groovy.lang.MetaProperty;
+import groovy.transform.Generated;
 import org.codehaus.groovy.reflection.CachedClass;
 import org.codehaus.groovy.reflection.CachedField;
 import org.codehaus.groovy.reflection.ParameterTypes;
@@ -334,7 +335,7 @@ public class AbstractCallSite implements CallSite {
         Class aClass = receiver.getClass();
         try {
             final Method method = aClass.getMethod("getProperty", String.class);
-            if (method != null && method.isSynthetic() && ((GroovyObject) receiver).getMetaClass() instanceof MetaClassImpl)
+            if (method != null && (method.isSynthetic() || method.getAnnotation(Generated.class) != null) && ((GroovyObject) receiver).getMetaClass() instanceof MetaClassImpl)
                 return createPogoMetaClassGetPropertySite((GroovyObject) receiver);
         } catch (NoSuchMethodException e) {
             // fall threw

http://git-wip-us.apache.org/repos/asf/groovy/blob/406ffc12/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
index 4e1eb8b..1b93b71 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
@@ -31,6 +31,7 @@ import groovy.lang.MetaClassImpl.MetaConstructor;
 import groovy.lang.MetaMethod;
 import groovy.lang.MetaProperty;
 import groovy.lang.MissingMethodException;
+import groovy.transform.Generated;
 import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.reflection.CachedField;
 import org.codehaus.groovy.reflection.CachedMethod;
@@ -300,7 +301,7 @@ public abstract class Selector {
                 Method reflectionMethod = null;
                 try {
                     reflectionMethod = aClass.getMethod("getProperty", String.class);
-                    if (!reflectionMethod.isSynthetic()) {
+                    if (!reflectionMethod.isSynthetic() && reflectionMethod.getAnnotation(Generated.class) == null) {
                         handle = MethodHandles.insertArguments(GROOVY_OBJECT_GET_PROPERTY, 1, name);
                         return;
                     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/406ffc12/src/test/groovy/bugs/Groovy3175_Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy3175_Bug.groovy b/src/test/groovy/bugs/Groovy3175_Bug.groovy
index a2b309b..257b7e8 100644
--- a/src/test/groovy/bugs/Groovy3175_Bug.groovy
+++ b/src/test/groovy/bugs/Groovy3175_Bug.groovy
@@ -18,10 +18,12 @@
  */
 package groovy.bugs
 
-public class Groovy3175_Bug extends GroovyTestCase {
+class Groovy3175_Bug extends GroovyTestCase {
 
    void testSyntheticModifier() {
      assertScript """
+        import groovy.transform.Generated
+
         class MyService {
             private fio
             def thing
@@ -29,9 +31,11 @@ public class Groovy3175_Bug extends GroovyTestCase {
             def anotherSomething() { assert true }
         }
         def fields = MyService.getDeclaredFields().grep { !it.synthetic }
-        assert fields.size() == 2
+        assert fields.size() == 2
         def methods = MyService.getDeclaredMethods().grep { !it.synthetic }
-        assert methods.size() == 4
+        assert methods.size() == 9
+        methods = methods.grep { !it.getAnnotation(Generated) }
+        assert methods.size() == 4
      """
    }
 }