/** * Create a new type descriptor from a {@link ResolvableType}. * <p>This constructor is used internally and may also be used by subclasses * that support non-Java languages with extended type systems. It is public * as of 5.1.4 whereas it was protected before. * @param resolvableType the resolvable type * @param type the backing type (or {@code null} if it should get resolved) * @param annotations the type annotations * @since 4.0 */ public TypeDescriptor(ResolvableType resolvableType, @Nullable Class<?> type, @Nullable Annotation[] annotations) { this.resolvableType = resolvableType; this.type = (type != null ? type : resolvableType.toClass()); this.annotatedElement = new AnnotatedElementAdapter(annotations); }
@Override @Nullable @SuppressWarnings("unchecked") public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { for (Annotation annotation : getAnnotations()) { if (annotation.annotationType() == annotationClass) { return (T) annotation; } } return null; }
/** * 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 */ @Nullable public <T extends Annotation> T getAnnotation(Class<T> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return null; } return AnnotatedElementUtils.getMergedAnnotation(this.annotatedElement, annotationType); }
/** * Determine if this type descriptor has the specified annotation. * <p>As of Spring Framework 4.2, this method supports arbitrary levels * of meta-annotations. * @param annotationType the annotation type * @return <tt>true</tt> if the annotation is present */ public boolean hasAnnotation(Class<? extends Annotation> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return false; } return AnnotatedElementUtils.isAnnotated(this.annotatedElement, annotationType); }
/** * Create a new type descriptor from a {@link ResolvableType}. * <p>This constructor is used internally and may also be used by subclasses * that support non-Java languages with extended type systems. It is public * as of 5.1.4 whereas it was protected before. * @param resolvableType the resolvable type * @param type the backing type (or {@code null} if it should get resolved) * @param annotations the type annotations * @since 4.0 */ public TypeDescriptor(ResolvableType resolvableType, @Nullable Class<?> type, @Nullable Annotation[] annotations) { this.resolvableType = resolvableType; this.type = (type != null ? type : resolvableType.toClass()); this.annotatedElement = new AnnotatedElementAdapter(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 */ @Nullable public <T extends Annotation> T getAnnotation(Class<T> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return null; } return AnnotatedElementUtils.getMergedAnnotation(this.annotatedElement, annotationType); }
/** * Determine if this type descriptor has the specified annotation. * <p>As of Spring Framework 4.2, this method supports arbitrary levels * of meta-annotations. * @param annotationType the annotation type * @return <tt>true</tt> if the annotation is present */ public boolean hasAnnotation(Class<? extends Annotation> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return false; } return AnnotatedElementUtils.isAnnotated(this.annotatedElement, annotationType); }
/** * 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 */ @Nullable public <T extends Annotation> T getAnnotation(Class<T> annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. return null; } return AnnotatedElementUtils.getMergedAnnotation(this.annotatedElement, annotationType); }
/** * Create a new type descriptor from a {@link ResolvableType}. This protected * constructor is used internally and may also be used by subclasses that support * non-Java languages with extended type systems. * @param resolvableType the resolvable type * @param type the backing type (or {@code null} if it should get resolved) * @param annotations the type annotations * @since 4.0 */ protected TypeDescriptor(ResolvableType resolvableType, @Nullable Class<?> type, @Nullable Annotation[] annotations) { this.resolvableType = resolvableType; this.type = (type != null ? type : resolvableType.toClass()); this.annotatedElement = new AnnotatedElementAdapter(annotations); }
/** * Create a new type descriptor from a {@link MethodParameter}. * <p>Use this constructor when a source or target conversion point is a * constructor parameter, method parameter, or method return value. * @param methodParameter the method parameter */ public TypeDescriptor(MethodParameter methodParameter) { this.resolvableType = ResolvableType.forMethodParameter(methodParameter); this.type = this.resolvableType.resolve(methodParameter.getNestedParameterType()); this.annotatedElement = new AnnotatedElementAdapter(methodParameter.getParameterIndex() == -1 ? methodParameter.getMethodAnnotations() : methodParameter.getParameterAnnotations()); }
/** * Return the annotations associated with this type descriptor, if any. * @return the annotations, or an empty array if none */ public Annotation[] getAnnotations() { return this.annotatedElement.getAnnotations(); }
@Override public Annotation[] getDeclaredAnnotations() { return getAnnotations(); }
/** * Create a new type descriptor from a {@link Property}. * <p>Use this constructor when a source or target conversion point is a * property on a Java class. * @param property the property */ public TypeDescriptor(Property property) { Assert.notNull(property, "Property must not be null"); this.resolvableType = ResolvableType.forMethodParameter(property.getMethodParameter()); this.type = this.resolvableType.resolve(property.getType()); this.annotatedElement = new AnnotatedElementAdapter(property.getAnnotations()); }
@Override @Nullable @SuppressWarnings("unchecked") public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { for (Annotation annotation : getAnnotations()) { if (annotation.annotationType() == annotationClass) { return (T) annotation; } } return null; }
/** * Create a new type descriptor from a {@link Field}. * <p>Use this constructor when a source or target conversion point is a field. * @param field the field */ public TypeDescriptor(Field field) { this.resolvableType = ResolvableType.forField(field); this.type = this.resolvableType.resolve(field.getType()); this.annotatedElement = new AnnotatedElementAdapter(field.getAnnotations()); }
/** * Create a new type descriptor from a {@link Field}. * <p>Use this constructor when a source or target conversion point is a field. * @param field the field */ public TypeDescriptor(Field field) { this.resolvableType = ResolvableType.forField(field); this.type = this.resolvableType.resolve(field.getType()); this.annotatedElement = new AnnotatedElementAdapter(field.getAnnotations()); }
@Override @Nullable @SuppressWarnings("unchecked") public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { for (Annotation annotation : getAnnotations()) { if (annotation.annotationType() == annotationClass) { return (T) annotation; } } return null; }
/** * Return the annotations associated with this type descriptor, if any. * @return the annotations, or an empty array if none */ public Annotation[] getAnnotations() { return this.annotatedElement.getAnnotations(); }
/** * Create a new type descriptor from a {@link Property}. * <p>Use this constructor when a source or target conversion point is a * property on a Java class. * @param property the property */ public TypeDescriptor(Property property) { Assert.notNull(property, "Property must not be null"); this.resolvableType = ResolvableType.forMethodParameter(property.getMethodParameter()); this.type = this.resolvableType.resolve(property.getType()); this.annotatedElement = new AnnotatedElementAdapter(property.getAnnotations()); }
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { for (Annotation annotation : getAnnotations()) { if (annotation.annotationType() == annotationClass) { return true; } } return false; }