Rethinking TypeAnnotation vs Annotation
Jonathan Gibbons
jonathan.gibbons at oracle.com
Thu Feb 6 13:12:00 PST 2014
Yes, I agree the wording can be improved, but it is reasonable to
replace "any" by "most", as in, "in the majority of cases, an annotation
can be either a declaration annotation or a type annotation". This
leads to Eric's claim regarding the implementation, that is is easier to
code for the possibility that it could be either (and allow that some
cases can never happen in practice) than to provide different code paths
for annos which can only be decl annos, and for annos which can only be
type annos, and for annos which could be either.
-- Jon
On 02/06/2014 12:15 PM, Alex Buckley wrote:
> Hi Eric,
>
> "Any given annotation is potentially a type annotation" doesn't smell
> right to me. For example, an annotation on a package declaration
> cannot reasonably be considered as a "type annotation".
>
> In fact, we can be real precise about this: there are eight
> declaration contexts defined in JLS 9.6.4.1, and only five of them are
> called out in 9.7.4 as being a syntactic opportunity to annotate a
> type. The three that aren't - package declarations, type declarations,
> and type parameter declarations - are where you "cannot" have a type
> annotation, by definition.
>
> It may be helpful to review 9.7.4:
>
> - A declaration annotation is an annotation that applies to a
> declaration, and whose own type is applicable in the declaration
> context (§9.6.4.1) represented by that declaration.
>
> - A type annotation is an annotation that applies to a type (or any
> part of a type), and whose own type is applicable in type contexts
> (§4.11).
>
> - Whether an annotation applies to a declaration or to the type of the
> declared entity - and thus, whether the annotation is a declaration
> annotation or a type annotation - depends on the applicability of the
> annotation's type: ...
>
> Alex
>
> On 2/6/2014 11:59 AM, Eric McCorkle wrote:
>> In the process of working on the next roadmap step for type annotations,
>> I've realized something.
>>
>> The current implementation, and I think most of everyone's thinking on
>> annotations treats type annotations as a special case of regular
>> annotations. Indeed, this is sort of the intuitive first thought.
>>
>> But looking at the actual implementation details, I think the reverse is
>> actually true. Any given annotation is potentially a type annotation,
>> especially earlier in the javac pipeline (where I'm presently generating
>> TypeAnnotationPositions in my new patch). So, on the implementation
>> front, it makes perfect sense to do things like store
>> TypeAnnotationPositions in Attribute.Compound, as opposed to
>> Attribute.TypeCompound.
>>
>> I think this would also go a long way towards creating the single
>> codepath for attaching annotations that I want to create.
>>
>> Comments?
>>
More information about the type-annotations-dev
mailing list