Re: @Generated requires java.compiler / what should my annotation processor do

2020-11-02 Thread Rob Bygrave
*> there are three invocations of javac*

For me I'd describe it as only 2 invocations of javac.

That is, what above has as "second compilation" and "third compilation" is
I'd say is just 1 invocation of javac of the "example" module that includes
an annotation processor.

I'd describe it as 1 invoke of javac will potentially involve a number of
*rounds* until it's done. Some application source is compiled, which then
invokes the annotation processor that generates source, that is then
compiled, which can then invoke other annotation processors etc and this
continues until it does the final round (which we can detect in the
annotation processor via RoundEnvironment.processingOver() - and we get a
nice warning if the annotation processor generates stuff in the final
round). Obviously this is pretty darn cool how javac does this as it means
we can have "normal source" depend on generated code which won't exist
until compilation starts (chicken and egg). I was sure this "multi-round
compilation dance" is just a single invoke of javac.  Is it not?

So my take is that this 1 invoke of javac when done with JPMS (tooling wise
the presence of a module-info) is now "tighter" and specifically this
*javac* can only see things defined in the module-info (and java.compiler
is not in there generally) ... hence the generated source which is also
compiled by this invoke of javac can't
include javax.annotation.processing.Generated as I see it (and that is what
the compilation error tells me).

I should put up an example but the problem with that is that the annotation
processor I have detects javax.annotation.processing.Generated isn't
available (when JPMS is used) and just generates the source without it. To
reproduce "the issue" I need to change the annotation processor to not do
that check and always include the javax.annotation.processing.Generated
(and release that to central).

I first noticed this when just flipping back and forth between traditional
class path compilation (no module-info) and JPMS compilation (has
module-info) and noticing the @Generated wasn't there in the generated
source when there was a module-info.

At this stage I'm pretty comfortable that the annotation processor can't
include the javax.annotation.processing.Generated in the generated source
with JPMS which is ok.


Cheers, Rob.

On Mon, 2 Nov 2020 at 23:02, Alan Bateman  wrote:

> On 02/11/2020 00:02, Rob Bygrave wrote:
> > *>  Since the type javax.annotation.processing.Generated has source *
> >
> >
> > * retention only, there are no @javax.annotation.processing.Generated
> > annotations in any class files compiled from source code emitted by your
> > processor*
> >
> >
> > The annotation processor generates *source code*. It does not generate
> byte
> > code. In this source generation case it does not seem to matter that the
> > annotation is retention source - it will not compile but result in
> > compilation errors [package javax.annotation.processing is not visible].
> >
> > That is, with tooling of maven (and intellij) both do not compile the
> > generated source that includes javax.annotation.processing.Generated
> > without java.compiler being added to the *project module path*. It is not
> > sufficient that requires java.compiler; is in the module-info of the
> > annotation processor.
> >
> > When the annotation processor generates java source code that includes
> > javax.annotation.processing.Generated and when this generated source is
> > compiled it fails to compile with compilation errors like:.
> >
> >
> > [ERROR] /.java:[4,24] package
> > javax.annotation.processing is not visible
> > [ERROR]   (package javax.annotation.processing is declared in module
> > java.compiler, but module example does not read it)
> >
> >
> > I believe the generated source is compiled along with the rest of the
> > project source code using the *projects module path* which should not
> > include the java.compiler module.
> >
> > To me this compile error is correct and reasonable.  I think it's telling
> > me that the generated source should only include things that are in the
> > project module path (and java.compiler is not in the project module
> path).
> If I read your mails correctly then there are three invocations of javac
> here.
>
> The first is to compile the annotation processor that is module
> io.avaje.inject.generator. Its module declaration `requires
> java.compiler` and `provides javax.annotation.processing.Processor with
> ...`, all good.
>
> The second compilation is done with module io.avaje.inject.generator on
> the processor module path (--processor-module-path). This generates a
> source file with @javax.annotation.processing.Generated in the source
> file. It sounds like this is working.
>
> I think the third compilation is compiling the generated source file.
> Your first mail suggests that it is not compiled into a named module (no
> module-info.java). This should work as all modules that export an API
> are resolved. 

Re: @Generated requires java.compiler / what should my annotation processor do

2020-11-02 Thread Alan Bateman

On 02/11/2020 00:02, Rob Bygrave wrote:

*>  Since the type javax.annotation.processing.Generated has source *


* retention only, there are no @javax.annotation.processing.Generated
annotations in any class files compiled from source code emitted by your
processor*


The annotation processor generates *source code*. It does not generate byte
code. In this source generation case it does not seem to matter that the
annotation is retention source - it will not compile but result in
compilation errors [package javax.annotation.processing is not visible].

That is, with tooling of maven (and intellij) both do not compile the
generated source that includes javax.annotation.processing.Generated
without java.compiler being added to the *project module path*. It is not
sufficient that requires java.compiler; is in the module-info of the
annotation processor.

