Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Dec 6, 2022
1 parent 348cc01 commit e124e80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Expand Up @@ -340,13 +340,13 @@ private boolean indexSupportsIncludeFilters() {
* @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;
Expand All @@ -361,11 +361,11 @@ private boolean indexSupportsIncludeFilter(TypeFilter filter) {
*/
@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;
}
Expand Down Expand Up @@ -536,10 +536,10 @@ protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
* 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();
}
}

Expand Down
@@ -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.
Expand All @@ -16,7 +16,6 @@

package example.scannable;


/**
* @author Juergen Hoeller
*/
Expand Down
Expand Up @@ -24,6 +24,7 @@

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
Expand All @@ -35,7 +36,7 @@
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
Expand All @@ -48,8 +49,9 @@ public static ClassLoader disableIndex(ClassLoader 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.
*/
Expand All @@ -66,8 +68,10 @@ public static ClassLoader index(ClassLoader classLoader, Resource... resources)
}


@Nullable
private final Enumeration<URL> resourceUrls;

@Nullable
private final IOException cause;

public CandidateComponentsTestClassLoader(ClassLoader classLoader, Enumeration<URL> resourceUrls) {
Expand Down

0 comments on commit e124e80

Please sign in to comment.