Skip to content

Commit

Permalink
fix: prevent ImportAnnotationVisitor walking non-visible classes (#540)
Browse files Browse the repository at this point in the history
Closes #521
  • Loading branch information
timyates authored and sdelamo committed Feb 13, 2024
1 parent 1cba81c commit d30b917
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
import io.micronaut.spring.core.type.ClassElementSpringMetadata;

/**
* Handles the import importDeclaration allowing importing of additional Spring beans into a Micronaut
application.
* Handles the import importDeclaration allowing importing of additional Spring beans into a Micronaut application.
*
* @author graemerocher
* @since 4.3.0
Expand All @@ -75,15 +74,21 @@ public void visitClass(ClassElement element, VisitorContext context) {
if (annType != null && element.hasStereotype(annType)) {
List<AnnotationValue<? extends Annotation>> values = element.getAnnotationValuesByType(annType);
if (!values.isEmpty()) {
for (AnnotationValue<?> av : values) {
AnnotationClassValue<?>[] acv = av.annotationClassValues(AnnotationMetadata.VALUE_MEMBER);
for (AnnotationClassValue<?> a : acv) {
String className = a.getName();
context.getClassElement(className).ifPresent(typeToImport -> {
handleImport(element, context, typeToImport);
});
visitValues(element, context, values);
}
}
}

private void visitValues(ClassElement element, VisitorContext context, List<AnnotationValue<? extends Annotation>> values) {
for (AnnotationValue<?> av : values) {
AnnotationClassValue<?>[] acv = av.annotationClassValues(AnnotationMetadata.VALUE_MEMBER);
for (AnnotationClassValue<?> a : acv) {
String className = a.getName();
context.getClassElement(className).ifPresent(typeToImport -> {
if (typeToImport.isPublic()) {
handleImport(element, context, typeToImport);
}
}
});
}
}
}
Expand Down

0 comments on commit d30b917

Please sign in to comment.