Polish annotation utils
This commit is contained in:
parent
53c9584025
commit
177f4ec3a7
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.core.annotation;
|
package org.springframework.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.AnnotatedElement;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
|
||||||
|
|
||||||
private static final String UNKNOWN = "unknown";
|
private static final String UNKNOWN = "unknown";
|
||||||
|
|
||||||
private Class<? extends Annotation> annotationType;
|
private final Class<? extends Annotation> annotationType;
|
||||||
|
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
|
|
||||||
|
@ -95,18 +95,23 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
|
||||||
* or {@code null} to just store the annotation type name
|
* or {@code null} to just store the annotation type name
|
||||||
* @since 4.3.2
|
* @since 4.3.2
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public AnnotationAttributes(String annotationType, ClassLoader classLoader) {
|
public AnnotationAttributes(String annotationType, ClassLoader classLoader) {
|
||||||
Assert.notNull(annotationType, "'annotationType' must not be null");
|
Assert.notNull(annotationType, "'annotationType' must not be null");
|
||||||
|
this.annotationType = getAnnotationType(annotationType, classLoader);
|
||||||
|
this.displayName = annotationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static Class<? extends Annotation> getAnnotationType(String annotationType, ClassLoader classLoader) {
|
||||||
if (classLoader != null) {
|
if (classLoader != null) {
|
||||||
try {
|
try {
|
||||||
this.annotationType = (Class<? extends Annotation>) classLoader.loadClass(annotationType);
|
return (Class<? extends Annotation>) classLoader.loadClass(annotationType);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
// Annotation Class not resolvable
|
// Annotation Class not resolvable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.displayName = annotationType;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1129,11 +1129,10 @@ public abstract class AnnotationUtils {
|
||||||
// Only do defaults scanning for public annotations; we'd run into
|
// Only do defaults scanning for public annotations; we'd run into
|
||||||
// IllegalAccessExceptions otherwise, and we don't want to mess with
|
// IllegalAccessExceptions otherwise, and we don't want to mess with
|
||||||
// accessibility in a SecurityManager environment.
|
// accessibility in a SecurityManager environment.
|
||||||
Class<?> annotationType = attributes.annotationType();
|
Class<? extends Annotation> annotationType = attributes.annotationType();
|
||||||
if (annotationType != null && Modifier.isPublic(annotationType.getModifiers())) {
|
if (annotationType != null && Modifier.isPublic(annotationType.getModifiers())) {
|
||||||
// Check declared default values of attributes in the annotation type.
|
// Check declared default values of attributes in the annotation type.
|
||||||
Method[] annotationAttributes = annotationType.getMethods();
|
for (Method annotationAttribute : getAttributeMethods(annotationType)) {
|
||||||
for (Method annotationAttribute : annotationAttributes) {
|
|
||||||
String attributeName = annotationAttribute.getName();
|
String attributeName = annotationAttribute.getName();
|
||||||
Object defaultValue = annotationAttribute.getDefaultValue();
|
Object defaultValue = annotationAttribute.getDefaultValue();
|
||||||
if (defaultValue != null && !attributes.containsKey(attributeName)) {
|
if (defaultValue != null && !attributes.containsKey(attributeName)) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
Loading…
Reference in New Issue