1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
48
48
public abstract class BeanFactoryAnnotationUtils {
49
49
50
50
/**
51
- * Retrieve all bean of type {@code T} from the given {@code BeanFactory} declaring a
51
+ * Retrieve all beans of type {@code T} from the given {@code BeanFactory} declaring a
52
52
* qualifier (e.g. via {@code <qualifier>} or {@code @Qualifier}) matching the given
53
53
* qualifier, or having a bean name matching the given qualifier.
54
54
* @param beanFactory the factory to get the target beans from (also searching ancestors)
@@ -90,9 +90,9 @@ public static <T> T qualifiedBeanOfType(BeanFactory beanFactory, Class<T> beanTy
90
90
91
91
Assert .notNull (beanFactory , "BeanFactory must not be null" );
92
92
93
- if (beanFactory instanceof ListableBeanFactory ) {
93
+ if (beanFactory instanceof ListableBeanFactory lbf ) {
94
94
// Full qualifier matching supported.
95
- return qualifiedBeanOfType (( ListableBeanFactory ) beanFactory , beanType , qualifier );
95
+ return qualifiedBeanOfType (lbf , beanType , qualifier );
96
96
}
97
97
else if (beanFactory .containsBean (qualifier )) {
98
98
// Fallback: target bean at least found by bean name.
@@ -163,8 +163,8 @@ public static boolean isQualifierMatch(
163
163
}
164
164
try {
165
165
Class <?> beanType = beanFactory .getType (beanName );
166
- if (beanFactory instanceof ConfigurableBeanFactory ) {
167
- BeanDefinition bd = (( ConfigurableBeanFactory ) beanFactory ) .getMergedBeanDefinition (beanName );
166
+ if (beanFactory instanceof ConfigurableBeanFactory cbf ) {
167
+ BeanDefinition bd = cbf .getMergedBeanDefinition (beanName );
168
168
// Explicit qualifier metadata on bean definition? (typically in XML definition)
169
169
if (bd instanceof AbstractBeanDefinition abd ) {
170
170
AutowireCandidateQualifier candidate = abd .getQualifier (Qualifier .class .getName ());
@@ -176,8 +176,8 @@ public static boolean isQualifierMatch(
176
176
}
177
177
}
178
178
// Corresponding qualifier on factory method? (typically in configuration class)
179
- if (bd instanceof RootBeanDefinition ) {
180
- Method factoryMethod = (( RootBeanDefinition ) bd ) .getResolvedFactoryMethod ();
179
+ if (bd instanceof RootBeanDefinition rbd ) {
180
+ Method factoryMethod = rbd .getResolvedFactoryMethod ();
181
181
if (factoryMethod != null ) {
182
182
Qualifier targetAnnotation = AnnotationUtils .getAnnotation (factoryMethod , Qualifier .class );
183
183
if (targetAnnotation != null ) {
0 commit comments