This is an automated email from the ASF dual-hosted git repository. emilles pushed a commit to branch GROOVY-6526 in repository https://gitbox.apache.org/repos/asf/groovy.git
commit b589d83b270311eed8febf2bdfd259a997fde392 Author: Eric Milles <[email protected]> AuthorDate: Thu Mar 5 11:01:33 2026 -0600 fit and finish --- .../org/codehaus/groovy/ast/AnnotationNode.java | 24 +++++++++--------- .../codehaus/groovy/classgen/ExtendedVerifier.java | 29 ++++------------------ .../ast/visitor/AnnotationProcessorVisitor.java | 2 -- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java b/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java index d43197be20..94b772f615 100644 --- a/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java +++ b/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java @@ -126,7 +126,7 @@ public class AnnotationNode extends ASTNode { throw new IllegalStateException("cannot check target at this time"); // GROOVY-6526: check class for @Target - int allowedTargets = classNode.getNodeMetaData(Target.class, (k) -> { + int allowedTargets = classNode.redirect().getNodeMetaData(Target.class, (k) -> { for (AnnotationNode an : classNode.getAnnotations()) { if ("java.lang.annotation.Target".equals(an.getClassNode().getName()) && an.getMember("value") instanceof ListExpression list) { @@ -165,7 +165,7 @@ public class AnnotationNode extends ASTNode { throw new IllegalStateException("cannot check retention at this time"); // GROOVY-6526: check class for @Retention - return classNode.getNodeMetaData(Retention.class, (k) -> { + return classNode.redirect().getNodeMetaData(Retention.class, (k) -> { for (AnnotationNode an : classNode.getAnnotations()) { if ("java.lang.annotation.Retention".equals(an.getClassNode().getName())) { if (an.getMember("value") instanceof PropertyExpression pe) { @@ -245,17 +245,17 @@ public class AnnotationNode extends ASTNode { } public static String targetToName(final int target) { + if ((target & 1) == 1) return "TYPE"; // GROOVY-7151 return switch (target) { - case TYPE_TARGET -> "TYPE"; - case CONSTRUCTOR_TARGET -> "CONSTRUCTOR"; - case METHOD_TARGET -> "METHOD"; - case FIELD_TARGET -> "FIELD"; - case PARAMETER_TARGET -> "PARAMETER"; - case LOCAL_VARIABLE_TARGET -> "LOCAL_VARIABLE"; - case ANNOTATION_TARGET -> "ANNOTATION"; - case PACKAGE_TARGET -> "PACKAGE"; - case TYPE_PARAMETER_TARGET -> "TYPE_PARAMETER"; - case TYPE_USE_TARGET -> "TYPE_USE"; + case CONSTRUCTOR_TARGET -> "CONSTRUCTOR"; + case METHOD_TARGET -> "METHOD"; + case FIELD_TARGET -> "FIELD"; + case PARAMETER_TARGET -> "PARAMETER"; + case LOCAL_VARIABLE_TARGET -> "LOCAL_VARIABLE"; + case ANNOTATION_TARGET -> "ANNOTATION"; + case PACKAGE_TARGET -> "PACKAGE"; + case TYPE_PARAMETER_TARGET -> "TYPE_PARAMETER"; + case TYPE_USE_TARGET -> "TYPE_USE"; case RECORD_COMPONENT_TARGET -> "RECORD_COMPONENT"; default -> "unknown target"; }; diff --git a/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java b/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java index 917d08ce67..7093788260 100644 --- a/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java +++ b/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java @@ -372,31 +372,12 @@ public class ExtendedVerifier extends ClassCodeVisitorSupport { if (nonSourceAnnotations.containsKey(repeatable.getName())) { addError("Cannot specify duplicate annotation on the same member. Explicit " + repeatable.getName() + " found when creating implicit container for " + entry.getKey(), node); } - AnnotationNode collector = new AnnotationNode(repeatable); -/* - if (repeatee.hasClassRetention()) { - collector.setClassRetention(true); - } else if (repeatee.hasRuntimeRetention()) { - collector.setRuntimeRetention(true); - } else { // load retention policy from annotation definition - List<AnnotationNode> retention = repeatable.getAnnotations(makeCached(Retention.class)); - if (!retention.isEmpty()) { - Object policy; - Expression value = retention.get(0).getMember("value"); - if (value instanceof PropertyExpression) { - policy = ((PropertyExpression) value).getPropertyAsString(); - } else { // NOTE: it is risky to evaluate the expression from repeatable's source this way: - policy = evaluateExpression(value, source.getConfiguration(), source.getClassLoader()); - } - if ("CLASS".equals(policy)) { - collector.setClassRetention(true); - } else if ("RUNTIME".equals(policy)) { - collector.setRuntimeRetention(true); - } - } - } -*/ + var collector = new AnnotationNode(repeatable); + assert collector.hasClassRetention() == repeatee.hasClassRetention(); + assert collector.hasSourceRetention() == repeatee.hasSourceRetention(); + assert collector.hasRuntimeRetention() == repeatee.hasRuntimeRetention(); collector.addMember("value", listX(entry.getValue().stream().map(AnnotationConstantExpression::new).collect(toList()))); + node.getAnnotations().removeAll(entry.getValue()); node.addAnnotation(collector); } diff --git a/subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/visitor/AnnotationProcessorVisitor.java b/subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/visitor/AnnotationProcessorVisitor.java index 56d59233df..bcdd4ab96e 100644 --- a/subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/visitor/AnnotationProcessorVisitor.java +++ b/subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/visitor/AnnotationProcessorVisitor.java @@ -199,8 +199,6 @@ public class AnnotationProcessorVisitor extends BaseVisitor { if (!AnnotationUtils.hasAnnotationOfType(methodNode, annotationNode.getClassNode().getName())) { AnnotationNode markerAnnotation = new AnnotationNode(annotationNode.getClassNode()); replaceCondition(markerAnnotation, valueExpression); - markerAnnotation.setRuntimeRetention(true); - markerAnnotation.setSourceRetention(false); methodNode.addAnnotation(markerAnnotation); } }
