Browse Source

Polishing

pull/808/head
Sam Brannen 11 years ago
parent
commit
2e4dabb349
  1. 3
      spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java
  2. 12
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java
  3. 7
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
  4. 3
      spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java

3
spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java

@ -88,8 +88,9 @@ import org.springframework.util.StringUtils;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
* @since 4.0 * @since 4.0
* @see AnnotationUtils * @see AliasFor
* @see AnnotationAttributes * @see AnnotationAttributes
* @see AnnotationUtils
* @see BridgeMethodResolver * @see BridgeMethodResolver
*/ */
public class AnnotatedElementUtils { public class AnnotatedElementUtils {

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

@ -44,12 +44,15 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
private final Class<? extends Annotation> annotationType; private final Class<? extends Annotation> annotationType;
private final String displayName;
/** /**
* Create a new, empty {@link AnnotationAttributes} instance. * Create a new, empty {@link AnnotationAttributes} instance.
*/ */
public AnnotationAttributes() { public AnnotationAttributes() {
this.annotationType = null; this.annotationType = null;
this.displayName = "unknown";
} }
/** /**
@ -61,6 +64,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
*/ */
public AnnotationAttributes(Class<? extends Annotation> annotationType) { public AnnotationAttributes(Class<? extends Annotation> annotationType) {
this.annotationType = annotationType; this.annotationType = annotationType;
this.displayName = (annotationType() != null ? annotationType.getName() : "unknown");
} }
/** /**
@ -71,6 +75,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
public AnnotationAttributes(int initialCapacity) { public AnnotationAttributes(int initialCapacity) {
super(initialCapacity); super(initialCapacity);
this.annotationType = null; this.annotationType = null;
this.displayName = "unknown";
} }
/** /**
@ -82,6 +87,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
public AnnotationAttributes(Map<String, Object> map) { public AnnotationAttributes(Map<String, Object> map) {
super(map); super(map);
this.annotationType = null; this.annotationType = null;
this.displayName = "unknown";
} }
/** /**
@ -139,8 +145,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
Object value = get(attributeName); Object value = get(attributeName);
if (value == null) { if (value == null) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Attribute '%s' not found in attributes for annotation [%s]", "Attribute '%s' not found in attributes for annotation [%s]", attributeName, this.displayName));
attributeName, (annotationType() != null ? annotationType.getName() : "unknown")));
} }
if (!expectedType.isInstance(value)) { if (!expectedType.isInstance(value)) {
if (expectedType.isArray() && expectedType.getComponentType().isInstance(value)) { if (expectedType.isArray() && expectedType.getComponentType().isInstance(value)) {
@ -151,8 +156,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
else { else {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Attribute '%s' is of type [%s], but [%s] was expected in attributes for annotation [%s]", "Attribute '%s' is of type [%s], but [%s] was expected in attributes for annotation [%s]",
attributeName, value.getClass().getSimpleName(), expectedType.getSimpleName(), attributeName, value.getClass().getSimpleName(), expectedType.getSimpleName(), this.displayName));
(annotationType() != null ? annotationType.getName() : "unknown")));
} }
} }
return (T) value; return (T) value;

7
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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.core.BridgeMethodResolver; import org.springframework.core.BridgeMethodResolver;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -86,6 +87,10 @@ import org.springframework.util.StringUtils;
* @author Chris Beams * @author Chris Beams
* @author Phillip Webb * @author Phillip Webb
* @since 2.0 * @since 2.0
* @see AliasFor
* @see AnnotationAttributes
* @see AnnotatedElementUtils
* @see BridgeMethodResolver
* @see java.lang.reflect.AnnotatedElement#getAnnotations() * @see java.lang.reflect.AnnotatedElement#getAnnotations()
* @see java.lang.reflect.AnnotatedElement#getAnnotation(Class) * @see java.lang.reflect.AnnotatedElement#getAnnotation(Class)
* @see java.lang.reflect.AnnotatedElement#getDeclaredAnnotations() * @see java.lang.reflect.AnnotatedElement#getDeclaredAnnotations()
@ -98,7 +103,7 @@ public abstract class AnnotationUtils {
public static final String VALUE = "value"; 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. * placeholder for an attribute's declared default value.
*/ */
public static final Object DEFAULT_VALUE_PLACEHOLDER = "<SPRING DEFAULT VALUE PLACEHOLDER>"; public static final Object DEFAULT_VALUE_PLACEHOLDER = "<SPRING DEFAULT VALUE PLACEHOLDER>";

3
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.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap; 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) @Retention(RetentionPolicy.RUNTIME)
@interface ContextConfig { @interface ContextConfig {

Loading…
Cancel
Save