Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 1d16c91

Browse files
committed
8291512: Snippetize modules API examples
Reviewed-by: darcy
1 parent 36c00fd commit 1d16c91

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

src/java.base/share/classes/java/lang/ModuleLayer.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,22 @@
122122
* in this class causes a {@link NullPointerException NullPointerException} to
123123
* be thrown. </p>
124124
*
125-
* <h2> Example usage: </h2>
125+
* <h2> Example </h2>
126126
*
127127
* <p> This example creates a configuration by resolving a module named
128128
* "{@code myapp}" with the configuration for the boot layer as the parent. It
129129
* then creates a new layer with the modules in this configuration. All modules
130130
* are defined to the same class loader. </p>
131131
*
132-
* <pre>{@code
132+
* {@snippet :
133133
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
134-
*
135134
* ModuleLayer parent = ModuleLayer.boot();
136-
*
137-
* Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("myapp"));
138-
*
135+
* Configuration cf = parent.configuration()
136+
* .resolve(finder, ModuleFinder.of(), Set.of("myapp"));
139137
* ClassLoader scl = ClassLoader.getSystemClassLoader();
140-
*
141138
* ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
142-
*
143139
* Class<?> c = layer.findLoader("myapp").loadClass("app.Main");
144-
* }</pre>
140+
* }
145141
*
146142
* @since 9
147143
* @see Module#getLayer()

src/java.base/share/classes/java/lang/module/Configuration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@
8383
* parent configuration. It prints the name of each resolved module and the
8484
* names of the modules that each module reads. </p>
8585
*
86-
* <pre>{@code
86+
* {@snippet :
87+
* Path dir1 = ..., dir2 = ..., dir3 = ...;
8788
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
88-
*
8989
* Configuration parent = ModuleLayer.boot().configuration();
90-
*
9190
* Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
9291
* cf.modules().forEach(m -> {
9392
* System.out.format("%s -> %s%n",
@@ -96,7 +95,7 @@
9695
* .map(ResolvedModule::name)
9796
* .collect(Collectors.joining(", ")));
9897
* });
99-
* }</pre>
98+
* }
10099
*
101100
* @since 9
102101
* @see java.lang.ModuleLayer

src/java.base/share/classes/java/lang/module/ModuleDescriptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,13 +1467,14 @@ public Set<String> packages() {
14671467
* <cite>The Java Language Specification</cite>. </p>
14681468
*
14691469
* <p> Example usage: </p>
1470-
* <pre>{@code ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
1470+
* {@snippet :
1471+
* ModuleDescriptor descriptor = ModuleDescriptor.newModule("stats.core")
14711472
* .requires("java.base")
14721473
* .exports("org.acme.stats.core.clustering")
14731474
* .exports("org.acme.stats.core.regression")
14741475
* .packages(Set.of("org.acme.stats.core.internal"))
14751476
* .build();
1476-
* }</pre>
1477+
* }
14771478
*
14781479
* @apiNote A {@code Builder} checks the components and invariants as
14791480
* components are added to the builder. The rationale for this is to detect

src/java.base/share/classes/java/lang/module/ModuleFinder.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@
5454
*
5555
* <p> Example usage: </p>
5656
*
57-
* <pre>{@code
58-
* Path dir1, dir2, dir3;
59-
*
57+
* {@snippet :
58+
* Path dir1 = ..., dir2 = ..., dir3 = ...;
6059
* ModuleFinder finder = ModuleFinder.of(dir1, dir2, dir3);
61-
*
6260
* Optional<ModuleReference> omref = finder.find("jdk.foo");
6361
* omref.ifPresent(mref -> ... );
64-
*
65-
* }</pre>
62+
* }
6663
*
6764
* <p> The {@link #find(String) find} and {@link #findAll() findAll} methods
6865
* defined here can fail for several reasons. These include I/O errors, errors

0 commit comments

Comments
 (0)