groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blackd...@apache.org
Subject [1/4] groovy git commit: Add a guard to figure out if @Generated should be created & added to methods
Date Mon, 16 Oct 2017 14:20:09 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 9061c4a15 -> 540826abc


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/f2f518d9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f2f518d9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f2f518d9

Branch: refs/heads/master
Commit: f2f518d97928aa8ca218f85f190f6e6385f15798
Parents: 3feea3e
Author: aalmiray <aalmiray@gmail.com>
Authored: Thu Oct 12 16:53:22 2017 +0200
Committer: Jochen Theodorou <blackdrag@gmx.org>
Committed: Mon Oct 16 16:18:22 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/f2f518d9/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);
         }
     }
 


Mime
View raw message