diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java b/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java index 32142bc59ec..7903bca448d 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConditionEvaluator.java @@ -42,9 +42,6 @@ import org.springframework.util.MultiValueMap; */ class ConditionEvaluator { - private static final String CONDITIONAL_ANNOTATION = Conditional.class.getName(); - - private final ConditionContextImpl context; @@ -52,10 +49,9 @@ class ConditionEvaluator { * Create a new {@link ConditionEvaluator} instance. */ public ConditionEvaluator(BeanDefinitionRegistry registry, Environment environment, - ApplicationContext applicationContext, ClassLoader classLoader, - ResourceLoader resourceLoader) { - this.context = new ConditionContextImpl(registry, environment, - applicationContext, classLoader, resourceLoader); + ApplicationContext applicationContext, ClassLoader classLoader, ResourceLoader resourceLoader) { + + this.context = new ConditionContextImpl(registry, environment, applicationContext, classLoader, resourceLoader); } @@ -77,7 +73,7 @@ class ConditionEvaluator { * @return if the item should be skipped */ public boolean shouldSkip(AnnotatedTypeMetadata metadata, ConfigurationPhase phase) { - if (metadata == null || !metadata.isAnnotated(CONDITIONAL_ANNOTATION)) { + if (metadata == null || !metadata.isAnnotated(Conditional.class.getName())) { return false; } @@ -108,16 +104,13 @@ class ConditionEvaluator { @SuppressWarnings("unchecked") private List getConditionClasses(AnnotatedTypeMetadata metadata) { - MultiValueMap attributes = metadata.getAllAnnotationAttributes( - CONDITIONAL_ANNOTATION, true); - Object values = attributes == null ? null : attributes.get("value"); - return (List) (values == null ? Collections.emptyList() : values); + MultiValueMap attributes = metadata.getAllAnnotationAttributes(Conditional.class.getName(), true); + Object values = (attributes != null ? attributes.get("value") : null); + return (List) (values != null ? values : Collections.emptyList()); } - private Condition getCondition(String conditionClassName, - ClassLoader classloader) { - Class conditionClass = ClassUtils.resolveClassName(conditionClassName, - classloader); + private Condition getCondition(String conditionClassName, ClassLoader classloader) { + Class conditionClass = ClassUtils.resolveClassName(conditionClassName, classloader); return (Condition) BeanUtils.instantiateClass(conditionClass); } @@ -139,7 +132,6 @@ class ConditionEvaluator { private ResourceLoader resourceLoader; - public ConditionContextImpl(BeanDefinitionRegistry registry, Environment environment, ApplicationContext applicationContext, ClassLoader classLoader, ResourceLoader resourceLoader) { @@ -169,7 +161,7 @@ class ConditionEvaluator { if (this.registry != null) { return this.registry; } - if(getBeanFactory() != null && getBeanFactory() instanceof BeanDefinitionRegistry) { + if (getBeanFactory() instanceof BeanDefinitionRegistry) { return (BeanDefinitionRegistry) getBeanFactory(); } return null; @@ -180,7 +172,7 @@ class ConditionEvaluator { if (this.environment != null) { return this.environment; } - if (getRegistry() != null && getRegistry() instanceof EnvironmentCapable) { + if (getRegistry() instanceof EnvironmentCapable) { return ((EnvironmentCapable) getRegistry()).getEnvironment(); } return null; @@ -197,7 +189,7 @@ class ConditionEvaluator { if (this.resourceLoader != null) { return this.resourceLoader; } - if (registry instanceof ResourceLoader) { + if (this.registry instanceof ResourceLoader) { return (ResourceLoader) registry; } return null; @@ -219,7 +211,7 @@ class ConditionEvaluator { if (this.applicationContext != null) { return this.applicationContext; } - if (getRegistry() != null && getRegistry() instanceof ApplicationContext) { + if (getRegistry() instanceof ApplicationContext) { return (ApplicationContext) getRegistry(); } return null; diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Profile.java b/spring-context/src/main/java/org/springframework/context/annotation/Profile.java index 27900952cdc..7489eb99d3b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Profile.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Profile.java @@ -45,11 +45,11 @@ import org.springframework.core.env.ConfigurableEnvironment; * *

If a {@code @Configuration} class is marked with {@code @Profile}, all of the * {@code @Bean} methods and {@link Import @Import} annotations associated with that class - * will be bypassed unless one or more the specified profiles are active. This is very + * will be bypassed unless one or more of the specified profiles are active. This is very * similar to the behavior in Spring XML: if the {@code profile} attribute of the * {@code beans} element is supplied e.g., {@code }, the * {@code beans} element will not be parsed unless profiles 'p1' and/or 'p2' have been - * activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked + * activated. Likewise, if a {@code @Component} or {@code @Configuration} class is marked * with {@code @Profile({"p1", "p2"})}, that class will not be registered/processed unless * profiles 'p1' and/or 'p2' have been activated. * @@ -74,7 +74,7 @@ import org.springframework.core.env.ConfigurableEnvironment; * @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME */ @Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD }) +@Target({ElementType.TYPE, ElementType.METHOD}) @Conditional(ProfileCondition.class) public @interface Profile { diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index 593cc07461e..b50b875872c 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -746,7 +746,7 @@ public abstract class ClassUtils { /** * Return a public static method of a class. * @param methodName the static method name - * @param clazz the class which defines the method + * @param clazz the class which defines the method * @param args the parameter types to the method * @return the static method, or {@code null} if no static method was found * @throws IllegalArgumentException if the method name is blank or the clazz is null