Expand configuration class eager filtering to imports
Previously, only root auto-configuration classes could be excluded eagerly via an AutoConfigurationImportFilter. Any configuration class loaded as a result of processing a particular auto-configuration were parsed and checked as usual. This commit makes use of the `getExclusionFilter` callback to expand this filter to all candidates that are considered. The annotation processor has also be expanded to generate metadata for non-root configuration classes. Closes gh-12157
This commit is contained in:
@@ -40,7 +40,6 @@ import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.tools.FileObject;
|
||||
@@ -127,10 +126,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
|
||||
TypeElement annotationType = this.processingEnv.getElementUtils().getTypeElement(annotationName);
|
||||
if (annotationType != null) {
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(annotationType)) {
|
||||
Element enclosingElement = element.getEnclosingElement();
|
||||
if (enclosingElement != null && enclosingElement.getKind() == ElementKind.PACKAGE) {
|
||||
processElement(element, propertyKey, annotationName);
|
||||
}
|
||||
processElement(element, propertyKey, annotationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,14 +49,14 @@ class AutoConfigureAnnotationProcessorTests {
|
||||
@Test
|
||||
void annotatedClass() throws Exception {
|
||||
Properties properties = compile(TestClassConfiguration.class);
|
||||
assertThat(properties).hasSize(5);
|
||||
assertThat(properties).hasSize(7);
|
||||
assertThat(properties).containsEntry(
|
||||
"org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.ConditionalOnClass",
|
||||
"java.io.InputStream,org.springframework.boot.autoconfigureprocessor."
|
||||
+ "TestClassConfiguration$Nested,org.springframework.foo");
|
||||
assertThat(properties).containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration");
|
||||
assertThat(properties)
|
||||
.doesNotContainKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested");
|
||||
.containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested");
|
||||
assertThat(properties).containsEntry(
|
||||
"org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.ConditionalOnBean",
|
||||
"java.io.OutputStream");
|
||||
|
||||
Reference in New Issue
Block a user