Skip to content

Commit 8f90eac

Browse files
committed
Polishing
1 parent aecf60d commit 8f90eac

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java

+13-21
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,16 @@
4242
*/
4343
class ConditionEvaluator {
4444

45-
private static final String CONDITIONAL_ANNOTATION = Conditional.class.getName();
46-
47-
4845
private final ConditionContextImpl context;
4946

5047

5148
/**
5249
* Create a new {@link ConditionEvaluator} instance.
5350
*/
5451
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);
5955
}
6056

6157

@@ -77,7 +73,7 @@ public boolean shouldSkip(AnnotatedTypeMetadata metadata) {
7773
* @return if the item should be skipped
7874
*/
7975
public boolean shouldSkip(AnnotatedTypeMetadata metadata, ConfigurationPhase phase) {
80-
if (metadata == null || !metadata.isAnnotated(CONDITIONAL_ANNOTATION)) {
76+
if (metadata == null || !metadata.isAnnotated(Conditional.class.getName())) {
8177
return false;
8278
}
8379

@@ -108,16 +104,13 @@ public boolean shouldSkip(AnnotatedTypeMetadata metadata, ConfigurationPhase pha
108104

109105
@SuppressWarnings("unchecked")
110106
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());
115110
}
116111

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);
121114
return (Condition) BeanUtils.instantiateClass(conditionClass);
122115
}
123116

@@ -139,7 +132,6 @@ private static class ConditionContextImpl implements ConditionContext {
139132

140133
private ResourceLoader resourceLoader;
141134

142-
143135
public ConditionContextImpl(BeanDefinitionRegistry registry,
144136
Environment environment, ApplicationContext applicationContext,
145137
ClassLoader classLoader, ResourceLoader resourceLoader) {
@@ -169,7 +161,7 @@ public BeanDefinitionRegistry getRegistry() {
169161
if (this.registry != null) {
170162
return this.registry;
171163
}
172-
if(getBeanFactory() != null && getBeanFactory() instanceof BeanDefinitionRegistry) {
164+
if (getBeanFactory() instanceof BeanDefinitionRegistry) {
173165
return (BeanDefinitionRegistry) getBeanFactory();
174166
}
175167
return null;
@@ -180,7 +172,7 @@ public Environment getEnvironment() {
180172
if (this.environment != null) {
181173
return this.environment;
182174
}
183-
if (getRegistry() != null && getRegistry() instanceof EnvironmentCapable) {
175+
if (getRegistry() instanceof EnvironmentCapable) {
184176
return ((EnvironmentCapable) getRegistry()).getEnvironment();
185177
}
186178
return null;
@@ -197,7 +189,7 @@ public ResourceLoader getResourceLoader() {
197189
if (this.resourceLoader != null) {
198190
return this.resourceLoader;
199191
}
200-
if (registry instanceof ResourceLoader) {
192+
if (this.registry instanceof ResourceLoader) {
201193
return (ResourceLoader) registry;
202194
}
203195
return null;
@@ -219,7 +211,7 @@ public ApplicationContext getApplicationContext() {
219211
if (this.applicationContext != null) {
220212
return this.applicationContext;
221213
}
222-
if (getRegistry() != null && getRegistry() instanceof ApplicationContext) {
214+
if (getRegistry() instanceof ApplicationContext) {
223215
return (ApplicationContext) getRegistry();
224216
}
225217
return null;

spring-context/src/main/java/org/springframework/context/annotation/Profile.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
*
4646
* <p>If a {@code @Configuration} class is marked with {@code @Profile}, all of the
4747
* {@code @Bean} methods and {@link Import @Import} annotations associated with that class
48-
* will be bypassed unless one or more the specified profiles are active. This is very
48+
* will be bypassed unless one or more of the specified profiles are active. This is very
4949
* similar to the behavior in Spring XML: if the {@code profile} attribute of the
5050
* {@code beans} element is supplied e.g., {@code <beans profile="p1,p2">}, the
5151
* {@code beans} element will not be parsed unless profiles 'p1' and/or 'p2' have been
52-
* activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
52+
* activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked
5353
* with {@code @Profile({"p1", "p2"})}, that class will not be registered/processed unless
5454
* profiles 'p1' and/or 'p2' have been activated.
5555
*
@@ -74,7 +74,7 @@
7474
* @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
7575
*/
7676
@Retention(RetentionPolicy.RUNTIME)
77-
@Target({ ElementType.TYPE, ElementType.METHOD })
77+
@Target({ElementType.TYPE, ElementType.METHOD})
7878
@Conditional(ProfileCondition.class)
7979
public @interface Profile {
8080

spring-core/src/main/java/org/springframework/util/ClassUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -746,7 +746,7 @@ private static boolean isOverridable(Method method, Class targetClass) {
746746
/**
747747
* Return a public static method of a class.
748748
* @param methodName the static method name
749-
* @param clazz the class which defines the method
749+
* @param clazz the class which defines the method
750750
* @param args the parameter types to the method
751751
* @return the static method, or {@code null} if no static method was found
752752
* @throws IllegalArgumentException if the method name is blank or the clazz is null

0 commit comments

Comments
 (0)