[Checkers] Note about asDefined method

Artemus Harper subanark at gmail.com
Tue Sep 16 17:13:58 EDT 2008


I don't think this will work for recursive types such as:
interface Invertable<From extends Invertable<To>,To extends
Invertable<From>> { From invert(); }

or more simply enumerations that are referenced as: Enum<MyEnum> someVal;

I think a simple getErased() is sufficient to combat this (although this
will get the annotation for Enum instead of MyEnum, but should not be a
problem since you can't invoke method from MyEnum if the type is declared
that way).

On Tue, Sep 16, 2008 at 12:33 PM, Mahmood Ali <mahmood at mit.edu> wrote:

> 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");
>>    }
>>
>


-- 
Artemus Harper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/mailman/private/checkers/attachments/20080916/1f628a4d/attachment.htm 


More information about the checkers mailing list