This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 06ed806 move duplicate annotation detection out of ResolveVisitor
into ExtendedVerifier with other similar checks
06ed806 is described below
commit 06ed8060078f5285b16a4e07e4aceef50b1ee3f0
Author: Paul King <[email protected]>
AuthorDate: Sat May 1 12:45:12 2021 +1000
move duplicate annotation detection out of ResolveVisitor into
ExtendedVerifier with other similar checks
---
.../codehaus/groovy/classgen/ExtendedVerifier.java | 15 +++++++++++++--
.../codehaus/groovy/control/ResolveVisitor.java | 22 ----------------------
2 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java
b/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java
index 4f29cbf..215d626 100644
--- a/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/ExtendedVerifier.java
@@ -175,6 +175,8 @@ public class ExtendedVerifier extends
ClassCodeVisitorSupport {
List<AnnotationNode> seen = nonSourceAnnotations.get(name);
if (seen == null) {
seen = new ArrayList<>();
+ } else if (!isRepeatable(visited.getClassNode())) {
+ addError("Cannot specify duplicate annotation on the same
member : " + name, visited);
}
seen.add(visited);
nonSourceAnnotations.put(name, seen);
@@ -189,10 +191,19 @@ public class ExtendedVerifier extends
ClassCodeVisitorSupport {
visitDeprecation(node, visited);
visitOverride(node, visited);
}
- checkForDuplicateAnnotations(node, nonSourceAnnotations);
+ processDuplicateAnnotationContainers(node, nonSourceAnnotations);
}
- private void checkForDuplicateAnnotations(AnnotatedNode node, Map<String,
List<AnnotationNode>> nonSourceAnnotations) {
+ private boolean isRepeatable(final ClassNode classNode) {
+ for (AnnotationNode anno : classNode.getAnnotations()) {
+ if
(anno.getClassNode().getName().equals("java.lang.annotation.Repeatable")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void processDuplicateAnnotationContainers(AnnotatedNode node,
Map<String, List<AnnotationNode>> nonSourceAnnotations) {
for (Map.Entry<String, List<AnnotationNode>> next :
nonSourceAnnotations.entrySet()) {
if (next.getValue().size() > 1) {
ClassNode repeatable = null;
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index c2aa72b..c2f9421 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -1329,7 +1329,6 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
public void visitAnnotations(final AnnotatedNode node) {
List<AnnotationNode> annotations = node.getAnnotations();
if (annotations.isEmpty()) return;
- Map<String, AnnotationNode> tmpAnnotations = new HashMap<>();
for (AnnotationNode an : annotations) {
// skip built-in properties
if (an.isBuiltIn()) continue;
@@ -1341,30 +1340,9 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
member.setValue(adjusted);
checkAnnotationMemberValue(adjusted);
}
- if (annType.isResolved()) {
- Class<?> annTypeClass = annType.getTypeClass();
- Retention retAnn = annTypeClass.getAnnotation(Retention.class);
- if (retAnn != null &&
!retAnn.value().equals(RetentionPolicy.SOURCE) && !isRepeatable(annTypeClass)) {
- // remember non-source/non-repeatable annos (auto
collecting of Repeatable annotations is handled elsewhere)
- AnnotationNode anyPrevAnnNode =
tmpAnnotations.put(annTypeClass.getName(), an);
- if (anyPrevAnnNode != null) {
- addError("Cannot specify duplicate annotation on the
same member : " + annType.getName(), an);
- }
- }
- }
}
}
- private boolean isRepeatable(final Class<?> annTypeClass) {
- Annotation[] annTypeAnnotations = annTypeClass.getAnnotations();
- for (Annotation annTypeAnnotation : annTypeAnnotations) {
- if
(annTypeAnnotation.annotationType().getName().equals("java.lang.annotation.Repeatable"))
{
- return true;
- }
- }
- return false;
- }
-
// resolve constant-looking expressions statically (do here as they get
transformed away later)
private static Expression transformInlineConstants(final Expression exp) {
if (exp instanceof AnnotationConstantExpression) {