8255273: jshell crashes with UnsupportedOperationException: Should not get here.
Reviewed-by: vromero
This commit is contained in:
parent
e43aee58e1
commit
325eecbccb
@ -364,11 +364,49 @@ class ConsoleIOContext extends IOContext {
|
|||||||
.distinct()
|
.distinct()
|
||||||
.count() == 2;
|
.count() == 2;
|
||||||
boolean tooManyItems = suggestions.size() > /*in.getAutoprintThreshold()*/AUTOPRINT_THRESHOLD;
|
boolean tooManyItems = suggestions.size() > /*in.getAutoprintThreshold()*/AUTOPRINT_THRESHOLD;
|
||||||
CompletionTask ordinaryCompletion =
|
CompletionTask ordinaryCompletion;
|
||||||
new OrdinaryCompletionTask(suggestions,
|
List<? extends CharSequence> ordinaryCompletionToShow;
|
||||||
anchor[0],
|
|
||||||
!command && !doc.isEmpty(),
|
if (hasBoth) {
|
||||||
hasBoth);
|
ordinaryCompletionToShow =
|
||||||
|
suggestions.stream()
|
||||||
|
.filter(Suggestion::matchesType)
|
||||||
|
.map(Suggestion::continuation)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
ordinaryCompletionToShow =
|
||||||
|
suggestions.stream()
|
||||||
|
.map(Suggestion::continuation)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ordinaryCompletionToShow.isEmpty()) {
|
||||||
|
ordinaryCompletion = new ContinueCompletionTask();
|
||||||
|
} else {
|
||||||
|
Optional<String> prefixOpt =
|
||||||
|
suggestions.stream()
|
||||||
|
.map(Suggestion::continuation)
|
||||||
|
.reduce(ConsoleIOContext::commonPrefix);
|
||||||
|
|
||||||
|
String prefix =
|
||||||
|
prefixOpt.orElse("").substring(cursor - anchor[0]);
|
||||||
|
|
||||||
|
if (!prefix.isEmpty() && !command) {
|
||||||
|
//the completion will fill in the prefix, which will invalidate
|
||||||
|
//the documentation, avoid adding documentation tasks into the
|
||||||
|
//todo list:
|
||||||
|
doc = List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
ordinaryCompletion =
|
||||||
|
new OrdinaryCompletionTask(ordinaryCompletionToShow,
|
||||||
|
prefix,
|
||||||
|
!command && !doc.isEmpty(),
|
||||||
|
hasBoth);
|
||||||
|
}
|
||||||
|
|
||||||
CompletionTask allCompletion = new AllSuggestionsCompletionTask(suggestions, anchor[0]);
|
CompletionTask allCompletion = new AllSuggestionsCompletionTask(suggestions, anchor[0]);
|
||||||
|
|
||||||
todo = new ArrayList<>();
|
todo = new ArrayList<>();
|
||||||
@ -567,17 +605,17 @@ class ConsoleIOContext extends IOContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class OrdinaryCompletionTask implements CompletionTask {
|
private final class OrdinaryCompletionTask implements CompletionTask {
|
||||||
private final List<Suggestion> suggestions;
|
private final List<? extends CharSequence> toShow;
|
||||||
private final int anchor;
|
private final String prefix;
|
||||||
private final boolean cont;
|
private final boolean cont;
|
||||||
private final boolean showSmart;
|
private final boolean showSmart;
|
||||||
|
|
||||||
public OrdinaryCompletionTask(List<Suggestion> suggestions,
|
public OrdinaryCompletionTask(List<? extends CharSequence> toShow,
|
||||||
int anchor,
|
String prefix,
|
||||||
boolean cont,
|
boolean cont,
|
||||||
boolean showSmart) {
|
boolean showSmart) {
|
||||||
this.suggestions = suggestions;
|
this.toShow = toShow;
|
||||||
this.anchor = anchor;
|
this.prefix = prefix;
|
||||||
this.cont = cont;
|
this.cont = cont;
|
||||||
this.showSmart = showSmart;
|
this.showSmart = showSmart;
|
||||||
}
|
}
|
||||||
@ -589,34 +627,7 @@ class ConsoleIOContext extends IOContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result perform(String text, int cursor) throws IOException {
|
public Result perform(String text, int cursor) throws IOException {
|
||||||
List<? extends CharSequence> toShow;
|
in.putString(prefix);
|
||||||
|
|
||||||
if (showSmart) {
|
|
||||||
toShow =
|
|
||||||
suggestions.stream()
|
|
||||||
.filter(Suggestion::matchesType)
|
|
||||||
.map(Suggestion::continuation)
|
|
||||||
.distinct()
|
|
||||||
.toList();
|
|
||||||
} else {
|
|
||||||
toShow =
|
|
||||||
suggestions.stream()
|
|
||||||
.map(Suggestion::continuation)
|
|
||||||
.distinct()
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toShow.isEmpty()) {
|
|
||||||
return Result.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<String> prefix =
|
|
||||||
suggestions.stream()
|
|
||||||
.map(Suggestion::continuation)
|
|
||||||
.reduce(ConsoleIOContext::commonPrefix);
|
|
||||||
|
|
||||||
String prefixStr = prefix.orElse("").substring(cursor - anchor);
|
|
||||||
in.putString(prefixStr);
|
|
||||||
|
|
||||||
boolean showItems = toShow.size() > 1 || showSmart;
|
boolean showItems = toShow.size() > 1 || showSmart;
|
||||||
|
|
||||||
@ -625,7 +636,7 @@ class ConsoleIOContext extends IOContext {
|
|||||||
printColumns(toShow);
|
printColumns(toShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!prefixStr.isEmpty())
|
if (!prefix.isEmpty())
|
||||||
return showItems ? Result.FINISH : Result.SKIP_NOREPAINT;
|
return showItems ? Result.FINISH : Result.SKIP_NOREPAINT;
|
||||||
|
|
||||||
return cont ? Result.CONTINUE : Result.FINISH;
|
return cont ? Result.CONTINUE : Result.FINISH;
|
||||||
@ -798,6 +809,19 @@ class ConsoleIOContext extends IOContext {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class ContinueCompletionTask implements ConsoleIOContext.CompletionTask {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String description() {
|
||||||
|
throw new UnsupportedOperationException("Should not get here.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletionTask.Result perform(String text, int cursor) throws IOException {
|
||||||
|
return CompletionTask.Result.CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean terminalEditorRunning() {
|
public boolean terminalEditorRunning() {
|
||||||
Terminal terminal = in.getTerminal();
|
Terminal terminal = in.getTerminal();
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8177076 8185426 8189595 8188072 8221759
|
* @bug 8177076 8185426 8189595 8188072 8221759 8255273
|
||||||
* @modules
|
* @modules
|
||||||
* jdk.compiler/com.sun.tools.javac.api
|
* jdk.compiler/com.sun.tools.javac.api
|
||||||
* jdk.compiler/com.sun.tools.javac.main
|
* jdk.compiler/com.sun.tools.javac.main
|
||||||
@ -331,4 +331,13 @@ public class ToolTabSnippetTest extends UITesting {
|
|||||||
//where:
|
//where:
|
||||||
private final Compiler compiler = new Compiler();
|
private final Compiler compiler = new Compiler();
|
||||||
|
|
||||||
|
public void testDocumentationAfterInsert() throws Exception {
|
||||||
|
doRunTest((inputSink, out) -> {
|
||||||
|
inputSink.write("import java.time.*\n");
|
||||||
|
waitOutput(out, PROMPT);
|
||||||
|
|
||||||
|
inputSink.write("new Instant" + TAB);
|
||||||
|
waitOutput(out, PROMPT + "new InstantiationE");
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user