diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AllAnnotationOverlays.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AllAnnotationOverlays.java deleted file mode 100644 index 6f73acd842bc12..00000000000000 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AllAnnotationOverlays.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.quarkus.arc.processor.bcextensions; - -class AllAnnotationOverlays { - final AnnotationsOverlay.Classes classes; - final AnnotationsOverlay.Methods methods; - final AnnotationsOverlay.Parameters parameters; - final AnnotationsOverlay.Fields fields; - - AllAnnotationOverlays() { - classes = new AnnotationsOverlay.Classes(); - methods = new AnnotationsOverlay.Methods(); - parameters = new AnnotationsOverlay.Parameters(); - fields = new AnnotationsOverlay.Fields(); - } - - void invalidate() { - classes.invalidate(); - methods.invalidate(); - parameters.invalidate(); - fields.invalidate(); - } -} diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AllAnnotationTransformations.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AllAnnotationTransformations.java deleted file mode 100644 index f3511cbb5a7f94..00000000000000 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AllAnnotationTransformations.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.quarkus.arc.processor.bcextensions; - -class AllAnnotationTransformations { - final AllAnnotationOverlays annotationOverlays; - final AnnotationsTransformation.Classes classes; - final AnnotationsTransformation.Methods methods; - final AnnotationsTransformation.Parameters parameters; - final AnnotationsTransformation.Fields fields; - - AllAnnotationTransformations(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays) { - this.annotationOverlays = annotationOverlays; - classes = new AnnotationsTransformation.Classes(jandexIndex, annotationOverlays); - methods = new AnnotationsTransformation.Methods(jandexIndex, annotationOverlays); - parameters = new AnnotationsTransformation.Parameters(jandexIndex, annotationOverlays); - fields = new AnnotationsTransformation.Fields(jandexIndex, annotationOverlays); - } - - void freeze() { - classes.freeze(); - methods.freeze(); - parameters.freeze(); - fields.freeze(); - } -} diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderFactoryImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderFactoryImpl.java index 2f840d5ecf2fb4..dda1dae25e048c 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderFactoryImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderFactoryImpl.java @@ -10,30 +10,31 @@ final class AnnotationBuilderFactoryImpl implements AnnotationBuilderFactory { private final org.jboss.jandex.IndexView beanArchiveIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; - AnnotationBuilderFactoryImpl(org.jboss.jandex.IndexView beanArchiveIndex, AllAnnotationOverlays annotationOverlays) { + AnnotationBuilderFactoryImpl(org.jboss.jandex.IndexView beanArchiveIndex, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay) { this.beanArchiveIndex = beanArchiveIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; } @Override public AnnotationBuilder create(Class annotationType) { - if (beanArchiveIndex == null || annotationOverlays == null) { + if (beanArchiveIndex == null || annotationOverlay == null) { throw new IllegalStateException("Can't create AnnotationBuilder right now"); } DotName jandexAnnotationName = DotName.createSimple(annotationType.getName()); - return new AnnotationBuilderImpl(beanArchiveIndex, annotationOverlays, jandexAnnotationName); + return new AnnotationBuilderImpl(beanArchiveIndex, annotationOverlay, jandexAnnotationName); } @Override public AnnotationBuilder create(ClassInfo annotationType) { - if (beanArchiveIndex == null || annotationOverlays == null) { + if (beanArchiveIndex == null || annotationOverlay == null) { throw new IllegalStateException("Can't create AnnotationBuilder right now"); } DotName jandexAnnotationName = ((ClassInfoImpl) annotationType).jandexDeclaration.name(); - return new AnnotationBuilderImpl(beanArchiveIndex, annotationOverlays, jandexAnnotationName); + return new AnnotationBuilderImpl(beanArchiveIndex, annotationOverlay, jandexAnnotationName); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderImpl.java index e45cf95bfeebc8..816ca82f69c4e3 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationBuilderImpl.java @@ -3,7 +3,6 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import jakarta.enterprise.inject.build.compatible.spi.AnnotationBuilder; import jakarta.enterprise.lang.model.AnnotationInfo; @@ -19,15 +18,15 @@ class AnnotationBuilderImpl implements AnnotationBuilder { private final org.jboss.jandex.IndexView jandexIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final DotName jandexClassName; private final List jandexAnnotationMembers = new ArrayList<>(); - AnnotationBuilderImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + AnnotationBuilderImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, DotName jandexAnnotationName) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.jandexClassName = jandexAnnotationName; } @@ -455,7 +454,7 @@ public AnnotationInfo build() { for (org.jboss.jandex.MethodInfo jandexAnnotationMember : jandexAnnotationClass.methods() .stream() .filter(MethodPredicates.IS_METHOD_JANDEX) - .collect(Collectors.toUnmodifiableList())) { + .toList()) { if (jandexAnnotationMember.defaultValue() != null) { continue; } @@ -471,6 +470,6 @@ public AnnotationInfo build() { org.jboss.jandex.AnnotationInstance jandexAnnotation = org.jboss.jandex.AnnotationInstance.create( jandexClassName, null, jandexAnnotationMembers); - return new AnnotationInfoImpl(jandexIndex, annotationOverlays, jandexAnnotation); + return new AnnotationInfoImpl(jandexIndex, annotationOverlay, jandexAnnotation); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationInfoImpl.java index c993d4745f40d9..1a6274ad5e9e48 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationInfoImpl.java @@ -13,13 +13,13 @@ class AnnotationInfoImpl implements AnnotationInfo { final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationOverlays annotationOverlays; + final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; final org.jboss.jandex.AnnotationInstance jandexAnnotation; - AnnotationInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + AnnotationInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.AnnotationInstance jandexAnnotation) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.jandexAnnotation = jandexAnnotation; } @@ -30,7 +30,7 @@ public ClassInfo declaration() { if (annotationClass == null) { throw new IllegalStateException("Class " + annotationClassName + " not found in Jandex"); } - return new ClassInfoImpl(jandexIndex, annotationOverlays, annotationClass); + return new ClassInfoImpl(jandexIndex, annotationOverlay, annotationClass); } @Override @@ -40,7 +40,7 @@ public boolean hasMember(String name) { @Override public AnnotationMember member(String name) { - return new AnnotationMemberImpl(jandexIndex, annotationOverlays, + return new AnnotationMemberImpl(jandexIndex, annotationOverlay, jandexAnnotation.valueWithDefault(jandexIndex, name)); } @@ -49,7 +49,7 @@ public Map members() { Map result = new HashMap<>(); for (org.jboss.jandex.AnnotationValue jandexAnnotationMember : jandexAnnotation.valuesWithDefaults(jandexIndex)) { result.put(jandexAnnotationMember.name(), - new AnnotationMemberImpl(jandexIndex, annotationOverlays, jandexAnnotationMember)); + new AnnotationMemberImpl(jandexIndex, annotationOverlay, jandexAnnotationMember)); } return Collections.unmodifiableMap(result); } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationMemberImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationMemberImpl.java index 210b849b9a6b7c..a11642626f5e6d 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationMemberImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationMemberImpl.java @@ -2,7 +2,6 @@ import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import jakarta.enterprise.lang.model.AnnotationInfo; import jakarta.enterprise.lang.model.AnnotationMember; @@ -11,50 +10,36 @@ class AnnotationMemberImpl implements AnnotationMember { final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationOverlays annotationOverlays; + final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; final Kind kind; final org.jboss.jandex.AnnotationValue jandexAnnotationMember; - AnnotationMemberImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + AnnotationMemberImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.AnnotationValue jandexAnnotationMember) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.kind = determineKind(jandexAnnotationMember); this.jandexAnnotationMember = jandexAnnotationMember; } private static Kind determineKind(org.jboss.jandex.AnnotationValue value) { - switch (value.kind()) { - case BOOLEAN: - return Kind.BOOLEAN; - case BYTE: - return Kind.BYTE; - case SHORT: - return Kind.SHORT; - case INTEGER: - return Kind.INT; - case LONG: - return Kind.LONG; - case FLOAT: - return Kind.FLOAT; - case DOUBLE: - return Kind.DOUBLE; - case CHARACTER: - return Kind.CHAR; - case STRING: - return Kind.STRING; - case ENUM: - return Kind.ENUM; - case CLASS: - return Kind.CLASS; - case NESTED: - return Kind.NESTED_ANNOTATION; - case ARRAY: - return Kind.ARRAY; - default: - throw new IllegalArgumentException("Unknown annotation member " + value); - } + return switch (value.kind()) { + case BOOLEAN -> Kind.BOOLEAN; + case BYTE -> Kind.BYTE; + case SHORT -> Kind.SHORT; + case INTEGER -> Kind.INT; + case LONG -> Kind.LONG; + case FLOAT -> Kind.FLOAT; + case DOUBLE -> Kind.DOUBLE; + case CHARACTER -> Kind.CHAR; + case STRING -> Kind.STRING; + case ENUM -> Kind.ENUM; + case CLASS -> Kind.CLASS; + case NESTED -> Kind.NESTED_ANNOTATION; + case ARRAY -> Kind.ARRAY; + default -> throw new IllegalArgumentException("Unknown annotation member " + value); + }; } private void checkKind(Kind kind) { @@ -137,20 +122,20 @@ public String asEnumConstant() { @Override public ClassInfo asEnumClass() { checkKind(Kind.ENUM); - return new ClassInfoImpl(jandexIndex, annotationOverlays, + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexIndex.getClassByName(jandexAnnotationMember.asEnumType())); } @Override public Type asType() { checkKind(Kind.CLASS); - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, jandexAnnotationMember.asClass()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, jandexAnnotationMember.asClass()); } @Override public AnnotationInfo asNestedAnnotation() { checkKind(Kind.NESTED_ANNOTATION); - return new AnnotationInfoImpl(jandexIndex, annotationOverlays, jandexAnnotationMember.asNested()); + return new AnnotationInfoImpl(jandexIndex, annotationOverlay, jandexAnnotationMember.asNested()); } @Override @@ -158,8 +143,8 @@ public List asArray() { checkKind(Kind.ARRAY); return jandexAnnotationMember.asArrayList() .stream() - .map(it -> new AnnotationMemberImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (AnnotationMember) new AnnotationMemberImpl(jandexIndex, annotationOverlay, it)) + .toList(); } @Override diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationSet.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationSet.java deleted file mode 100644 index 1bf4c672f7ba65..00000000000000 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationSet.java +++ /dev/null @@ -1,133 +0,0 @@ -package io.quarkus.arc.processor.bcextensions; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Repeatable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Predicate; - -import org.jboss.jandex.DotName; - -class AnnotationSet { - private final Map data; - - // used only when this AnnotationSet represents annotations on a class declaration, - // because in such case, annotations may be inherited from superclasses - // - // for each annotation type, this map contains a distance from the original class - // to the class on which an annotation of that type is declared (0 means the annotation - // is declared directly on the original class, 1 means the annotation is declared - // directly on a direct superclass of the original class, etc.) - // - // if this AnnotationSet represents annotations on any other annotation target, - // this map contains 0 for all annotation types - private final Map inheritanceDistances; - - private static Map zeroDistances(Collection jandexAnnotations) { - Map distances = new ConcurrentHashMap<>(); - for (org.jboss.jandex.AnnotationInstance jandexAnnotation : jandexAnnotations) { - distances.put(jandexAnnotation.name(), 0); - } - return distances; - } - - AnnotationSet(Collection jandexAnnotations) { - this(jandexAnnotations, zeroDistances(jandexAnnotations)); - } - - AnnotationSet(Collection jandexAnnotations, - Map inheritanceDistances) { - Map data = new ConcurrentHashMap<>(); - for (org.jboss.jandex.AnnotationInstance jandexAnnotation : jandexAnnotations) { - data.put(jandexAnnotation.name(), jandexAnnotation); - } - this.data = data; - this.inheritanceDistances = inheritanceDistances; - } - - boolean hasAnnotation(Class annotationType) { - DotName name = DotName.createSimple(annotationType.getName()); - return hasAnnotation(name); - } - - boolean hasAnnotation(DotName annotationName) { - return data.containsKey(annotationName); - } - - org.jboss.jandex.AnnotationInstance annotation(Class annotationType) { - DotName name = DotName.createSimple(annotationType.getName()); - return data.get(name); - } - - Collection annotationsWithRepeatable(Class annotationType) { - Repeatable repeatable = annotationType.getAnnotation(Repeatable.class); - - DotName name = DotName.createSimple(annotationType.getName()); - DotName containerName = repeatable != null - ? DotName.createSimple(repeatable.value().getName()) - : DotName.OBJECT_NAME; // not an annotation name, so never present in the map - - if (data.containsKey(name) && data.containsKey(containerName)) { - int annDistance = inheritanceDistances.get(name); - int containerAnnDistance = inheritanceDistances.get(containerName); - if (annDistance < containerAnnDistance) { - return List.of(data.get(name)); - } else if (annDistance == containerAnnDistance) { - // equal inheritance distances may happen if a single annotation of a repeatable annotation type - // is declared, and an annotation of the containing annotation type is also (explicitly!) declared - // (on the same annotation target) - List result = new ArrayList<>(); - result.add(data.get(name)); - org.jboss.jandex.AnnotationInstance container = data.get(containerName); - org.jboss.jandex.AnnotationInstance[] values = container.value().asNestedArray(); - result.addAll(Arrays.asList(values)); - return result; - } else { - org.jboss.jandex.AnnotationInstance container = data.get(containerName); - org.jboss.jandex.AnnotationInstance[] values = container.value().asNestedArray(); - return List.of(values); - } - } else if (data.containsKey(name)) { - return List.of(data.get(name)); - } else if (data.containsKey(containerName)) { - org.jboss.jandex.AnnotationInstance container = data.get(containerName); - org.jboss.jandex.AnnotationInstance[] values = container.value().asNestedArray(); - return List.of(values); - } else { - return List.of(); - } - } - - Collection annotations() { - return Collections.unmodifiableCollection(data.values()); - } - - // --- - // modifications, can only be called from AnnotationsTransformation - - void add(org.jboss.jandex.AnnotationInstance jandexAnnotation) { - data.put(jandexAnnotation.name(), jandexAnnotation); - inheritanceDistances.put(jandexAnnotation.name(), 0); - } - - void removeIf(Predicate predicate) { - Set toRemove = new HashSet<>(); - for (org.jboss.jandex.AnnotationInstance jandexAnnotation : data.values()) { - if (predicate.test(jandexAnnotation)) { - toRemove.add(jandexAnnotation.name()); - } - } - - for (DotName name : toRemove) { - data.remove(name); - inheritanceDistances.remove(name); - } - } -} diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationTargetImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationTargetImpl.java new file mode 100644 index 00000000000000..39af3dc7ef4dca --- /dev/null +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationTargetImpl.java @@ -0,0 +1,24 @@ +package io.quarkus.arc.processor.bcextensions; + +abstract class AnnotationTargetImpl { + final org.jboss.jandex.IndexView jandexIndex; + final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; + private final org.jboss.jandex.EquivalenceKey key; // for equals/hashCode + + AnnotationTargetImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, + org.jboss.jandex.EquivalenceKey key) { + this.jandexIndex = jandexIndex; + this.annotationOverlay = annotationOverlay; + this.key = key; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof AnnotationTargetImpl && key.equals(((AnnotationTargetImpl) obj).key); + } + + @Override + public int hashCode() { + return key.hashCode(); + } +} diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationsOverlay.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationsOverlay.java deleted file mode 100644 index 2ccc6a78a12abd..00000000000000 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationsOverlay.java +++ /dev/null @@ -1,168 +0,0 @@ -package io.quarkus.arc.processor.bcextensions; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -import org.jboss.jandex.DotName; - -// JandexDeclaration must be a Jandex declaration for which Arc supports annotation transformations -// directly (classes, methods, fields) or indirectly (parameters); see also AnnotationsTransformation -abstract class AnnotationsOverlay { - private final Map overlay = new ConcurrentHashMap<>(); - private volatile boolean invalid = false; - - AnnotationSet getAnnotations(JandexDeclaration jandexDeclaration, org.jboss.jandex.IndexView jandexIndex) { - if (invalid) { - throw new IllegalStateException("Annotations overlay no longer valid"); - } - - org.jboss.jandex.EquivalenceKey key = org.jboss.jandex.EquivalenceKey.of(jandexDeclaration); - if (overlay.containsKey(key)) { - return overlay.get(key); - } - - AnnotationSet annotationSet = createAnnotationSet(jandexDeclaration, jandexIndex); - overlay.put(key, annotationSet); - return annotationSet; - } - - boolean hasAnnotation(JandexDeclaration jandexDeclaration, DotName annotationName, org.jboss.jandex.IndexView jandexIndex) { - if (invalid) { - throw new IllegalStateException("Annotations overlay no longer valid"); - } - - org.jboss.jandex.EquivalenceKey key = org.jboss.jandex.EquivalenceKey.of(jandexDeclaration); - boolean hasOverlay = overlay.containsKey(key); - - if (hasOverlay) { - return getAnnotations(jandexDeclaration, jandexIndex).hasAnnotation(annotationName); - } else { - return originalJandexAnnotationsContain(jandexDeclaration, annotationName, jandexIndex); - } - } - - void invalidate() { - overlay.clear(); - invalid = true; - } - - abstract AnnotationSet createAnnotationSet(JandexDeclaration jandexDeclaration, org.jboss.jandex.IndexView jandexIndex); - - // this is "just" an optimization to avoid creating and populating an `AnnotationSet` - // when the only thing we need to know is if an annotation is present - abstract boolean originalJandexAnnotationsContain(JandexDeclaration jandexDeclaration, DotName annotationName, - org.jboss.jandex.IndexView jandexIndex); - - static class Classes extends AnnotationsOverlay { - @Override - AnnotationSet createAnnotationSet(org.jboss.jandex.ClassInfo classInfo, - org.jboss.jandex.IndexView jandexIndex) { - // if an `@Inherited` annotation of some type is declared directly on class C, then annotations - // of the same type declared directly on any direct or indirect superclass are _not_ present on C - Set alreadySeen = new HashSet<>(); - - List jandexAnnotations = new ArrayList<>(); - Map inheritanceDistances = new ConcurrentHashMap<>(); - - int currentDistance = 0; - while (classInfo != null && !classInfo.name().equals(DotNames.OBJECT)) { - for (org.jboss.jandex.AnnotationInstance jandexAnnotation : classInfo.declaredAnnotations()) { - if (!jandexAnnotation.runtimeVisible()) { - continue; - } - - if (alreadySeen.contains(jandexAnnotation.name())) { - continue; - } - alreadySeen.add(jandexAnnotation.name()); - - jandexAnnotations.add(jandexAnnotation); - inheritanceDistances.put(jandexAnnotation.name(), currentDistance); - } - - DotName superClassName = classInfo.superName(); - classInfo = jandexIndex.getClassByName(superClassName); - currentDistance++; - } - - return new AnnotationSet(jandexAnnotations, inheritanceDistances); - } - - @Override - boolean originalJandexAnnotationsContain(org.jboss.jandex.ClassInfo classInfo, DotName annotationName, - org.jboss.jandex.IndexView jandexIndex) { - while (classInfo != null && !classInfo.name().equals(DotNames.OBJECT)) { - org.jboss.jandex.AnnotationInstance jandexAnnotation = classInfo.declaredAnnotation(annotationName); - if (jandexAnnotation != null && jandexAnnotation.runtimeVisible()) { - return true; - } - - DotName superClassName = classInfo.superName(); - classInfo = jandexIndex.getClassByName(superClassName); - } - return false; - } - } - - static class Methods extends AnnotationsOverlay { - @Override - AnnotationSet createAnnotationSet(org.jboss.jandex.MethodInfo methodInfo, - org.jboss.jandex.IndexView jandexIndex) { - List jandexAnnotations = methodInfo.declaredAnnotations() - .stream() - .filter(org.jboss.jandex.AnnotationInstance::runtimeVisible) - .collect(Collectors.toUnmodifiableList()); - return new AnnotationSet(jandexAnnotations); - } - - @Override - boolean originalJandexAnnotationsContain(org.jboss.jandex.MethodInfo methodInfo, DotName annotationName, - org.jboss.jandex.IndexView jandexIndex) { - org.jboss.jandex.AnnotationInstance jandexAnnotation = methodInfo.declaredAnnotation(annotationName); - return jandexAnnotation != null && jandexAnnotation.runtimeVisible(); - } - } - - static class Parameters extends AnnotationsOverlay { - @Override - AnnotationSet createAnnotationSet(org.jboss.jandex.MethodParameterInfo methodParameterInfo, - org.jboss.jandex.IndexView jandexIndex) { - List jandexAnnotations = methodParameterInfo.declaredAnnotations() - .stream() - .filter(org.jboss.jandex.AnnotationInstance::runtimeVisible) - .collect(Collectors.toUnmodifiableList()); - return new AnnotationSet(jandexAnnotations); - } - - @Override - boolean originalJandexAnnotationsContain(org.jboss.jandex.MethodParameterInfo methodParameterInfo, - DotName annotationName, org.jboss.jandex.IndexView jandexIndex) { - org.jboss.jandex.AnnotationInstance jandexAnnotation = methodParameterInfo.declaredAnnotation(annotationName); - return jandexAnnotation != null && jandexAnnotation.runtimeVisible(); - } - } - - static class Fields extends AnnotationsOverlay { - @Override - AnnotationSet createAnnotationSet(org.jboss.jandex.FieldInfo fieldInfo, - org.jboss.jandex.IndexView jandexIndex) { - List jandexAnnotations = fieldInfo.declaredAnnotations() - .stream() - .filter(org.jboss.jandex.AnnotationInstance::runtimeVisible) - .collect(Collectors.toUnmodifiableList()); - return new AnnotationSet(jandexAnnotations); - } - - @Override - boolean originalJandexAnnotationsContain(org.jboss.jandex.FieldInfo fieldInfo, DotName annotationName, - org.jboss.jandex.IndexView jandexIndex) { - org.jboss.jandex.AnnotationInstance jandexAnnotation = fieldInfo.declaredAnnotation(annotationName); - return jandexAnnotation != null && jandexAnnotation.runtimeVisible(); - } - } -} diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationsTransformation.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationsTransformation.java deleted file mode 100644 index 955204c767a998..00000000000000 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/AnnotationsTransformation.java +++ /dev/null @@ -1,215 +0,0 @@ -package io.quarkus.arc.processor.bcextensions; - -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Consumer; -import java.util.function.Predicate; - -import jakarta.enterprise.lang.model.AnnotationInfo; - -import org.jboss.jandex.DotName; - -import io.quarkus.arc.processor.Annotations; - -// this must be symmetric with AnnotationsOverlay -abstract class AnnotationsTransformation - implements io.quarkus.arc.processor.AnnotationsTransformer { - - final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationOverlays annotationOverlays; - - private final org.jboss.jandex.AnnotationTarget.Kind kind; - private final Map>> transformations = new ConcurrentHashMap<>(); - - private volatile boolean frozen = false; - - AnnotationsTransformation(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, - org.jboss.jandex.AnnotationTarget.Kind kind) { - this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; - this.kind = kind; - } - - private void addAnnotation(JandexDeclaration jandexDeclaration, org.jboss.jandex.AnnotationInstance jandexAnnotation) { - if (frozen) { - throw new IllegalStateException("Annotations transformation frozen"); - } - - org.jboss.jandex.EquivalenceKey key = org.jboss.jandex.EquivalenceKey.of(jandexDeclaration); - - org.jboss.jandex.AnnotationInstance jandexAnnotationWithTarget = org.jboss.jandex.AnnotationInstance.create( - jandexAnnotation.name(), jandexDeclaration, jandexAnnotation.values()); - - annotationsOverlay().getAnnotations(jandexDeclaration, jandexIndex).add(jandexAnnotationWithTarget); - - Consumer transformation = ctx -> { - ctx.transform().add(jandexAnnotationWithTarget).done(); - }; - transformations.computeIfAbsent(key, ignored -> new ArrayList<>()).add(transformation); - } - - void addAnnotation(JandexDeclaration jandexDeclaration, Class clazz) { - org.jboss.jandex.AnnotationInstance jandexAnnotation = org.jboss.jandex.AnnotationInstance.create( - DotName.createSimple(clazz.getName()), null, AnnotationValueArray.EMPTY); - - addAnnotation(jandexDeclaration, jandexAnnotation); - } - - void addAnnotation(JandexDeclaration jandexDeclaration, AnnotationInfo annotation) { - addAnnotation(jandexDeclaration, ((AnnotationInfoImpl) annotation).jandexAnnotation); - } - - void addAnnotation(JandexDeclaration jandexDeclaration, Annotation annotation) { - addAnnotation(jandexDeclaration, Annotations.jandexAnnotation(annotation)); - } - - private void removeMatchingAnnotations(JandexDeclaration declaration, - Predicate predicate) { - - if (frozen) { - throw new IllegalStateException("Annotations transformation frozen"); - } - - org.jboss.jandex.EquivalenceKey key = org.jboss.jandex.EquivalenceKey.of(declaration); - - annotationsOverlay().getAnnotations(declaration, jandexIndex).removeIf(predicate); - - Consumer transformation = ctx -> { - ctx.transform().remove(predicate).done(); - }; - transformations.computeIfAbsent(key, ignored -> new ArrayList<>()).add(transformation); - } - - void removeAnnotation(JandexDeclaration declaration, Predicate predicate) { - org.jboss.jandex.EquivalenceKey key = org.jboss.jandex.EquivalenceKey.of(declaration); - - removeMatchingAnnotations(declaration, new Predicate() { - @Override - public boolean test(org.jboss.jandex.AnnotationInstance jandexAnnotation) { - // we only verify the target here because ArC doesn't support annotation transformation - // on method parameters directly; instead, it must be implemented indirectly by transforming - // annotations on the _method_ - return key.equals(org.jboss.jandex.EquivalenceKey.of(jandexAnnotation.target())) - && predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlays, jandexAnnotation)); - } - }); - } - - void removeAllAnnotations(JandexDeclaration declaration) { - removeAnnotation(declaration, ignored -> true); - } - - void freeze() { - frozen = true; - } - - // `appliesTo` and `transform` must be overridden for `Parameters`, because ArC doesn't - // support annotation transformation on method parameters directly; instead, it must be - // implemented indirectly by transforming annotations on the _method_ (and setting proper - // annotation target) - - @Override - public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) { - return this.kind == kind; - } - - @Override - public void transform(TransformationContext ctx) { - JandexDeclaration jandexDeclaration = targetJandexDeclaration(ctx); - org.jboss.jandex.EquivalenceKey key = org.jboss.jandex.EquivalenceKey.of(jandexDeclaration); - transformations.getOrDefault(key, Collections.emptyList()) - .forEach(it -> it.accept(ctx)); - } - - abstract JandexDeclaration targetJandexDeclaration(TransformationContext ctx); - - abstract AnnotationsOverlay annotationsOverlay(); - - static class Classes extends AnnotationsTransformation { - Classes(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays) { - super(jandexIndex, annotationOverlays, org.jboss.jandex.AnnotationTarget.Kind.CLASS); - } - - @Override - protected org.jboss.jandex.ClassInfo targetJandexDeclaration( - io.quarkus.arc.processor.AnnotationsTransformer.TransformationContext ctx) { - return ctx.getTarget().asClass(); - } - - @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.classes; - } - } - - static class Methods extends AnnotationsTransformation { - Methods(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays) { - super(jandexIndex, annotationOverlays, org.jboss.jandex.AnnotationTarget.Kind.METHOD); - } - - @Override - protected org.jboss.jandex.MethodInfo targetJandexDeclaration( - io.quarkus.arc.processor.AnnotationsTransformer.TransformationContext ctx) { - return ctx.getTarget().asMethod(); - } - - @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.methods; - } - } - - static class Parameters extends AnnotationsTransformation { - Parameters(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays) { - super(jandexIndex, annotationOverlays, org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER); - } - - @Override - protected org.jboss.jandex.MethodParameterInfo targetJandexDeclaration( - io.quarkus.arc.processor.AnnotationsTransformer.TransformationContext ctx) { - // `targetJandexDeclaration` is only called from `super.transform`, which we override here - throw new UnsupportedOperationException(); - } - - @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.parameters; - } - - @Override - public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) { - return org.jboss.jandex.AnnotationTarget.Kind.METHOD == kind; - } - - @Override - public void transform(TransformationContext ctx) { - org.jboss.jandex.MethodInfo jandexMethod = ctx.getTarget().asMethod(); - for (org.jboss.jandex.MethodParameterInfo jandexDeclaration : jandexMethod.parameters()) { - org.jboss.jandex.EquivalenceKey key = org.jboss.jandex.EquivalenceKey.of(jandexDeclaration); - super.transformations.getOrDefault(key, Collections.emptyList()) - .forEach(it -> it.accept(ctx)); - } - } - } - - static class Fields extends AnnotationsTransformation { - Fields(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays) { - super(jandexIndex, annotationOverlays, org.jboss.jandex.AnnotationTarget.Kind.FIELD); - } - - @Override - protected org.jboss.jandex.FieldInfo targetJandexDeclaration( - io.quarkus.arc.processor.AnnotationsTransformer.TransformationContext ctx) { - return ctx.getTarget().asField(); - } - - @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.fields; - } - } -} diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ArrayTypeImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ArrayTypeImpl.java index 88e20c2c9cfe63..f0e697834c7249 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ArrayTypeImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ArrayTypeImpl.java @@ -4,9 +4,9 @@ import jakarta.enterprise.lang.model.types.Type; class ArrayTypeImpl extends TypeImpl implements ArrayType { - ArrayTypeImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + ArrayTypeImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.ArrayType jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); } @Override @@ -15,6 +15,6 @@ public Type componentType() { org.jboss.jandex.Type componentType = dimensions == 1 ? jandexType.constituent() : org.jboss.jandex.ArrayType.create(jandexType.constituent(), dimensions - 1); - return fromJandexType(jandexIndex, annotationOverlays, componentType); + return fromJandexType(jandexIndex, annotationOverlay, componentType); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BeanInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BeanInfoImpl.java index 7be224753d5cca..430008708b6d1f 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BeanInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BeanInfoImpl.java @@ -16,35 +16,36 @@ class BeanInfoImpl implements BeanInfo { final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationOverlays annotationOverlays; + final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; final io.quarkus.arc.processor.BeanInfo arcBeanInfo; - static BeanInfoImpl create(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + static BeanInfoImpl create(org.jboss.jandex.IndexView jandexIndex, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.BeanInfo arcBeanInfo) { if (arcBeanInfo.isInterceptor()) { - return new InterceptorInfoImpl(jandexIndex, annotationOverlays, + return new InterceptorInfoImpl(jandexIndex, annotationOverlay, (io.quarkus.arc.processor.InterceptorInfo) arcBeanInfo); } - return new BeanInfoImpl(jandexIndex, annotationOverlays, arcBeanInfo); + return new BeanInfoImpl(jandexIndex, annotationOverlay, arcBeanInfo); } - BeanInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + BeanInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.BeanInfo arcBeanInfo) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.arcBeanInfo = arcBeanInfo; } @Override public ScopeInfo scope() { - return new ScopeInfoImpl(jandexIndex, annotationOverlays, arcBeanInfo.getScope()); + return new ScopeInfoImpl(jandexIndex, annotationOverlay, arcBeanInfo.getScope()); } @Override public Collection types() { return arcBeanInfo.getTypes() .stream() - .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlays, it)) + .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlay, it)) .collect(Collectors.toUnmodifiableSet()); } @@ -52,14 +53,14 @@ public Collection types() { public Collection qualifiers() { return arcBeanInfo.getQualifiers() .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (AnnotationInfo) new AnnotationInfoImpl(jandexIndex, annotationOverlay, it)) + .toList(); } @Override public ClassInfo declaringClass() { org.jboss.jandex.ClassInfo beanClass = jandexIndex.getClassByName(arcBeanInfo.getBeanClass()); - return new ClassInfoImpl(jandexIndex, annotationOverlays, beanClass); + return new ClassInfoImpl(jandexIndex, annotationOverlay, beanClass); } @Override @@ -85,7 +86,7 @@ public boolean isSynthetic() { @Override public MethodInfo producerMethod() { if (arcBeanInfo.isProducerMethod()) { - return new MethodInfoImpl(jandexIndex, annotationOverlays, arcBeanInfo.getTarget().get().asMethod()); + return new MethodInfoImpl(jandexIndex, annotationOverlay, arcBeanInfo.getTarget().get().asMethod()); } return null; } @@ -93,7 +94,7 @@ public MethodInfo producerMethod() { @Override public FieldInfo producerField() { if (arcBeanInfo.isProducerField()) { - return new FieldInfoImpl(jandexIndex, annotationOverlays, arcBeanInfo.getTarget().get().asField()); + return new FieldInfoImpl(jandexIndex, annotationOverlay, arcBeanInfo.getTarget().get().asField()); } return null; } @@ -116,23 +117,23 @@ public String name() { @Override public DisposerInfo disposer() { io.quarkus.arc.processor.DisposerInfo disposer = arcBeanInfo.getDisposer(); - return disposer != null ? new DisposerInfoImpl(jandexIndex, annotationOverlays, disposer) : null; + return disposer != null ? new DisposerInfoImpl(jandexIndex, annotationOverlay, disposer) : null; } @Override public Collection stereotypes() { return arcBeanInfo.getStereotypes() .stream() - .map(it -> new StereotypeInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (StereotypeInfo) new StereotypeInfoImpl(jandexIndex, annotationOverlay, it)) + .toList(); } @Override public Collection injectionPoints() { return arcBeanInfo.getAllInjectionPoints() .stream() - .map(it -> new InjectionPointInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (InjectionPointInfo) new InjectionPointInfoImpl(jandexIndex, annotationOverlay, it)) + .toList(); } @Override diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BuildServicesImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BuildServicesImpl.java index 59eabf9063d23e..ee8abcfeec094b 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BuildServicesImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/BuildServicesImpl.java @@ -5,21 +5,21 @@ public class BuildServicesImpl implements BuildServices { private static volatile org.jboss.jandex.IndexView beanArchiveIndex; - private static volatile AllAnnotationOverlays annotationOverlays; + private static volatile org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; - static void init(org.jboss.jandex.IndexView beanArchiveIndex, AllAnnotationOverlays annotationOverlays) { + static void init(org.jboss.jandex.IndexView beanArchiveIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay) { BuildServicesImpl.beanArchiveIndex = beanArchiveIndex; - BuildServicesImpl.annotationOverlays = annotationOverlays; + BuildServicesImpl.annotationOverlay = annotationOverlay; } static void reset() { BuildServicesImpl.beanArchiveIndex = null; - BuildServicesImpl.annotationOverlays = null; + BuildServicesImpl.annotationOverlay = null; } @Override public AnnotationBuilderFactory annotationBuilderFactory() { - return new AnnotationBuilderFactoryImpl(beanArchiveIndex, annotationOverlays); + return new AnnotationBuilderFactoryImpl(beanArchiveIndex, annotationOverlay); } @Override diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassConfigImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassConfigImpl.java index a3e04d0cc1fb63..1a8f3975b5637d 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassConfigImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassConfigImpl.java @@ -13,21 +13,21 @@ import jakarta.enterprise.lang.model.declarations.MethodInfo; class ClassConfigImpl extends DeclarationConfigImpl implements ClassConfig { - ClassConfigImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationTransformations allTransformations, + ClassConfigImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.ClassInfo jandexDeclaration) { - super(jandexIndex, allTransformations, allTransformations.classes, jandexDeclaration); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override public ClassInfo info() { - return new ClassInfoImpl(jandexIndex, allTransformations.annotationOverlays, jandexDeclaration); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration); } @Override public Collection constructors() { List result = new ArrayList<>(); for (MethodInfo constructor : info().constructors()) { - result.add(new MethodConfigImpl(jandexIndex, allTransformations, ((MethodInfoImpl) constructor).jandexDeclaration)); + result.add(new MethodConfigImpl(jandexIndex, annotationOverlay, ((MethodInfoImpl) constructor).jandexDeclaration)); } return Collections.unmodifiableList(result); } @@ -36,7 +36,7 @@ public Collection constructors() { public Collection methods() { List result = new ArrayList<>(); for (MethodInfo method : info().methods()) { - result.add(new MethodConfigImpl(jandexIndex, allTransformations, ((MethodInfoImpl) method).jandexDeclaration)); + result.add(new MethodConfigImpl(jandexIndex, annotationOverlay, ((MethodInfoImpl) method).jandexDeclaration)); } return Collections.unmodifiableList(result); } @@ -45,7 +45,7 @@ public Collection methods() { public Collection fields() { List result = new ArrayList<>(); for (FieldInfo field : info().fields()) { - result.add(new FieldConfigImpl(jandexIndex, allTransformations, ((FieldInfoImpl) field).jandexDeclaration)); + result.add(new FieldConfigImpl(jandexIndex, annotationOverlay, ((FieldInfoImpl) field).jandexDeclaration)); } return Collections.unmodifiableList(result); } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassInfoImpl.java index d39cdd033e8e6e..56f792b0bf2367 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassInfoImpl.java @@ -7,10 +7,8 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Queue; import java.util.Set; -import java.util.stream.Collectors; import jakarta.enterprise.lang.model.declarations.ClassInfo; import jakarta.enterprise.lang.model.declarations.FieldInfo; @@ -23,13 +21,9 @@ import org.jboss.jandex.DotName; class ClassInfoImpl extends DeclarationInfoImpl implements ClassInfo { - // only for equals/hashCode - private final DotName name; - - ClassInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + ClassInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.ClassInfo jandexDeclaration) { - super(jandexIndex, annotationOverlays, jandexDeclaration); - this.name = jandexDeclaration.name(); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override @@ -47,17 +41,17 @@ public PackageInfo packageInfo() { String packageName = jandexDeclaration.name().packagePrefix(); org.jboss.jandex.ClassInfo packageClass = jandexIndex.getClassByName( DotName.createSimple(packageName + ".package-info")); - return new PackageInfoImpl(jandexIndex, annotationOverlays, packageClass); + return new PackageInfoImpl(jandexIndex, annotationOverlay, packageClass); } @Override public List typeParameters() { return jandexDeclaration.typeParameters() .stream() - .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlays, it)) + .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlay, it)) .filter(Type::isTypeVariable) // not necessary, just as a precaution .map(Type::asTypeVariable) // not necessary, just as a precaution - .collect(Collectors.toUnmodifiableList()); + .toList(); } @Override @@ -66,7 +60,7 @@ public Type superClass() { if (jandexSuperType == null) { return null; } - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, jandexSuperType); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, jandexSuperType); } @Override @@ -75,23 +69,23 @@ public ClassInfo superClassDeclaration() { if (jandexSuperType == null) { return null; } - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexIndex.getClassByName(jandexSuperType)); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexIndex.getClassByName(jandexSuperType)); } @Override public List superInterfaces() { return jandexDeclaration.interfaceTypes() .stream() - .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlay, it)) + .toList(); } @Override public List superInterfacesDeclarations() { return jandexDeclaration.interfaceNames() .stream() - .map(it -> new ClassInfoImpl(jandexIndex, annotationOverlays, jandexIndex.getClassByName(it))) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (ClassInfo) new ClassInfoImpl(jandexIndex, annotationOverlay, jandexIndex.getClassByName(it))) + .toList(); } @Override @@ -145,7 +139,7 @@ public Collection constructors() { continue; } if (MethodPredicates.IS_CONSTRUCTOR_JANDEX.test(jandexMethod)) { - result.add(new MethodInfoImpl(jandexIndex, annotationOverlays, jandexMethod)); + result.add(new MethodInfoImpl(jandexIndex, annotationOverlay, jandexMethod)); } } return Collections.unmodifiableList(result); @@ -187,7 +181,7 @@ public Collection methods() { continue; } if (MethodPredicates.IS_METHOD_JANDEX.test(jandexMethod)) { - result.add(new MethodInfoImpl(jandexIndex, annotationOverlays, jandexMethod)); + result.add(new MethodInfoImpl(jandexIndex, annotationOverlay, jandexMethod)); } } } @@ -202,7 +196,7 @@ public Collection fields() { if (jandexField.isSynthetic()) { continue; } - result.add(new FieldInfoImpl(jandexIndex, annotationOverlays, jandexField)); + result.add(new FieldInfoImpl(jandexIndex, annotationOverlay, jandexField)); } } return Collections.unmodifiableList(result); @@ -210,29 +204,10 @@ public Collection fields() { @Override public Collection recordComponents() { - return jandexDeclaration.recordComponents() - .stream() - .map(it -> new RecordComponentInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); - } - - @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.classes; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - ClassInfoImpl classInfo = (ClassInfoImpl) o; - return Objects.equals(name, classInfo.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); + List result = new ArrayList<>(); + for (org.jboss.jandex.RecordComponentInfo recordComponent : jandexDeclaration.recordComponents()) { + result.add(new RecordComponentInfoImpl(jandexIndex, annotationOverlay, recordComponent)); + } + return Collections.unmodifiableList(result); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassTypeImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassTypeImpl.java index faa789d1b89c1d..e1e4e5b262c253 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassTypeImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ClassTypeImpl.java @@ -6,14 +6,14 @@ import org.jboss.jandex.DotName; class ClassTypeImpl extends TypeImpl implements ClassType { - ClassTypeImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + ClassTypeImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.ClassType jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); } @Override public ClassInfo declaration() { DotName name = jandexType.name(); - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexIndex.getClassByName(name)); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexIndex.getClassByName(name)); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationConfigImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationConfigImpl.java index d88e14473d7038..1ae02cca43cc60 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationConfigImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationConfigImpl.java @@ -6,48 +6,51 @@ import jakarta.enterprise.inject.build.compatible.spi.DeclarationConfig; import jakarta.enterprise.lang.model.AnnotationInfo; -abstract class DeclarationConfigImpl> +abstract class DeclarationConfigImpl> implements DeclarationConfig { final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationTransformations allTransformations; - final AnnotationsTransformation transformations; + final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; final JandexDeclaration jandexDeclaration; - DeclarationConfigImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationTransformations allTransformations, - AnnotationsTransformation transformations, JandexDeclaration jandexDeclaration) { + DeclarationConfigImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, + JandexDeclaration jandexDeclaration) { this.jandexIndex = jandexIndex; - this.allTransformations = allTransformations; - this.transformations = transformations; + this.annotationOverlay = annotationOverlay; this.jandexDeclaration = jandexDeclaration; } @Override public THIS addAnnotation(Class annotationType) { - transformations.addAnnotation(jandexDeclaration, annotationType); + annotationOverlay.addAnnotation(jandexDeclaration, org.jboss.jandex.AnnotationInstance.builder(annotationType).build()); return (THIS) this; } @Override public THIS addAnnotation(AnnotationInfo annotation) { - transformations.addAnnotation(jandexDeclaration, annotation); + annotationOverlay.addAnnotation(jandexDeclaration, ((AnnotationInfoImpl) annotation).jandexAnnotation); return (THIS) this; } @Override public THIS addAnnotation(Annotation annotation) { - transformations.addAnnotation(jandexDeclaration, annotation); + annotationOverlay.addAnnotation(jandexDeclaration, io.quarkus.arc.processor.Annotations.jandexAnnotation(annotation)); return (THIS) this; } @Override public THIS removeAnnotation(Predicate predicate) { - transformations.removeAnnotation(jandexDeclaration, predicate); + annotationOverlay.removeAnnotations(jandexDeclaration, new Predicate() { + @Override + public boolean test(org.jboss.jandex.AnnotationInstance annotationInstance) { + return predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotationInstance)); + } + }); return (THIS) this; } @Override public THIS removeAllAnnotations() { - transformations.removeAllAnnotations(jandexDeclaration); + annotationOverlay.removeAnnotations(jandexDeclaration, ignored -> true); return (THIS) this; } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationInfoImpl.java index 72da5f7d03bd3b..e7571b769de700 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DeclarationInfoImpl.java @@ -1,93 +1,80 @@ package io.quarkus.arc.processor.bcextensions; import java.lang.annotation.Annotation; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.function.Predicate; -import java.util.stream.Collectors; import jakarta.enterprise.lang.model.AnnotationInfo; import jakarta.enterprise.lang.model.declarations.DeclarationInfo; -import org.jboss.jandex.DotName; - -abstract class DeclarationInfoImpl implements DeclarationInfo { - final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationOverlays annotationOverlays; +abstract class DeclarationInfoImpl extends AnnotationTargetImpl + implements DeclarationInfo { final JandexDeclaration jandexDeclaration; - DeclarationInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + DeclarationInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, JandexDeclaration jandexDeclaration) { - this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + super(jandexIndex, annotationOverlay, org.jboss.jandex.EquivalenceKey.of(jandexDeclaration)); this.jandexDeclaration = jandexDeclaration; } - static DeclarationInfo fromJandexDeclaration(org.jboss.jandex.IndexView jandexIndex, - AllAnnotationOverlays annotationOverlays, - org.jboss.jandex.AnnotationTarget jandexDeclaration) { - switch (jandexDeclaration.kind()) { - case CLASS: - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.asClass()); - case METHOD: - return new MethodInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.asMethod()); - case METHOD_PARAMETER: - return new ParameterInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.asMethodParameter()); - case FIELD: - return new FieldInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.asField()); - default: - throw new IllegalStateException("Unknown declaration " + jandexDeclaration); - } - } - @Override public boolean hasAnnotation(Class annotationType) { - return annotationsOverlay().hasAnnotation(jandexDeclaration, DotName.createSimple(annotationType.getName()), - jandexIndex); + return annotationOverlay.hasAnnotation(jandexDeclaration, annotationType); } @Override public boolean hasAnnotation(Predicate predicate) { - return annotationsOverlay().getAnnotations(jandexDeclaration, jandexIndex).annotations() - .stream() - .anyMatch(it -> predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlays, it))); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration)) { + if (predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation))) { + return true; + } + } + return false; } @Override public AnnotationInfo annotation(Class annotationType) { - org.jboss.jandex.AnnotationInstance jandexAnnotation = annotationsOverlay().getAnnotations( - jandexDeclaration, jandexIndex).annotation(annotationType); - if (jandexAnnotation == null) { + org.jboss.jandex.AnnotationInstance annotation = annotationOverlay.annotation(jandexDeclaration, annotationType); + if (annotation == null) { return null; } - return new AnnotationInfoImpl(jandexIndex, annotationOverlays, jandexAnnotation); + return new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation); } @Override public Collection repeatableAnnotation(Class annotationType) { - return annotationsOverlay().getAnnotations(jandexDeclaration, jandexIndex) - .annotationsWithRepeatable(annotationType) - .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotationsWithRepeatable(jandexDeclaration, + annotationType)) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + return Collections.unmodifiableList(result); } @Override public Collection annotations(Predicate predicate) { - return annotationsOverlay().getAnnotations(jandexDeclaration, jandexIndex) - .annotations() - .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .filter(predicate) - .collect(Collectors.toUnmodifiableList()); + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration)) { + AnnotationInfo annotationInfo = new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation); + if (predicate.test(annotationInfo)) { + result.add(annotationInfo); + } + } + return Collections.unmodifiableList(result); } @Override public Collection annotations() { - return annotations(it -> true); + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration)) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + return Collections.unmodifiableList(result); } - abstract AnnotationsOverlay annotationsOverlay(); - @Override public String toString() { return jandexDeclaration.toString(); diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DisposerInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DisposerInfoImpl.java index 7dbe54ed0ea0b8..4c14bed64d6925 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DisposerInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/DisposerInfoImpl.java @@ -6,25 +6,25 @@ class DisposerInfoImpl implements DisposerInfo { private final org.jboss.jandex.IndexView jandexIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final io.quarkus.arc.processor.DisposerInfo arcDisposerInfo; - DisposerInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + DisposerInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.DisposerInfo arcDisposerInfo) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.arcDisposerInfo = arcDisposerInfo; } @Override public MethodInfo disposerMethod() { org.jboss.jandex.MethodInfo jandexMethod = arcDisposerInfo.getDisposerMethod(); - return new MethodInfoImpl(jandexIndex, annotationOverlays, jandexMethod); + return new MethodInfoImpl(jandexIndex, annotationOverlay, jandexMethod); } @Override public ParameterInfo disposedParameter() { org.jboss.jandex.MethodParameterInfo jandexParameter = arcDisposerInfo.getDisposedParameter(); - return new ParameterInfoImpl(jandexIndex, annotationOverlays, jandexParameter); + return new ParameterInfoImpl(jandexIndex, annotationOverlay, jandexParameter); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionInvoker.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionInvoker.java index bdfa4e8542ec7b..72dc4ef9ca3a03 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionInvoker.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionInvoker.java @@ -10,13 +10,11 @@ import java.util.Map; import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; import jakarta.interceptor.Interceptor; import org.jboss.jandex.DotName; -import org.jboss.jandex.JandexReflection; // only this class uses reflection, everything else in this package is reflection-free class ExtensionInvoker { @@ -69,7 +67,7 @@ List findExtensionMethods(DotName annotation) { return p1 < p2 ? -1 : 1; }) .map(ExtensionMethod::new) - .collect(Collectors.toUnmodifiableList()); + .toList(); } private int getExtensionMethodPriority(org.jboss.jandex.MethodInfo method) { @@ -85,7 +83,7 @@ void callExtensionMethod(ExtensionMethod method, List arguments) Class[] parameterTypes = new Class[arguments.size()]; for (int i = 0; i < parameterTypes.length; i++) { - parameterTypes[i] = JandexReflection.loadRawType(method.parameterType(i)); + parameterTypes[i] = org.jboss.jandex.JandexReflection.loadRawType(method.parameterType(i)); } Class extensionClass = extensionClasses.get(method.extensionClass.name().toString()); diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseDiscovery.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseDiscovery.java index ca4a3cf79cc5cc..3451406386f834 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseDiscovery.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseDiscovery.java @@ -11,19 +11,19 @@ class ExtensionPhaseDiscovery extends ExtensionPhaseBase { private final Set additionalClasses; - private final AllAnnotationTransformations annotationTransformations; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final Map qualifiers; private final Map interceptorBindings; private final Map stereotypes; private final List contexts; ExtensionPhaseDiscovery(ExtensionInvoker invoker, org.jboss.jandex.IndexView applicationIndex, SharedErrors errors, - Set additionalClasses, AllAnnotationTransformations annotationTransformations, + Set additionalClasses, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, Map qualifiers, Map interceptorBindings, Map stereotypes, List contexts) { super(ExtensionPhase.DISCOVERY, invoker, applicationIndex, errors); this.additionalClasses = additionalClasses; - this.annotationTransformations = annotationTransformations; + this.annotationOverlay = annotationOverlay; this.qualifiers = qualifiers; this.interceptorBindings = interceptorBindings; this.stereotypes = stereotypes; @@ -32,15 +32,11 @@ class ExtensionPhaseDiscovery extends ExtensionPhaseBase { @Override Object argumentForExtensionMethod(ExtensionMethodParameter type, ExtensionMethod method) { - switch (type) { - case META_ANNOTATIONS: - return new MetaAnnotationsImpl(index, annotationTransformations, qualifiers, interceptorBindings, - stereotypes, contexts); - case SCANNED_CLASSES: - return new ScannedClassesImpl(additionalClasses); - - default: - return super.argumentForExtensionMethod(type, method); - } + return switch (type) { + case META_ANNOTATIONS -> new MetaAnnotationsImpl(index, annotationOverlay, qualifiers, interceptorBindings, + stereotypes, contexts); + case SCANNED_CLASSES -> new ScannedClassesImpl(additionalClasses); + default -> super.argumentForExtensionMethod(type, method); + }; } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseEnhancement.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseEnhancement.java index 87f36c5d07edba..05933271b4cef9 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseEnhancement.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseEnhancement.java @@ -7,7 +7,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import jakarta.enterprise.inject.spi.DefinitionException; @@ -15,14 +14,12 @@ import org.jboss.jandex.DotName; class ExtensionPhaseEnhancement extends ExtensionPhaseBase { - private final AllAnnotationOverlays annotationOverlays; - private final AllAnnotationTransformations annotationTransformations; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; ExtensionPhaseEnhancement(ExtensionInvoker invoker, org.jboss.jandex.IndexView beanArchiveIndex, - SharedErrors errors, AllAnnotationTransformations annotationTransformations) { + SharedErrors errors, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay) { super(ExtensionPhase.ENHANCEMENT, invoker, beanArchiveIndex, errors); - this.annotationOverlays = annotationTransformations.annotationOverlays; - this.annotationTransformations = annotationTransformations; + this.annotationOverlay = annotationOverlay; } @Override @@ -56,35 +53,35 @@ void runExtensionMethod(ExtensionMethod method) throws ReflectiveOperationExcept .get(); // guaranteed to be there List matchingClasses = matchingClasses(method.jandex); - List allValuesForQueryParameter; + List allValuesForQueryParameter; if (query == ExtensionMethodParameter.CLASS_INFO) { allValuesForQueryParameter = matchingClasses.stream() - .map(it -> new ClassInfoImpl(index, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> new ClassInfoImpl(index, annotationOverlay, it)) + .toList(); } else if (query == ExtensionMethodParameter.METHOD_INFO) { allValuesForQueryParameter = matchingClasses.stream() - .map(it -> new ClassInfoImpl(index, annotationOverlays, it)) + .map(it -> new ClassInfoImpl(index, annotationOverlay, it)) .flatMap(it -> Stream.concat(it.constructors().stream(), it.methods().stream())) - .collect(Collectors.toUnmodifiableList()); + .toList(); } else if (query == ExtensionMethodParameter.FIELD_INFO) { allValuesForQueryParameter = matchingClasses.stream() - .map(it -> new ClassInfoImpl(index, annotationOverlays, it)) + .map(it -> new ClassInfoImpl(index, annotationOverlay, it)) .flatMap(it -> it.fields().stream()) - .collect(Collectors.toUnmodifiableList()); + .toList(); } else if (query == ExtensionMethodParameter.CLASS_CONFIG) { allValuesForQueryParameter = matchingClasses.stream() - .map(it -> new ClassConfigImpl(index, annotationTransformations, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> new ClassConfigImpl(index, annotationOverlay, it)) + .toList(); } else if (query == ExtensionMethodParameter.METHOD_CONFIG) { allValuesForQueryParameter = matchingClasses.stream() - .map(it -> new ClassConfigImpl(index, annotationTransformations, it)) + .map(it -> new ClassConfigImpl(index, annotationOverlay, it)) .flatMap(it -> Stream.concat(it.constructors().stream(), it.methods().stream())) - .collect(Collectors.toUnmodifiableList()); + .toList(); } else if (query == ExtensionMethodParameter.FIELD_CONFIG) { allValuesForQueryParameter = matchingClasses.stream() - .map(it -> new ClassConfigImpl(index, annotationTransformations, it)) + .map(it -> new ClassConfigImpl(index, annotationOverlay, it)) .flatMap(it -> it.fields().stream()) - .collect(Collectors.toUnmodifiableList()); + .toList(); } else { throw new IllegalArgumentException("Unknown query parameter " + query); } @@ -168,7 +165,7 @@ && isAnyAnnotationPresent(annotationNames, annotationDeclaration, alreadyProcess @Override Object argumentForExtensionMethod(ExtensionMethodParameter type, ExtensionMethod method) { if (type == ExtensionMethodParameter.TYPES) { - return new TypesImpl(index, annotationOverlays); + return new TypesImpl(index, annotationOverlay); } return super.argumentForExtensionMethod(type, method); diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseRegistration.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseRegistration.java index 40cf58d2612fc3..7f5e3667f84e27 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseRegistration.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseRegistration.java @@ -5,31 +5,28 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import jakarta.enterprise.inject.build.compatible.spi.BeanInfo; import jakarta.enterprise.inject.build.compatible.spi.ObserverInfo; import jakarta.enterprise.inject.spi.DefinitionException; -import org.jboss.jandex.IndexView; - import io.quarkus.arc.processor.InterceptorInfo; class ExtensionPhaseRegistration extends ExtensionPhaseBase { - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final Collection allBeans; private final Collection allInterceptors; private final Collection allObservers; private final io.quarkus.arc.processor.InvokerFactory invokerFactory; private final io.quarkus.arc.processor.AssignabilityCheck assignability; - ExtensionPhaseRegistration(ExtensionInvoker invoker, IndexView beanArchiveIndex, SharedErrors errors, - AllAnnotationOverlays annotationOverlays, Collection allBeans, + ExtensionPhaseRegistration(ExtensionInvoker invoker, org.jboss.jandex.IndexView beanArchiveIndex, SharedErrors errors, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, Collection allBeans, Collection allInterceptors, Collection allObservers, io.quarkus.arc.processor.InvokerFactory invokerFactory) { super(ExtensionPhase.REGISTRATION, invoker, beanArchiveIndex, errors); - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.allBeans = allBeans; this.allInterceptors = allInterceptors; this.allObservers = allObservers; @@ -106,8 +103,8 @@ private List matchingBeans(org.jboss.jandex.MethodInfo jandexMethod, b } return false; }) - .map(it -> BeanInfoImpl.create(index, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (BeanInfo) BeanInfoImpl.create(index, annotationOverlay, it)) + .toList(); } private List matchingObservers(org.jboss.jandex.MethodInfo jandexMethod) { @@ -122,18 +119,17 @@ private List matchingObservers(org.jboss.jandex.MethodInfo jandexM } return false; }) - .map(it -> new ObserverInfoImpl(index, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (ObserverInfo) new ObserverInfoImpl(index, annotationOverlay, it)) + .toList(); } @Override Object argumentForExtensionMethod(ExtensionMethodParameter type, ExtensionMethod method) { - if (type == ExtensionMethodParameter.INVOKER_FACTORY) { - return new InvokerFactoryImpl(invokerFactory); - } else if (type == ExtensionMethodParameter.TYPES) { - return new TypesImpl(index, annotationOverlays); - } + return switch (type) { + case INVOKER_FACTORY -> new InvokerFactoryImpl(invokerFactory); + case TYPES -> new TypesImpl(index, annotationOverlay); + default -> super.argumentForExtensionMethod(type, method); + }; - return super.argumentForExtensionMethod(type, method); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseSynthesis.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseSynthesis.java index 40f4e18b2ff8fb..cd4ec5135d0c1a 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseSynthesis.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseSynthesis.java @@ -2,34 +2,28 @@ import java.util.List; -import org.jboss.jandex.DotName; - class ExtensionPhaseSynthesis extends ExtensionPhaseBase { - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final List> syntheticBeans; private final List> syntheticObservers; ExtensionPhaseSynthesis(ExtensionInvoker invoker, org.jboss.jandex.IndexView beanArchiveIndex, SharedErrors errors, - AllAnnotationOverlays annotationOverlays, List> syntheticBeans, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, List> syntheticBeans, List> syntheticObservers) { super(ExtensionPhase.SYNTHESIS, invoker, beanArchiveIndex, errors); - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.syntheticBeans = syntheticBeans; this.syntheticObservers = syntheticObservers; } @Override Object argumentForExtensionMethod(ExtensionMethodParameter type, ExtensionMethod method) { - switch (type) { - case SYNTHETIC_COMPONENTS: - DotName extensionClass = method.extensionClass.name(); - return new SyntheticComponentsImpl(syntheticBeans, syntheticObservers, extensionClass); - case TYPES: - return new TypesImpl(index, annotationOverlays); - - default: - return super.argumentForExtensionMethod(type, method); - } + return switch (type) { + case SYNTHETIC_COMPONENTS -> new SyntheticComponentsImpl(syntheticBeans, syntheticObservers, + method.extensionClass.name()); + case TYPES -> new TypesImpl(index, annotationOverlay); + default -> super.argumentForExtensionMethod(type, method); + }; } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseValidation.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseValidation.java index aaf22610e81c55..0e8d8852ecefe0 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseValidation.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionPhaseValidation.java @@ -3,15 +3,15 @@ import java.util.Collection; class ExtensionPhaseValidation extends ExtensionPhaseBase { - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final Collection allBeans; private final Collection allObservers; ExtensionPhaseValidation(ExtensionInvoker invoker, org.jboss.jandex.IndexView beanArchiveIndex, SharedErrors errors, - AllAnnotationOverlays annotationOverlays, Collection allBeans, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, Collection allBeans, Collection allObservers) { super(ExtensionPhase.VALIDATION, invoker, beanArchiveIndex, errors); - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.allBeans = allBeans; this.allObservers = allObservers; } @@ -19,7 +19,7 @@ class ExtensionPhaseValidation extends ExtensionPhaseBase { @Override Object argumentForExtensionMethod(ExtensionMethodParameter type, ExtensionMethod method) { if (type == ExtensionMethodParameter.TYPES) { - return new TypesImpl(index, annotationOverlays); + return new TypesImpl(index, annotationOverlay); } return super.argumentForExtensionMethod(type, method); diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionsEntryPoint.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionsEntryPoint.java index f75bc6c805b4d6..9bb597fd67d439 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionsEntryPoint.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ExtensionsEntryPoint.java @@ -29,7 +29,9 @@ import jakarta.enterprise.inject.spi.EventContext; import jakarta.enterprise.util.Nonbinding; +import org.jboss.jandex.AnnotationTransformation; import org.jboss.jandex.DotName; +import org.jboss.jandex.MutableAnnotationOverlay; import io.quarkus.arc.InjectableContext; import io.quarkus.arc.impl.CreationalContextImpl; @@ -73,15 +75,15 @@ */ public class ExtensionsEntryPoint { private final ExtensionInvoker invoker; - private final AllAnnotationOverlays annotationOverlays; private final SharedErrors errors; private final Map qualifiers; private final Map interceptorBindings; private final Map stereotypes; private final List contexts; + private final List preAnnotationTransformations; - private volatile AllAnnotationTransformations preAnnotationTransformations; + private volatile MutableAnnotationOverlay annotationOverlay; private final List> syntheticBeans; private final List> syntheticObservers; @@ -94,21 +96,21 @@ public ExtensionsEntryPoint() { public ExtensionsEntryPoint(List extensions) { invoker = new ExtensionInvoker(extensions); if (invoker.isEmpty()) { - annotationOverlays = null; errors = null; qualifiers = null; interceptorBindings = null; stereotypes = null; contexts = null; + preAnnotationTransformations = null; syntheticBeans = null; syntheticObservers = null; } else { - annotationOverlays = new AllAnnotationOverlays(); errors = new SharedErrors(); qualifiers = new ConcurrentHashMap<>(); interceptorBindings = new ConcurrentHashMap<>(); stereotypes = new ConcurrentHashMap<>(); contexts = Collections.synchronizedList(new ArrayList<>()); + preAnnotationTransformations = Collections.synchronizedList(new ArrayList<>()); syntheticBeans = Collections.synchronizedList(new ArrayList<>()); syntheticObservers = Collections.synchronizedList(new ArrayList<>()); } @@ -123,10 +125,14 @@ public void runDiscovery(org.jboss.jandex.IndexView applicationIndex, Set(), applicationIndex); new ExtensionPhaseDiscovery(invoker, computingApplicationIndex, errors, additionalClasses, - preAnnotationTransformations, qualifiers, interceptorBindings, stereotypes, contexts).run(); + overlay, qualifiers, interceptorBindings, stereotypes, contexts).run(); } finally { // noone should attempt annotation transformations on custom meta-annotations after `@Discovery` is finished - preAnnotationTransformations.freeze(); + preAnnotationTransformations.addAll(overlay.freeze()); BuildServicesImpl.reset(); } @@ -152,10 +158,17 @@ public void registerMetaAnnotations(BeanProcessor.Builder builder, CustomAlterab if (invoker.isEmpty()) { return; } - builder.addAnnotationTransformer(preAnnotationTransformations.classes); - builder.addAnnotationTransformer(preAnnotationTransformations.methods); - builder.addAnnotationTransformer(preAnnotationTransformations.parameters); - builder.addAnnotationTransformer(preAnnotationTransformations.fields); + + builder.addAnnotationTransformation(new AnnotationTransformation() { + @Override + public void apply(TransformationContext context) { + for (AnnotationTransformation preAnnotationTransformation : preAnnotationTransformations) { + if (preAnnotationTransformation.supports(context.declaration().kind())) { + preAnnotationTransformation.apply(context); + } + } + } + }); if (!qualifiers.isEmpty()) { builder.addQualifierRegistrar(new QualifierRegistrar() { @@ -196,7 +209,7 @@ public List getAdditionalBindings() { return InterceptorBinding.of(annotationName, nonbindingMembers); }) - .collect(Collectors.toUnmodifiableList()); + .toList(); } }); } @@ -247,20 +260,31 @@ public void runEnhancement(org.jboss.jandex.IndexView beanArchiveIndex, BeanProc if (invoker.isEmpty()) { return; } - AllAnnotationTransformations annotationTransformations = new AllAnnotationTransformations(beanArchiveIndex, - annotationOverlays); - builder.addAnnotationTransformer(annotationTransformations.classes); - builder.addAnnotationTransformer(annotationTransformations.methods); - builder.addAnnotationTransformer(annotationTransformations.parameters); - builder.addAnnotationTransformer(annotationTransformations.fields); - BuildServicesImpl.init(beanArchiveIndex, annotationOverlays); + annotationOverlay = MutableAnnotationOverlay.builder(beanArchiveIndex) + .compatibleMode() + .runtimeAnnotationsOnly() + .inheritedAnnotations() + .build(); + + BuildServicesImpl.init(beanArchiveIndex, annotationOverlay); try { - new ExtensionPhaseEnhancement(invoker, beanArchiveIndex, errors, annotationTransformations).run(); + new ExtensionPhaseEnhancement(invoker, beanArchiveIndex, errors, annotationOverlay).run(); } finally { // noone should attempt annotation transformations on application classes after `@Enhancement` is finished - annotationTransformations.freeze(); + List annotationTransformations = annotationOverlay.freeze(); + + builder.addAnnotationTransformation(new AnnotationTransformation() { + @Override + public void apply(TransformationContext context) { + for (AnnotationTransformation annotationTransformation : annotationTransformations) { + if (annotationTransformation.supports(context.declaration().kind())) { + annotationTransformation.apply(context); + } + } + } + }); BuildServicesImpl.reset(); } @@ -280,10 +304,10 @@ public void runRegistration(org.jboss.jandex.IndexView beanArchiveIndex, return; } - BuildServicesImpl.init(beanArchiveIndex, annotationOverlays); + BuildServicesImpl.init(beanArchiveIndex, annotationOverlay); try { - new ExtensionPhaseRegistration(invoker, beanArchiveIndex, errors, annotationOverlays, + new ExtensionPhaseRegistration(invoker, beanArchiveIndex, errors, annotationOverlay, allBeans, allInterceptors, allObservers, invokerFactory).run(); } finally { BuildServicesImpl.reset(); @@ -300,10 +324,10 @@ public void runSynthesis(org.jboss.jandex.IndexView beanArchiveIndex) { return; } - BuildServicesImpl.init(beanArchiveIndex, annotationOverlays); + BuildServicesImpl.init(beanArchiveIndex, annotationOverlay); try { - new ExtensionPhaseSynthesis(invoker, beanArchiveIndex, errors, annotationOverlays, + new ExtensionPhaseSynthesis(invoker, beanArchiveIndex, errors, annotationOverlay, syntheticBeans, syntheticObservers).run(); } finally { BuildServicesImpl.reset(); @@ -579,15 +603,15 @@ public void runRegistrationAgain(org.jboss.jandex.IndexView beanArchiveIndex, Collection syntheticBeans = allBeans.stream() .filter(BeanInfo::isSynthetic) - .collect(Collectors.toUnmodifiableList()); + .toList(); Collection syntheticObservers = allObservers.stream() .filter(ObserverInfo::isSynthetic) - .collect(Collectors.toUnmodifiableList()); + .toList(); - BuildServicesImpl.init(beanArchiveIndex, annotationOverlays); + BuildServicesImpl.init(beanArchiveIndex, annotationOverlay); try { - new ExtensionPhaseRegistration(invoker, beanArchiveIndex, errors, annotationOverlays, + new ExtensionPhaseRegistration(invoker, beanArchiveIndex, errors, annotationOverlay, syntheticBeans, Collections.emptyList(), syntheticObservers, invokerFactory).run(); } finally { BuildServicesImpl.reset(); @@ -606,10 +630,10 @@ public void runValidation(org.jboss.jandex.IndexView beanArchiveIndex, return; } - BuildServicesImpl.init(beanArchiveIndex, annotationOverlays); + BuildServicesImpl.init(beanArchiveIndex, annotationOverlay); try { - new ExtensionPhaseValidation(invoker, beanArchiveIndex, errors, annotationOverlays, + new ExtensionPhaseValidation(invoker, beanArchiveIndex, errors, annotationOverlay, allBeans, allObservers).run(); } finally { BuildServicesImpl.reset(); @@ -631,7 +655,5 @@ public void registerValidationErrors(BeanDeploymentValidator.ValidationContext c } invoker.invalidate(); - - annotationOverlays.invalidate(); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldConfigImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldConfigImpl.java index 0bfe085f125ad6..5026fa263e4349 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldConfigImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldConfigImpl.java @@ -4,13 +4,13 @@ import jakarta.enterprise.lang.model.declarations.FieldInfo; class FieldConfigImpl extends DeclarationConfigImpl implements FieldConfig { - FieldConfigImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationTransformations allTransformations, + FieldConfigImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.FieldInfo jandexDeclaration) { - super(jandexIndex, allTransformations, allTransformations.fields, jandexDeclaration); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override public FieldInfo info() { - return new FieldInfoImpl(jandexIndex, allTransformations.annotationOverlays, jandexDeclaration); + return new FieldInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldInfoImpl.java index 7198a4133198be..cd310185c7b95c 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/FieldInfoImpl.java @@ -1,24 +1,15 @@ package io.quarkus.arc.processor.bcextensions; import java.lang.reflect.Modifier; -import java.util.Objects; import jakarta.enterprise.lang.model.declarations.ClassInfo; import jakarta.enterprise.lang.model.declarations.FieldInfo; import jakarta.enterprise.lang.model.types.Type; -import org.jboss.jandex.DotName; - class FieldInfoImpl extends DeclarationInfoImpl implements FieldInfo { - // only for equals/hashCode - private final DotName className; - private final String name; - - FieldInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + FieldInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.FieldInfo jandexDeclaration) { - super(jandexIndex, annotationOverlays, jandexDeclaration); - this.className = jandexDeclaration.declaringClass().name(); - this.name = jandexDeclaration.name(); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override @@ -28,7 +19,7 @@ public String name() { @Override public Type type() { - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, jandexDeclaration.type()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, jandexDeclaration.type()); } @Override @@ -48,27 +39,6 @@ public int modifiers() { @Override public ClassInfo declaringClass() { - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.declaringClass()); - } - - @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.fields; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - FieldInfoImpl fieldInfo = (FieldInfoImpl) o; - return Objects.equals(className, fieldInfo.className) - && Objects.equals(name, fieldInfo.name); - } - - @Override - public int hashCode() { - return Objects.hash(className, name); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration.declaringClass()); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java index 790a7a56a28c92..a4f99e34b50aa7 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java @@ -1,7 +1,6 @@ package io.quarkus.arc.processor.bcextensions; import java.util.Collection; -import java.util.stream.Collectors; import jakarta.enterprise.inject.build.compatible.spi.InjectionPointInfo; import jakarta.enterprise.lang.model.AnnotationInfo; @@ -10,40 +9,40 @@ class InjectionPointInfoImpl implements InjectionPointInfo { private final org.jboss.jandex.IndexView jandexIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final io.quarkus.arc.processor.InjectionPointInfo arcInjectionPointInfo; - InjectionPointInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + InjectionPointInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.InjectionPointInfo arcInjectionPointInfo) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.arcInjectionPointInfo = arcInjectionPointInfo; } @Override public Type type() { - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, arcInjectionPointInfo.getRequiredType()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, arcInjectionPointInfo.getRequiredType()); } @Override public Collection qualifiers() { return arcInjectionPointInfo.getRequiredQualifiers() .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (AnnotationInfo) new AnnotationInfoImpl(jandexIndex, annotationOverlay, it)) + .toList(); } @Override public DeclarationInfo declaration() { if (arcInjectionPointInfo.isField()) { org.jboss.jandex.FieldInfo jandexField = arcInjectionPointInfo.getTarget().asField(); - return new FieldInfoImpl(jandexIndex, annotationOverlays, jandexField); + return new FieldInfoImpl(jandexIndex, annotationOverlay, jandexField); } else if (arcInjectionPointInfo.isParam()) { org.jboss.jandex.MethodInfo jandexMethod = arcInjectionPointInfo.getTarget().asMethod(); int parameterPosition = arcInjectionPointInfo.getPosition(); org.jboss.jandex.MethodParameterInfo jandexParameter = org.jboss.jandex.MethodParameterInfo.create( jandexMethod, (short) parameterPosition); - return new ParameterInfoImpl(jandexIndex, annotationOverlays, jandexParameter); + return new ParameterInfoImpl(jandexIndex, annotationOverlay, jandexParameter); } else { throw new IllegalStateException("Unknown injection point: " + arcInjectionPointInfo); } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InterceptorInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InterceptorInfoImpl.java index a447078cd26272..97333ddd58a3d0 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InterceptorInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InterceptorInfoImpl.java @@ -10,9 +10,9 @@ class InterceptorInfoImpl extends BeanInfoImpl implements InterceptorInfo { private final io.quarkus.arc.processor.InterceptorInfo arcInterceptorInfo; - InterceptorInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + InterceptorInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.InterceptorInfo arcInterceptorInfo) { - super(jandexIndex, annotationOverlays, arcInterceptorInfo); + super(jandexIndex, annotationOverlay, arcInterceptorInfo); this.arcInterceptorInfo = arcInterceptorInfo; } @@ -25,7 +25,7 @@ public Integer priority() { public Collection interceptorBindings() { return arcInterceptorInfo.getBindings() .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) + .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlay, it)) .collect(Collectors.toUnmodifiableSet()); } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MetaAnnotationsImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MetaAnnotationsImpl.java index 03ce0d17128425..c825d5eed3f38d 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MetaAnnotationsImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MetaAnnotationsImpl.java @@ -13,18 +13,19 @@ class MetaAnnotationsImpl implements MetaAnnotations { private final org.jboss.jandex.IndexView applicationIndex; - private final AllAnnotationTransformations annotationTransformations; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final Map qualifiers; private final Map interceptorBindings; private final Map stereotypes; private final List contexts; - MetaAnnotationsImpl(org.jboss.jandex.IndexView applicationIndex, AllAnnotationTransformations annotationTransformations, + MetaAnnotationsImpl(org.jboss.jandex.IndexView applicationIndex, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, Map qualifiers, Map interceptorBindings, Map stereotypes, List contexts) { this.applicationIndex = applicationIndex; - this.annotationTransformations = annotationTransformations; + this.annotationOverlay = annotationOverlay; this.qualifiers = qualifiers; this.interceptorBindings = interceptorBindings; this.stereotypes = stereotypes; @@ -49,7 +50,7 @@ public ClassConfig addStereotype(Class annotation) { private ClassConfig addMetaAnnotation(Class annotation, Map map) { DotName annotationName = DotName.createSimple(annotation.getName()); org.jboss.jandex.ClassInfo jandexClass = applicationIndex.getClassByName(annotationName); - ClassConfig classConfig = new ClassConfigImpl(applicationIndex, annotationTransformations, jandexClass); + ClassConfig classConfig = new ClassConfigImpl(applicationIndex, annotationOverlay, jandexClass); map.put(annotationName, classConfig); return classConfig; } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodConfigImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodConfigImpl.java index efed586c47b2b4..6ccdc0ebad1036 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodConfigImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodConfigImpl.java @@ -9,21 +9,21 @@ import jakarta.enterprise.lang.model.declarations.MethodInfo; class MethodConfigImpl extends DeclarationConfigImpl implements MethodConfig { - MethodConfigImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationTransformations allTransformations, + MethodConfigImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.MethodInfo jandexDeclaration) { - super(jandexIndex, allTransformations, allTransformations.methods, jandexDeclaration); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override public MethodInfo info() { - return new MethodInfoImpl(jandexIndex, allTransformations.annotationOverlays, jandexDeclaration); + return new MethodInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration); } @Override public List parameters() { List result = new ArrayList<>(jandexDeclaration.parametersCount()); for (org.jboss.jandex.MethodParameterInfo jandexParameter : jandexDeclaration.parameters()) { - result.add(new ParameterConfigImpl(jandexIndex, allTransformations, jandexParameter)); + result.add(new ParameterConfigImpl(jandexIndex, annotationOverlay, jandexParameter)); } return Collections.unmodifiableList(result); } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodInfoImpl.java index 9cda38188d6989..992b393ff5920c 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/MethodInfoImpl.java @@ -1,11 +1,14 @@ package io.quarkus.arc.processor.bcextensions; +import java.lang.annotation.Annotation; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; +import java.util.function.Predicate; +import jakarta.enterprise.lang.model.AnnotationInfo; import jakarta.enterprise.lang.model.declarations.ClassInfo; import jakarta.enterprise.lang.model.declarations.MethodInfo; import jakarta.enterprise.lang.model.declarations.ParameterInfo; @@ -15,17 +18,9 @@ import org.jboss.jandex.DotName; class MethodInfoImpl extends DeclarationInfoImpl implements MethodInfo { - // only for equals/hashCode - private final DotName className; - private final String name; - private final List parameterTypes; - - MethodInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + MethodInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.MethodInfo jandexDeclaration) { - super(jandexIndex, annotationOverlays, jandexDeclaration); - this.className = jandexDeclaration.declaringClass().name(); - this.name = jandexDeclaration.name(); - this.parameterTypes = jandexDeclaration.parameterTypes(); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override @@ -40,7 +35,7 @@ public String name() { public List parameters() { List result = new ArrayList<>(jandexDeclaration.parametersCount()); for (org.jboss.jandex.MethodParameterInfo jandexParameter : jandexDeclaration.parameters()) { - result.add(new ParameterInfoImpl(jandexIndex, annotationOverlays, jandexParameter)); + result.add(new ParameterInfoImpl(jandexIndex, annotationOverlay, jandexParameter)); } return result; } @@ -56,9 +51,9 @@ public Type returnType() { .toArray(new org.jboss.jandex.AnnotationInstance[0]); org.jboss.jandex.Type classType = org.jboss.jandex.Type.createWithAnnotations( jandexDeclaration.declaringClass().name(), org.jboss.jandex.Type.Kind.CLASS, typeAnnotations); - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, classType); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, classType); } - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, jandexDeclaration.returnType()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, jandexDeclaration.returnType()); } @Override @@ -81,25 +76,25 @@ public Type receiverType() { } } - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, jandexDeclaration.receiverType()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, jandexDeclaration.receiverType()); } @Override public List throwsTypes() { return jandexDeclaration.exceptions() .stream() - .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlay, it)) + .toList(); } @Override public List typeParameters() { return jandexDeclaration.typeParameters() .stream() - .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlays, it)) + .map(it -> TypeImpl.fromJandexType(jandexIndex, annotationOverlay, it)) .filter(Type::isTypeVariable) // not necessary, just as a precaution .map(Type::asTypeVariable) // not necessary, just as a precaution - .collect(Collectors.toUnmodifiableList()); + .toList(); } @Override @@ -129,28 +124,82 @@ public int modifiers() { @Override public ClassInfo declaringClass() { - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.declaringClass()); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration.declaringClass()); + } + + @Override + public boolean hasAnnotation(Class annotationType) { + DotName annotationName = DotName.createSimple(annotationType); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration)) { + if (annotation.name().equals(annotationName) + && annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD) { + return true; + } + } + return false; + } + + @Override + public boolean hasAnnotation(Predicate predicate) { + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration)) { + if (predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)) + && annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD) { + return true; + } + } + return false; } @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.methods; + public AnnotationInfo annotation(Class annotationType) { + org.jboss.jandex.AnnotationInstance jandexAnnotation = annotationOverlay.annotation(jandexDeclaration, annotationType); + if (jandexAnnotation == null + || jandexAnnotation.target() == null + || jandexAnnotation.target().kind() != org.jboss.jandex.AnnotationTarget.Kind.METHOD) { + return null; + } + return new AnnotationInfoImpl(jandexIndex, annotationOverlay, jandexAnnotation); } @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - MethodInfoImpl that = (MethodInfoImpl) o; - return Objects.equals(className, that.className) - && Objects.equals(name, that.name) - && Objects.equals(parameterTypes, that.parameterTypes); + public Collection repeatableAnnotation(Class annotationType) { + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotationsWithRepeatable(jandexDeclaration, + annotationType)) { + if (annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + } + return Collections.unmodifiableList(result); } @Override - public int hashCode() { - return Objects.hash(className, name, parameterTypes); + public Collection annotations(Predicate predicate) { + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration)) { + if (annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD) { + AnnotationInfo annotationInfo = new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation); + if (predicate.test(annotationInfo)) { + result.add(annotationInfo); + } + } + } + return Collections.unmodifiableList(result); + } + + @Override + public Collection annotations() { + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration)) { + if (annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + } + return Collections.unmodifiableList(result); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ObserverInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ObserverInfoImpl.java index 9171adf46be448..e17d91ffd4344d 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ObserverInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ObserverInfoImpl.java @@ -1,7 +1,6 @@ package io.quarkus.arc.processor.bcextensions; import java.util.Collection; -import java.util.stream.Collectors; import jakarta.enterprise.event.Reception; import jakarta.enterprise.event.TransactionPhase; @@ -15,33 +14,33 @@ class ObserverInfoImpl implements ObserverInfo { private final org.jboss.jandex.IndexView jandexIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final io.quarkus.arc.processor.ObserverInfo arcObserverInfo; - ObserverInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + ObserverInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.ObserverInfo arcObserverInfo) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.arcObserverInfo = arcObserverInfo; } @Override public Type eventType() { - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, arcObserverInfo.getObservedType()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, arcObserverInfo.getObservedType()); } @Override public Collection qualifiers() { return arcObserverInfo.getQualifiers() .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (AnnotationInfo) new AnnotationInfoImpl(jandexIndex, annotationOverlay, it)) + .toList(); } @Override public ClassInfo declaringClass() { org.jboss.jandex.ClassInfo jandexClass = jandexIndex.getClassByName(arcObserverInfo.getBeanClass()); - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexClass); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexClass); } @Override @@ -49,7 +48,7 @@ public MethodInfo observerMethod() { if (arcObserverInfo.isSynthetic()) { return null; } - return new MethodInfoImpl(jandexIndex, annotationOverlays, arcObserverInfo.getObserverMethod()); + return new MethodInfoImpl(jandexIndex, annotationOverlay, arcObserverInfo.getObserverMethod()); } @Override @@ -58,7 +57,7 @@ public ParameterInfo eventParameter() { return null; } org.jboss.jandex.MethodParameterInfo jandexParameter = arcObserverInfo.getEventParameter(); - return new ParameterInfoImpl(jandexIndex, annotationOverlays, jandexParameter); + return new ParameterInfoImpl(jandexIndex, annotationOverlay, jandexParameter); } @Override @@ -66,7 +65,7 @@ public BeanInfo bean() { if (arcObserverInfo.isSynthetic()) { return null; } - return BeanInfoImpl.create(jandexIndex, annotationOverlays, arcObserverInfo.getDeclaringBean()); + return BeanInfoImpl.create(jandexIndex, annotationOverlay, arcObserverInfo.getDeclaringBean()); } @Override diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PackageInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PackageInfoImpl.java index 3b103594512e49..6c54401300e2a9 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PackageInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PackageInfoImpl.java @@ -1,96 +1,15 @@ package io.quarkus.arc.processor.bcextensions; -import java.lang.annotation.Annotation; -import java.util.Collection; -import java.util.Objects; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import jakarta.enterprise.lang.model.AnnotationInfo; import jakarta.enterprise.lang.model.declarations.PackageInfo; -class PackageInfoImpl implements PackageInfo { - final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationOverlays annotationOverlays; - final org.jboss.jandex.ClassInfo jandexDeclaration; // package-info.class - - private AnnotationSet annotationSet; - - PackageInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, +class PackageInfoImpl extends DeclarationInfoImpl implements PackageInfo { + PackageInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.ClassInfo jandexDeclaration) { - this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; - this.jandexDeclaration = jandexDeclaration; + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override public String name() { return jandexDeclaration.name().packagePrefix(); } - - private AnnotationSet annotationSet() { - if (annotationSet == null) { - annotationSet = new AnnotationSet(jandexDeclaration.declaredAnnotations()); - } - - return annotationSet; - } - - @Override - public boolean hasAnnotation(Class annotationType) { - return annotationSet().hasAnnotation(annotationType); - } - - @Override - public boolean hasAnnotation(Predicate predicate) { - return annotationSet().annotations() - .stream() - .anyMatch(it -> predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlays, it))); - } - - @Override - public AnnotationInfo annotation(Class annotationType) { - org.jboss.jandex.AnnotationInstance jandexAnnotation = annotationSet().annotation(annotationType); - if (jandexAnnotation == null) { - return null; - } - return new AnnotationInfoImpl(jandexIndex, annotationOverlays, jandexAnnotation); - } - - @Override - public Collection repeatableAnnotation(Class annotationType) { - return annotationSet().annotationsWithRepeatable(annotationType) - .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); - } - - @Override - public Collection annotations(Predicate predicate) { - return annotationSet().annotations() - .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .filter(predicate) - .collect(Collectors.toUnmodifiableList()); - } - - @Override - public Collection annotations() { - return annotations(it -> true); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - PackageInfoImpl that = (PackageInfoImpl) o; - return Objects.equals(jandexDeclaration.name(), that.jandexDeclaration.name()); - } - - @Override - public int hashCode() { - return Objects.hash(jandexDeclaration.name()); - } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterConfigImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterConfigImpl.java index 50c99e2452ef45..9c8435baeab556 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterConfigImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterConfigImpl.java @@ -5,13 +5,13 @@ class ParameterConfigImpl extends DeclarationConfigImpl implements ParameterConfig { - ParameterConfigImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationTransformations allTransformations, + ParameterConfigImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.MethodParameterInfo jandexDeclaration) { - super(jandexIndex, allTransformations, allTransformations.parameters, jandexDeclaration); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override public ParameterInfo info() { - return new ParameterInfoImpl(jandexIndex, allTransformations.annotationOverlays, jandexDeclaration); + return new ParameterInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterInfoImpl.java index c1ce57570be72e..8c047020fa1c18 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterInfoImpl.java @@ -1,21 +1,23 @@ package io.quarkus.arc.processor.bcextensions; -import java.util.Objects; +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.function.Predicate; +import jakarta.enterprise.lang.model.AnnotationInfo; import jakarta.enterprise.lang.model.declarations.MethodInfo; import jakarta.enterprise.lang.model.declarations.ParameterInfo; import jakarta.enterprise.lang.model.types.Type; -class ParameterInfoImpl extends DeclarationInfoImpl implements ParameterInfo { - // only for equals/hashCode - private final MethodInfoImpl method; - private final short position; +import org.jboss.jandex.DotName; - ParameterInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, +class ParameterInfoImpl extends DeclarationInfoImpl implements ParameterInfo { + ParameterInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.MethodParameterInfo jandexDeclaration) { - super(jandexIndex, annotationOverlays, jandexDeclaration); - this.method = new MethodInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.method()); - this.position = jandexDeclaration.position(); + super(jandexIndex, annotationOverlay, jandexDeclaration); } @Override @@ -26,37 +28,100 @@ public String name() { @Override public Type type() { - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, jandexDeclaration.type()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, jandexDeclaration.type()); } @Override public MethodInfo declaringMethod() { - return new MethodInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.method()); + return new MethodInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration.method()); } @Override - public String toString() { - return "parameter " + name() + " of method " + jandexDeclaration.method(); + public boolean hasAnnotation(Class annotationType) { + DotName annotationName = DotName.createSimple(annotationType); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration.method())) { + if (annotation.name().equals(annotationName) + && annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER + && annotation.target().asMethodParameter().position() == jandexDeclaration.position()) { + return true; + } + } + return false; } @Override - AnnotationsOverlay annotationsOverlay() { - return annotationOverlays.parameters; + public boolean hasAnnotation(Predicate predicate) { + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration.method())) { + if (predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)) + && annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER + && annotation.target().asMethodParameter().position() == jandexDeclaration.position()) { + return true; + } + } + return false; } @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - ParameterInfoImpl that = (ParameterInfoImpl) o; - return position == that.position - && Objects.equals(method, that.method); + public AnnotationInfo annotation(Class annotationType) { + DotName annotationName = DotName.createSimple(annotationType); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration.method())) { + if (annotation.name().equals(annotationName) + && annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER + && annotation.target().asMethodParameter().position() == jandexDeclaration.position()) { + return new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation); + } + } + return null; } @Override - public int hashCode() { - return Objects.hash(method, position); + public Collection repeatableAnnotation(Class annotationType) { + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotationsWithRepeatable( + jandexDeclaration.method(), annotationType)) { + if (annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER + && annotation.target().asMethodParameter().position() == jandexDeclaration.position()) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + } + return Collections.unmodifiableList(result); + } + + @Override + public Collection annotations(Predicate predicate) { + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration.method())) { + if (annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER + && annotation.target().asMethodParameter().position() == jandexDeclaration.position()) { + AnnotationInfo annotationInfo = new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation); + if (predicate.test(annotationInfo)) { + result.add(annotationInfo); + } + } + } + return Collections.unmodifiableList(result); + } + + @Override + public Collection annotations() { + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : annotationOverlay.annotations(jandexDeclaration.method())) { + if (annotation.target() != null + && annotation.target().kind() == org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER + && annotation.target().asMethodParameter().position() == jandexDeclaration.position()) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + } + return Collections.unmodifiableList(result); + } + + @Override + public String toString() { + return "parameter " + name() + " of method " + jandexDeclaration.method(); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterizedTypeImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterizedTypeImpl.java index ee87ab384ace1f..09c8d5ad41f88d 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterizedTypeImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ParameterizedTypeImpl.java @@ -1,30 +1,29 @@ package io.quarkus.arc.processor.bcextensions; import java.util.List; -import java.util.stream.Collectors; import jakarta.enterprise.lang.model.types.ClassType; import jakarta.enterprise.lang.model.types.ParameterizedType; import jakarta.enterprise.lang.model.types.Type; class ParameterizedTypeImpl extends TypeImpl implements ParameterizedType { - ParameterizedTypeImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + ParameterizedTypeImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.ParameterizedType jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); } @Override public ClassType genericClass() { org.jboss.jandex.Type jandexClassType = org.jboss.jandex.Type.create(jandexType.name(), org.jboss.jandex.Type.Kind.CLASS); - return new ClassTypeImpl(jandexIndex, annotationOverlays, (org.jboss.jandex.ClassType) jandexClassType); + return new ClassTypeImpl(jandexIndex, annotationOverlay, (org.jboss.jandex.ClassType) jandexClassType); } @Override public List typeArguments() { return jandexType.arguments() .stream() - .map(it -> fromJandexType(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> fromJandexType(jandexIndex, annotationOverlay, it)) + .toList(); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PrimitiveTypeImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PrimitiveTypeImpl.java index 63b2f9d1a970af..0474875d4e1548 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PrimitiveTypeImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/PrimitiveTypeImpl.java @@ -3,9 +3,9 @@ import jakarta.enterprise.lang.model.types.PrimitiveType; class PrimitiveTypeImpl extends TypeImpl implements PrimitiveType { - PrimitiveTypeImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + PrimitiveTypeImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.PrimitiveType jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); } @Override @@ -16,25 +16,16 @@ public String name() { @Override public PrimitiveKind primitiveKind() { org.jboss.jandex.PrimitiveType.Primitive primitive = jandexType.primitive(); - switch (primitive) { - case BOOLEAN: - return PrimitiveKind.BOOLEAN; - case BYTE: - return PrimitiveKind.BYTE; - case SHORT: - return PrimitiveKind.SHORT; - case INT: - return PrimitiveKind.INT; - case LONG: - return PrimitiveKind.LONG; - case FLOAT: - return PrimitiveKind.FLOAT; - case DOUBLE: - return PrimitiveKind.DOUBLE; - case CHAR: - return PrimitiveKind.CHAR; - default: - throw new IllegalStateException("Unknown primitive type " + primitive); - } + return switch (primitive) { + case BOOLEAN -> PrimitiveKind.BOOLEAN; + case BYTE -> PrimitiveKind.BYTE; + case SHORT -> PrimitiveKind.SHORT; + case INT -> PrimitiveKind.INT; + case LONG -> PrimitiveKind.LONG; + case FLOAT -> PrimitiveKind.FLOAT; + case DOUBLE -> PrimitiveKind.DOUBLE; + case CHAR -> PrimitiveKind.CHAR; + default -> throw new IllegalStateException("Unknown primitive type " + primitive); + }; } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/RecordComponentInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/RecordComponentInfoImpl.java index db936b15d019fb..5fc347b8ebaf09 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/RecordComponentInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/RecordComponentInfoImpl.java @@ -1,25 +1,16 @@ package io.quarkus.arc.processor.bcextensions; -import java.util.Objects; - import jakarta.enterprise.lang.model.declarations.ClassInfo; import jakarta.enterprise.lang.model.declarations.FieldInfo; import jakarta.enterprise.lang.model.declarations.MethodInfo; import jakarta.enterprise.lang.model.declarations.RecordComponentInfo; import jakarta.enterprise.lang.model.types.Type; -import org.jboss.jandex.DotName; - class RecordComponentInfoImpl extends DeclarationInfoImpl implements RecordComponentInfo { - // only for equals/hashCode - private final DotName className; - private final String name; - - public RecordComponentInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + public RecordComponentInfoImpl(org.jboss.jandex.IndexView jandexIndex, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.RecordComponentInfo recordComponentInfo) { - super(jandexIndex, annotationOverlays, recordComponentInfo); - this.className = recordComponentInfo.declaringClass().name(); - this.name = recordComponentInfo.name(); + super(jandexIndex, annotationOverlay, recordComponentInfo); } @Override @@ -29,43 +20,21 @@ public String name() { @Override public Type type() { - return TypeImpl.fromJandexType(jandexIndex, annotationOverlays, jandexDeclaration.type()); + return TypeImpl.fromJandexType(jandexIndex, annotationOverlay, jandexDeclaration.type()); } @Override public FieldInfo field() { - return new FieldInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.field()); + return new FieldInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration.field()); } @Override public MethodInfo accessor() { - return new MethodInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.accessor()); + return new MethodInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration.accessor()); } @Override public ClassInfo declaringRecord() { - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexDeclaration.declaringClass()); - } - - @Override - AnnotationsOverlay annotationsOverlay() { - // we don't care about record components at all (yet) - return null; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof RecordComponentInfoImpl)) - return false; - RecordComponentInfoImpl that = (RecordComponentInfoImpl) o; - return Objects.equals(className, that.className) - && Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(className, name); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexDeclaration.declaringClass()); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ScopeInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ScopeInfoImpl.java index d0f28f59919b99..aa83a95a1b62d1 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ScopeInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/ScopeInfoImpl.java @@ -5,20 +5,20 @@ class ScopeInfoImpl implements ScopeInfo { private final org.jboss.jandex.IndexView jandexIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final io.quarkus.arc.processor.ScopeInfo arcScopeInfo; - ScopeInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + ScopeInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.ScopeInfo arcScopeInfo) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.arcScopeInfo = arcScopeInfo; } @Override public ClassInfo annotation() { org.jboss.jandex.ClassInfo jandexClass = jandexIndex.getClassByName(arcScopeInfo.getDotName()); - return new ClassInfoImpl(jandexIndex, annotationOverlays, jandexClass); + return new ClassInfoImpl(jandexIndex, annotationOverlay, jandexClass); } @Override diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/StereotypeInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/StereotypeInfoImpl.java index 5b6c306544f2a2..9970c62cbfba16 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/StereotypeInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/StereotypeInfoImpl.java @@ -1,7 +1,6 @@ package io.quarkus.arc.processor.bcextensions; import java.util.Collection; -import java.util.stream.Collectors; import jakarta.enterprise.inject.build.compatible.spi.ScopeInfo; import jakarta.enterprise.inject.build.compatible.spi.StereotypeInfo; @@ -9,27 +8,27 @@ class StereotypeInfoImpl implements StereotypeInfo { private final org.jboss.jandex.IndexView jandexIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; private final io.quarkus.arc.processor.StereotypeInfo arcStereotype; - StereotypeInfoImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + StereotypeInfoImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, io.quarkus.arc.processor.StereotypeInfo arcStereotype) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; this.arcStereotype = arcStereotype; } @Override public ScopeInfo defaultScope() { - return new ScopeInfoImpl(jandexIndex, annotationOverlays, arcStereotype.getDefaultScope()); + return new ScopeInfoImpl(jandexIndex, annotationOverlay, arcStereotype.getDefaultScope()); } @Override public Collection interceptorBindings() { return arcStereotype.getInterceptorBindings() .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> (AnnotationInfo) new AnnotationInfoImpl(jandexIndex, annotationOverlay, it)) + .toList(); } @Override diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeImpl.java index cb0c32c32220e3..4ee06d21bd2557 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeImpl.java @@ -1,108 +1,114 @@ package io.quarkus.arc.processor.bcextensions; import java.lang.annotation.Annotation; +import java.util.ArrayList; import java.util.Collection; -import java.util.Objects; +import java.util.Collections; +import java.util.List; import java.util.function.Predicate; -import java.util.stream.Collectors; import jakarta.enterprise.lang.model.AnnotationInfo; import jakarta.enterprise.lang.model.types.Type; import org.jboss.jandex.DotName; -abstract class TypeImpl implements Type { - final org.jboss.jandex.IndexView jandexIndex; - final AllAnnotationOverlays annotationOverlays; +abstract class TypeImpl extends AnnotationTargetImpl implements Type { final JandexType jandexType; - TypeImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, JandexType jandexType) { - this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + TypeImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, + JandexType jandexType) { + super(jandexIndex, annotationOverlay, org.jboss.jandex.EquivalenceKey.of(jandexType)); this.jandexType = jandexType; } - static Type fromJandexType(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + static Type fromJandexType(org.jboss.jandex.IndexView jandexIndex, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.Type jandexType) { - switch (jandexType.kind()) { - case VOID: - return new VoidTypeImpl(jandexIndex, annotationOverlays, jandexType.asVoidType()); - case PRIMITIVE: - return new PrimitiveTypeImpl(jandexIndex, annotationOverlays, jandexType.asPrimitiveType()); - case CLASS: - return new ClassTypeImpl(jandexIndex, annotationOverlays, jandexType.asClassType()); - case ARRAY: - return new ArrayTypeImpl(jandexIndex, annotationOverlays, jandexType.asArrayType()); - case PARAMETERIZED_TYPE: - return new ParameterizedTypeImpl(jandexIndex, annotationOverlays, jandexType.asParameterizedType()); - case TYPE_VARIABLE: - return new TypeVariableImpl(jandexIndex, annotationOverlays, jandexType.asTypeVariable()); - case UNRESOLVED_TYPE_VARIABLE: - return new UnresolvedTypeVariableImpl(jandexIndex, annotationOverlays, jandexType.asUnresolvedTypeVariable()); - case WILDCARD_TYPE: - return new WildcardTypeImpl(jandexIndex, annotationOverlays, jandexType.asWildcardType()); - default: - throw new IllegalArgumentException("Unknown type " + jandexType); - } + return switch (jandexType.kind()) { + case VOID -> new VoidTypeImpl(jandexIndex, annotationOverlay, jandexType.asVoidType()); + case PRIMITIVE -> new PrimitiveTypeImpl(jandexIndex, annotationOverlay, jandexType.asPrimitiveType()); + case CLASS -> new ClassTypeImpl(jandexIndex, annotationOverlay, jandexType.asClassType()); + case ARRAY -> new ArrayTypeImpl(jandexIndex, annotationOverlay, jandexType.asArrayType()); + case PARAMETERIZED_TYPE -> + new ParameterizedTypeImpl(jandexIndex, annotationOverlay, jandexType.asParameterizedType()); + case TYPE_VARIABLE -> new TypeVariableImpl(jandexIndex, annotationOverlay, jandexType.asTypeVariable()); + case UNRESOLVED_TYPE_VARIABLE -> + new UnresolvedTypeVariableImpl(jandexIndex, annotationOverlay, jandexType.asUnresolvedTypeVariable()); + case WILDCARD_TYPE -> new WildcardTypeImpl(jandexIndex, annotationOverlay, jandexType.asWildcardType()); + default -> throw new IllegalArgumentException("Unknown type " + jandexType); + }; } @Override public boolean hasAnnotation(Class annotationType) { - return jandexType.hasAnnotation(DotName.createSimple(annotationType.getName())); + DotName annotationName = DotName.createSimple(annotationType); + for (org.jboss.jandex.AnnotationInstance annotation : jandexType.annotations()) { + if (annotation.runtimeVisible() && annotation.name().equals(annotationName)) { + return true; + } + } + return false; } @Override public boolean hasAnnotation(Predicate predicate) { - return jandexType.annotations() - .stream() - .anyMatch(it -> predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlays, it))); + for (org.jboss.jandex.AnnotationInstance annotation : jandexType.annotations()) { + if (annotation.runtimeVisible() + && predicate.test(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation))) { + return true; + } + } + return false; } @Override public AnnotationInfo annotation(Class annotationType) { - return new AnnotationInfoImpl(jandexIndex, annotationOverlays, - jandexType.annotation(DotName.createSimple(annotationType.getName()))); + org.jboss.jandex.AnnotationInstance jandexAnnotation = jandexType.annotation(DotName.createSimple(annotationType)); + if (jandexAnnotation == null || !jandexAnnotation.runtimeVisible()) { + return null; + } + return new AnnotationInfoImpl(jandexIndex, annotationOverlay, jandexAnnotation); } @Override public Collection repeatableAnnotation(Class annotationType) { - return jandexType.annotationsWithRepeatable(DotName.createSimple(annotationType.getName()), jandexIndex) - .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : jandexType.annotationsWithRepeatable( + DotName.createSimple(annotationType), jandexIndex)) { + if (annotation.runtimeVisible()) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + } + return Collections.unmodifiableList(result); } @Override public Collection annotations(Predicate predicate) { - return jandexType.annotations() - .stream() - .map(it -> new AnnotationInfoImpl(jandexIndex, annotationOverlays, it)) - .filter(predicate) - .collect(Collectors.toUnmodifiableList()); + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : jandexType.annotations()) { + if (annotation.runtimeVisible()) { + AnnotationInfo annotationInfo = new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation); + if (predicate.test(annotationInfo)) { + result.add(annotationInfo); + } + } + } + return Collections.unmodifiableList(result); } @Override public Collection annotations() { - return annotations(it -> true); + List result = new ArrayList<>(); + for (org.jboss.jandex.AnnotationInstance annotation : jandexType.annotations()) { + if (annotation.runtimeVisible()) { + result.add(new AnnotationInfoImpl(jandexIndex, annotationOverlay, annotation)); + } + } + return Collections.unmodifiableList(result); } @Override public String toString() { return jandexType.toString(); } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof TypeImpl)) - return false; - TypeImpl type = (TypeImpl) o; - return Objects.equals(jandexType, type.jandexType); - } - - @Override - public int hashCode() { - return Objects.hash(jandexType); - } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeVariableImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeVariableImpl.java index c4b64644050a64..debbffb5ff7f20 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeVariableImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypeVariableImpl.java @@ -1,15 +1,14 @@ package io.quarkus.arc.processor.bcextensions; import java.util.List; -import java.util.stream.Collectors; import jakarta.enterprise.lang.model.types.Type; import jakarta.enterprise.lang.model.types.TypeVariable; class TypeVariableImpl extends TypeImpl implements TypeVariable { - TypeVariableImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + TypeVariableImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.TypeVariable jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); } @Override @@ -21,7 +20,7 @@ public String name() { public List bounds() { return jandexType.bounds() .stream() - .map(it -> fromJandexType(jandexIndex, annotationOverlays, it)) - .collect(Collectors.toUnmodifiableList()); + .map(it -> fromJandexType(jandexIndex, annotationOverlay, it)) + .toList(); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypesImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypesImpl.java index 097da7fc562c24..2ec98181be2199 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypesImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/TypesImpl.java @@ -16,11 +16,11 @@ class TypesImpl implements Types { private final org.jboss.jandex.IndexView jandexIndex; - private final AllAnnotationOverlays annotationOverlays; + private final org.jboss.jandex.MutableAnnotationOverlay annotationOverlay; - TypesImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays) { + TypesImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay) { this.jandexIndex = jandexIndex; - this.annotationOverlays = annotationOverlays; + this.annotationOverlay = annotationOverlay; } @Override @@ -61,7 +61,7 @@ public Type of(Class clazz) { org.jboss.jandex.Type jandexType = org.jboss.jandex.Type.create(DotName.createSimple(clazz.getName()), org.jboss.jandex.Type.Kind.CLASS); - return new ClassTypeImpl(jandexIndex, annotationOverlays, jandexType.asClassType()); + return new ClassTypeImpl(jandexIndex, annotationOverlay, jandexType.asClassType()); } @@ -69,21 +69,21 @@ public Type of(Class clazz) { public VoidType ofVoid() { org.jboss.jandex.Type jandexType = org.jboss.jandex.Type.create(DotName.createSimple("void"), org.jboss.jandex.Type.Kind.VOID); - return new VoidTypeImpl(jandexIndex, annotationOverlays, jandexType.asVoidType()); + return new VoidTypeImpl(jandexIndex, annotationOverlay, jandexType.asVoidType()); } @Override public PrimitiveType ofPrimitive(PrimitiveType.PrimitiveKind kind) { org.jboss.jandex.Type jandexType = org.jboss.jandex.Type.create(DotName.createSimple(kind.name().toLowerCase()), org.jboss.jandex.Type.Kind.PRIMITIVE); - return new PrimitiveTypeImpl(jandexIndex, annotationOverlays, jandexType.asPrimitiveType()); + return new PrimitiveTypeImpl(jandexIndex, annotationOverlay, jandexType.asPrimitiveType()); } @Override public ClassType ofClass(ClassInfo clazz) { org.jboss.jandex.Type jandexType = org.jboss.jandex.Type.create(((ClassInfoImpl) clazz).jandexDeclaration.name(), org.jboss.jandex.Type.Kind.CLASS); - return new ClassTypeImpl(jandexIndex, annotationOverlays, jandexType.asClassType()); + return new ClassTypeImpl(jandexIndex, annotationOverlay, jandexType.asClassType()); } @Override @@ -94,14 +94,14 @@ public ClassType ofClass(String name) { return null; } org.jboss.jandex.Type jandexType = org.jboss.jandex.Type.create(className, org.jboss.jandex.Type.Kind.CLASS); - return new ClassTypeImpl(jandexIndex, annotationOverlays, jandexType.asClassType()); + return new ClassTypeImpl(jandexIndex, annotationOverlay, jandexType.asClassType()); } @Override public ArrayType ofArray(Type componentType, int dimensions) { org.jboss.jandex.ArrayType jandexType = org.jboss.jandex.ArrayType.create(((TypeImpl) componentType).jandexType, dimensions); - return new ArrayTypeImpl(jandexIndex, annotationOverlays, jandexType); + return new ArrayTypeImpl(jandexIndex, annotationOverlay, jandexType); } @Override @@ -130,26 +130,26 @@ private ParameterizedType parameterizedType(DotName genericTypeName, Type... typ org.jboss.jandex.ParameterizedType jandexType = org.jboss.jandex.ParameterizedType.create(genericTypeName, jandexTypeArguments, null); - return new ParameterizedTypeImpl(jandexIndex, annotationOverlays, jandexType); + return new ParameterizedTypeImpl(jandexIndex, annotationOverlay, jandexType); } @Override public WildcardType wildcardWithUpperBound(Type upperBound) { org.jboss.jandex.WildcardType jandexType = org.jboss.jandex.WildcardType .createUpperBound(((TypeImpl) upperBound).jandexType); - return new WildcardTypeImpl(jandexIndex, annotationOverlays, jandexType); + return new WildcardTypeImpl(jandexIndex, annotationOverlay, jandexType); } @Override public WildcardType wildcardWithLowerBound(Type lowerBound) { org.jboss.jandex.WildcardType jandexType = org.jboss.jandex.WildcardType .createLowerBound(((TypeImpl) lowerBound).jandexType); - return new WildcardTypeImpl(jandexIndex, annotationOverlays, jandexType); + return new WildcardTypeImpl(jandexIndex, annotationOverlay, jandexType); } @Override public WildcardType wildcardUnbounded() { - org.jboss.jandex.WildcardType jandexType = org.jboss.jandex.WildcardType.create(null, true); - return new WildcardTypeImpl(jandexIndex, annotationOverlays, jandexType); + org.jboss.jandex.WildcardType jandexType = org.jboss.jandex.WildcardType.UNBOUNDED; + return new WildcardTypeImpl(jandexIndex, annotationOverlay, jandexType); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/UnresolvedTypeVariableImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/UnresolvedTypeVariableImpl.java index 286941114cba87..cd9e6b57b061b7 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/UnresolvedTypeVariableImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/UnresolvedTypeVariableImpl.java @@ -6,9 +6,10 @@ import jakarta.enterprise.lang.model.types.TypeVariable; class UnresolvedTypeVariableImpl extends TypeImpl implements TypeVariable { - UnresolvedTypeVariableImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + UnresolvedTypeVariableImpl(org.jboss.jandex.IndexView jandexIndex, + org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.UnresolvedTypeVariable jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); } @Override @@ -18,6 +19,6 @@ public String name() { @Override public List bounds() { - return List.of(fromJandexType(jandexIndex, annotationOverlays, org.jboss.jandex.ClassType.OBJECT_TYPE)); + return List.of(fromJandexType(jandexIndex, annotationOverlay, org.jboss.jandex.ClassType.OBJECT_TYPE)); } } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/VoidTypeImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/VoidTypeImpl.java index 49ccddb43fa2c6..6ad302fd8d73b4 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/VoidTypeImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/VoidTypeImpl.java @@ -3,9 +3,9 @@ import jakarta.enterprise.lang.model.types.VoidType; class VoidTypeImpl extends TypeImpl implements VoidType { - VoidTypeImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + VoidTypeImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.VoidType jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); } @Override diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/WildcardTypeImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/WildcardTypeImpl.java index 5566a27acbc2f7..b5491dc37a4659 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/WildcardTypeImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/WildcardTypeImpl.java @@ -6,9 +6,9 @@ class WildcardTypeImpl extends TypeImpl implements WildcardType { private final boolean hasUpperBound; - WildcardTypeImpl(org.jboss.jandex.IndexView jandexIndex, AllAnnotationOverlays annotationOverlays, + WildcardTypeImpl(org.jboss.jandex.IndexView jandexIndex, org.jboss.jandex.MutableAnnotationOverlay annotationOverlay, org.jboss.jandex.WildcardType jandexType) { - super(jandexIndex, annotationOverlays, jandexType); + super(jandexIndex, annotationOverlay, jandexType); this.hasUpperBound = jandexType.superBound() == null; } @@ -17,7 +17,7 @@ public Type upperBound() { if (!hasUpperBound) { return null; } - return fromJandexType(jandexIndex, annotationOverlays, jandexType.extendsBound()); + return fromJandexType(jandexIndex, annotationOverlay, jandexType.extendsBound()); } @Override @@ -25,6 +25,6 @@ public Type lowerBound() { if (hasUpperBound) { return null; } - return fromJandexType(jandexIndex, annotationOverlays, jandexType.superBound()); + return fromJandexType(jandexIndex, annotationOverlay, jandexType.superBound()); } }