On the impl of AnnotatedType

Werner Dietl wdietl at gmail.com
Thu Jan 24 09:40:00 PST 2013


>> First, note that there are 3 types called AnnotatedType, so we need to be careful to distinguish them.
>>
>
> Well there should actually (IMHO) only be two with that name. For the language model, the proposed name is AnnotatedTypeMirror (in the current model TypeMirror is the base type abstraction).

All other subtypes of TypeMirror don't use "Mirror" in the interface
name. That's why I chose AnnotatedType over AnnotatedTypeMirror.

It looks like the prevailing opinion is to try the anonymous subtype approach.
Should I or do you want to do this in the type-annotations repo or in TL?

cu, WMD.

>> 1. javax.lang.model.type.AnnotatedType
>> This is a public JCP-controlled interface in the javax.lang.model package.
>>
>> 2. com.sun.javadoc.AnnotatedType
>> This is a public interface, part of the Doclet API.
>>
>> 3. com.sun.tools.javac.code.Type.AnnotatedType
>> This is an internal impl class only.
>>
>>
>> So, the jx.l.m class exists because we do not want to add extra methods to the supertype interface, jx.l.m.TypeMirror.    Likewise, c.s.j.AnnotatedType exists because we don't want to add methods to c.s.j.Type.
>>
>> But, these reasons do not apply to c.s.t.j.code.Type, and we can add methods to that as we choose. So that leads us to the impl choice we now have: whether to use a delegation model or anon-subtype model to impl the jx.l.m.t.AT.
>>
>> Within javac, we are not so constrained to avoid code.Type either, and it would be nice, as far as possible, to add virtual methods on code.Type to avoid unnecessary instanceof and cast tests within the javac code.
>>
>> As for delegation vs anon-subtyping, the more we can hide that choice behind methods on Type, the less it matters.  I am concerned, in the webrevs I've done so far, at the number of anon-subtypes required, such that this is not a slam-dunk choice.  But the delegation approach requires a fair-amount of undelegating to the underlying type as well.
>
> I have uploaded a patch [1] that cleans out  javax.lang.model.type.AnnotatedType and adds AnnotatedTypeMirror. The patch also removes all TypeKind.ANNOATED checks in favor for a call to Type.isAnnotatedType() and does some minor cleaning. Also I copied getTypeCompound() from Jon. With this and Jon's patch I think we have a foundation for starting to convert to anonymous classes which would make the job of providing javax.lang.model easier.
>
> A couple of points:
>
> - I'm very doubtful that TypeKind.ANNOTATED belongs in the model at least as a kind. To me this feels like an orthogonal quality.
> - The reason I want to move from the delegation model is that I need to further subdivide AnnotatedType into AnnotatedTypeVariable, AnnotatedWildcardType, AnnotatedParameterizedType and AnnotatedArrayType. While you can have AnnotatedType implement the union of all the functionality of the above and do dispatching this feels very brittle. If we move to a subtype model instead it should be easy and type-safe to provide the functionality in the subclasses where we know for a fact that the base type is for example a WildcardType.
>
> [1]  http://cr.openjdk.java.net/~jfranck/type-annotations/langmodel-cleanup3.patch
>
> cheers
> /Joel



-- 
http://www.google.com/profiles/wdietl


More information about the type-annotations-dev mailing list