[JSR308] Use of @Target meta-annotation
gafter at google.com
Sat May 19 01:08:52 EDT 2007
I think we'll have to agree to disagree about the importance of this. In my
opinion, a language should be syntactically unambiguous, and the
relationships among the elements of the syntax should be based on uniform
syntactic rules (i.e. the grammar) rather than determined based on tertiary
information like annotations on the declarations of annotations whose names
are used. Your proposal to make the meaning of an annotation change based on
its meta-annotation violates the principle that an annotation should not
affect the meaning of the program elements.
We should not base our design on the absence of "use cases" for particular
interactions of the elements of the language. Just because we fail to
imagine such use cases doesn't mean they don't exist. We won't have a full
understanding of the use cases for the language feature until programmers
much more creative than us begin using them in real programs. We should not
hobble them by limiting them to only what is required for the specific use
cases we imagine now.
On May 18, 2007 8:35 PM, Michael Ernst <mernst at csail.mit.edu> wrote:
> Background: In the syntax currently used by the JSR 308 proposal, a
> source location for an annotation may correspond to multiple targets (say,
> to both a method declaration and the return value, or to both a variable
> declaration and to the type in the declaration). There is no ambiguity in
> the Java grammar, only in where the annotation should be placed for use by
> annotation processors. The annotation's @Target meta-annotation
> this, and the compiler automatically places the annotation on the
> appropriate target.
> Eugene noted two arguments that could be made against this approach.
> 1. It may be a burden to compiler writers.
> The compiler is already required to read and enforce the Target
> meta-annotation. The Target Javadocs state
> If such a meta-annotation is present, the compiler will enforce the
> specified usage restriction.
> (See http://java.sun.com/javase/6/docs/api/java/lang/annotation
> Thus, the burden on the compiler writer of applying the annotation to the
> correct target is minimal.
> 2. It may be confusing to programmers.
> It's possible that annotations may be so poorly designed, named, and
> documented that a competent programmer cannot determine to what they
> However, I believe it will be clear in normal usage.
> The JSR 308 community has not yet found a single example of an annotation
> that has different meaning depending on whether it is applied to one
> or another. (It's hard to even come up with an example that can be
> to multiple targets at a location in the current syntax.)
> It would be easy for a compiler to issue a warning if an annotation is
> in a location where it applies to two program targets (because is has no
> Target meta-annotation, or because it has both Target meta-annotations).
> JSR308 mailing list
> JSR308 at lists.csail.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the JSR308