mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8268056: Update java.net and java.nio to use switch expressions
Reviewed-by: dfuchs, michaelm, chegar, iris, alanb
This commit is contained in:
parent
9cfd560bb1
commit
438895903b
2 changed files with 30 additions and 41 deletions
|
@ -2803,40 +2803,37 @@ public final class Files {
|
|||
try (FileTreeWalker walker = new FileTreeWalker(options, maxDepth)) {
|
||||
FileTreeWalker.Event ev = walker.walk(start);
|
||||
do {
|
||||
FileVisitResult result;
|
||||
switch (ev.type()) {
|
||||
case ENTRY :
|
||||
FileVisitResult result = switch (ev.type()) {
|
||||
case ENTRY -> {
|
||||
IOException ioe = ev.ioeException();
|
||||
if (ioe == null) {
|
||||
assert ev.attributes() != null;
|
||||
result = visitor.visitFile(ev.file(), ev.attributes());
|
||||
yield visitor.visitFile(ev.file(), ev.attributes());
|
||||
} else {
|
||||
result = visitor.visitFileFailed(ev.file(), ioe);
|
||||
yield visitor.visitFileFailed(ev.file(), ioe);
|
||||
}
|
||||
break;
|
||||
|
||||
case START_DIRECTORY :
|
||||
result = visitor.preVisitDirectory(ev.file(), ev.attributes());
|
||||
}
|
||||
case START_DIRECTORY -> {
|
||||
var res = visitor.preVisitDirectory(ev.file(), ev.attributes());
|
||||
|
||||
// if SKIP_SIBLINGS and SKIP_SUBTREE is returned then
|
||||
// there shouldn't be any more events for the current
|
||||
// directory.
|
||||
if (result == FileVisitResult.SKIP_SUBTREE ||
|
||||
result == FileVisitResult.SKIP_SIBLINGS)
|
||||
if (res == FileVisitResult.SKIP_SUBTREE ||
|
||||
res == FileVisitResult.SKIP_SIBLINGS)
|
||||
walker.pop();
|
||||
break;
|
||||
|
||||
case END_DIRECTORY :
|
||||
result = visitor.postVisitDirectory(ev.file(), ev.ioeException());
|
||||
yield res;
|
||||
}
|
||||
case END_DIRECTORY -> {
|
||||
var res = visitor.postVisitDirectory(ev.file(), ev.ioeException());
|
||||
|
||||
// SKIP_SIBLINGS is a no-op for postVisitDirectory
|
||||
if (result == FileVisitResult.SKIP_SIBLINGS)
|
||||
result = FileVisitResult.CONTINUE;
|
||||
break;
|
||||
|
||||
default :
|
||||
throw new AssertionError("Should not get here");
|
||||
}
|
||||
if (res == FileVisitResult.SKIP_SIBLINGS)
|
||||
res = FileVisitResult.CONTINUE;
|
||||
yield res;
|
||||
}
|
||||
default -> throw new AssertionError("Should not get here");
|
||||
};
|
||||
|
||||
if (Objects.requireNonNull(result) != FileVisitResult.CONTINUE) {
|
||||
if (result == FileVisitResult.TERMINATE) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue