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

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 47867dcbc3d17e6661305de8deebbe2b7253f436
Author: Eric Milles <[email protected]>
AuthorDate: Fri Aug 25 08:59:06 2023 -0500

    vmplugin: reuse `toAnnotationNode` not lower-level `configureAnnotation`
---
 .../org/codehaus/groovy/vmplugin/v16/Java16.java   | 29 ++++++----------------
 .../org/codehaus/groovy/vmplugin/v8/Java8.java     |  4 +--
 2 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v16/Java16.java 
b/src/main/java/org/codehaus/groovy/vmplugin/v16/Java16.java
index 11cf439b49..ae02c4295b 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v16/Java16.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v16/Java16.java
@@ -20,24 +20,22 @@ package org.codehaus.groovy.vmplugin.v16;
 
 import groovy.lang.GroovyRuntimeException;
 import org.codehaus.groovy.ast.AnnotationNode;
-import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.CompileUnit;
 import org.codehaus.groovy.ast.RecordComponentNode;
 import org.codehaus.groovy.vmplugin.v10.Java10;
 
+import java.lang.annotation.ElementType;
 import java.lang.invoke.MethodHandle;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.Arrays;
 import java.util.stream.Collectors;
 
-import static java.lang.annotation.ElementType.RECORD_COMPONENT;
-
 public class Java16 extends Java10 {
 
     {
-        elementTypeToTarget.put(RECORD_COMPONENT, 
AnnotationNode.RECORD_COMPONENT_TARGET);
+        elementTypeToTarget.put(ElementType.RECORD_COMPONENT, 
AnnotationNode.RECORD_COMPONENT_TARGET);
     }
 
     @Override
@@ -74,22 +72,11 @@ public class Java16 extends Java10 {
     }
 
     @Override
-    protected void makeRecordComponents(final CompileUnit cu, final ClassNode 
classNode, final Class<?> clazz) {
-        if (!clazz.isRecord()) return;
-        
classNode.setRecordComponents(Arrays.stream(clazz.getRecordComponents())
-                .map(rc -> {
-                    ClassNode type = makeClassNode(cu, rc.getGenericType(), 
rc.getType());
-                    
type.addTypeAnnotations(Arrays.stream(rc.getAnnotatedType().getAnnotations()).map(annotation
 -> {
-                        AnnotationNode node = new 
AnnotationNode(ClassHelper.make(annotation.annotationType()));
-                        configureAnnotation(node, annotation);
-                        return node;
-                    }).collect(Collectors.toList()));
-                    return new RecordComponentNode(classNode, rc.getName(), 
type, Arrays.stream(rc.getAnnotations()).map(annotation -> {
-                        AnnotationNode node = new 
AnnotationNode(ClassHelper.make(annotation.annotationType()));
-                        configureAnnotation(node, annotation);
-                        return node;
-                    }).collect(Collectors.toList()));
-                })
-                .collect(Collectors.toList()));
+    protected void makeRecordComponents(final CompileUnit cu, final ClassNode 
cn, final Class<?> c) {
+        if (c.isRecord()) 
cn.setRecordComponents(Arrays.stream(c.getRecordComponents()).map(rc -> {
+            ClassNode type = makeClassNode(cu, rc.getGenericType(), 
rc.getType());
+            
type.addTypeAnnotations(Arrays.stream(rc.getAnnotatedType().getAnnotations()).map(this::toAnnotationNode).collect(Collectors.toList()));
+            return new RecordComponentNode(cn, rc.getName(), type, 
Arrays.stream(rc.getAnnotations()).map(this::toAnnotationNode).collect(Collectors.toList()));
+        }).collect(Collectors.toList()));
     }
 }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java 
b/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java
index 9fa4d5cd6d..8abd4f3b85 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java
@@ -261,7 +261,7 @@ public class Java8 implements VMPlugin {
         }
     }
 
-    protected void configureAnnotation(final AnnotationNode node, final 
Annotation annotation) {
+    private void configureAnnotation(final AnnotationNode node, final 
Annotation annotation) {
         Class<?> type = annotation.annotationType();
         if (type == Retention.class) {
             Retention r = (Retention) annotation;
@@ -304,7 +304,7 @@ public class Java8 implements VMPlugin {
         }
     }
 
-    private AnnotationNode toAnnotationNode(final Annotation annotation) {
+    protected AnnotationNode toAnnotationNode(final Annotation annotation) {
         ClassNode type = ClassHelper.make(annotation.annotationType());
         AnnotationNode node = new AnnotationNode(type);
         configureAnnotation(node, annotation);

Reply via email to