You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by bl...@apache.org on 2017/10/16 14:21:01 UTC

[3/4] groovy git commit: Add a guard to figure out if @Generated should be created & added to methods

Add a guard to figure out if @Generated should be created & added to methods


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 8ca188c4b64cd01652e36d88651118b6f4f8e8c7
Parents: 1caa180
Author: aalmiray <aa...@gmail.com>
Authored: Thu Oct 12 16:53:22 2017 +0200
Committer: Jochen Theodorou <bl...@gmx.org>
Committed: Mon Oct 16 16:20:47 2017 +0200

----------------------------------------------------------------------
 .../org/codehaus/groovy/classgen/Verifier.java  | 29 ++++++++++++--------
 1 file changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/8ca188c4/src/main/org/codehaus/groovy/classgen/Verifier.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/Verifier.java b/src/main/org/codehaus/groovy/classgen/Verifier.java
index f1251d7..20fe156 100644
--- a/src/main/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/org/codehaus/groovy/classgen/Verifier.java
@@ -387,11 +387,13 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
     protected void addGroovyObjectInterfaceAndMethods(ClassNode node, final String classInternalName) {
         if (!node.isDerivedFromGroovyObject()) node.addInterface(ClassHelper.make(GroovyObject.class));
         FieldNode metaClassField = getMetaClassField(node);
-        AnnotationNode generatedAnnotation = new AnnotationNode(ClassHelper.make(GENERATED_ANNOTATION));
+
+        boolean shouldAnnotate = classNode.getModule().getContext() != null;
+        AnnotationNode generatedAnnotation = shouldAnnotate ? new AnnotationNode(ClassHelper.make(GENERATED_ANNOTATION)) : null;
 
         if (!node.hasMethod("getMetaClass", Parameter.EMPTY_ARRAY)) {
             metaClassField = setMetaClassFieldIfNotExists(node, metaClassField);
-            addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
                     "getMetaClass",
                     ACC_PUBLIC,
                     ClassHelper.METACLASS_TYPE,
@@ -429,7 +431,8 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                             mv.visitInsn(ARETURN);
                         }
                     })
-            ).addAnnotation(generatedAnnotation);
+            );
+            if (shouldAnnotate) methodNode.addAnnotation(generatedAnnotation);
         }
 
         Parameter[] parameters = new Parameter[]{new Parameter(ClassHelper.METACLASS_TYPE, "mc")};
@@ -458,12 +461,13 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                 setMetaClassCode = new BytecodeSequence(list);
             }
 
-            addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
                     "setMetaClass",
                     ACC_PUBLIC, ClassHelper.VOID_TYPE,
                     SET_METACLASS_PARAMS, ClassNode.EMPTY_ARRAY,
                     setMetaClassCode
-            ).addAnnotation(generatedAnnotation);
+            );
+            if (shouldAnnotate) methodNode.addAnnotation(generatedAnnotation);
         }
 
         if (!node.hasMethod("invokeMethod", INVOKE_METHOD_PARAMS)) {
@@ -473,7 +477,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
             blockScope.putReferencedLocalVariable(vMethods);
             blockScope.putReferencedLocalVariable(vArguments);
 
-            addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
                     "invokeMethod",
                     ACC_PUBLIC,
                     ClassHelper.OBJECT_TYPE, INVOKE_METHOD_PARAMS,
@@ -489,11 +493,12 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                             mv.visitInsn(ARETURN);
                         }
                     })
-            ).addAnnotation(generatedAnnotation);
+            );
+            if (shouldAnnotate) methodNode.addAnnotation(generatedAnnotation);
         }
 
         if (!node.hasMethod("getProperty", GET_PROPERTY_PARAMS)) {
-            addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
                     "getProperty",
                     ACC_PUBLIC,
                     ClassHelper.OBJECT_TYPE,
@@ -509,11 +514,12 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                             mv.visitInsn(ARETURN);
                         }
                     })
-            ).addAnnotation(generatedAnnotation);
+            );
+            if (shouldAnnotate) methodNode.addAnnotation(generatedAnnotation);
         }
 
         if (!node.hasMethod("setProperty", SET_PROPERTY_PARAMS)) {
-            addMethod(node, !isAbstract(node.getModifiers()),
+            MethodNode methodNode = addMethod(node, !isAbstract(node.getModifiers()),
                     "setProperty",
                     ACC_PUBLIC,
                     ClassHelper.VOID_TYPE,
@@ -530,7 +536,8 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                             mv.visitInsn(RETURN);
                         }
                     })
-            ).addAnnotation(generatedAnnotation);
+            );
+            if (shouldAnnotate) methodNode.addAnnotation(generatedAnnotation);
         }
     }