You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/08/12 23:47:06 UTC

[groovy] branch danielsun/mark-generated created (now 9ff1aef)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/mark-generated
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 9ff1aef  Attach annotations to internal methods

This branch includes the following new commits:

     new 9ff1aef  Attach annotations to internal methods

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[groovy] 01/01: Attach annotations to internal methods

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/mark-generated
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 9ff1aef8baf9a8483ae5702fd00b947125b50e15
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Aug 13 07:45:39 2021 +0800

    Attach annotations to internal methods
---
 src/main/java/org/codehaus/groovy/classgen/Verifier.java | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index 5425c24..281037f 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -416,7 +416,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
             modifiers |= ACC_STATIC;
         }
 
-        node.addSyntheticMethod(
+        MethodNode getLookupMethodNode = node.addSyntheticMethod(
                 "$getLookup",
                 modifiers,
                 ClassHelper.make(MethodHandles.Lookup.class),
@@ -430,6 +430,11 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                     }
                 })
         );
+        boolean shouldAnnotate = classNode.getModule().getContext() != null;
+        if (shouldAnnotate) {
+            getLookupMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(GENERATED_ANNOTATION)));
+            getLookupMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(INTERNAL_ANNOTATION)));
+        }
     }
 
     private void addStaticMetaClassField(final ClassNode node, final String classInternalName) {
@@ -441,7 +446,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
         FieldNode staticMetaClassField = node.addField(staticMetaClassFieldName, ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC, ClassHelper.make(ClassInfo.class, false), null);
         staticMetaClassField.setSynthetic(true);
 
-        node.addSyntheticMethod(
+        MethodNode getStaticMetaClassMethodNode = node.addSyntheticMethod(
                 "$getStaticMetaClass",
                 ACC_PROTECTED,
                 ClassHelper.make(MetaClass.class),
@@ -487,6 +492,12 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
                     }
                 })
         );
+
+        boolean shouldAnnotate = classNode.getModule().getContext() != null;
+        if (shouldAnnotate) {
+            getStaticMetaClassMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(GENERATED_ANNOTATION)));
+            getStaticMetaClassMethodNode.addAnnotation(new AnnotationNode(ClassHelper.make(INTERNAL_ANNOTATION)));
+        }
     }
 
     protected void addGroovyObjectInterfaceAndMethods(final ClassNode node, final String classInternalName) {