Class identity comparisons wherever possible
Issue: SPR-12926
This commit is contained in:
parent
e8417ea6e1
commit
0524f3a474
|
@ -248,20 +248,17 @@ public class TypeDescriptor implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Obtain the annotation of the specified {@code annotationType} that is
|
||||
* on this type descriptor.
|
||||
* <p>As of Spring Framework 4.2, this method supports arbitrary levels
|
||||
* of meta-annotations.
|
||||
* Obtain the annotation of the specified {@code annotationType} that is on this type descriptor.
|
||||
* <p>As of Spring Framework 4.2, this method supports arbitrary levels of meta-annotations.
|
||||
* @param annotationType the annotation type
|
||||
* @return the annotation, or {@code null} if no such annotation exists on this type descriptor
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
|
||||
// Search in annotations that are "present" (i.e., locally declared or inherited)
|
||||
//
|
||||
// NOTE: this unfortunately favors inherited annotations over locally declared composed annotations.
|
||||
for (Annotation annotation : getAnnotations()) {
|
||||
if (annotation.annotationType().equals(annotationType)) {
|
||||
if (annotation.annotationType() == annotationType) {
|
||||
return (T) annotation;
|
||||
}
|
||||
}
|
||||
|
@ -471,7 +468,7 @@ public class TypeDescriptor implements Serializable {
|
|||
return false;
|
||||
}
|
||||
for (Annotation ann : getAnnotations()) {
|
||||
if (other.getAnnotation(ann.annotationType()) == null) {
|
||||
if (!other.hasAnnotation(ann.annotationType())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,23 +144,22 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
|
|||
return ClassUtils.getConstructorIfAvailable(targetClass, sourceClass);
|
||||
}
|
||||
|
||||
private static boolean hasToMethodOrFactoryMethodOrConstructor(Class<?> targetClass,
|
||||
Class<?> sourceClass) {
|
||||
private static boolean hasToMethodOrFactoryMethodOrConstructor(Class<?> targetClass, Class<?> sourceClass) {
|
||||
return (hasToMethod(targetClass, sourceClass) ||
|
||||
hasFactoryMethod(targetClass, sourceClass) ||
|
||||
hasFactoryConstructor(targetClass, sourceClass));
|
||||
}
|
||||
|
||||
static boolean hasToMethod(Class<?> targetClass, Class<?> sourceClass) {
|
||||
return getToMethod(targetClass, sourceClass) != null;
|
||||
return (getToMethod(targetClass, sourceClass) != null);
|
||||
}
|
||||
|
||||
static boolean hasFactoryMethod(Class<?> targetClass, Class<?> sourceClass) {
|
||||
return getFactoryMethod(targetClass, sourceClass) != null;
|
||||
return (getFactoryMethod(targetClass, sourceClass) != null);
|
||||
}
|
||||
|
||||
static boolean hasFactoryConstructor(Class<?> targetClass, Class<?> sourceClass) {
|
||||
return getFactoryConstructor(targetClass, sourceClass) != null;
|
||||
return (getFactoryConstructor(targetClass, sourceClass) != null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue