Re: Type annotation appears before the type’s simple name
Werner Dietl
wdietl at gmail.com
Thu Dec 13 12:06:50 PST 2012
Hi Paul,
thanks for your interest in type-annotations and your comments.
This is the developers mailing list. For questions to the EG you have
to message the type-annotations-spec-comments mailing list.
This syntax was recently changed, as raised by Srikanth:
http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2012-October/000012.html
I do prefer this new syntax and was advocating for it when we
initially discussed this issue.
To me, it is more logical to have the annotation right before the
element you want to annotate.
Also, it made the implementation in OpenJDK significantly simpler.
In your first examples:
> 1a) Map. at NonNull Entry
> 1b) @NonNull Map.Entry
In the old approach (example 1b), it depends on whether class
Map.Entry is a static inner class or not to decide where the
annotation belongs.
For non-static nested classes, all three of the following are possible:
Outer. @A Inner
@A Outer.Inner
@A Outer. @B Inner
It makes parsing easier if this semantic knowledge is not needed to
decide where to attach the annotation.
Similarly for package names:
> 2a) java.util. @Marker List
> 2b) @Marker java.util.List
In 2a we can simply attach the annotation on List.
In 2b we need to know whether java or util are the right class to attach to.
In the implementation, this changeset:
http://hg.openjdk.java.net/type-annotations/type-annotations/langtools/rev/4e24226764cb
removes the ugly "onRightType" hack that was necessary to support the
previous syntax.
So to me the approach of putting type annotations before the type's
simple name seems both more logical and easier to implement.
Please do let me know whether this makes sense or whether I should
elaborate more on some aspect.
I am also not quite sure what you mean with "It seems to go against
the 99% usage in the rest of the
spec." Could you elaborate on what your concerns are?
For an answer from the EG you probably need to re-send your message to
the spec-comments list.
Thanks,
cu, WMD.
--
http://www.google.com/profiles/wdietl
More information about the type-annotations-dev
mailing list