42
42
*/
43
43
class ConditionEvaluator {
44
44
45
- private static final String CONDITIONAL_ANNOTATION = Conditional .class .getName ();
46
-
47
-
48
45
private final ConditionContextImpl context ;
49
46
50
47
51
48
/**
52
49
* Create a new {@link ConditionEvaluator} instance.
53
50
*/
54
51
public ConditionEvaluator (BeanDefinitionRegistry registry , Environment environment ,
55
- ApplicationContext applicationContext , ClassLoader classLoader ,
56
- ResourceLoader resourceLoader ) {
57
- this .context = new ConditionContextImpl (registry , environment ,
58
- applicationContext , classLoader , resourceLoader );
52
+ ApplicationContext applicationContext , ClassLoader classLoader , ResourceLoader resourceLoader ) {
53
+
54
+ this .context = new ConditionContextImpl (registry , environment , applicationContext , classLoader , resourceLoader );
59
55
}
60
56
61
57
@@ -77,7 +73,7 @@ public boolean shouldSkip(AnnotatedTypeMetadata metadata) {
77
73
* @return if the item should be skipped
78
74
*/
79
75
public boolean shouldSkip (AnnotatedTypeMetadata metadata , ConfigurationPhase phase ) {
80
- if (metadata == null || !metadata .isAnnotated (CONDITIONAL_ANNOTATION )) {
76
+ if (metadata == null || !metadata .isAnnotated (Conditional . class . getName () )) {
81
77
return false ;
82
78
}
83
79
@@ -108,16 +104,13 @@ public boolean shouldSkip(AnnotatedTypeMetadata metadata, ConfigurationPhase pha
108
104
109
105
@ SuppressWarnings ("unchecked" )
110
106
private List <String []> getConditionClasses (AnnotatedTypeMetadata metadata ) {
111
- MultiValueMap <String , Object > attributes = metadata .getAllAnnotationAttributes (
112
- CONDITIONAL_ANNOTATION , true );
113
- Object values = attributes == null ? null : attributes .get ("value" );
114
- return (List <String []>) (values == null ? Collections .emptyList () : values );
107
+ MultiValueMap <String , Object > attributes = metadata .getAllAnnotationAttributes (Conditional .class .getName (), true );
108
+ Object values = (attributes != null ? attributes .get ("value" ) : null );
109
+ return (List <String []>) (values != null ? values : Collections .emptyList ());
115
110
}
116
111
117
- private Condition getCondition (String conditionClassName ,
118
- ClassLoader classloader ) {
119
- Class <?> conditionClass = ClassUtils .resolveClassName (conditionClassName ,
120
- classloader );
112
+ private Condition getCondition (String conditionClassName , ClassLoader classloader ) {
113
+ Class <?> conditionClass = ClassUtils .resolveClassName (conditionClassName , classloader );
121
114
return (Condition ) BeanUtils .instantiateClass (conditionClass );
122
115
}
123
116
@@ -139,7 +132,6 @@ private static class ConditionContextImpl implements ConditionContext {
139
132
140
133
private ResourceLoader resourceLoader ;
141
134
142
-
143
135
public ConditionContextImpl (BeanDefinitionRegistry registry ,
144
136
Environment environment , ApplicationContext applicationContext ,
145
137
ClassLoader classLoader , ResourceLoader resourceLoader ) {
@@ -169,7 +161,7 @@ public BeanDefinitionRegistry getRegistry() {
169
161
if (this .registry != null ) {
170
162
return this .registry ;
171
163
}
172
- if ( getBeanFactory () != null && getBeanFactory () instanceof BeanDefinitionRegistry ) {
164
+ if ( getBeanFactory () instanceof BeanDefinitionRegistry ) {
173
165
return (BeanDefinitionRegistry ) getBeanFactory ();
174
166
}
175
167
return null ;
@@ -180,7 +172,7 @@ public Environment getEnvironment() {
180
172
if (this .environment != null ) {
181
173
return this .environment ;
182
174
}
183
- if (getRegistry () != null && getRegistry () instanceof EnvironmentCapable ) {
175
+ if (getRegistry () instanceof EnvironmentCapable ) {
184
176
return ((EnvironmentCapable ) getRegistry ()).getEnvironment ();
185
177
}
186
178
return null ;
@@ -197,7 +189,7 @@ public ResourceLoader getResourceLoader() {
197
189
if (this .resourceLoader != null ) {
198
190
return this .resourceLoader ;
199
191
}
200
- if (registry instanceof ResourceLoader ) {
192
+ if (this . registry instanceof ResourceLoader ) {
201
193
return (ResourceLoader ) registry ;
202
194
}
203
195
return null ;
@@ -219,7 +211,7 @@ public ApplicationContext getApplicationContext() {
219
211
if (this .applicationContext != null ) {
220
212
return this .applicationContext ;
221
213
}
222
- if (getRegistry () != null && getRegistry () instanceof ApplicationContext ) {
214
+ if (getRegistry () instanceof ApplicationContext ) {
223
215
return (ApplicationContext ) getRegistry ();
224
216
}
225
217
return null ;
0 commit comments