Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated AnnotationsTransformerBuildItem usage in RESTEasy Reactive #45726

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.jboss.jandex.AnnotationTransformation;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.Declaration;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.IndexView;
Expand Down Expand Up @@ -893,64 +894,65 @@ public void transformEndpoints(
Set<DotName> nonRecordParameterContainerClassNames = aggregatedParameterContainersBuildItem.getNonRecordClassNames();

annotationsTransformer.produce(new io.quarkus.arc.deployment.AnnotationsTransformerBuildItem(
new io.quarkus.arc.processor.AnnotationsTransformer() {

@Override
public boolean appliesTo(AnnotationTarget.Kind kind) {
return kind == AnnotationTarget.Kind.CLASS || kind == AnnotationTarget.Kind.FIELD;
}

@Override
public void transform(TransformationContext context) {
if (context.getTarget().kind() == AnnotationTarget.Kind.CLASS) {
ClassInfo clazz = context.getTarget().asClass();
// check if the class is one of resources/sub-resources
if (allResources.contains(clazz.name())
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
context.transform().add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem)).done();
return;
}
// check if the class is one of providers, either explicitly declaring the annotation
// or discovered as resource interceptor or filter
if ((clazz.declaredAnnotation(ResteasyReactiveDotNames.PROVIDER) != null
|| filtersAndInterceptors.contains(clazz.name().toString()))
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
// Add @Typed(MyResource.class)
context.transform().add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem)).done();
return;
}
// check if the class is a parameter container
if (nonRecordParameterContainerClassNames.contains(clazz.name())
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
// Add @Typed(MyBean.class)
context.transform().add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem)).done();
return;
}
} else if (context.getTarget().kind() == AnnotationTarget.Kind.FIELD) {
FieldInfo field = context.getTarget().asField();
ClassInfo declaringClass = field.declaringClass();
// remove @BeanParam annotations from record fields
if (declaringClass.isRecord()
&& field.declaredAnnotation(ResteasyReactiveDotNames.BEAN_PARAM) != null) {
context.transform().remove(a -> a.name().equals(ResteasyReactiveDotNames.BEAN_PARAM)).done();
return;
}
// also remove @BeanParam annotations targeting records
if (field.declaredAnnotation(ResteasyReactiveDotNames.BEAN_PARAM) != null
&& isRecord(resourceScanningResultBuildItem.getResult().getIndex(),
field.type().asClassType().name())) {
context.transform().remove(a -> a.name().equals(ResteasyReactiveDotNames.BEAN_PARAM)).done();
return;
AnnotationTransformation.builder().whenDeclaration(
new Predicate<>() {
@Override
public boolean test(Declaration declaration) {
return declaration.kind() == AnnotationTarget.Kind.CLASS
|| declaration.kind() == AnnotationTarget.Kind.FIELD;
}
}).transform(new Consumer<>() {
@Override
public void accept(AnnotationTransformation.TransformationContext context) {
if (context.declaration().kind() == AnnotationTarget.Kind.CLASS) {
ClassInfo clazz = context.declaration().asClass();
// check if the class is one of resources/sub-resources
if (allResources.contains(clazz.name())
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
context.add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem));
return;
}
// check if the class is one of providers, either explicitly declaring the annotation
// or discovered as resource interceptor or filter
if ((clazz.declaredAnnotation(ResteasyReactiveDotNames.PROVIDER) != null
|| filtersAndInterceptors.contains(clazz.name().toString()))
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
// Add @Typed(MyResource.class)
context.add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem));
return;
}
// check if the class is a parameter container
if (nonRecordParameterContainerClassNames.contains(clazz.name())
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
// Add @Typed(MyBean.class)
context.add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem));
return;
}
} else if (context.declaration().kind() == AnnotationTarget.Kind.FIELD) {
FieldInfo field = context.declaration().asField();
ClassInfo declaringClass = field.declaringClass();
// remove @BeanParam annotations from record fields
if (declaringClass.isRecord()
&& field.declaredAnnotation(ResteasyReactiveDotNames.BEAN_PARAM) != null) {
context.remove(a -> a.name().equals(ResteasyReactiveDotNames.BEAN_PARAM));
return;
}
// also remove @BeanParam annotations targeting records
if (field.declaredAnnotation(ResteasyReactiveDotNames.BEAN_PARAM) != null
&& isRecord(resourceScanningResultBuildItem.getResult().getIndex(),
field.type().asClassType().name())) {
context.remove(a -> a.name().equals(ResteasyReactiveDotNames.BEAN_PARAM));
return;
}

}
}
}
}

private boolean isRecord(IndexView index, DotName name) {
ClassInfo classInfo = index.getClassByName(name);
return classInfo.isRecord();
}
}));
private boolean isRecord(IndexView index, DotName name) {
ClassInfo classInfo = index.getClassByName(name);
return classInfo.isRecord();
}
})));
}

private AnnotationInstance createTypedAnnotationInstance(ClassInfo clazz,
Expand Down
Loading