Skip to content

Commit 7febc2f

Browse files
committed
Make PathFileObject into an interface and hide the implementation
1 parent 224c031 commit 7febc2f

19 files changed

+471
-335
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@
1515
*/
1616
package io.github.ascopes.jct.assertions;
1717

18+
import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
19+
import static io.github.ascopes.jct.utils.IterableUtils.combineOneOrMore;
20+
import static io.github.ascopes.jct.utils.IterableUtils.requireNonNullValues;
21+
import static io.github.ascopes.jct.utils.StringUtils.quoted;
22+
import static io.github.ascopes.jct.utils.StringUtils.quotedIterable;
23+
import static java.util.Objects.requireNonNull;
24+
import static java.util.function.Predicate.not;
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
1827
import io.github.ascopes.jct.containers.PackageContainerGroup;
1928
import io.github.ascopes.jct.repr.LocationRepresentation;
2029
import io.github.ascopes.jct.utils.StringUtils;
21-
import org.apiguardian.api.API;
22-
import org.apiguardian.api.API.Status;
23-
import org.assertj.core.api.AbstractPathAssert;
24-
import org.jspecify.annotations.Nullable;
2530
import java.nio.file.Path;
2631
import java.util.Objects;
2732
import java.util.Optional;
2833
import java.util.Set;
2934
import java.util.stream.Collectors;
3035
import java.util.stream.StreamSupport;
31-
32-
import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
33-
import static io.github.ascopes.jct.utils.IterableUtils.combineOneOrMore;
34-
import static io.github.ascopes.jct.utils.IterableUtils.requireNonNullValues;
35-
import static io.github.ascopes.jct.utils.StringUtils.quoted;
36-
import static io.github.ascopes.jct.utils.StringUtils.quotedIterable;
37-
import static java.util.Objects.requireNonNull;
38-
import static java.util.function.Predicate.not;
39-
import static org.assertj.core.api.Assertions.assertThat;
36+
import org.apiguardian.api.API;
37+
import org.apiguardian.api.API.Status;
38+
import org.assertj.core.api.AbstractPathAssert;
39+
import org.jspecify.annotations.Nullable;
4040

