Initial webrev with changes for JDK 9

Peter Levart peter.levart at gmail.com
Wed Mar 16 22:18:11 UTC 2016


Hi Mandy,

On 03/16/2016 10:03 PM, Mandy Chung wrote:
> I have cleaned up the code to use toPackage instead:
>    http://cr.openjdk.java.net/~mchung/jigsaw/webrevs/jigsaw-m3/webrev-03-16/index.html
>
> Mandy

Was your intention for public methods getDefinedPackage(name), 
getPackages() and getDefinedPackages() to return transient Package 
instances in cases where NamedPackage(s) are present in 'packages' map? 
Previously, NamedPackage(s) were replaced with Package(s) in 'packages' 
map when 1st requested. The toPackage(String, NamedPackage, Module) does 
not replace - it just creates new Package instance if needed.

Perhaps we need a method like:

private Package definePackageIfNeeded(String name, Module m, /* nullable 
*/ NamedPackage np) {
     return (np instanceof Package)
         ? (Package) np
         : packages.compute(name, (n, p) ->
               (p instanceof Package)
                   ? (Package) p
                   : NamedPackage.toPackage(n, m));
}


Then we can use it everywhere:

     public final Package getDefinedPackage(String name) {
         NamedPackage p = packages.get(name);
         return (p == null) ? null : 
definePackageIfNeeded(p.packageName(), p.module(), p);
     }

     Stream<Package> packages() {
         return packages.values().stream()
                        .map(p -> definePackageIfNeeded(p.packageName(), 
p.module(), p));
     }

     Package definePackage(String name, Module m) {
         if (name.isEmpty() && m.isNamed()) {
             throw new InternalError("unnamed package in  " + m);
         }

         return definePackageIfNeeded(name, m, null);
     }



What do you think?


Regards, Peter



More information about the jigsaw-dev mailing list