When the annotation processor generates java source code that includes
javax.annotation.processing.Generated and when this generated source is
compiled it fails to compile with compilation errors like:.


[ERROR] /.java:[4,24] package
javax.annotation.processing is not visible
[ERROR]   (package javax.annotation.processing is declared in module
java.compiler, but module example does not read it)


I believe the generated source is compiled along with the rest of the
project source code using the *projects module path* which should not
include the java.compiler module.

To me this compile error is correct and reasonable.  I think it's telling
me that the generated source should only include things that are in the
project module path (and java.compiler is not in the project module path).
If I read your mails correctly then there are three invocations of javac 
here.


The first is to compile the annotation processor that is module 
io.avaje.inject.generator. Its module declaration `requires 
java.compiler` and `provides javax.annotation.processing.Processor with 
...`, all good.


The second compilation is done with module io.avaje.inject.generator on 
the processor module path (--processor-module-path). This generates a 
source file with @javax.annotation.processing.Generated in the source 
file. It sounds like this is working.


I think the third compilation is compiling the generated source file. 
Your first mail suggests that it is not compiled into a named module (no 
module-info.java). This should work as all modules that export an API 
are resolved. However the compiler error that you show above looks like 
it is arises when compiling module "example". Is that a surprise? The 
error suggests that the module declaration for module example doesn't 
have `requires static java.compiler` so maybe the issue you are running 
into is in the POM or a tooling issue?


-Alan


Re: @Generated requires java.compiler / what should my annotation processor do

2020-11-01 Thread Rob Bygrave
*>  Since the type javax.annotation.processing.Generated has source *


* retention only, there are no @javax.annotation.processing.Generated
annotations in any class files compiled from source code emitted by your
processor*


The annotation processor generates *source code*. It does not generate byte
code. In this source generation case it does not seem to matter that the
annotation is retention source - it will not compile but result in
compilation errors [package javax.annotation.processing is not visible].

That is, with tooling of maven (and intellij) both do not compile the
generated source that includes javax.annotation.processing.Generated
without java.compiler being added to the *project module path*. It is not
sufficient that requires java.compiler; is in the module-info of the
annotation processor.

When the annotation processor generates java source code that includes
javax.annotation.processing.Generated and when this generated source is
compiled it fails to compile with compilation errors like:.


[ERROR] /.java:[4,24] package
javax.annotation.processing is not visible
[ERROR]   (package javax.annotation.processing is declared in module
java.compiler, but module example does not read it)


I believe the generated source is compiled along with the rest of the
project source code using the *projects module path* which should not
include the java.compiler module.

To me this compile error is correct and reasonable.  I think it's telling
me that the generated source should only include things that are in the
project module path (and java.compiler is not in the project module path).


*> so your downstream users don't need `requires java.compiler;`.*

That is the plan. As I see it the generated source compilation uses the
project module path.  So generated source that includes
javax.annotation.processing.Generated would then require java.compiler in
the project module path regardless of the fact that the annotation is
defined with retention source.



*> P.S. Your annotation processor `requires java.annotation;` but there is *
* no such module.*

Note that this exists via Automatic-Module-Name of the JEE dependency
(which we want people to migrate to the jakarta equivalent over time).

 Automatic-Module-Name: java.annotation


  javax.annotation
  javax.annotation-api
  1.3.2





Thanks, Rob.



