Skip to content

Commit

Permalink
ArC: use Jandex annotation overlay in Build Compatible Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed May 16, 2024
1 parent b5d76b7 commit 7931613
Show file tree
Hide file tree
Showing 48 changed files with 634 additions and 1,252 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends Annotation> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<org.jboss.jandex.AnnotationValue> 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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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));
}

Expand All @@ -49,7 +49,7 @@ public Map<String, AnnotationMember> members() {
Map<String, AnnotationMember> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -137,29 +122,29 @@ 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
public List<AnnotationMember> 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
Expand Down
Loading

0 comments on commit 7931613

Please sign in to comment.