mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8291512: Snippetize modules API examples
Reviewed-by: darcy
This commit is contained in:
parent
36c00fdd74
commit
1d16c91ba7
4 changed files with 14 additions and 21 deletions
|
@ -122,26 +122,22 @@ import sun.security.util.SecurityConstants;
|
||||||
* in this class causes a {@link NullPointerException NullPointerException} to
|
* in this class causes a {@link NullPointerException NullPointerException} to
|
||||||
* be thrown. </p>
|
* be thrown. </p>
|
||||||
*
|
*
|
||||||
* <h2> Example usage: </h2>
|
* <h2> Example </h2>
|
||||||
*
|
*
|
||||||
* <p> This example creates a configuration by resolving a module named
|
* <p> This example creates a configuration by resolving a module named
|
||||||
* "{@code myapp}" with the configuration for the boot layer as the parent. It
|
* "{@code myapp}" with the configuration for the boot layer as the parent. It
|
||||||
* then creates a new layer with the modules in this configuration. All modules
|
* then creates a new layer with the modules in this configuration. All modules
|
||||||
* are defined to the same class loader. </p>
|
* are defined to the same class loader. </p>
|
||||||
*
|
*
|
||||||
* <pre>{@code
|
* {@snippet :
|
||||||
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
|
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
|
||||||
*
|
|
||||||
* ModuleLayer parent = ModuleLayer.boot();
|
* ModuleLayer parent = ModuleLayer.boot();
|
||||||
*
|
* Configuration cf = parent.configuration()
|
||||||
* Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp"));
|
* .resolve(finder, ModuleFinder.of(), Set.of("myapp"));
|
||||||
*
|
|
||||||
* ClassLoader scl = ClassLoader.getSystemClassLoader();
|
* ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||||
*
|
|
||||||
* ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
|
* ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
|
||||||
*
|
|
||||||
* Class<?> c = layer.findLoader("myapp").loadClass("app.Main");
|
* Class<?> c = layer.findLoader("myapp").loadClass("app.Main");
|
||||||
* }</pre>
|
* }
|
||||||
*
|
*
|
||||||
* @since 9
|
* @since 9
|
||||||
* @see Module#getLayer()
|
* @see Module#getLayer()
|
||||||
|
|
|
@ -83,11 +83,10 @@ import jdk.internal.vm.annotation.Stable;
|
||||||
* parent configuration. It prints the name of each resolved module and the
|
* parent configuration. It prints the name of each resolved module and the
|
||||||
* names of the modules that each module reads. </p>
|
* names of the modules that each module reads. </p>
|
||||||
*
|
*
|
||||||
* <pre>{@code
|
* {@snippet :
|
||||||
|
* Path dir1 = ..., dir2 = ..., dir3 = ...;
|
||||||
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
|
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
|
||||||
*
|
|
||||||
* Configuration parent = ModuleLayer.boot().configuration();
|
* Configuration parent = ModuleLayer.boot().configuration();
|
||||||
*
|
|
||||||
* Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
|
* Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
|
||||||
* cf.modules().forEach(m -> {
|
* cf.modules().forEach(m -> {
|
||||||
* System.out.format("%s -> %s%n",
|
* System.out.format("%s -> %s%n",
|
||||||
|
@ -96,7 +95,7 @@ import jdk.internal.vm.annotation.Stable;
|
||||||
* .map(ResolvedModule::name)
|
* .map(ResolvedModule::name)
|
||||||
* .collect(Collectors.joining(", ")));
|
* .collect(Collectors.joining(", ")));
|
||||||
* });
|
* });
|
||||||
* }</pre>
|
* }
|
||||||
*
|
*
|
||||||
* @since 9
|
* @since 9
|
||||||
* @see java.lang.ModuleLayer
|
* @see java.lang.ModuleLayer
|
||||||
|
|
|
@ -1467,13 +1467,14 @@ public class ModuleDescriptor
|
||||||
* <cite>The Java Language Specification</cite>. </p>
|
* <cite>The Java Language Specification</cite>. </p>
|
||||||
*
|
*
|
||||||
* <p> Example usage: </p>
|
* <p> Example usage: </p>
|
||||||
* <pre>{@code ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
|
* {@snippet :
|
||||||
|
* ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
|
||||||
* .requires("java.base")
|
* .requires("java.base")
|
||||||
* .exports("org.acme.stats.core.clustering")
|
* .exports("org.acme.stats.core.clustering")
|
||||||
* .exports("org.acme.stats.core.regression")
|
* .exports("org.acme.stats.core.regression")
|
||||||
* .packages(Set.of("org.acme.stats.core.internal"))
|
* .packages(Set.of("org.acme.stats.core.internal"))
|
||||||
* .build();
|
* .build();
|
||||||
* }</pre>
|
* }
|
||||||
*
|
*
|
||||||
* @apiNote A {@code Builder} checks the components and invariants as
|
* @apiNote A {@code Builder} checks the components and invariants as
|
||||||
* components are added to the builder. The rationale for this is to detect
|
* components are added to the builder. The rationale for this is to detect
|
||||||
|
|
|
@ -54,15 +54,12 @@ import jdk.internal.module.SystemModuleFinders;
|
||||||
*
|
*
|
||||||
* <p> Example usage: </p>
|
* <p> Example usage: </p>
|
||||||
*
|
*
|
||||||
* <pre>{@code
|
* {@snippet :
|
||||||
* Path dir1, dir2, dir3;
|
* Path dir1 = ..., dir2 = ..., dir3 = ...;
|
||||||
*
|
|
||||||
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
|
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
|
||||||
*
|
|
||||||
* Optional<ModuleReference> omref = finder.find("jdk.foo");
|
* Optional<ModuleReference> omref = finder.find("jdk.foo");
|
||||||
* omref.ifPresent(mref -> ... );
|
* omref.ifPresent(mref -> ... );
|
||||||
*
|
* }
|
||||||
* }</pre>
|
|
||||||
*
|
*
|
||||||
* <p> The {@link #find(String) find} and {@link #findAll() findAll} methods
|
* <p> The {@link #find(String) find} and {@link #findAll() findAll} methods
|
||||||
* defined here can fail for several reasons. These include I/O errors, errors
|
* defined here can fail for several reasons. These include I/O errors, errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue