Modular annotation processor registration
Jaroslav Tulach
jaroslav.tulach at oracle.com
Mon Aug 20 16:10:05 PDT 2012
Dne Po 20. srpna 2012 15:37:15, Alex Buckley napsal(a):
> On 8/20/2012 3:26 PM, Jaroslav Tulach wrote:
> > If we want to have processors separated from annotations, then we also
> > need a link from the annotation to its processor. I guess a
> > meta-annotation like:
> >
> > @Target(ElementType.ANNOTATION_TYPE)
> > @Retention(RetentionType.CLASS)
> > @interface WhichModuleProvidesMyProcessor {
> >
> > String value();
> >
> > }
> >
> > which I could use to define my source annotation
> >
> > @Retention(SOURCE)
> > @WhichModuleProvidesMyProcessor("my.processor.module at 2.7")
> > @interface MyAnnotation {
> > }
> >
> > would be enough for javac to know that it has to find and turn on
> > my.processor.module in order to compile sources refering to MyAnnotation.
> > If the module my.processor.module at 2.7 is not found, the compilation fails
> > with error.
> >
> > Just my 2Kč to discussion about annotation processors (when you get to
> > it).
> > -jt
>
> Thanks. While "annotation processing dependencies" are an interesting
> special case, we should stick to the common case of module dependencies
> for now.
>
> I'll just note that binding an annotation type to a processor only works
> when there's an annotation type involved - in general, you can write
> processors which have no interest in annotations whatsoever.
True. But those who wish to use such processors need to be aware of their
existence and need to include their modules on compilation path. That is not
much different from what people need to do these days and good enough for a
common clueless programmer to handle.
The case of a separate annotation (like @GenerateBeanInfo discussed
previously) and its processor is new. These days people usually package the
processor next to the annotation. Then it is guaranteed javac will find the
processor and use it by default.
It is desirable (from a modular point of view) to support annotations
separated from their processors. The major thing to be aware of is the danger
of producing different result depending whether end users forget/don't forget
to include also dependency on the module with the processor.
If we allow people to use @GenerateBeanInfo without java.beans.impl module
with appropriate processor, there will be surprises. I certainly don't want to
be on the hotline to explain why something compiles, but don't not produce the
desirable results...
A hint from the annotation alá @WhichModuleProvidesMyProcessor to javac would
guarantee reliable compilation results.
-jt
More information about the jigsaw-dev
mailing list