From 9698f2389d817b804ff3057d6773ffd81e932eb5 Mon Sep 17 00:00:00 2001 From: Knut Wannheden Date: Tue, 8 Jun 2021 08:23:11 +0200 Subject: [PATCH] Cleanup: Remove `isAnnotation(ClassInfo)` utility methods There is now a dedicated `ClassInfo#isAnnotation()` method. Also removes no longer used field `BeanDeployment#CLASS_TYPES`. --- .../spring/di/deployment/SpringDIProcessor.java | 14 ++++---------- .../deployment/SpringSecurityProcessor.java | 8 +------- .../io/quarkus/arc/processor/BeanDeployment.java | 13 +++---------- .../quarkus/test/common/TestResourceManager.java | 8 +------- .../quarkus/test/junit/QuarkusTestExtension.java | 8 +------- 5 files changed, 10 insertions(+), 41 deletions(-) diff --git a/extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java b/extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java index ac1cab78a2852..bf12ca33fe460 100644 --- a/extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java +++ b/extensions/spring-di/deployment/src/main/java/io/quarkus/spring/di/deployment/SpringDIProcessor.java @@ -78,12 +78,6 @@ public class SpringDIProcessor { private static final DotName CDI_PRODUCES_ANNOTATION = DotNames.PRODUCES; private static final DotName MP_CONFIG_PROPERTY_ANNOTATION = DotName.createSimple(ConfigProperty.class.getName()); - static final int ANNOTATION = 0x00002000; - - static boolean isAnnotation(final int mod) { - return (mod & ANNOTATION) != 0; - } - @BuildStep FeatureBuildItem registerFeature() { return new FeatureBuildItem(Feature.SPRING_DI); @@ -131,7 +125,7 @@ AnnotationsTransformerBuildItem beanTransformer( instances.put(name, index.getAnnotations(name) .stream() .filter(it -> it.target().kind() == AnnotationTarget.Kind.CLASS - && isAnnotation(it.target().asClass().flags())) + && it.target().asClass().isAnnotation()) .collect(Collectors.toSet())); } additionalStereotypeBuildItemBuildProducer.produce(new AdditionalStereotypeBuildItem(instances)); @@ -248,7 +242,7 @@ private DotName getScope(final AnnotationTarget target) { private List getOrderedAnnotations(final IndexView index) { final Map> deps = new HashMap<>(); for (final ClassInfo clazz : index.getKnownClasses()) { - if (isAnnotation(clazz.flags())) { + if (clazz.isAnnotation()) { deps.put(clazz.name(), clazz.annotations().keySet()); } } @@ -318,7 +312,7 @@ Set getAnnotationsToAdd( if (scopeNames != null) { scopes.addAll(scopeNames); } - if (SPRING_STEREOTYPE_ANNOTATIONS.contains(clazzAnnotation) && !isAnnotation(classInfo.flags())) { + if (SPRING_STEREOTYPE_ANNOTATIONS.contains(clazzAnnotation) && !classInfo.isAnnotation()) { names.add(getBeanNameFromStereotypeInstance(classInfo.classAnnotation(clazzAnnotation))); } } @@ -328,7 +322,7 @@ Set getAnnotationsToAdd( if (declaredScope == null && classInfo.classAnnotation(CDI_NAMED_ANNOTATION) != null) { declaredScope = CDI_SINGLETON_ANNOTATION; // implicit default scope in spring } - final boolean isAnnotation = isAnnotation(classInfo.flags()); + final boolean isAnnotation = classInfo.isAnnotation(); if (declaredScope != null) { annotationsToAdd.add(create( declaredScope, diff --git a/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityProcessor.java b/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityProcessor.java index 1fa035ba13254..d6c7a8cd702e9 100644 --- a/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityProcessor.java +++ b/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityProcessor.java @@ -59,12 +59,6 @@ class SpringSecurityProcessor { private static final int PARAMETER_EQ_PRINCIPAL_USERNAME_PARAMETER_NAME_GROUP = 1; private static final int PARAMETER_EQ_PRINCIPAL_USERNAME_PROPERTY_ACCESSOR_MATCHER_GROUP = 3; - static final int ANNOTATION = 0x00002000; - - static boolean isAnnotation(final int mod) { - return (mod & ANNOTATION) != 0; - } - @BuildStep FeatureBuildItem feature() { return new FeatureBuildItem(Feature.SPRING_SECURITY); @@ -209,7 +203,7 @@ void locatePreAuthorizedInstances( continue; } ClassInfo classInfo = instance.target().asClass(); - if (isAnnotation(classInfo.flags())) { + if (classInfo.isAnnotation()) { // if the instance is an annotation we need to record it and handle it later metaAnnotations.put(classInfo.name(), classInfo); continue; diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java index 27a59755be1d6..1c21a23e01df6 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java @@ -16,7 +16,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -50,10 +49,6 @@ public class BeanDeployment { private static final Logger LOGGER = Logger.getLogger(BeanDeployment.class); - private static final int ANNOTATION = 0x00002000; - - static final EnumSet CLASS_TYPES = EnumSet.of(Type.Kind.CLASS, Type.Kind.PARAMETERIZED_TYPE); - private final BuildContextImpl buildContext; private final IndexView beanArchiveIndex; @@ -173,7 +168,7 @@ public class BeanDeployment { builder.additionalStereotypes, annotationStore); buildContextPut(Key.STEREOTYPES.asString(), Collections.unmodifiableMap(stereotypes)); - this.transitiveInterceptorBindings = findTransitiveInterceptorBindigs(interceptorBindings.keySet(), + this.transitiveInterceptorBindings = findTransitiveInterceptorBindings(interceptorBindings.keySet(), this.beanArchiveIndex, new HashMap<>(), interceptorBindings, annotationStore); @@ -586,7 +581,7 @@ private Map findInterceptorBindings(IndexView index) { return bindings; } - private static Map> findTransitiveInterceptorBindigs(Collection initialBindings, + private static Map> findTransitiveInterceptorBindings(Collection initialBindings, IndexView index, Map> result, Map interceptorBindings, AnnotationStore annotationStore) { @@ -738,9 +733,7 @@ private List findBeans(Collection beanDefiningAnnotations, Li for (ClassInfo beanClass : beanArchiveIndex.getKnownClasses()) { if (Modifier.isInterface(beanClass.flags()) || Modifier.isAbstract(beanClass.flags()) - // Replace with ClassInfo#isAnnotation() and ClassInfo#isEnum() when using Jandex 2.1.4+ - || (beanClass.flags() & ANNOTATION) != 0 - || DotNames.ENUM.equals(beanClass.superName())) { + || beanClass.isAnnotation() || beanClass.isEnum()) { // Skip interfaces, abstract classes, annotations and enums continue; } diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java b/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java index 619ba7d866baf..4ab06ff9bfe30 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java @@ -32,8 +32,6 @@ public class TestResourceManager implements Closeable { public static final String CLOSEABLE_NAME = TestResourceManager.class.getName() + ".closeable"; - private static final int ANNOTATION = 0x00002000; - private final List sequentialTestResourceEntries; private final List parallelTestResourceEntries; private final List allTestResourceEntries; @@ -376,7 +374,7 @@ public boolean hasPerTestResources() { } private boolean keepTestResourceAnnotation(AnnotationInstance annotation, ClassInfo targetClass, Set testClasses) { - if (isAnnotation(targetClass)) { + if (targetClass.isAnnotation()) { // meta-annotations have already been handled in collectMetaAnnotations return false; } @@ -387,10 +385,6 @@ private boolean keepTestResourceAnnotation(AnnotationInstance annotation, ClassI return true; } - private boolean isAnnotation(ClassInfo info) { - return (info.flags() & ANNOTATION) != 0; - } - public static class TestResourceClassEntry { private Class clazz; diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index 4122ebbad410d..7c34d80cb5693 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -1162,12 +1162,6 @@ public List> apply(Map stringObjectM List> allCustomizers = new ArrayList<>(1); Consumer defaultCustomizer = new Consumer() { - private static final int ANNOTATION = 0x00002000; - - boolean isAnnotation(final int mod) { - return (mod & ANNOTATION) != 0; - } - @Override public void accept(BuildChainBuilder buildChainBuilder) { buildChainBuilder.addBuildStep(new BuildStep() { @@ -1217,7 +1211,7 @@ public void execute(BuildContext context) { continue; } ClassInfo classInfo = annotationInstance.target().asClass(); - if (isAnnotation(classInfo.flags())) { + if (classInfo.isAnnotation()) { continue; } Type[] extendsWithTypes = annotationInstance.value().asClassArray();