From 53dd88437e81f8ef3c95ed36671048c2a7d4738e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 15 Jul 2016 19:51:33 +0200 Subject: [PATCH] Delete dead code in AnnotationAttributes --- .../core/annotation/AnnotationAttributes.java | 96 ------------------- 1 file changed, 96 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index d4c74b3a74..e30ed5b767 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java @@ -17,15 +17,12 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Array; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** @@ -349,104 +346,11 @@ public class AnnotationAttributes extends LinkedHashMap { return (T) value; } - /** - * Get the value stored under the specified {@code attributeName} as an - * object of the {@code expectedType}, taking into account alias semantics - * defined via {@link AliasFor @AliasFor}. - *

If there is no value stored under the specified {@code attributeName} - * but the attribute has an alias declared via {@code @AliasFor}, the - * value of the alias will be returned. - * @param attributeName the name of the attribute to get; never - * {@code null} or empty - * @param annotationType the type of annotation represented by this - * {@code AnnotationAttributes} instance; never {@code null} - * @param annotationSource the source of the annotation represented by - * this {@code AnnotationAttributes} (e.g., the {@link AnnotatedElement}); - * or {@code null} if unknown - * @param expectedType the expected type; never {@code null} - * @return the value - * @throws IllegalArgumentException if the attribute and its alias do - * not exist or are not of the {@code expectedType} - * @throws AnnotationConfigurationException if the attribute and its - * alias are both present with different non-empty values - * @since 4.2 - * @see ObjectUtils#isEmpty(Object) - */ - private T getRequiredAttributeWithAlias(String attributeName, Class annotationType, - Object annotationSource, Class expectedType) { - - Assert.hasText(attributeName, "'attributeName' must not be null or empty"); - Assert.notNull(annotationType, "'annotationType' must not be null"); - Assert.notNull(expectedType, "'expectedType' must not be null"); - - T attributeValue = getAttribute(attributeName, expectedType); - - List aliasNames = AnnotationUtils.getAttributeAliasMap(annotationType).get(attributeName); - if (aliasNames != null) { - for (String aliasName : aliasNames) { - T aliasValue = getAttribute(aliasName, expectedType); - boolean attributeEmpty = ObjectUtils.isEmpty(attributeValue); - boolean aliasEmpty = ObjectUtils.isEmpty(aliasValue); - - if (!attributeEmpty && !aliasEmpty && !ObjectUtils.nullSafeEquals(attributeValue, aliasValue)) { - String elementName = (annotationSource == null ? "unknown element" : annotationSource.toString()); - String msg = String.format("In annotation [%s] declared on [%s], attribute [%s] and its " + - "alias [%s] are present with values of [%s] and [%s], but only one is permitted.", - annotationType.getName(), elementName, attributeName, aliasName, - ObjectUtils.nullSafeToString(attributeValue), ObjectUtils.nullSafeToString(aliasValue)); - throw new AnnotationConfigurationException(msg); - } - - // If we expect an array and the current tracked value is null but the - // current alias value is non-null, then replace the current null value - // with the non-null value (which may be an empty array). - if (expectedType.isArray() && attributeValue == null && aliasValue != null) { - attributeValue = aliasValue; - } - // Else: if we're not expecting an array, we can rely on the behavior of - // ObjectUtils.isEmpty(). - else if (attributeEmpty && !aliasEmpty) { - attributeValue = aliasValue; - } - } - assertAttributePresence(attributeName, aliasNames, attributeValue); - } - - return attributeValue; - } - - /** - * Get the value stored under the specified {@code attributeName}, - * ensuring that the value is of the {@code expectedType}. - * @param attributeName the name of the attribute to get; never - * {@code null} or empty - * @param expectedType the expected type; never {@code null} - * @return the value - * @throws IllegalArgumentException if the attribute is not of the - * expected type - * @see #getRequiredAttribute(String, Class) - */ - @SuppressWarnings("unchecked") - private T getAttribute(String attributeName, Class expectedType) { - Object value = get(attributeName); - if (value != null) { - assertNotException(attributeName, value); - assertAttributeType(attributeName, value, expectedType); - } - return (T) value; - } - private void assertAttributePresence(String attributeName, Object attributeValue) { Assert.notNull(attributeValue, () -> String.format("Attribute '%s' not found in attributes for annotation [%s]", attributeName, this.displayName)); } - private void assertAttributePresence(String attributeName, List aliases, Object attributeValue) { - Assert.notNull(attributeValue, () -> String.format( - "Neither attribute '%s' nor one of its aliases %s was found in attributes for annotation [%s]", - attributeName, aliases, this.displayName)); - } - private void assertNotException(String attributeName, Object attributeValue) { if (attributeValue instanceof Exception) { throw new IllegalArgumentException(String.format(