Browse Source

Polishing

This commit removes unnecessary not-null checks for annotation
attribute alias names.
pull/867/head
Sam Brannen 9 years ago
parent
commit
a066143a5b
  1. 36
      spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java
  2. 12
      spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java

36
spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java

@ -91,25 +91,23 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor<S> implements Anno @@ -91,25 +91,23 @@ abstract class AbstractAliasAwareAnnotationAttributeExtractor<S> implements Anno
if (aliasNames != null) {
final Object defaultValue = AnnotationUtils.getDefaultValue(getAnnotationType(), attributeName);
for (String aliasName : aliasNames) {
if (aliasName != null) {
Object aliasValue = getRawAttributeValue(aliasName);
if (!ObjectUtils.nullSafeEquals(attributeValue, aliasValue) &&
!ObjectUtils.nullSafeEquals(attributeValue, defaultValue) &&
!ObjectUtils.nullSafeEquals(aliasValue, defaultValue)) {
String elementName = (getAnnotatedElement() != null ? getAnnotatedElement().toString() : "unknown element");
throw new AnnotationConfigurationException(String.format(
"In annotation [%s] declared on %s and synthesized from [%s], attribute '%s' and its " +
"alias '%s' are present with values of [%s] and [%s], but only one is permitted.",
getAnnotationType().getName(), elementName, getSource(), attributeName, aliasName,
ObjectUtils.nullSafeToString(attributeValue), ObjectUtils.nullSafeToString(aliasValue)));
}
// If the user didn't declare the annotation with an explicit value,
// use the value of the alias instead.
if (ObjectUtils.nullSafeEquals(attributeValue, defaultValue)) {
attributeValue = aliasValue;
}
Object aliasValue = getRawAttributeValue(aliasName);
if (!ObjectUtils.nullSafeEquals(attributeValue, aliasValue) &&
!ObjectUtils.nullSafeEquals(attributeValue, defaultValue) &&
!ObjectUtils.nullSafeEquals(aliasValue, defaultValue)) {
String elementName = (getAnnotatedElement() != null ? getAnnotatedElement().toString() : "unknown element");
throw new AnnotationConfigurationException(String.format(
"In annotation [%s] declared on %s and synthesized from [%s], attribute '%s' and its " +
"alias '%s' are present with values of [%s] and [%s], but only one is permitted.",
getAnnotationType().getName(), elementName, getSource(), attributeName, aliasName,
ObjectUtils.nullSafeToString(attributeValue), ObjectUtils.nullSafeToString(aliasValue)));
}
// If the user didn't declare the annotation with an explicit value,
// use the value of the alias instead.
if (ObjectUtils.nullSafeEquals(attributeValue, defaultValue)) {
attributeValue = aliasValue;
}
}
}

12
spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java

@ -99,13 +99,11 @@ class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttrib @@ -99,13 +99,11 @@ class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttrib
List<String> aliasNames = attributeAliasMap.get(attributeName);
if (aliasNames != null) {
for (String aliasName : aliasNames) {
if (aliasName != null) {
Object aliasValue = attributes.get(aliasName);
if (aliasValue != null) {
attributeValue = aliasValue;
attributes.put(attributeName, attributeValue);
break;
}
Object aliasValue = attributes.get(aliasName);
if (aliasValue != null) {
attributeValue = aliasValue;
attributes.put(attributeName, attributeValue);
break;
}
}
}

Loading…
Cancel
Save