Improve annotation methods in TypeDescriptor
- Use generic typing for getAnnotation() - Add hasAnnoation() method - Update existing code and tests to make use of changes Issue: SPR-9744
This commit is contained in:
@@ -271,15 +271,25 @@ public class TypeDescriptor {
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this type descriptor has the specified annotation.
|
||||
* @param annotationType the annotation type
|
||||
* @return <tt>true</tt> if the annotation is present
|
||||
*/
|
||||
public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
|
||||
return getAnnotation(annotationType) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the annotation associated with this type descriptor of the specified type.
|
||||
* @param annotationType the annotation type
|
||||
* @return the annotation, or null if no such annotation exists on this type descriptor
|
||||
*/
|
||||
public Annotation getAnnotation(Class<? extends Annotation> annotationType) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
|
||||
for (Annotation annotation : getAnnotations()) {
|
||||
if (annotation.annotationType().equals(annotationType)) {
|
||||
return annotation;
|
||||
return (T) annotation;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user