[Checkers] Note about asDefined method
Mahmood Ali
mahmood at MIT.EDU
Tue Sep 16 15:33:50 EDT 2008
Hi Artemus,
The method sounds good for your purposes.
However, it would fail for cases where type variables extend each
other, like in:
class MyClass<E, V extends E> { V field; }
You can use a while-loop instead of the first 'if' or call the method
recursively.
Regards,
Mahmood
On Sep 16, 2008, at 1:22 PM, Artemus Harper wrote:
> /**
> * Gets the a type as its defined. For example if type was @Anno
> String s = "hello". This would return the annotations as declared on
> the String class.
> * Primitives and arrays are returned without any annotations.
> * @param type
> * @param factory
> * @return The type as its defined
> */
> public static AnnotatedTypeMirror asDefined(AnnotatedTypeMirror
> type, AnnotatedTypeFactory factory)
> {
> if(type instanceof AnnotatedTypeVariable)
> {
> type = ((AnnotatedTypeVariable)type).getUpperBound();
> }
> if(type instanceof AnnotatedDeclaredType)
> return
> factory
> .getAnnotatedType
> (((AnnotatedDeclaredType)type).getUnderlyingType().asElement());
> else if(type instanceof AnnotatedPrimitiveType || type
> instanceof AnnotatedArrayType)
> return type.getCopy(false);
> else
> throw new IllegalArgumentException("type is not
> assignable");
> }
More information about the checkers
mailing list