Modular annotation processor registration was: Scopes in the Jigsaw module system

Jaroslav Tulach jaroslav.tulach at oracle.com
Mon Aug 20 15:26:47 PDT 2012


Dne Po 20. srpna 2012 10:39:25, Alex Buckley napsal(a):
> On 8/17/2012 11:05 PM, Jaroslav Tulach wrote:
> > If I interpret it correctly, you suggest to package the processor into
> > independent module, separated from the module hosting the annotation.
> > Good,
> > that is how it should be!
> 
> Agreed. Caveat: the Jigsaw team hasn't discussed annotation processors
> much, so people shouldn't assume much about how other use cases will be
> handled.

OK. I keep that in mind.

> > However how do we guarantee that a source only annotation is properly
> > processed whenever somebody compiles against the API?
> > 
> > Imagine that java.beans module provides @GenerateBeanInfo annotation to be
> > placed on any JavaBean class and generate appropriate BeanInfo class
> > automatically rather than requiring it to be code manually. If I correctly
> > understood, the associated GenerateBeanInfoProcessor should be placed in a
> > separate java.beans.processor module. How will the javac know that
> > whenever
> > somebody uses @GenerateBeanInfo annotation in own code the
> > java.beans.processor module must be consulted during compilation?
> 
> Good question. Again, the Jigsaw team hasn't discussed how to identify,
> package, or execute annotation processors yet. JSR 269 defines the
> environment that an annotation processor can see (e.g.
> ProcessingEnvironment, Filer) but the identification and execution of
> annotation processors is not standardized. How much can easily be
> standardized in a module system is an open question.

I have an idea I'd like to share. Right now the Processor subclass is 
registered as "provides service" and then it identifies which annotations it 
processes. There is a pointer from the processor to the annotation.

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




More information about the jigsaw-dev mailing list