< prev index next >

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

Print this page

        

@@ -29,10 +29,11 @@
 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,11 +136,10 @@
         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;

@@ -163,15 +163,10 @@
     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;
     }
 

@@ -226,17 +221,14 @@
     /**
      * 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);

@@ -244,67 +236,61 @@
         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;
 
+        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,
-                                        open,
-                                        automatic,
-                                        synthetic,
+                                        modifiers,
                                         requires,
                                         exports,
                                         opens,
                                         uses,
                                         provides,
< prev index next >