4141
/**
4242
* Assertions for package container groups.

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
import io.github.ascopes.jct.filemanagers.PathFileObject;
1919
import io.github.ascopes.jct.workspaces.PathRoot;
20-
import java.io.UnsupportedEncodingException;
21-
import org.apiguardian.api.API;
22-
import org.apiguardian.api.API.Status;
23-
20+
import java.io.IOException;
21+
import java.nio.file.Path;
22+
import java.util.Collection;
23+
import java.util.List;
24+
import java.util.Map;
25+
import java.util.Set;
2426
import javax.tools.FileObject;
2527
import javax.tools.JavaFileManager.Location;
2628
import javax.tools.JavaFileObject;
2729
import javax.tools.JavaFileObject.Kind;
28-
import java.io.IOException;
29-
import java.nio.file.Path;
30-
import java.util.*;
30+
import org.apiguardian.api.API;
31+
import org.apiguardian.api.API.Status;
3132

3233
/**
3334
* Base interface representing a group of package-oriented paths.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@
2727
import io.github.ascopes.jct.workspaces.PathRoot;
2828
import java.io.IOException;
2929
import java.nio.file.Path;
30-
import java.util.*;
30+
import java.util.ArrayList;
31+
import java.util.Collection;
32+
import java.util.Collections;
33+
import java.util.HashSet;
34+
import java.util.LinkedHashMap;
35+
import java.util.LinkedHashSet;
36+
import java.util.List;
37+
import java.util.Locale;
38+
import java.util.Map;
39+
import java.util.ServiceLoader;
40+
import java.util.Set;
3141
import javax.tools.JavaFileManager.Location;
3242
import javax.tools.JavaFileObject;
3343
import javax.tools.JavaFileObject.Kind;

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import io.github.ascopes.jct.containers.Container;
2222
import io.github.ascopes.jct.filemanagers.PathFileObject;
23+
import io.github.ascopes.jct.filemanagers.impl.PathFileObjectImpl;
2324
import io.github.ascopes.jct.utils.FileUtils;
2425
import io.github.ascopes.jct.utils.Lazy;
2526
import io.github.ascopes.jct.utils.ToStringBuilder;
@@ -33,7 +34,12 @@
3334
import java.nio.file.Path;
3435
import java.nio.file.ProviderNotFoundException;
3536
import java.nio.file.spi.FileSystemProvider;
36-
import java.util.*;
37+
import java.util.ArrayList;
38+
import java.util.Collection;
39+
import java.util.Collections;
40+
import java.util.HashMap;
41+
import java.util.Map;
42+
import java.util.Set;
3743
import javax.tools.JavaFileManager.Location;
3844
import javax.tools.JavaFileObject;
3945
import javax.tools.JavaFileObject.Kind;
@@ -119,7 +125,7 @@ public PathFileObject getFileForInput(String packageName, String relativeName) {
119125
return null;
120126
}
121127

122-
return new PathFileObject(location, file.getRoot(), file);
128+
return new PathFileObjectImpl(location, file.getRoot(), file);
123129
}
124130

125131
@Override
@@ -149,7 +155,7 @@ public PathFileObject getJavaFileForInput(String binaryName, Kind kind) {
149155
return null;
150156
}
151157

152-
return new PathFileObject(location, file.getRoot(), file);
158+
return new PathFileObjectImpl(location, file.getRoot(), file);
153159
}
154160

155161
@Override
@@ -216,7 +222,7 @@ public void listFileObjects(
216222
try (var walker = Files.walk(packagePath, maxDepth, FileVisitOption.FOLLOW_LINKS)) {
217223
walker
218224
.filter(FileUtils.fileWithAnyKind(kinds))
219-
.map(path -> new PathFileObject(location, path.getRoot(), path))
225+
.map(path -> new PathFileObjectImpl(location, path.getRoot(), path))
220226
.forEach(collection::add);
221227
}
222228
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import org.apiguardian.api.API;
2424
import org.apiguardian.api.API.Status;
2525

26-
import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
27-
2826
/**
2927
* An extension of the Java {@link URLClassLoader} that wraps around container groups.
3028
*

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import io.github.ascopes.jct.containers.Container;
2121
import io.github.ascopes.jct.filemanagers.PathFileObject;
22+
import io.github.ascopes.jct.filemanagers.impl.PathFileObjectImpl;
2223
import io.github.ascopes.jct.utils.FileUtils;
2324
import io.github.ascopes.jct.utils.ToStringBuilder;
2425
import io.github.ascopes.jct.workspaces.PathRoot;
@@ -92,14 +93,14 @@ public PathFileObject getFileForInput(String packageName, String relativeName) {
9293
var path = FileUtils.resourceNameToPath(root.getPath(), packageName, relativeName);
9394

9495
return Files.isRegularFile(path)
95-
? new PathFileObject(location, root.getPath(), path)
96+
? new PathFileObjectImpl(location, root.getPath(), path)
9697
: null;
9798
}
9899

99100
@Override
100101
public PathFileObject getFileForOutput(String packageName, String relativeName) {
101102
var path = FileUtils.resourceNameToPath(root.getPath(), packageName, relativeName);
102-
return new PathFileObject(location, root.getPath(), path);
103+
return new PathFileObjectImpl(location, root.getPath(), path);
103104
}
104105

105106
@Override
@@ -111,14 +112,14 @@ public PathRoot getInnerPathRoot() {
111112
public PathFileObject getJavaFileForInput(String binaryName, Kind kind) {
112113
var path = FileUtils.binaryNameToPath(root.getPath(), binaryName, kind);
113114
return Files.isRegularFile(path)
114-
? new PathFileObject(location, root.getPath(), path)
115+
? new PathFileObjectImpl(location, root.getPath(), path)
115116
: null;
116117
}
117118

118119
@Override
119120
public PathFileObject getJavaFileForOutput(String className, Kind kind) {
120121
var path = FileUtils.binaryNameToPath(root.getPath(), className, kind);
121-
return new PathFileObject(location, root.getPath(), path);
122+
return new PathFileObjectImpl(location, root.getPath(), path);
122123
}
123124

124125
@Override
@@ -168,7 +169,7 @@ public void listFileObjects(
168169
try (var walker = Files.walk(basePath, maxDepth, FileVisitOption.FOLLOW_LINKS)) {
169170
walker
170171
.filter(FileUtils.fileWithAnyKind(kinds))
171-
.map(path -> new PathFileObject(location, root.getPath(), path))
172+
.map(path -> new PathFileObjectImpl(location, root.getPath(), path))
172173
.forEach(collection::add);
173174
} catch (NoSuchFileException ex) {
174175
LOGGER.trace("Directory {} does not exist so is being ignored", root.getPath());

java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TeeWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package io.github.ascopes.jct.diagnostics;
1717

1818
import static java.util.Objects.requireNonNull;
19-
import static java.util.Objects.requireNonNullElse;
2019

2120
import java.io.IOException;
2221
import java.io.OutputStream;

0 commit comments

Comments
 (0)