Skip to content

Commit

Permalink
Cleanup: Remove isAnnotation(ClassInfo) utility methods
Browse files Browse the repository at this point in the history
There is now a dedicated `ClassInfo#isAnnotation()` method.

Also removes no longer used field `BeanDeployment#CLASS_TYPES`.
  • Loading branch information
knutwannheden committed Jun 8, 2021
1 parent 1871e8e commit 9698f23
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -248,7 +242,7 @@ private DotName getScope(final AnnotationTarget target) {
private List<ClassInfo> getOrderedAnnotations(final IndexView index) {
final Map<DotName, Set<DotName>> deps = new HashMap<>();
for (final ClassInfo clazz : index.getKnownClasses()) {
if (isAnnotation(clazz.flags())) {
if (clazz.isAnnotation()) {
deps.put(clazz.name(), clazz.annotations().keySet());
}
}
Expand Down Expand Up @@ -318,7 +312,7 @@ Set<AnnotationInstance> 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)));
}
}
Expand All @@ -328,7 +322,7 @@ Set<AnnotationInstance> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Type.Kind> CLASS_TYPES = EnumSet.of(Type.Kind.CLASS, Type.Kind.PARAMETERIZED_TYPE);

private final BuildContextImpl buildContext;

private final IndexView beanArchiveIndex;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -586,7 +581,7 @@ private Map<DotName, ClassInfo> findInterceptorBindings(IndexView index) {
return bindings;
}

private static Map<DotName, Set<AnnotationInstance>> findTransitiveInterceptorBindigs(Collection<DotName> initialBindings,
private static Map<DotName, Set<AnnotationInstance>> findTransitiveInterceptorBindings(Collection<DotName> initialBindings,
IndexView index,
Map<DotName, Set<AnnotationInstance>> result, Map<DotName, ClassInfo> interceptorBindings,
AnnotationStore annotationStore) {
Expand Down Expand Up @@ -738,9 +733,7 @@ private List<BeanInfo> findBeans(Collection<DotName> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestResourceEntry> sequentialTestResourceEntries;
private final List<TestResourceEntry> parallelTestResourceEntries;
private final List<TestResourceEntry> allTestResourceEntries;
Expand Down Expand Up @@ -376,7 +374,7 @@ public boolean hasPerTestResources() {
}

private boolean keepTestResourceAnnotation(AnnotationInstance annotation, ClassInfo targetClass, Set<String> testClasses) {
if (isAnnotation(targetClass)) {
if (targetClass.isAnnotation()) {
// meta-annotations have already been handled in collectMetaAnnotations
return false;
}
Expand All @@ -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<? extends QuarkusTestResourceLifecycleManager> clazz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,12 +1162,6 @@ public List<Consumer<BuildChainBuilder>> apply(Map<String, Object> stringObjectM
List<Consumer<BuildChainBuilder>> allCustomizers = new ArrayList<>(1);
Consumer<BuildChainBuilder> defaultCustomizer = new Consumer<BuildChainBuilder>() {

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() {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9698f23

Please sign in to comment.