A couple of questions

Alan Bateman Alan.Bateman at oracle.com
Thu Jan 11 13:30:02 UTC 2024


On 10/01/2024 10:29, PavelTurk wrote:
> :
>
> Still can't get reference to read modules:
>
>         layerC.configuration().modules().stream().forEach((m) -> {
>             for (ResolvedModule r : m.reads()) {
>                 //LINE X
>             }
>         });
>
> At LINE X I need to get `Module` from `ResolvedModule` to use 
> Module.getLayer() method. How to do it?

Starting in model world (Configuration/ResolvedModule) is right and you 
first need to find the Configuration containing the moduleX that moduleY 
reads, this should do it:

         Configuration cf = layerC.configuration()
                 .findModule("moduleY")
                 .orElseThrow()
                 .reads().stream()
                 .filter(m -> m.name().equals("moduleX"))
                 .map(ResolvedModule::configuration)
                 .findAny()
                 .orElseThrow();

Once you have the Configuration then you need to find the ModuleLayer 
that was reifed from that Configuration, this should do it:

         ModuleLayer layer = layerC.parents().stream()
                 .filter(l -> l.configuration() == cf)
                 .findAny()
                 .orElseThrow();

Can you try it?

-Alan




More information about the jigsaw-dev mailing list