< prev index next >

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

Print this page




 128     }
 129 
 130     /**
 131      * Returns a {@link Provides} for a service with a given list of
 132      * implementation classes.
 133      */
 134     public static Provides newProvides(String st, List<String> pcs) {
 135         return JLMA.newProvides(st, pcs);
 136     }
 137 
 138     final String name;
 139     boolean open, synthetic, mandated;
 140     Set<Requires> requires;
 141     Set<Exports> exports;
 142     Set<Opens> opens;
 143     Set<String> packages;
 144     Set<String> uses;
 145     Set<Provides> provides;
 146     Version version;
 147     String mainClass;
 148     String osName;
 149     String osArch;
 150     String osVersion;
 151 
 152     Builder(String name) {
 153         this.name = name;
 154         this.requires = Collections.emptySet();
 155         this.exports = Collections.emptySet();
 156         this.opens = Collections.emptySet();
 157         this.provides = Collections.emptySet();
 158         this.uses = Collections.emptySet();
 159     }
 160 
 161     Builder open(boolean value) {
 162         this.open = value;
 163         return this;
 164     }
 165 
 166     Builder synthetic(boolean value) {
 167         this.synthetic = value;
 168         return this;
 169     }
 170 


 231      */
 232     public Builder version(String v) {
 233         Version ver = cachedVersion;
 234         if (ver != null && v.equals(ver.toString())) {
 235             version = ver;
 236         } else {
 237             cachedVersion = version = Version.parse(v);
 238         }
 239         return this;
 240     }
 241 
 242     /**
 243      * Sets the module main class.
 244      */
 245     public Builder mainClass(String mc) {
 246         mainClass = mc;
 247         return this;
 248     }
 249 
 250     /**
 251      * Sets the OS name.
 252      */
 253     public Builder osName(String name) {
 254         this.osName = name;
 255         return this;
 256     }
 257 
 258     /**
 259      * Sets the OS arch.
 260      */
 261     public Builder osArch(String arch) {
 262         this.osArch = arch;
 263         return this;
 264     }
 265 
 266     /**
 267      * Sets the OS version.
 268      */
 269     public Builder osVersion(String version) {
 270         this.osVersion = version;
 271         return this;
 272     }
 273 
 274     /**
 275      * Returns an immutable set of the module modifiers derived from the flags.
 276      */
 277     private Set<ModuleDescriptor.Modifier> modifiers() {
 278         int n = 0;
 279         if (open) n++;
 280         if (synthetic) n++;
 281         if (mandated) n++;
 282         if (n == 0) {
 283             return Collections.emptySet();
 284         } else {
 285             ModuleDescriptor.Modifier[] mods = new ModuleDescriptor.Modifier[n];
 286             if (open) mods[--n] = ModuleDescriptor.Modifier.OPEN;
 287             if (synthetic) mods[--n] = ModuleDescriptor.Modifier.SYNTHETIC;
 288             if (mandated) mods[--n] = ModuleDescriptor.Modifier.MANDATED;
 289             return Set.of(mods);
 290         }
 291     }
 292 
 293     /**
 294      * Builds a {@code ModuleDescriptor} from the components.
 295      */
 296     public ModuleDescriptor build(int hashCode) {
 297         assert name != null;
 298         return JLMA.newModuleDescriptor(name,
 299                                         version,
 300                                         modifiers(),
 301                                         requires,
 302                                         exports,
 303                                         opens,
 304                                         uses,
 305                                         provides,
 306                                         packages,
 307                                         mainClass,
 308                                         osName,
 309                                         osArch,
 310                                         osVersion,
 311                                         hashCode);
 312     }
 313 }


 128     }
 129 
 130     /**
 131      * Returns a {@link Provides} for a service with a given list of
 132      * implementation classes.
 133      */
 134     public static Provides newProvides(String st, List<String> pcs) {
 135         return JLMA.newProvides(st, pcs);
 136     }
 137 
 138     final String name;
 139     boolean open, synthetic, mandated;
 140     Set<Requires> requires;
 141     Set<Exports> exports;
 142     Set<Opens> opens;
 143     Set<String> packages;
 144     Set<String> uses;
 145     Set<Provides> provides;
 146     Version version;
 147     String mainClass;



 148 
 149     Builder(String name) {
 150         this.name = name;
 151         this.requires = Collections.emptySet();
 152         this.exports = Collections.emptySet();
 153         this.opens = Collections.emptySet();
 154         this.provides = Collections.emptySet();
 155         this.uses = Collections.emptySet();
 156     }
 157 
 158     Builder open(boolean value) {
 159         this.open = value;
 160         return this;
 161     }
 162 
 163     Builder synthetic(boolean value) {
 164         this.synthetic = value;
 165         return this;
 166     }
 167 


 228      */
 229     public Builder version(String v) {
 230         Version ver = cachedVersion;
 231         if (ver != null && v.equals(ver.toString())) {
 232             version = ver;
 233         } else {
 234             cachedVersion = version = Version.parse(v);
 235         }
 236         return this;
 237     }
 238 
 239     /**
 240      * Sets the module main class.
 241      */
 242     public Builder mainClass(String mc) {
 243         mainClass = mc;
 244         return this;
 245     }
 246 
 247     /**
























 248      * Returns an immutable set of the module modifiers derived from the flags.
 249      */
 250     private Set<ModuleDescriptor.Modifier> modifiers() {
 251         int n = 0;
 252         if (open) n++;
 253         if (synthetic) n++;
 254         if (mandated) n++;
 255         if (n == 0) {
 256             return Collections.emptySet();
 257         } else {
 258             ModuleDescriptor.Modifier[] mods = new ModuleDescriptor.Modifier[n];
 259             if (open) mods[--n] = ModuleDescriptor.Modifier.OPEN;
 260             if (synthetic) mods[--n] = ModuleDescriptor.Modifier.SYNTHETIC;
 261             if (mandated) mods[--n] = ModuleDescriptor.Modifier.MANDATED;
 262             return Set.of(mods);
 263         }
 264     }
 265 
 266     /**
 267      * Builds a {@code ModuleDescriptor} from the components.
 268      */
 269     public ModuleDescriptor build(int hashCode) {
 270         assert name != null;
 271         return JLMA.newModuleDescriptor(name,
 272                                         version,
 273                                         modifiers(),
 274                                         requires,
 275                                         exports,
 276                                         opens,
 277                                         uses,
 278                                         provides,
 279                                         packages,
 280                                         mainClass,



 281                                         hashCode);
 282     }
 283 }
< prev index next >