Polishing

This commit is contained in:
Sam Brannen
2015-05-22 21:37:50 +02:00
parent bbd3f902d0
commit 2e4dabb349
4 changed files with 18 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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> {
*/
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> {
public AnnotationAttributes(int initialCapacity) {
super(initialCapacity);
this.annotationType = null;
this.displayName = "unknown";
}
/**
@@ -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> {
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> {
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;

View File

@@ -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 = "<SPRING DEFAULT VALUE PLACEHOLDER>";