@@ -215,8 +215,9 @@ public static TypeDescriptor forObject(Object source) {
215
215
/**
216
216
* The type of the backing class, method parameter, field, or property described by this TypeDescriptor.
217
217
* Returns primitive types as-is.
218
- * See {@link #getObjectType()} for a variation of this operation that resolves primitive types to their corresponding Object types if necessary.
219
- * @return the type, or <code>null</code> if this is {@link TypeDescriptor#NULL}
218
+ * <p>See {@link #getObjectType()} for a variation of this operation that resolves primitive types
219
+ * to their corresponding Object types if necessary.
220
+ * @return the type, or <code>null</code>
220
221
* @see #getObjectType()
221
222
*/
222
223
public Class <?> getType () {
@@ -225,20 +226,21 @@ public Class<?> getType() {
225
226
226
227
/**
227
228
* Variation of {@link #getType()} that accounts for a primitive type by returning its object wrapper type.
228
- * This is useful for conversion service implementations that wish to normalize to object-based types and not work with primitive types directly.
229
+ * <p>This is useful for conversion service implementations that wish to normalize to object-based types
230
+ * and not work with primitive types directly.
229
231
*/
230
232
public Class <?> getObjectType () {
231
233
return ClassUtils .resolvePrimitiveIfNecessary (getType ());
232
234
}
233
235
234
236
/**
235
237
* Narrows this {@link TypeDescriptor} by setting its type to the class of the provided value.
236
- * If the value is null, no narrowing is performed and this TypeDescriptor is returned unchanged.
237
- * Designed to be called by binding frameworks when they read property, field, or method return values.
238
+ * If the value is <code> null</code> , no narrowing is performed and this TypeDescriptor is returned unchanged.
239
+ * <p> Designed to be called by binding frameworks when they read property, field, or method return values.
238
240
* Allows such frameworks to narrow a TypeDescriptor built from a declared property, field, or method return value type.
239
- * For example, a field declared as java.lang.Object would be narrowed to java.util.HashMap if it was set to a java.util.HashMap value.
240
- * The narrowed TypeDescriptor can then be used to convert the HashMap to some other type.
241
- * Annotation and nested type context is preserved by the narrowed copy.
241
+ * For example, a field declared as <code> java.lang.Object</code> would be narrowed to <code> java.util.HashMap</code>
242
+ * if it was set to a <code>java.util.HashMap</code> value. The narrowed TypeDescriptor can then be used to convert
243
+ * the HashMap to some other type. Annotation and nested type context is preserved by the narrowed copy.
242
244
* @param value the value to use for narrowing this type descriptor
243
245
* @return this TypeDescriptor narrowed (returns a copy with its type updated to the class of the provided value)
244
246
*/
@@ -302,15 +304,21 @@ public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
302
304
/**
303
305
* Obtain the annotation associated with this type descriptor of the specified type.
304
306
* @param annotationType the annotation type
305
- * @return the annotation, or null if no such annotation exists on this type descriptor
307
+ * @return the annotation, or <code> null</code> if no such annotation exists on this type descriptor
306
308
*/
307
309
@ SuppressWarnings ("unchecked" )
308
310
public <T extends Annotation > T getAnnotation (Class <T > annotationType ) {
309
- for (Annotation annotation : getAnnotations () ) {
311
+ for (Annotation annotation : this . annotations ) {
310
312
if (annotation .annotationType ().equals (annotationType )) {
311
313
return (T ) annotation ;
312
314
}
313
315
}
316
+ for (Annotation metaAnn : this .annotations ) {
317
+ T ann = metaAnn .annotationType ().getAnnotation (annotationType );
318
+ if (ann != null ) {
319
+ return ann ;
320
+ }
321
+ }
314
322
return null ;
315
323
}
316
324
@@ -573,24 +581,23 @@ public boolean equals(Object obj) {
573
581
return false ;
574
582
}
575
583
TypeDescriptor other = (TypeDescriptor ) obj ;
576
- if (!ObjectUtils .nullSafeEquals (getType () , other .getType () )) {
584
+ if (!ObjectUtils .nullSafeEquals (this . type , other .type )) {
577
585
return false ;
578
586
}
579
- Annotation [] annotations = getAnnotations ();
580
- if (annotations .length != other .getAnnotations ().length ) {
587
+ if (this .annotations .length != other .annotations .length ) {
581
588
return false ;
582
589
}
583
- for (Annotation ann : annotations ) {
590
+ for (Annotation ann : this . annotations ) {
584
591
if (other .getAnnotation (ann .annotationType ()) == null ) {
585
592
return false ;
586
593
}
587
594
}
588
595
if (isCollection () || isArray ()) {
589
- return ObjectUtils .nullSafeEquals (getElementTypeDescriptor () , other .getElementTypeDescriptor () );
596
+ return ObjectUtils .nullSafeEquals (this . elementTypeDescriptor , other .elementTypeDescriptor );
590
597
}
591
598
else if (isMap ()) {
592
- return ObjectUtils .nullSafeEquals (getMapKeyTypeDescriptor () , other .getMapKeyTypeDescriptor () ) &&
593
- ObjectUtils .nullSafeEquals (getMapValueTypeDescriptor () , other .getMapValueTypeDescriptor () );
599
+ return ObjectUtils .nullSafeEquals (this . mapKeyTypeDescriptor , other .mapKeyTypeDescriptor ) &&
600
+ ObjectUtils .nullSafeEquals (this . mapValueTypeDescriptor , other .mapValueTypeDescriptor );
594
601
}
595
602
else {
596
603
return true ;
@@ -603,17 +610,16 @@ public int hashCode() {
603
610
604
611
public String toString () {
605
612
StringBuilder builder = new StringBuilder ();
606
- Annotation [] anns = getAnnotations ();
607
- for (Annotation ann : anns ) {
613
+ for (Annotation ann : this .annotations ) {
608
614
builder .append ("@" ).append (ann .annotationType ().getName ()).append (' ' );
609
615
}
610
616
builder .append (ClassUtils .getQualifiedName (getType ()));
611
617
if (isMap ()) {
612
- builder .append ("<" ).append (wildcard (getMapKeyTypeDescriptor () ));
613
- builder .append (", " ).append (wildcard (getMapValueTypeDescriptor () )).append (">" );
618
+ builder .append ("<" ).append (wildcard (this . mapKeyTypeDescriptor ));
619
+ builder .append (", " ).append (wildcard (this . mapValueTypeDescriptor )).append (">" );
614
620
}
615
621
else if (isCollection ()) {
616
- builder .append ("<" ).append (wildcard (getElementTypeDescriptor () )).append (">" );
622
+ builder .append ("<" ).append (wildcard (this . elementTypeDescriptor )).append (">" );
617
623
}
618
624
return builder .toString ();
619
625
}
0 commit comments