Re: module annotations

2018-10-10 Thread Peter Levart

Hi Michał,

On 10/09/2018 09:11 PM, Alan Bateman wrote:

On 09/10/2018 17:27, Michał Zegan wrote:

Hello,
I know that modules/module declarations can be annotated. Contrary to
other elements from packages downwards, java has a way to read module
descriptions before creating modules themselves (in fact it is a
required step). I am wondering, why doesn't ModuleDescriptor
contain/parse module annotations from class file? That way the
module-info.class has to be read twice, once for module descriptor, once
for annotations. In addition, if I would like to load annotations of a
module x before it is instantiated (like introspection), I would have to
still use a library like asm or similar.
This is to avoid bloating the API and also to avoid overlapping with 
the javax.lang.model API. So yes, if you are scanning observable 
modules, maybe to select which modules to resolve based on 
annotations, then you will need ASM or something to help you parse the 
class files. It's the same thing for tools that scan classes or 
elements for annotations.


-Alan


In addition to what Alan says, I may add that I have tried to prototype 
an API that would allow reading of annotations at the ModuleDescriptor 
time, before Module is instantiated. I had the following problem: the 
API can't be the same as implemented in existing AnnotatedElement 
classes (Class, Method, Field, Constructor, Module, ...). Why? Because 
of chicken-egg problem. The annotation types used in a particular 
module-info.java may be declared in the module itself. For constructing 
annotation objects (which is a necessity for AnnotatedElement API), the 
annotation types have to be loaded 1st and if they are declared in a 
module, the Module has to be instantiated first.


So this would technically be possible only with an entirely different 
API than what we have today in java.lang[.relfect]. Something like the 
javax.lang.model API.


That said, I wonder what is the status of JEP 119 today. If it was 
updated to support module(s) then I guess it uses the instantiated 
Module(s) to get the job done.


OTOH there's java compiler API that implements javax.lang.model too. I 
haven't investigated it but it might be possible to employ it to parse 
class files and provide you with javax.lang.model objects including 
annotations. Something to try...


Regards, Peter



Re: module annotations

2018-10-09 Thread Alan Bateman

On 09/10/2018 17:27, Michał Zegan wrote:

Hello,
I know that modules/module declarations can be annotated. Contrary to
other elements from packages downwards, java has a way to read module
descriptions before creating modules themselves (in fact it is a
required step). I am wondering, why doesn't ModuleDescriptor
contain/parse module annotations from class file? That way the
module-info.class has to be read twice, once for module descriptor, once
for annotations. In addition, if I would like to load annotations of a
module x before it is instantiated (like introspection), I would have to
still use a library like asm or similar.
This is to avoid bloating the API and also to avoid overlapping with the 
javax.lang.model API. So yes, if you are scanning observable modules, 
maybe to select which modules to resolve based on annotations, then you 
will need ASM or something to help you parse the class files. It's the 
same thing for tools that scan classes or elements for annotations.


-Alan


Re: Module annotations

2016-10-15 Thread Jonathan Ross

> On Oct 14, 2016, at 10:59, Alan Bateman  wrote:
>
>> On 14/10/2016 18:52, Jonathan Ross wrote:
>> I found myself wondering whether or not module-level annotations have been 
>> added as part of project jigsaw? Sorry if this has been discussed a lot 
>> before... I see a thread about removing support for them in the mailing list 
>> archive, but I didn't find much else.
>>
>> My specific use-case would be to add findbugs- or checkerframework default 
>> annotations for an entire module, rather than on a per-type or a per-package 
>> level.
>>
>>
> I assume you are looking for the #ModuleAnnotations proposal [1]. The Jigsaw 
> EA builds have the initial implementation of this for some time.
>
> -Alan
>
> [1] 
> http://mail.openjdk.java.net/pipermail/jpms-spec-experts/2016-June/000308.html

Indeed, thanks!

Jonathan



The information in this e-mail is intended only for the person or entity to 
which it is addressed.

It may contain confidential and /or privileged material. If someone other than 
the intended recipient should receive this e-mail, he / she shall not be 
entitled to read, disseminate, disclose or duplicate it.

If you receive this e-mail unintentionally, please inform us immediately by 
"reply" and then delete it from your system. Although this information has been 
compiled with great care, neither IMC Financial Markets & Asset Management nor 
any of its related entities shall accept any responsibility for any errors, 
omissions or other inaccuracies in this information or for the consequences 
thereof, nor shall it be bound in any way by the contents of this e-mail or its 
attachments. In the event of incomplete or incorrect transmission, please 
return the e-mail to the sender and permanently delete this message and any 
attachments.

Messages and attachments are scanned for all known viruses. Always scan 
attachments before opening them.


Re: Module annotations

2016-10-14 Thread Alan Bateman

On 14/10/2016 18:52, Jonathan Ross wrote:


Hi all,

I found myself wondering whether or not module-level annotations have been 
added as part of project jigsaw? Sorry if this has been discussed a lot 
before... I see a thread about removing support for them in the mailing list 
archive, but I didn't find much else.

My specific use-case would be to add findbugs- or checkerframework default 
annotations for an entire module, rather than on a per-type or a per-package 
level.


I assume you are looking for the #ModuleAnnotations proposal [1]. The 
Jigsaw EA builds have the initial implementation of this for some time.


-Alan

[1] 
http://mail.openjdk.java.net/pipermail/jpms-spec-experts/2016-June/000308.html