From mark.reinhold at oracle.com Tue Oct 27 17:34:28 2020 From: mark.reinhold at oracle.com (mark.reinhold at oracle.com) Date: Tue, 27 Oct 2020 10:34:28 -0700 (PDT) Subject: New candidate JEP: 396: Strongly Encapsulate JDK Internals by Default Message-ID: <20201027173428.717863C750B@eggemoggin.niobe.net> https://openjdk.java.net/jeps/396 - Mark From robin.bygrave at gmail.com Fri Oct 30 05:49:23 2020 From: robin.bygrave at gmail.com (Rob Bygrave) Date: Fri, 30 Oct 2020 18:49:23 +1300 Subject: @Generated requires java.compiler / what should my annotation processor do Message-ID: 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. From alex.buckley at oracle.com Fri Oct 30 15:34:55 2020 From: alex.buckley at oracle.com (Alex Buckley) Date: Fri, 30 Oct 2020 08:34:55 -0700 Subject: @Generated requires java.compiler / what should my annotation processor do In-Reply-To: References: Message-ID: <04734ad0-faa3-0870-7d17-3c7fe7d92139@oracle.com> 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. >