Skip to content

Commit 4582d23

Browse files
committed
Simplify relativization of paths in JDKFileTreeWatch
1 parent 3bdafe6 commit 4582d23

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/main/java/engineering/swat/watch/WatchEvent.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ public Path calculateFullPath() {
106106
}
107107

108108
/**
109-
* @return The file name of the full path of this event, but without
109+
* @return The file name of the full path of this event, or {@code null} if
110+
* it has zero elements (cf. {@link Path#getFileName()}), but without
110111
* calculating the full path. This method is equivalent to, but more
111-
* efficient than, <code>calculateFullPath().getFileName()</code>.
112+
* efficient than, {@code calculateFullPath().getFileName()}.
112113
*/
113-
public Path getFileName() {
114+
public @Nullable Path getFileName() {
114115
return relativePath.getParent() == null ? rootPath.getFileName() : relativePath.getFileName();
115116
}
116117

src/main/java/engineering/swat/watch/impl/jdk/JDKFileTreeWatch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public JDKFileTreeWatch(Path rootPath, Path relativePathParent, Executor exec,
6868
// `rootPath` (instead of `path`, as is the default behavior)
6969
@Override
7070
public WatchEvent relativize(WatchEvent event) {
71+
var fileName = event.getFileName();
7172
return new WatchEvent(event.getKind(), rootPath,
72-
relativePathParent.resolve(event.getFileName()));
73+
fileName == null ? relativePathParent : relativePathParent.resolve(fileName));
7374
}
7475

7576
// Override to ensure that this watch translates JDK events using

0 commit comments

Comments
 (0)