Skip to content

Commit 9bdda4d

Browse files
committed
Clarify 'fragments' in JavaDocs for file manipulation operations
1 parent bcdfe2d commit 9bdda4d

File tree

7 files changed

+85
-17
lines changed

7 files changed

+85
-17
lines changed

java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/PackageContainerGroupAssert.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,16 @@ public ClassLoaderAssert classLoader() {
105105
/**
106106
* Assert that the given file does not exist.
107107
*
108+
* <pre><code>
109+
* // Using platform-specific separators.
110+
* assertions.fileDoesNotExist("foo/bar/baz.txt")...;
111+
*
112+
* // Letting JCT infer the correct path separators to use (recommended).
113+
* assertions.fileDoesNotExist("foo", "bar", "baz.txt");
114+
* </code></pre>
115+
*
108116
* @param fragment the first part of the path.
109-
* @param fragments additional parts of the path.
117+
* @param fragments any additional parts of the path.
110118
* @return this assertion object for further assertions.
111119
* @throws AssertionError if the file exists, or if the container group is null.
112120
* @throws NullPointerException if any of the fragments are null.
@@ -138,8 +146,16 @@ public PackageContainerGroupAssert fileDoesNotExist(String fragment, String... f
138146
/**
139147
* Assert that the given file exists.
140148
*
141-
* @param fragment the path fragment.
142-
* @param fragments any additional path fragments.
149+
* <pre><code>
150+
* // Using platform-specific separators.
151+
* assertions.fileExists("foo/bar/baz.txt")...;
152+
*
153+
* // Letting JCT infer the correct path separators to use (recommended).
154+
* assertions.fileExists("foo", "bar", "baz.txt");
155+
* </code></pre>
156+
*
157+
* @param fragment the first part of the path.
158+
* @param fragments any additional parts of the path.
143159
* @return assertions to perform on the path of the file that exists.
144160
* @throws AssertionError if the file does not exist, or if the container group is null.
145161
* @throws NullPointerException if any of the fragments are null.

java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/Container.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,18 @@ public interface Container extends Closeable {
5656
/**
5757
* Find the physical path to a given string file path.
5858
*
59-
* @param fragment the first fragment to the file to find.
60-
* @param fragments any additional fragments to the file to find.
59+
* <p>Examples:
60+
*
61+
* <pre><code>
62+
* // Using platform-specific separators ('/' for in-memory file systems).
63+
* container.getFile("foo/bar/baz.txt");
64+
*
65+
* // Letting JCT infer the correct path separators to use.
66+
* container.getFile("foo", "bar", "baz.txt");
67+
* </code></pre>
68+
*
69+
* @param fragment the first part of the file name.
70+
* @param fragments any additional parts of the file name to find.
6171
* @return the path if the file exists, or null if it does not exist.
6272
*/
6373
@Nullable
@@ -121,6 +131,8 @@ public interface Container extends Closeable {
121131
/**
122132
* Get a module finder for this container.
123133
*
134+
* <p>Note that this will not detect modules that are not yet compiled.
135+
*
124136
* @return the module finder for this container, or {@code null} if not relevant to the
125137
* implementation.
126138
*/
@@ -161,8 +173,12 @@ public interface Container extends Closeable {
161173
/**
162174
* List all the file objects that match the given criteria in this group.
163175
*
176+
* <p>The results are filled into a given collection, since this call may be made many times
177+
* per compliation, and this reduces the memory overhead needed in such cases.
178+
*
164179
* @param packageName the package name to look in.
165-
* @param kinds the kinds of file to look for.
180+
* @param kinds the kinds of file to look for. Set to {@code Set.of(Kind.OTHER)} to find
181+
* all types of file.
166182
* @param recurse {@code true} to recurse subpackages, {@code false} to only consider the
167183
* given package.
168184
* @param collection the collection to fill.

java-compiler-testing/src/main/java/io/github/ascopes/jct/containers/PackageContainerGroup.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ public interface PackageContainerGroup extends ContainerGroup {
8484
*
8585
* <p>Modules are treated as subdirectories.
8686
*
87+
* <pre><code>
88+
* // Using platform-specific separators.
89+
* containerGroup.getFile("foo/bar/baz.txt")...;
90+
*
91+
* // Letting JCT infer the correct path separators to use (recommended).
92+
* containerGroup.getFile("foo", "bar", "baz.txt");
93+
* </code></pre>
94+
*
8795
* @param fragment the first part of the path.
8896
* @param fragments any additional parts of the path.
8997
* @return the first occurrence of the path in this group, or null if not found.

java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ public static Path resourceNameToPath(Path directory, String packageName, String
258258
* Convert a relative class path resource path to a NIO path.
259259
*
260260
* @param directory the directory the resource sits within.
261-
* @param fragment the first path fragment.
262-
* @param fragments any additional path fragments.
261+
* @param fragment the first part of the path.
262+
* @param fragments the rest of the path.
263263
* @return the path to the resource on the file system.
264264
*/
265265
public static Path relativeResourceNameToPath(

java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/DirectoryBuilder.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ public interface DirectoryBuilder {
3838
*
3939
* <p>This uses the default file system.
4040
*
41-
* @param first the first path fragment of the directory to copy from.
42-
* @param rest any additional path fragments to copy from.
41+
* <p>Examples:
42+
*
43+
* <pre><code>
44+
* // Using platform-specific separators.
45+
* directoryBuilder.copyContentsFrom("foo/bar/baz");
46+
*
47+
* // Letting JCT infer the correct path separators to use (recommended).
48+
* directoryBuilder.copyContentsFrom("foo", "bar", "baz");
49+
* </code></pre>
50+
*
51+
* @param first the first part of the path to the directory to copy from.
52+
* @param rest any additional parts of the path.
4353
* @return the root managed directory for further configuration.
4454
*/
4555
ManagedDirectory copyContentsFrom(String first, String... rest);

java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/ManagedDirectory.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,18 @@ default ManagedDirectory and() {
7575
/**
7676
* Create a directory builder for the given path in this RAM file system.
7777
*
78-
* @param first the first path fragment.
79-
* @param rest any additional path fragments.
78+
* <p>Examples:
79+
*
80+
* <pre><code>
81+
* // Using platform-specific separators.
82+
* dir.createDirectory("foo/bar/baz")...;
83+
*
84+
* // Letting JCT infer the correct path separators to use (recommended).
85+
* dir.createDirectory("foo", "bar", "baz")...;
86+
* </code></pre>
87+
*
88+
* @param first the first part of the path.
89+
* @param rest any additional parts of the path.
8090
* @return the directory builder.
8191
*/
8292
@CheckReturnValue
@@ -85,12 +95,20 @@ default ManagedDirectory and() {
8595
/**
8696
* Create a file builder for the given path in this RAM file system.
8797
*
88-
* @param first the first path fragment.
89-
* @param rest any additional path fragments.
98+
* <pre><code>
99+
* // Using platform-specific separators.
100+
* dir.createFile("foo/bar/baz.txt")...;
101+
*
102+
* // Letting JCT infer the correct path separators to use (recommended).
103+
* dir.createFile("foo", "bar", "baz.txt")...;
104+
* </code></pre>
105+
*
106+
* @param fragment the first part of the path.
107+
* @param fragments any additional parts of the path.
90108
* @return the file builder.
91109
*/
92110
@CheckReturnValue
93-
FileBuilder createFile(String first, String... rest);
111+
FileBuilder createFile(String fragment, String... fragments);
94112

95113
/**
96114
* Get the identifying name of the temporary file system.

java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/AbstractManagedDirectory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public String getName() {
104104

105105
@CheckReturnValue
106106
@Override
107-
public FileBuilder createFile(String first, String... rest) {
108-
return new FileBuilderImpl(this, first, rest);
107+
public FileBuilder createFile(String fragment, String... fragments) {
108+
return new FileBuilderImpl(this, fragment, fragments);
109109
}
110110

111111
@CheckReturnValue

0 commit comments

Comments
 (0)