Polishing
This commit is contained in:
@@ -58,7 +58,6 @@ public class AnnotatedElementUtils {
|
|||||||
|
|
||||||
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationType) {
|
public static boolean hasMetaAnnotationTypes(AnnotatedElement element, String annotationType) {
|
||||||
return Boolean.TRUE.equals(process(element, annotationType, false, new Processor<Boolean>() {
|
return Boolean.TRUE.equals(process(element, annotationType, false, new Processor<Boolean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean process(Annotation annotation, int metaDepth) {
|
public Boolean process(Annotation annotation, int metaDepth) {
|
||||||
if (metaDepth > 0) {
|
if (metaDepth > 0) {
|
||||||
@@ -66,7 +65,6 @@ public class AnnotatedElementUtils {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcess(Annotation annotation, Boolean result) {
|
public void postProcess(Annotation annotation, Boolean result) {
|
||||||
}
|
}
|
||||||
@@ -75,12 +73,10 @@ public class AnnotatedElementUtils {
|
|||||||
|
|
||||||
public static boolean isAnnotated(AnnotatedElement element, String annotationType) {
|
public static boolean isAnnotated(AnnotatedElement element, String annotationType) {
|
||||||
return Boolean.TRUE.equals(process(element, annotationType, false, new Processor<Boolean>() {
|
return Boolean.TRUE.equals(process(element, annotationType, false, new Processor<Boolean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean process(Annotation annotation, int metaDepth) {
|
public Boolean process(Annotation annotation, int metaDepth) {
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcess(Annotation annotation, Boolean result) {
|
public void postProcess(Annotation annotation, Boolean result) {
|
||||||
}
|
}
|
||||||
@@ -95,12 +91,10 @@ public class AnnotatedElementUtils {
|
|||||||
final boolean classValuesAsString, final boolean nestedAnnotationsAsMap) {
|
final boolean classValuesAsString, final boolean nestedAnnotationsAsMap) {
|
||||||
|
|
||||||
return process(element, annotationType, false, new Processor<AnnotationAttributes>() {
|
return process(element, annotationType, false, new Processor<AnnotationAttributes>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnnotationAttributes process(Annotation annotation, int metaDepth) {
|
public AnnotationAttributes process(Annotation annotation, int metaDepth) {
|
||||||
return AnnotationUtils.getAnnotationAttributes(annotation, classValuesAsString, nestedAnnotationsAsMap);
|
return AnnotationUtils.getAnnotationAttributes(annotation, classValuesAsString, nestedAnnotationsAsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcess(Annotation annotation, AnnotationAttributes result) {
|
public void postProcess(Annotation annotation, AnnotationAttributes result) {
|
||||||
for (String key : result.keySet()) {
|
for (String key : result.keySet()) {
|
||||||
@@ -125,7 +119,6 @@ public class AnnotatedElementUtils {
|
|||||||
|
|
||||||
final MultiValueMap<String, Object> attributes = new LinkedMultiValueMap<String, Object>();
|
final MultiValueMap<String, Object> attributes = new LinkedMultiValueMap<String, Object>();
|
||||||
process(element, annotationType, false, new Processor<Void>() {
|
process(element, annotationType, false, new Processor<Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void process(Annotation annotation, int metaDepth) {
|
public Void process(Annotation annotation, int metaDepth) {
|
||||||
if (annotation.annotationType().getName().equals(annotationType)) {
|
if (annotation.annotationType().getName().equals(annotationType)) {
|
||||||
@@ -136,7 +129,6 @@ public class AnnotatedElementUtils {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcess(Annotation annotation, Void result) {
|
public void postProcess(Annotation annotation, Void result) {
|
||||||
for (String key : attributes.keySet()) {
|
for (String key : attributes.keySet()) {
|
||||||
@@ -199,8 +191,8 @@ public class AnnotatedElementUtils {
|
|||||||
Processor<T> processor, Set<AnnotatedElement> visited, int metaDepth) {
|
Processor<T> processor, Set<AnnotatedElement> visited, int metaDepth) {
|
||||||
|
|
||||||
if (visited.add(element)) {
|
if (visited.add(element)) {
|
||||||
Annotation[] annotations = (traverseClassHierarchy ? element.getDeclaredAnnotations()
|
Annotation[] annotations =
|
||||||
: element.getAnnotations());
|
(traverseClassHierarchy ? element.getDeclaredAnnotations() : element.getAnnotations());
|
||||||
for (Annotation annotation : annotations) {
|
for (Annotation annotation : annotations) {
|
||||||
if (annotation.annotationType().getName().equals(annotationType) || metaDepth > 0) {
|
if (annotation.annotationType().getName().equals(annotationType) || metaDepth > 0) {
|
||||||
T result = processor.process(annotation, metaDepth);
|
T result = processor.process(annotation, metaDepth);
|
||||||
@@ -228,7 +220,7 @@ public class AnnotatedElementUtils {
|
|||||||
if (traverseClassHierarchy && element instanceof Class) {
|
if (traverseClassHierarchy && element instanceof Class) {
|
||||||
Class<?> superclass = ((Class<?>) element).getSuperclass();
|
Class<?> superclass = ((Class<?>) element).getSuperclass();
|
||||||
if (superclass != null && !superclass.equals(Object.class)) {
|
if (superclass != null && !superclass.equals(Object.class)) {
|
||||||
T result = doProcess(superclass, annotationType, traverseClassHierarchy, processor, visited,
|
T result = doProcess(superclass, annotationType, true, processor, visited,
|
||||||
metaDepth);
|
metaDepth);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -137,14 +137,14 @@ public abstract class AnnotationUtils {
|
|||||||
* @param containerAnnotationType the class of the container that holds the annotations
|
* @param containerAnnotationType the class of the container that holds the annotations
|
||||||
* @param annotationType the annotation class to look for
|
* @param annotationType the annotation class to look for
|
||||||
* @return the annotations found
|
* @return the annotations found
|
||||||
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
||||||
*/
|
*/
|
||||||
public static <A extends Annotation> Set<A> getRepeatableAnnotation(Method method,
|
public static <A extends Annotation> Set<A> getRepeatableAnnotation(Method method,
|
||||||
Class<? extends Annotation> containerAnnotationType, Class<A> annotationType) {
|
Class<? extends Annotation> containerAnnotationType, Class<A> annotationType) {
|
||||||
|
|
||||||
Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
return getRepeatableAnnotation((AnnotatedElement) resolvedMethod,
|
return getRepeatableAnnotation((AnnotatedElement) resolvedMethod, containerAnnotationType, annotationType);
|
||||||
containerAnnotationType, annotationType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,11 +156,12 @@ public abstract class AnnotationUtils {
|
|||||||
* @param containerAnnotationType the class of the container that holds the annotations
|
* @param containerAnnotationType the class of the container that holds the annotations
|
||||||
* @param annotationType the annotation class to look for
|
* @param annotationType the annotation class to look for
|
||||||
* @return the annotations found
|
* @return the annotations found
|
||||||
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
* @see org.springframework.core.BridgeMethodResolver#findBridgedMethod(Method)
|
||||||
*/
|
*/
|
||||||
public static <A extends Annotation> Set<A> getRepeatableAnnotation(AnnotatedElement annotatedElement,
|
public static <A extends Annotation> Set<A> getRepeatableAnnotation(AnnotatedElement annotatedElement,
|
||||||
Class<? extends Annotation> containerAnnotationType, Class<A> annotationType) {
|
Class<? extends Annotation> containerAnnotationType, Class<A> annotationType) {
|
||||||
|
|
||||||
if (annotatedElement.getAnnotations().length == 0) {
|
if (annotatedElement.getAnnotations().length == 0) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
@@ -507,14 +508,14 @@ public abstract class AnnotationUtils {
|
|||||||
}
|
}
|
||||||
if (nestedAnnotationsAsMap && value instanceof Annotation) {
|
if (nestedAnnotationsAsMap && value instanceof Annotation) {
|
||||||
attrs.put(method.getName(),
|
attrs.put(method.getName(),
|
||||||
getAnnotationAttributes((Annotation) value, classValuesAsString, nestedAnnotationsAsMap));
|
getAnnotationAttributes((Annotation) value, classValuesAsString, true));
|
||||||
}
|
}
|
||||||
else if (nestedAnnotationsAsMap && value instanceof Annotation[]) {
|
else if (nestedAnnotationsAsMap && value instanceof Annotation[]) {
|
||||||
Annotation[] realAnnotations = (Annotation[]) value;
|
Annotation[] realAnnotations = (Annotation[]) value;
|
||||||
AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
|
AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
|
||||||
for (int i = 0; i < realAnnotations.length; i++) {
|
for (int i = 0; i < realAnnotations.length; i++) {
|
||||||
mappedAnnotations[i] = getAnnotationAttributes(
|
mappedAnnotations[i] = getAnnotationAttributes(
|
||||||
realAnnotations[i], classValuesAsString, nestedAnnotationsAsMap);
|
realAnnotations[i], classValuesAsString, true);
|
||||||
}
|
}
|
||||||
attrs.put(method.getName(), mappedAnnotations);
|
attrs.put(method.getName(), mappedAnnotations);
|
||||||
}
|
}
|
||||||
@@ -550,7 +551,7 @@ public abstract class AnnotationUtils {
|
|||||||
*/
|
*/
|
||||||
public static Object getValue(Annotation annotation, String attributeName) {
|
public static Object getValue(Annotation annotation, String attributeName) {
|
||||||
try {
|
try {
|
||||||
Method method = annotation.annotationType().getDeclaredMethod(attributeName, new Class<?>[0]);
|
Method method = annotation.annotationType().getDeclaredMethod(attributeName);
|
||||||
ReflectionUtils.makeAccessible(method);
|
ReflectionUtils.makeAccessible(method);
|
||||||
return method.invoke(annotation);
|
return method.invoke(annotation);
|
||||||
}
|
}
|
||||||
@@ -601,8 +602,7 @@ public abstract class AnnotationUtils {
|
|||||||
*/
|
*/
|
||||||
public static Object getDefaultValue(Class<? extends Annotation> annotationType, String attributeName) {
|
public static Object getDefaultValue(Class<? extends Annotation> annotationType, String attributeName) {
|
||||||
try {
|
try {
|
||||||
Method method = annotationType.getDeclaredMethod(attributeName, new Class<?>[0]);
|
return annotationType.getDeclaredMethod(attributeName).getDefaultValue();
|
||||||
return method.getDefaultValue();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
return null;
|
return null;
|
||||||
@@ -620,14 +620,11 @@ public abstract class AnnotationUtils {
|
|||||||
|
|
||||||
private final Set<A> result = new LinkedHashSet<A>();
|
private final Set<A> result = new LinkedHashSet<A>();
|
||||||
|
|
||||||
|
public AnnotationCollector(Class<? extends Annotation> containerAnnotationType, Class<A> annotationType) {
|
||||||
public AnnotationCollector(Class<? extends Annotation> containerAnnotationType,
|
|
||||||
Class<A> annotationType) {
|
|
||||||
this.containerAnnotationType = containerAnnotationType;
|
this.containerAnnotationType = containerAnnotationType;
|
||||||
this.annotationType = annotationType;
|
this.annotationType = annotationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<A> getResult(AnnotatedElement element) {
|
public Set<A> getResult(AnnotatedElement element) {
|
||||||
process(element);
|
process(element);
|
||||||
return Collections.unmodifiableSet(this.result);
|
return Collections.unmodifiableSet(this.result);
|
||||||
@@ -662,6 +659,6 @@ public abstract class AnnotationUtils {
|
|||||||
+ this.containerAnnotationType.getName(), ex);
|
+ this.containerAnnotationType.getName(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,8 +119,8 @@ public class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnnotationAttributes getAnnotationAttributes(String annotationType, boolean classValuesAsString) {
|
public AnnotationAttributes getAnnotationAttributes(String annotationType, boolean classValuesAsString) {
|
||||||
AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes(this.attributesMap,
|
AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes(
|
||||||
annotationType);
|
this.attributesMap, annotationType);
|
||||||
return AnnotationReadingVisitorUtils.convertClassValues(this.classLoader, raw, classValuesAsString);
|
return AnnotationReadingVisitorUtils.convertClassValues(this.classLoader, raw, classValuesAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
@@ -59,12 +59,12 @@ public class AssignableTypeFilter extends AbstractTypeHierarchyTraversingFilter
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (Object.class.getName().equals(typeName)) {
|
else if (Object.class.getName().equals(typeName)) {
|
||||||
return Boolean.FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
else if (typeName.startsWith("java.")) {
|
else if (typeName.startsWith("java.")) {
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = getClass().getClassLoader().loadClass(typeName);
|
Class<?> clazz = getClass().getClassLoader().loadClass(typeName);
|
||||||
return Boolean.valueOf(this.targetType.isAssignableFrom(clazz));
|
return this.targetType.isAssignableFrom(clazz);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
// Class not found - can't determine a match that way.
|
// Class not found - can't determine a match that way.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
@@ -287,7 +287,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|||||||
* method is <b>not</b> symmetric.
|
* method is <b>not</b> symmetric.
|
||||||
* @param other the reference media type with which to compare
|
* @param other the reference media type with which to compare
|
||||||
* @return {@code true} if this media type includes the given media type;
|
* @return {@code true} if this media type includes the given media type;
|
||||||
* {@code false} otherwise
|
* {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
public boolean includes(MimeType other) {
|
public boolean includes(MimeType other) {
|
||||||
if (other == null) {
|
if (other == null) {
|
||||||
@@ -424,7 +424,8 @@ public class MimeType implements Comparable<MimeType>, Serializable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MimeType otherType = (MimeType) other;
|
MimeType otherType = (MimeType) other;
|
||||||
return (this.type.equalsIgnoreCase(otherType.type) && this.subtype.equalsIgnoreCase(otherType.subtype) &&
|
return (this.type.equalsIgnoreCase(otherType.type) &&
|
||||||
|
this.subtype.equalsIgnoreCase(otherType.subtype) &&
|
||||||
this.parameters.equals(otherType.parameters));
|
this.parameters.equals(otherType.parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user