From 2e4dabb349a2d2604f436755c36dc9636c92af59 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 22 May 2015 21:37:50 +0200 Subject: [PATCH] Polishing --- .../core/annotation/AnnotatedElementUtils.java | 3 ++- .../core/annotation/AnnotationAttributes.java | 12 ++++++++---- .../core/annotation/AnnotationUtils.java | 7 ++++++- .../core/annotation/AnnotatedElementUtilsTests.java | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java index 26277312251..c56e72e779d 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java @@ -88,8 +88,9 @@ import org.springframework.util.StringUtils; * @author Juergen Hoeller * @author Sam Brannen * @since 4.0 - * @see AnnotationUtils + * @see AliasFor * @see AnnotationAttributes + * @see AnnotationUtils * @see BridgeMethodResolver */ public class AnnotatedElementUtils { 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 e3eab8da1ec..c4a44f57d6f 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 @@ -44,12 +44,15 @@ public class AnnotationAttributes extends LinkedHashMap { private final Class annotationType; + private final String displayName; + /** * Create a new, empty {@link AnnotationAttributes} instance. */ public AnnotationAttributes() { this.annotationType = null; + this.displayName = "unknown"; } /** @@ -61,6 +64,7 @@ public class AnnotationAttributes extends LinkedHashMap { */ public AnnotationAttributes(Class annotationType) { this.annotationType = annotationType; + this.displayName = (annotationType() != null ? annotationType.getName() : "unknown"); } /** @@ -71,6 +75,7 @@ public class AnnotationAttributes extends LinkedHashMap { public AnnotationAttributes(int initialCapacity) { super(initialCapacity); this.annotationType = null; + this.displayName = "unknown"; } /** @@ -82,6 +87,7 @@ public class AnnotationAttributes extends LinkedHashMap { public AnnotationAttributes(Map map) { super(map); this.annotationType = null; + this.displayName = "unknown"; } /** @@ -139,8 +145,7 @@ public class AnnotationAttributes extends LinkedHashMap { Object value = get(attributeName); if (value == null) { throw new IllegalArgumentException(String.format( - "Attribute '%s' not found in attributes for annotation [%s]", - attributeName, (annotationType() != null ? annotationType.getName() : "unknown"))); + "Attribute '%s' not found in attributes for annotation [%s]", attributeName, this.displayName)); } if (!expectedType.isInstance(value)) { if (expectedType.isArray() && expectedType.getComponentType().isInstance(value)) { @@ -151,8 +156,7 @@ public class AnnotationAttributes extends LinkedHashMap { else { throw new IllegalArgumentException(String.format( "Attribute '%s' is of type [%s], but [%s] was expected in attributes for annotation [%s]", - attributeName, value.getClass().getSimpleName(), expectedType.getSimpleName(), - (annotationType() != null ? annotationType.getName() : "unknown"))); + attributeName, value.getClass().getSimpleName(), expectedType.getSimpleName(), this.displayName)); } } return (T) value; diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 7c35d70ca4b..89d291a83d4 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -33,6 +33,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.BridgeMethodResolver; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -86,6 +87,10 @@ import org.springframework.util.StringUtils; * @author Chris Beams * @author Phillip Webb * @since 2.0 + * @see AliasFor + * @see AnnotationAttributes + * @see AnnotatedElementUtils + * @see BridgeMethodResolver * @see java.lang.reflect.AnnotatedElement#getAnnotations() * @see java.lang.reflect.AnnotatedElement#getAnnotation(Class) * @see java.lang.reflect.AnnotatedElement#getDeclaredAnnotations() @@ -98,7 +103,7 @@ public abstract class AnnotationUtils { public static final String VALUE = "value"; /** - * A object that can be stored in {@link AnnotationAttributes} as a + * An object that can be stored in {@link AnnotationAttributes} as a * placeholder for an attribute's declared default value. */ public static final Object DEFAULT_VALUE_PLACEHOLDER = ""; diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index 77ba824b5a3..305de6537cf 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -28,6 +28,7 @@ import java.util.stream.Collectors; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; + import org.springframework.stereotype.Component; import org.springframework.util.MultiValueMap; @@ -570,7 +571,7 @@ public class AnnotatedElementUtilsTests { } /** - * Mock of {@link org.springframework.test.context.ContextConfiguration}. + * Mock of {@code org.springframework.test.context.ContextConfiguration}. */ @Retention(RetentionPolicy.RUNTIME) @interface ContextConfig {