Polishing
This commit is contained in:
parent
348cc01284
commit
e124e802a3
|
|
@ -340,13 +340,13 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
|
||||||
* @see #extractStereotype(TypeFilter)
|
* @see #extractStereotype(TypeFilter)
|
||||||
*/
|
*/
|
||||||
private boolean indexSupportsIncludeFilter(TypeFilter filter) {
|
private boolean indexSupportsIncludeFilter(TypeFilter filter) {
|
||||||
if (filter instanceof AnnotationTypeFilter) {
|
if (filter instanceof AnnotationTypeFilter annotationTypeFilter) {
|
||||||
Class<? extends Annotation> annotation = ((AnnotationTypeFilter) filter).getAnnotationType();
|
Class<? extends Annotation> annotationType = annotationTypeFilter.getAnnotationType();
|
||||||
return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotation) ||
|
return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotationType) ||
|
||||||
annotation.getName().startsWith("javax."));
|
annotationType.getName().startsWith("javax."));
|
||||||
}
|
}
|
||||||
if (filter instanceof AssignableTypeFilter) {
|
if (filter instanceof AssignableTypeFilter assignableTypeFilter) {
|
||||||
Class<?> target = ((AssignableTypeFilter) filter).getTargetType();
|
Class<?> target = assignableTypeFilter.getTargetType();
|
||||||
return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target);
|
return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -361,11 +361,11 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private String extractStereotype(TypeFilter filter) {
|
private String extractStereotype(TypeFilter filter) {
|
||||||
if (filter instanceof AnnotationTypeFilter) {
|
if (filter instanceof AnnotationTypeFilter annotationTypeFilter) {
|
||||||
return ((AnnotationTypeFilter) filter).getAnnotationType().getName();
|
return annotationTypeFilter.getAnnotationType().getName();
|
||||||
}
|
}
|
||||||
if (filter instanceof AssignableTypeFilter) {
|
if (filter instanceof AssignableTypeFilter assignableTypeFilter) {
|
||||||
return ((AssignableTypeFilter) filter).getTargetType().getName();
|
return assignableTypeFilter.getTargetType().getName();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -536,10 +536,10 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
|
||||||
* Clear the local metadata cache, if any, removing all cached class metadata.
|
* Clear the local metadata cache, if any, removing all cached class metadata.
|
||||||
*/
|
*/
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
if (this.metadataReaderFactory instanceof CachingMetadataReaderFactory) {
|
if (this.metadataReaderFactory instanceof CachingMetadataReaderFactory cmrf) {
|
||||||
// Clear cache in externally provided MetadataReaderFactory; this is a no-op
|
// Clear cache in externally provided MetadataReaderFactory; this is a no-op
|
||||||
// for a shared cache since it'll be cleared by the ApplicationContext.
|
// for a shared cache since it'll be cleared by the ApplicationContext.
|
||||||
((CachingMetadataReaderFactory) this.metadataReaderFactory).clearCache();
|
cmrf.clearCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package example.scannable;
|
package example.scannable;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.springframework.context.index.CandidateComponentsIndexLoader;
|
import org.springframework.context.index.CandidateComponentsIndexLoader;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test {@link ClassLoader} that can be used in a testing context to control the
|
* A test {@link ClassLoader} that can be used in a testing context to control the
|
||||||
|
|
@ -35,7 +36,7 @@ import org.springframework.core.io.Resource;
|
||||||
public class CandidateComponentsTestClassLoader extends ClassLoader {
|
public class CandidateComponentsTestClassLoader extends ClassLoader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a test {@link ClassLoader} that disable the use of the index, even
|
* Create a test {@link ClassLoader} that disables the use of the index, even
|
||||||
* if resources are present at the standard location.
|
* if resources are present at the standard location.
|
||||||
* @param classLoader the classloader to use for all other operations
|
* @param classLoader the classloader to use for all other operations
|
||||||
* @return a test {@link ClassLoader} that has no index
|
* @return a test {@link ClassLoader} that has no index
|
||||||
|
|
@ -48,8 +49,9 @@ public class CandidateComponentsTestClassLoader extends ClassLoader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a test {@link ClassLoader} that creates an index with the
|
* Create a test {@link ClassLoader} that creates an index with the
|
||||||
* specified {@link Resource} instances
|
* specified {@link Resource} instances.
|
||||||
* @param classLoader the classloader to use for all other operations
|
* @param classLoader the classloader to use for all other operations
|
||||||
|
* @param resources the resources for index files
|
||||||
* @return a test {@link ClassLoader} with an index built based on the
|
* @return a test {@link ClassLoader} with an index built based on the
|
||||||
* specified resources.
|
* specified resources.
|
||||||
*/
|
*/
|
||||||
|
|
@ -66,8 +68,10 @@ public class CandidateComponentsTestClassLoader extends ClassLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final Enumeration<URL> resourceUrls;
|
private final Enumeration<URL> resourceUrls;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final IOException cause;
|
private final IOException cause;
|
||||||
|
|
||||||
public CandidateComponentsTestClassLoader(ClassLoader classLoader, Enumeration<URL> resourceUrls) {
|
public CandidateComponentsTestClassLoader(ClassLoader classLoader, Enumeration<URL> resourceUrls) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue