Polishing
This commit is contained in:
parent
348cc01284
commit
e124e802a3
|
|
@ -340,13 +340,13 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
|
|||
* @see #extractStereotype(TypeFilter)
|
||||
*/
|
||||
private boolean indexSupportsIncludeFilter(TypeFilter filter) {
|
||||
if (filter instanceof AnnotationTypeFilter) {
|
||||
Class<? extends Annotation> annotation = ((AnnotationTypeFilter) filter).getAnnotationType();
|
||||
return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotation) ||
|
||||
annotation.getName().startsWith("javax."));
|
||||
if (filter instanceof AnnotationTypeFilter annotationTypeFilter) {
|
||||
Class<? extends Annotation> annotationType = annotationTypeFilter.getAnnotationType();
|
||||
return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotationType) ||
|
||||
annotationType.getName().startsWith("javax."));
|
||||
}
|
||||
if (filter instanceof AssignableTypeFilter) {
|
||||
Class<?> target = ((AssignableTypeFilter) filter).getTargetType();
|
||||
if (filter instanceof AssignableTypeFilter assignableTypeFilter) {
|
||||
Class<?> target = assignableTypeFilter.getTargetType();
|
||||
return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -361,11 +361,11 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
|
|||
*/
|
||||
@Nullable
|
||||
private String extractStereotype(TypeFilter filter) {
|
||||
if (filter instanceof AnnotationTypeFilter) {
|
||||
return ((AnnotationTypeFilter) filter).getAnnotationType().getName();
|
||||
if (filter instanceof AnnotationTypeFilter annotationTypeFilter) {
|
||||
return annotationTypeFilter.getAnnotationType().getName();
|
||||
}
|
||||
if (filter instanceof AssignableTypeFilter) {
|
||||
return ((AssignableTypeFilter) filter).getTargetType().getName();
|
||||
if (filter instanceof AssignableTypeFilter assignableTypeFilter) {
|
||||
return assignableTypeFilter.getTargetType().getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -536,10 +536,10 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
|
|||
* Clear the local metadata cache, if any, removing all cached class metadata.
|
||||
*/
|
||||
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
|
||||
// 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package example.scannable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.stream.Stream;
|
|||
|
||||
import org.springframework.context.index.CandidateComponentsIndexLoader;
|
||||
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
|
||||
|
|
@ -35,7 +36,7 @@ import org.springframework.core.io.Resource;
|
|||
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.
|
||||
* @param classLoader the classloader to use for all other operations
|
||||
* @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
|
||||
* specified {@link Resource} instances
|
||||
* specified {@link Resource} instances.
|
||||
* @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
|
||||
* specified resources.
|
||||
*/
|
||||
|
|
@ -66,8 +68,10 @@ public class CandidateComponentsTestClassLoader extends ClassLoader {
|
|||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private final Enumeration<URL> resourceUrls;
|
||||
|
||||
@Nullable
|
||||
private final IOException cause;
|
||||
|
||||
public CandidateComponentsTestClassLoader(ClassLoader classLoader, Enumeration<URL> resourceUrls) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue