Rethinking TypeAnnotation vs Annotation

Alex Buckley alex.buckley at
Thu Feb 6 18:36:34 PST 2014

My point was that the javac data model ought to use JLS concepts as a 
starting point, if appropriate and practical.


On 2/6/2014 4:11 PM, Eric McCorkle wrote:
> Alex,
> I am talking in terms of javac compiler internals, not the JLS spec.  To
> be clear, I'm proposing changes to the way we model data inside javac,
> not any changes to the JLS.
> At many stages in the pipeline, the applicability of an annotation is
> not yet known.  So the annotation might potentially need a
> TypeAnnotationPosition, because there is the potential that further down
> the pipeline it will be discovered that it is actually a type annotation.
> On 02/06/14 15:15, 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, 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
>> (§ 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 compiler-dev mailing list