< prev index next >

src/java.base/share/classes/jdk/internal/module/Builder.java

Print this page

        

*** 29,38 **** --- 29,39 ---- import java.lang.module.ModuleDescriptor.Opens; import java.lang.module.ModuleDescriptor.Provides; import java.lang.module.ModuleDescriptor.Requires; import java.lang.module.ModuleDescriptor.Version; import java.util.Collections; + import java.util.HashSet; import java.util.List; import java.util.Set; import jdk.internal.misc.JavaLangModuleAccess; import jdk.internal.misc.SharedSecrets;
*** 135,145 **** return JLMA.newProvides(st, pcs); } final String name; boolean open; - boolean automatic; boolean synthetic; Set<Requires> requires; Set<Exports> exports; Set<Opens> opens; Set<String> packages; --- 136,145 ----
*** 163,177 **** Builder open(boolean value) { this.open = value; return this; } - Builder automatic(boolean value) { - this.automatic = value; - return this; - } - Builder synthetic(boolean value) { this.synthetic = value; return this; } --- 163,172 ----
*** 226,242 **** /** * Sets the module version. * * @throws IllegalArgumentException if {@code v} is null or cannot be * parsed as a version string - * @throws IllegalStateException if the module version is already set * * @see Version#parse(String) */ public Builder version(String v) { - if (version != null) - throw new IllegalStateException("module version already set"); Version ver = cachedVersion; if (ver != null && v.equals(ver.toString())) { version = ver; } else { cachedVersion = version = Version.parse(v); --- 221,234 ----
*** 244,310 **** return this; } /** * Sets the module main class. - * - * @throws IllegalStateException if already set */ public Builder mainClass(String mc) { - if (mainClass != null) - throw new IllegalStateException("main class already set"); mainClass = mc; return this; } /** * Sets the OS name. - * - * @throws IllegalStateException if already set */ public Builder osName(String name) { - if (osName != null) - throw new IllegalStateException("OS name already set"); this.osName = name; return this; } /** * Sets the OS arch. - * - * @throws IllegalStateException if already set */ public Builder osArch(String arch) { - if (osArch != null) - throw new IllegalStateException("OS arch already set"); this.osArch = arch; return this; } /** * Sets the OS version. * * @throws IllegalStateException if already set */ public Builder osVersion(String version) { - if (osVersion != null) - throw new IllegalStateException("OS version already set"); this.osVersion = version; return this; } /** * Builds a {@code ModuleDescriptor} from the components. */ public ModuleDescriptor build(int hashCode) { assert name != null; return JLMA.newModuleDescriptor(name, version, ! open, ! automatic, ! synthetic, requires, exports, opens, uses, provides, --- 236,296 ---- return this; } /** * Sets the module main class. */ public Builder mainClass(String mc) { mainClass = mc; return this; } /** * Sets the OS name. */ public Builder osName(String name) { this.osName = name; return this; } /** * Sets the OS arch. */ public Builder osArch(String arch) { this.osArch = arch; return this; } /** * Sets the OS version. * * @throws IllegalStateException if already set */ public Builder osVersion(String version) { this.osVersion = version; return this; } /** * Builds a {@code ModuleDescriptor} from the components. */ public ModuleDescriptor build(int hashCode) { assert name != null; + Set<ModuleDescriptor.Modifier> modifiers; + if (open || synthetic) { + modifiers = new HashSet<>(); + if (open) modifiers.add(ModuleDescriptor.Modifier.OPEN); + if (synthetic) modifiers.add(ModuleDescriptor.Modifier.SYNTHETIC); + modifiers = Collections.unmodifiableSet(modifiers); + } else { + modifiers = Collections.emptySet(); + } + return JLMA.newModuleDescriptor(name, version, ! modifiers, requires, exports, opens, uses, provides,
< prev index next >