Browse Source

Polishing

pull/808/head
Sam Brannen 10 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; @@ -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 {

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

@ -44,12 +44,15 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> { @@ -44,12 +44,15 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
private final Class<? extends Annotation> 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<String, Object> { @@ -61,6 +64,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
*/
public AnnotationAttributes(Class<? extends Annotation> annotationType) {
this.annotationType = annotationType;
this.displayName = (annotationType() != null ? annotationType.getName() : "unknown");
}
/**
@ -71,6 +75,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> { @@ -71,6 +75,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
public AnnotationAttributes(int initialCapacity) {
super(initialCapacity);
this.annotationType = null;
this.displayName = "unknown";
}
/**
@ -82,6 +87,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> { @@ -82,6 +87,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
public AnnotationAttributes(Map<String, Object> map) {
super(map);
this.annotationType = null;
this.displayName = "unknown";
}
/**
@ -139,8 +145,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> { @@ -139,8 +145,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
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<String, Object> { @@ -151,8 +156,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
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;

7
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

@ -33,6 +33,7 @@ import java.util.Set; @@ -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; @@ -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 { @@ -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 = "<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; @@ -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 { @@ -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 {

Loading…
Cancel
Save