Skip to content

Commit

Permalink
Merge pull request #348 from Charliocat/master
Browse files Browse the repository at this point in the history
Changed to try with resources
  • Loading branch information
gnodet committed Jan 23, 2019
2 parents 7783c03 + 804959e commit 8de0b68
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions builtins/src/main/java/org/jline/builtins/Completers.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -302,20 +303,17 @@ public void complete(LineReader reader, ParsedLine commandLine, final List<Candi
curBuf = "";
current = getUserDir();
}
try {
Files.newDirectoryStream(current, this::accept).forEach(p -> {
try (DirectoryStream<Path> directory = Files.newDirectoryStream(current, this::accept)) {
directory.forEach(p -> {
String value = curBuf + p.getFileName().toString();
if (Files.isDirectory(p)) {
candidates.add(new Candidate(
value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : ""),
getDisplay(reader.getTerminal(), p),
null, null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null,
null,
false));
candidates.add(
new Candidate(value + (reader.isSet(LineReader.Option.AUTO_PARAM_SLASH) ? sep : ""),
getDisplay(reader.getTerminal(), p), null, null,
reader.isSet(LineReader.Option.AUTO_REMOVE_SLASH) ? sep : null, null, false));
} else {
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p),
null, null, null, null, true));
candidates.add(new Candidate(value, getDisplay(reader.getTerminal(), p), null, null, null, null,
true));
}
});
} catch (IOException e) {
Expand Down

0 comments on commit 8de0b68

Please sign in to comment.