> -- Forwarded message --
> From: Alex Buckley 
> To: jigsaw-dev@openjdk.java.net
> Cc:
> Bcc:
> Date: Fri, 30 Oct 2020 08:34:55 -0700
> Subject: Re: @Generated requires java.compiler / what should my annotation
> processor do
> The type javax.annotation.processing.Generated was the replacement
> introduced in Java SE 9 for the type javax.annotation.Generated.
>
> Why was a replacement needed for the type javax.annotation.Generated?
> Because the package javax.annotation belonged to Java EE, and was
> removed in Java SE 11.
>
> By contrast, the package javax.annotation.processing has always been
> part of Java SE and is the logical home for a "Generated" type
> associated with annotation processors.
>
> Since the type javax.annotation.processing.Generated has source
> retention only, there are no @javax.annotation.processing.Generated
> annotations in any class files compiled from source code emitted by your
> processor, so your downstream users don't need `requires java.compiler;`.
>
> Alex
>
> P.S. Your annotation processor `requires java.annotation;` but there is
> no such module.
>
> On 10/29/2020 10:49 PM, Rob Bygrave wrote:
> > Are Java 9+ annotation processors using module path supposed to generate
> > source code that has a javax.annotation.processing.Generated annotation?
> > (which is part of java.compile)
> >
> > I have an annotation processor that supports modules and is fine except
> > that when module applications use it the @Generated will not be included
> in
> > the generated source unless the application module-info adds a *requires
> > java.compiler;*  (which seems wrong).
> >
> > So this is a minor niggle that the @Generated no longer is included in
> the
> > generated source when apps go from class path to module path.
> >
> > Apologies is this has been asked before.  I was unable to find anything
> on
> > this issue.
> >
> > Any pointers or thoughts?
> >
> >
> > *Background*
> >
> > I have an annotation processor that generates source code (that now
> > supports java modules with a module-info via a Multi-Release jar).  The
> > module-info for the annotation processor is:
> >
> > module io.avaje.inject.generator {
> >
> >requires java.compiler;
> >requires io.avaje.inject;
> >requires java.annotation;
> >
> >provides javax.annotation.processing.Proces

Re: @Generated requires java.compiler / what should my annotation processor do

2020-10-30 Thread Alex Buckley
The type javax.annotation.processing.Generated was the replacement 
introduced in Java SE 9 for the type javax.annotation.Generated.


Why was a replacement needed for the type javax.annotation.Generated? 
Because the package javax.annotation belonged to Java EE, and was 
removed in Java SE 11.


By contrast, the package javax.annotation.processing has always been 
part of Java SE and is the logical home for a "Generated" type 
associated with annotation processors.


Since the type javax.annotation.processing.Generated has source 
retention only, there are no @javax.annotation.processing.Generated 
annotations in any class files compiled from source code emitted by your 
processor, so your downstream users don't need `requires java.compiler;`.


Alex

P.S. Your annotation processor `requires java.annotation;` but there is 
no such module.


On 10/29/2020 10:49 PM, Rob Bygrave wrote:

Are Java 9+ annotation processors using module path supposed to generate
source code that has a javax.annotation.processing.Generated annotation?
(which is part of java.compile)

I have an annotation processor that supports modules and is fine except
that when module applications use it the @Generated will not be included in
the generated source unless the application module-info adds a *requires
java.compiler;*  (which seems wrong).

So this is a minor niggle that the @Generated no longer is included in the
generated source when apps go from class path to module path.

Apologies is this has been asked before.  I was unable to find anything on
this issue.

Any pointers or thoughts?


*Background*

I have an annotation processor that generates source code (that now
supports java modules with a module-info via a Multi-Release jar).  The
module-info for the annotation processor is:

module io.avaje.inject.generator {

   requires java.compiler;
   requires io.avaje.inject;
   requires java.annotation;

   provides javax.annotation.processing.Processor with
io.avaje.inject.generator.Processor;
}


The annotation processor adds a @Generated to the generated source to
document that the source code is generated. The annotation processor only
adds the @Generated if javax.annotation.processing.Generated is deemed
available by using:

  *elements.getTypeElement("javax.annotation.processing.Generated") != null*



The annotation processor generates source that includes the @Generated in
the cases of:

- There is no module-info.java  (app is using class path and not module
path)
- The app module-info.java includes:   *requires java.compiler;*

I'm not expecting users of this annotation processor to put a *requires
java.compiler;* into their module-info.

I think I must be doing something wrong or should not try to
use javax.annotation.processing.Generated which is part of java.compile.


Cheers, Rob.



@Generated requires java.compiler / what should my annotation processor do

2020-10-29 Thread Rob Bygrave
Are Java 9+ annotation processors using module path supposed to generate
source code that has a javax.annotation.processing.Generated annotation?
(which is part of java.compile)

I have an annotation processor that supports modules and is fine except
that when module applications use it the @Generated will not be included in
the generated source unless the application module-info adds a *requires
java.compiler;*  (which seems wrong).

So this is a minor niggle that the @Generated no longer is included in the
generated source when apps go from class path to module path.

Apologies is this has been asked before.  I was unable to find anything on
this issue.

Any pointers or thoughts?


*Background*

I have an annotation processor that generates source code (that now
supports java modules with a module-info via a Multi-Release jar).  The
module-info for the annotation processor is:

module io.avaje.inject.generator {

  requires java.compiler;
  requires io.avaje.inject;
  requires java.annotation;

  provides javax.annotation.processing.Processor with
io.avaje.inject.generator.Processor;
}


The annotation processor adds a @Generated to the generated source to
document that the source code is generated. The annotation processor only
adds the @Generated if javax.annotation.processing.Generated is deemed
available by using:

 *elements.getTypeElement("javax.annotation.processing.Generated") != null*



The annotation processor generates source that includes the @Generated in
the cases of:

- There is no module-info.java  (app is using class path and not module
path)
- The app module-info.java includes:   *requires java.compiler;*

I'm not expecting users of this annotation processor to put a *requires
java.compiler;* into their module-info.

I think I must be doing something wrong or should not try to
use javax.annotation.processing.Generated which is part of java.compile.


Cheers, Rob.