Skip plain Java annotations in SourceClass.getAnnotations() upfront
Includes direct reflective introspection of annotations when possible. Closes gh-22750
This commit is contained in:
parent
a1668ad1c2
commit
fc9ce7cd99
|
@ -531,7 +531,7 @@ class ConfigurationClassParser {
|
||||||
if (visited.add(sourceClass)) {
|
if (visited.add(sourceClass)) {
|
||||||
for (SourceClass annotation : sourceClass.getAnnotations()) {
|
for (SourceClass annotation : sourceClass.getAnnotations()) {
|
||||||
String annName = annotation.getMetadata().getClassName();
|
String annName = annotation.getMetadata().getClassName();
|
||||||
if (!annName.startsWith("java") && !annName.equals(Import.class.getName())) {
|
if (!annName.equals(Import.class.getName())) {
|
||||||
collectImports(annotation, imports, visited);
|
collectImports(annotation, imports, visited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -539,8 +539,6 @@ class ConfigurationClassParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void processImports(ConfigurationClass configClass, SourceClass currentSourceClass,
|
private void processImports(ConfigurationClass configClass, SourceClass currentSourceClass,
|
||||||
Collection<SourceClass> importCandidates, boolean checkForCircularImports) {
|
Collection<SourceClass> importCandidates, boolean checkForCircularImports) {
|
||||||
|
|
||||||
|
@ -562,8 +560,7 @@ class ConfigurationClassParser {
|
||||||
ParserStrategyUtils.invokeAwareMethods(
|
ParserStrategyUtils.invokeAwareMethods(
|
||||||
selector, this.environment, this.resourceLoader, this.registry);
|
selector, this.environment, this.resourceLoader, this.registry);
|
||||||
if (selector instanceof DeferredImportSelector) {
|
if (selector instanceof DeferredImportSelector) {
|
||||||
this.deferredImportSelectorHandler.handle(
|
this.deferredImportSelectorHandler.handle(configClass, (DeferredImportSelector) selector);
|
||||||
configClass, (DeferredImportSelector) selector);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String[] importClassNames = selector.selectImports(currentSourceClass.getMetadata());
|
String[] importClassNames = selector.selectImports(currentSourceClass.getMetadata());
|
||||||
|
@ -1016,7 +1013,24 @@ class ConfigurationClassParser {
|
||||||
|
|
||||||
public Set<SourceClass> getAnnotations() {
|
public Set<SourceClass> getAnnotations() {
|
||||||
Set<SourceClass> result = new LinkedHashSet<>();
|
Set<SourceClass> result = new LinkedHashSet<>();
|
||||||
|
if (this.source instanceof Class) {
|
||||||
|
Class<?> sourceClass = (Class<?>) this.source;
|
||||||
|
for (Annotation ann : sourceClass.getAnnotations()) {
|
||||||
|
Class<?> annType = ann.annotationType();
|
||||||
|
if (!annType.getName().startsWith("java")) {
|
||||||
|
try {
|
||||||
|
result.add(asSourceClass(annType));
|
||||||
|
}
|
||||||
|
catch (Throwable ex) {
|
||||||
|
// An annotation not present on the classpath is being ignored
|
||||||
|
// by the JVM's class loading -> ignore here as well.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
for (String className : this.metadata.getAnnotationTypes()) {
|
for (String className : this.metadata.getAnnotationTypes()) {
|
||||||
|
if (!className.startsWith("java")) {
|
||||||
try {
|
try {
|
||||||
result.add(getRelated(className));
|
result.add(getRelated(className));
|
||||||
}
|
}
|
||||||
|
@ -1025,6 +1039,8 @@ class ConfigurationClassParser {
|
||||||
// by the JVM's class loading -> ignore here as well.
|
// by the JVM's class loading -> ignore here as well.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue