author | jlahoda |
Tue, 24 Jan 2017 13:29:58 +0100 | |
changeset 43363 | a4ed2006a4c5 |
parent 42843 | a8d83044a192 |
child 43583 | d16e490ec827 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
38521 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33362 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.internal.jshell.tool; |
|
27 |
||
41865 | 28 |
import jdk.jshell.SourceCodeAnalysis.Documentation; |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
29 |
import jdk.jshell.SourceCodeAnalysis.QualifiedNames; |
33362 | 30 |
import jdk.jshell.SourceCodeAnalysis.Suggestion; |
31 |
||
32 |
import java.io.IOException; |
|
33 |
import java.io.InputStream; |
|
41628 | 34 |
import java.io.InterruptedIOException; |
33362 | 35 |
import java.io.PrintStream; |
36 |
import java.io.UncheckedIOException; |
|
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
37 |
import java.util.ArrayList; |
41865 | 38 |
import java.util.Arrays; |
38521 | 39 |
import java.util.Collection; |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
40 |
import java.util.Collections; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
41 |
import java.util.HashMap; |
41865 | 42 |
import java.util.Iterator; |
33362 | 43 |
import java.util.List; |
44 |
import java.util.Locale; |
|
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
45 |
import java.util.Map; |
33362 | 46 |
import java.util.Objects; |
47 |
import java.util.Optional; |
|
43363
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
48 |
import java.util.concurrent.atomic.AtomicBoolean; |
41865 | 49 |
import java.util.function.Function; |
38521 | 50 |
import java.util.stream.Collectors; |
51 |
import java.util.stream.Stream; |
|
33362 | 52 |
|
41865 | 53 |
import jdk.internal.shellsupport.doc.JavadocFormatter; |
33362 | 54 |
import jdk.internal.jline.NoInterruptUnixTerminal; |
55 |
import jdk.internal.jline.Terminal; |
|
56 |
import jdk.internal.jline.TerminalFactory; |
|
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
57 |
import jdk.internal.jline.TerminalSupport; |
33362 | 58 |
import jdk.internal.jline.WindowsTerminal; |
59 |
import jdk.internal.jline.console.ConsoleReader; |
|
60 |
import jdk.internal.jline.console.KeyMap; |
|
43363
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
61 |
import jdk.internal.jline.console.Operation; |
33362 | 62 |
import jdk.internal.jline.console.UserInterruptException; |
63 |
import jdk.internal.jline.console.completer.Completer; |
|
40767 | 64 |
import jdk.internal.jline.console.history.History; |
65 |
import jdk.internal.jline.console.history.MemoryHistory; |
|
38521 | 66 |
import jdk.internal.jline.extra.EditingHistory; |
33362 | 67 |
import jdk.internal.jshell.tool.StopDetectingInputStream.State; |
41631
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
68 |
import jdk.internal.misc.Signal; |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
69 |
import jdk.internal.misc.Signal.Handler; |
33362 | 70 |
|
71 |
class ConsoleIOContext extends IOContext { |
|
72 |
||
38521 | 73 |
private static final String HISTORY_LINE_PREFIX = "HISTORY_LINE_"; |
74 |
||
33362 | 75 |
final JShellTool repl; |
76 |
final StopDetectingInputStream input; |
|
77 |
final ConsoleReader in; |
|
78 |
final EditingHistory history; |
|
40767 | 79 |
final MemoryHistory userInputHistory = new MemoryHistory(); |
33362 | 80 |
|
81 |
String prefix = ""; |
|
82 |
||
83 |
ConsoleIOContext(JShellTool repl, InputStream cmdin, PrintStream cmdout) throws Exception { |
|
84 |
this.repl = repl; |
|
85 |
this.input = new StopDetectingInputStream(() -> repl.state.stop(), ex -> repl.hard("Error on input: %s", ex)); |
|
86 |
Terminal term; |
|
36501 | 87 |
if (System.getProperty("test.jdk") != null) { |
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
88 |
term = new TestTerminal(input); |
36501 | 89 |
} else if (System.getProperty("os.name").toLowerCase(Locale.US).contains(TerminalFactory.WINDOWS)) { |
33362 | 90 |
term = new JShellWindowsTerminal(input); |
91 |
} else { |
|
92 |
term = new JShellUnixTerminal(input); |
|
93 |
} |
|
94 |
term.init(); |
|
43363
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
95 |
AtomicBoolean allowSmart = new AtomicBoolean(); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
96 |
in = new ConsoleReader(cmdin, cmdout, term) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
97 |
@Override public KeyMap getKeys() { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
98 |
return new CheckCompletionKeyMap(super.getKeys(), allowSmart); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
99 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
100 |
}; |
33362 | 101 |
in.setExpandEvents(false); |
102 |
in.setHandleUserInterrupt(true); |
|
38521 | 103 |
List<String> persistenHistory = Stream.of(repl.prefs.keys()) |
104 |
.filter(key -> key.startsWith(HISTORY_LINE_PREFIX)) |
|
105 |
.sorted() |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
106 |
.map(key -> repl.prefs.get(key)) |
38521 | 107 |
.collect(Collectors.toList()); |
108 |
in.setHistory(history = new EditingHistory(in, persistenHistory) { |
|
109 |
@Override protected boolean isComplete(CharSequence input) { |
|
38908
f0c186d76c8a
8139829: JShell API: No use of fields to return information from public types
rfield
parents:
38541
diff
changeset
|
110 |
return repl.analysis.analyzeCompletion(input.toString()).completeness().isComplete(); |
33362 | 111 |
} |
112 |
}); |
|
113 |
in.setBellEnabled(true); |
|
38541
44e95493fd13
8131017: jshell tool: pasting code with tabs invokes tab completion
jlahoda
parents:
38521
diff
changeset
|
114 |
in.setCopyPasteDetection(true); |
33362 | 115 |
in.addCompleter(new Completer() { |
116 |
@Override public int complete(String test, int cursor, List<CharSequence> result) { |
|
117 |
int[] anchor = new int[] {-1}; |
|
118 |
List<Suggestion> suggestions; |
|
119 |
if (prefix.isEmpty() && test.trim().startsWith("/")) { |
|
120 |
suggestions = repl.commandCompletionSuggestions(test, cursor, anchor); |
|
121 |
} else { |
|
122 |
int prefixLength = prefix.length(); |
|
123 |
suggestions = repl.analysis.completionSuggestions(prefix + test, cursor + prefixLength, anchor); |
|
124 |
anchor[0] -= prefixLength; |
|
125 |
} |
|
43363
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
126 |
boolean smart = allowSmart.get() && |
33362 | 127 |
suggestions.stream() |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42258
diff
changeset
|
128 |
.anyMatch(Suggestion::matchesType); |
33362 | 129 |
|
43363
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
130 |
allowSmart.set(!allowSmart.get()); |
33362 | 131 |
|
132 |
suggestions.stream() |
|
38908
f0c186d76c8a
8139829: JShell API: No use of fields to return information from public types
rfield
parents:
38541
diff
changeset
|
133 |
.filter(s -> !smart || s.matchesType()) |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42258
diff
changeset
|
134 |
.map(Suggestion::continuation) |
33362 | 135 |
.forEach(result::add); |
136 |
||
137 |
boolean onlySmart = suggestions.stream() |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42258
diff
changeset
|
138 |
.allMatch(Suggestion::matchesType); |
33362 | 139 |
|
140 |
if (smart && !onlySmart) { |
|
141 |
Optional<String> prefix = |
|
142 |
suggestions.stream() |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42258
diff
changeset
|
143 |
.map(Suggestion::continuation) |
33362 | 144 |
.reduce(ConsoleIOContext::commonPrefix); |
145 |
||
146 |
String prefixStr = prefix.orElse("").substring(cursor - anchor[0]); |
|
147 |
try { |
|
148 |
in.putString(prefixStr); |
|
149 |
cursor += prefixStr.length(); |
|
150 |
} catch (IOException ex) { |
|
151 |
throw new IllegalStateException(ex); |
|
152 |
} |
|
36990 | 153 |
result.add(repl.messageFormat("jshell.console.see.more")); |
33362 | 154 |
return cursor; //anchor should not be used. |
155 |
} |
|
156 |
||
157 |
if (result.isEmpty()) { |
|
158 |
try { |
|
159 |
//provide "empty completion" feedback |
|
160 |
//XXX: this only works correctly when there is only one Completer: |
|
161 |
in.beep(); |
|
162 |
} catch (IOException ex) { |
|
163 |
throw new UncheckedIOException(ex); |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
return anchor[0]; |
|
168 |
} |
|
169 |
}); |
|
41934
a4da50688dc7
8167636: jshell tool: Edit Pad should be in its own module
rfield
parents:
41865
diff
changeset
|
170 |
bind(DOCUMENTATION_SHORTCUT, (Runnable) () -> documentation(repl)); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
171 |
for (FixComputer computer : FIX_COMPUTERS) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
172 |
for (String shortcuts : SHORTCUT_FIXES) { |
41934
a4da50688dc7
8167636: jshell tool: Edit Pad should be in its own module
rfield
parents:
41865
diff
changeset
|
173 |
bind(shortcuts + computer.shortcut, (Runnable) () -> fixes(computer)); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
174 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
175 |
} |
41631
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
176 |
try { |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
177 |
Signal.handle(new Signal("CONT"), new Handler() { |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
178 |
@Override public void handle(Signal sig) { |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
179 |
try { |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
180 |
in.getTerminal().reset(); |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
181 |
in.redrawLine(); |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
182 |
in.flush(); |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
183 |
} catch (Exception ex) { |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
184 |
ex.printStackTrace(); |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
185 |
} |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
186 |
} |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
187 |
}); |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
188 |
} catch (IllegalArgumentException ignored) { |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
189 |
//the CONT signal does not exist on this platform |
a348d1cc8d9d
8166183: jshell tool: on return from Ctrl-Z, garbage on screen, dies with Ctrl-C
jlahoda
parents:
41628
diff
changeset
|
190 |
} |
33362 | 191 |
} |
192 |
||
193 |
@Override |
|
194 |
public String readLine(String prompt, String prefix) throws IOException, InputInterruptedException { |
|
195 |
this.prefix = prefix; |
|
196 |
try { |
|
197 |
return in.readLine(prompt); |
|
198 |
} catch (UserInterruptException ex) { |
|
199 |
throw (InputInterruptedException) new InputInterruptedException().initCause(ex); |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
@Override |
|
204 |
public boolean interactiveOutput() { |
|
205 |
return true; |
|
206 |
} |
|
207 |
||
208 |
@Override |
|
209 |
public Iterable<String> currentSessionHistory() { |
|
210 |
return history.currentSessionEntries(); |
|
211 |
} |
|
212 |
||
213 |
@Override |
|
214 |
public void close() throws IOException { |
|
38521 | 215 |
//save history: |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
216 |
for (String key : repl.prefs.keys()) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
217 |
if (key.startsWith(HISTORY_LINE_PREFIX)) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
218 |
repl.prefs.remove(key); |
38521 | 219 |
} |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
220 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
221 |
Collection<? extends String> savedHistory = history.save(); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
222 |
if (!savedHistory.isEmpty()) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
223 |
int len = (int) Math.ceil(Math.log10(savedHistory.size()+1)); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
224 |
String format = HISTORY_LINE_PREFIX + "%0" + len + "d"; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
225 |
int index = 0; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
226 |
for (String historyLine : savedHistory) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
227 |
repl.prefs.put(String.format(format, index++), historyLine); |
38521 | 228 |
} |
229 |
} |
|
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
230 |
repl.prefs.flush(); |
33362 | 231 |
in.shutdown(); |
232 |
try { |
|
233 |
in.getTerminal().restore(); |
|
234 |
} catch (Exception ex) { |
|
235 |
throw new IOException(ex); |
|
236 |
} |
|
38909
80e42e2d475b
8158174: jshell tool: leaks threads waiting on StopDetectingInputStream
jlahoda
parents:
38908
diff
changeset
|
237 |
input.shutdown(); |
33362 | 238 |
} |
239 |
||
240 |
private void bind(String shortcut, Object action) { |
|
241 |
KeyMap km = in.getKeys(); |
|
242 |
for (int i = 0; i < shortcut.length(); i++) { |
|
243 |
Object value = km.getBound(Character.toString(shortcut.charAt(i))); |
|
244 |
if (value instanceof KeyMap) { |
|
245 |
km = (KeyMap) value; |
|
246 |
} else { |
|
247 |
km.bind(shortcut.substring(i), action); |
|
248 |
} |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
private static final String DOCUMENTATION_SHORTCUT = "\033\133\132"; //Shift-TAB |
|
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
253 |
private static final String[] SHORTCUT_FIXES = { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
254 |
"\033\015", //Alt-Enter (Linux) |
39811
b8d3d2487379
8162255: 'Alt-Enter v'/'Alt-Enter i' not working on some terminals
jlahoda
parents:
38909
diff
changeset
|
255 |
"\033\012", //Alt-Enter (Linux) |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
256 |
"\033\133\061\067\176", //F6/Alt-F1 (Mac) |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
257 |
"\u001BO3P" //Alt-F1 (Linux) |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
258 |
}; |
33362 | 259 |
|
41865 | 260 |
private String lastDocumentationBuffer; |
261 |
private int lastDocumentationCursor = (-1); |
|
262 |
||
33362 | 263 |
private void documentation(JShellTool repl) { |
264 |
String buffer = in.getCursorBuffer().buffer.toString(); |
|
265 |
int cursor = in.getCursorBuffer().cursor; |
|
41865 | 266 |
boolean firstInvocation = !buffer.equals(lastDocumentationBuffer) || cursor != lastDocumentationCursor; |
267 |
lastDocumentationBuffer = buffer; |
|
268 |
lastDocumentationCursor = cursor; |
|
269 |
List<String> doc; |
|
270 |
String seeMore; |
|
271 |
Terminal term = in.getTerminal(); |
|
33362 | 272 |
if (prefix.isEmpty() && buffer.trim().startsWith("/")) { |
41865 | 273 |
doc = Arrays.asList(repl.commandDocumentation(buffer, cursor, firstInvocation)); |
274 |
seeMore = "jshell.console.see.help"; |
|
33362 | 275 |
} else { |
41865 | 276 |
JavadocFormatter formatter = new JavadocFormatter(term.getWidth(), |
277 |
term.isAnsiSupported()); |
|
278 |
Function<Documentation, String> convertor; |
|
279 |
if (firstInvocation) { |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
42258
diff
changeset
|
280 |
convertor = Documentation::signature; |
41865 | 281 |
} else { |
42258
a1aafd5ea6ec
8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents:
41996
diff
changeset
|
282 |
convertor = d -> formatter.formatJavadoc(d.signature(), d.javadoc()) + |
a1aafd5ea6ec
8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents:
41996
diff
changeset
|
283 |
(d.javadoc() == null ? repl.messageFormat("jshell.console.no.javadoc") |
a1aafd5ea6ec
8169561: jshell tool: double shift-tab on variable crashes tool
jlahoda
parents:
41996
diff
changeset
|
284 |
: ""); |
41865 | 285 |
} |
286 |
doc = repl.analysis.documentation(prefix + buffer, cursor + prefix.length(), !firstInvocation) |
|
287 |
.stream() |
|
288 |
.map(convertor) |
|
289 |
.collect(Collectors.toList()); |
|
290 |
seeMore = "jshell.console.see.javadoc"; |
|
33362 | 291 |
} |
292 |
||
293 |
try { |
|
41865 | 294 |
if (doc != null && !doc.isEmpty()) { |
295 |
if (firstInvocation) { |
|
296 |
in.println(); |
|
297 |
in.println(doc.stream().collect(Collectors.joining("\n"))); |
|
298 |
in.println(repl.messageFormat(seeMore)); |
|
299 |
in.redrawLine(); |
|
300 |
in.flush(); |
|
301 |
} else { |
|
302 |
in.println(); |
|
303 |
||
304 |
int height = term.getHeight(); |
|
305 |
String lastNote = ""; |
|
306 |
||
307 |
PRINT_DOC: for (Iterator<String> docIt = doc.iterator(); docIt.hasNext(); ) { |
|
308 |
String currentDoc = docIt.next(); |
|
309 |
String[] lines = currentDoc.split("\n"); |
|
310 |
int firstLine = 0; |
|
311 |
||
312 |
PRINT_PAGE: while (true) { |
|
313 |
int toPrint = height - 1; |
|
314 |
||
315 |
while (toPrint > 0 && firstLine < lines.length) { |
|
316 |
in.println(lines[firstLine++]); |
|
317 |
toPrint--; |
|
318 |
} |
|
319 |
||
320 |
if (firstLine >= lines.length) { |
|
321 |
break; |
|
322 |
} |
|
323 |
||
324 |
lastNote = repl.getResourceString("jshell.console.see.next.page"); |
|
325 |
in.print(lastNote + ConsoleReader.RESET_LINE); |
|
326 |
in.flush(); |
|
327 |
||
328 |
while (true) { |
|
329 |
int r = in.readCharacter(); |
|
330 |
||
331 |
switch (r) { |
|
332 |
case ' ': continue PRINT_PAGE; |
|
333 |
case 'q': |
|
334 |
case 3: |
|
335 |
break PRINT_DOC; |
|
336 |
default: |
|
337 |
in.beep(); |
|
338 |
break; |
|
339 |
} |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
if (docIt.hasNext()) { |
|
344 |
lastNote = repl.getResourceString("jshell.console.see.next.javadoc"); |
|
345 |
in.print(lastNote + ConsoleReader.RESET_LINE); |
|
346 |
in.flush(); |
|
347 |
||
348 |
while (true) { |
|
349 |
int r = in.readCharacter(); |
|
350 |
||
351 |
switch (r) { |
|
352 |
case ' ': continue PRINT_DOC; |
|
353 |
case 'q': |
|
354 |
case 3: |
|
355 |
break PRINT_DOC; |
|
356 |
default: |
|
357 |
in.beep(); |
|
358 |
break; |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
//clear the "press space" line: |
|
364 |
in.getCursorBuffer().buffer.replace(0, buffer.length(), lastNote); |
|
365 |
in.getCursorBuffer().cursor = 0; |
|
366 |
in.killLine(); |
|
367 |
in.getCursorBuffer().buffer.append(buffer); |
|
368 |
in.getCursorBuffer().cursor = cursor; |
|
369 |
in.redrawLine(); |
|
370 |
in.flush(); |
|
371 |
} |
|
33362 | 372 |
} else { |
373 |
in.beep(); |
|
374 |
} |
|
375 |
} catch (IOException ex) { |
|
376 |
throw new IllegalStateException(ex); |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
private static String commonPrefix(String str1, String str2) { |
|
381 |
for (int i = 0; i < str2.length(); i++) { |
|
382 |
if (!str1.startsWith(str2.substring(0, i + 1))) { |
|
383 |
return str2.substring(0, i); |
|
384 |
} |
|
385 |
} |
|
386 |
||
387 |
return str2; |
|
388 |
} |
|
389 |
||
390 |
@Override |
|
391 |
public boolean terminalEditorRunning() { |
|
392 |
Terminal terminal = in.getTerminal(); |
|
393 |
if (terminal instanceof JShellUnixTerminal) |
|
394 |
return ((JShellUnixTerminal) terminal).isRaw(); |
|
395 |
return false; |
|
396 |
} |
|
397 |
||
398 |
@Override |
|
399 |
public void suspend() { |
|
400 |
try { |
|
401 |
in.getTerminal().restore(); |
|
402 |
} catch (Exception ex) { |
|
403 |
throw new IllegalStateException(ex); |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
@Override |
|
408 |
public void resume() { |
|
409 |
try { |
|
410 |
in.getTerminal().init(); |
|
411 |
} catch (Exception ex) { |
|
412 |
throw new IllegalStateException(ex); |
|
413 |
} |
|
414 |
} |
|
415 |
||
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
416 |
@Override |
33362 | 417 |
public void beforeUserCode() { |
40767 | 418 |
synchronized (this) { |
419 |
inputBytes = null; |
|
420 |
} |
|
33362 | 421 |
input.setState(State.BUFFER); |
422 |
} |
|
423 |
||
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
42827
diff
changeset
|
424 |
@Override |
33362 | 425 |
public void afterUserCode() { |
426 |
input.setState(State.WAIT); |
|
427 |
} |
|
428 |
||
429 |
@Override |
|
430 |
public void replaceLastHistoryEntry(String source) { |
|
431 |
history.fullHistoryReplace(source); |
|
432 |
} |
|
433 |
||
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
434 |
//compute possible options/Fixes based on the selected FixComputer, present them to the user, |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
435 |
//and perform the selected one: |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
436 |
private void fixes(FixComputer computer) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
437 |
String input = prefix + in.getCursorBuffer().toString(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
438 |
int cursor = prefix.length() + in.getCursorBuffer().cursor; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
439 |
FixResult candidates = computer.compute(repl, input, cursor); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
440 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
441 |
try { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
442 |
final boolean printError = candidates.error != null && !candidates.error.isEmpty(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
443 |
if (printError) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
444 |
in.println(candidates.error); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
445 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
446 |
if (candidates.fixes.isEmpty()) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
447 |
in.beep(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
448 |
if (printError) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
449 |
in.redrawLine(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
450 |
in.flush(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
451 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
452 |
} else if (candidates.fixes.size() == 1 && !computer.showMenu) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
453 |
if (printError) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
454 |
in.redrawLine(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
455 |
in.flush(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
456 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
457 |
candidates.fixes.get(0).perform(in); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
458 |
} else { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
459 |
List<Fix> fixes = new ArrayList<>(candidates.fixes); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
460 |
fixes.add(0, new Fix() { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
461 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
462 |
public String displayName() { |
36990 | 463 |
return repl.messageFormat("jshell.console.do.nothing"); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
464 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
465 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
466 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
467 |
public void perform(ConsoleReader in) throws IOException { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
468 |
in.redrawLine(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
469 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
470 |
}); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
471 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
472 |
Map<Character, Fix> char2Fix = new HashMap<>(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
473 |
in.println(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
474 |
for (int i = 0; i < fixes.size(); i++) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
475 |
Fix fix = fixes.get(i); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
476 |
char2Fix.put((char) ('0' + i), fix); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
477 |
in.println("" + i + ": " + fixes.get(i).displayName()); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
478 |
} |
36990 | 479 |
in.print(repl.messageFormat("jshell.console.choice")); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
480 |
in.flush(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
481 |
int read; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
482 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
483 |
read = in.readCharacter(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
484 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
485 |
Fix fix = char2Fix.get((char) read); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
486 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
487 |
if (fix == null) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
488 |
in.beep(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
489 |
fix = fixes.get(0); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
490 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
491 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
492 |
in.println(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
493 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
494 |
fix.perform(in); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
495 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
496 |
in.flush(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
497 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
498 |
} catch (IOException ex) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
499 |
ex.printStackTrace(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
500 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
501 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
502 |
|
40767 | 503 |
private byte[] inputBytes; |
504 |
private int inputBytesPointer; |
|
505 |
||
506 |
@Override |
|
41628 | 507 |
public synchronized int readUserInput() throws IOException { |
40767 | 508 |
while (inputBytes == null || inputBytes.length <= inputBytesPointer) { |
509 |
boolean prevHandleUserInterrupt = in.getHandleUserInterrupt(); |
|
510 |
History prevHistory = in.getHistory(); |
|
511 |
||
512 |
try { |
|
513 |
input.setState(State.WAIT); |
|
514 |
in.setHandleUserInterrupt(true); |
|
515 |
in.setHistory(userInputHistory); |
|
516 |
inputBytes = (in.readLine("") + System.getProperty("line.separator")).getBytes(); |
|
517 |
inputBytesPointer = 0; |
|
518 |
} catch (UserInterruptException ex) { |
|
41628 | 519 |
throw new InterruptedIOException(); |
40767 | 520 |
} finally { |
521 |
in.setHistory(prevHistory); |
|
522 |
in.setHandleUserInterrupt(prevHandleUserInterrupt); |
|
523 |
input.setState(State.BUFFER); |
|
524 |
} |
|
525 |
} |
|
526 |
return inputBytes[inputBytesPointer++]; |
|
527 |
} |
|
528 |
||
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
529 |
/** |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
530 |
* A possible action which the user can choose to perform. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
531 |
*/ |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
532 |
public interface Fix { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
533 |
/** |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
534 |
* A name that should be shown to the user. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
535 |
*/ |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
536 |
public String displayName(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
537 |
/** |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
538 |
* Perform the given action. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
539 |
*/ |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
540 |
public void perform(ConsoleReader in) throws IOException; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
541 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
542 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
543 |
/** |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
544 |
* A factory for {@link Fix}es. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
545 |
*/ |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
546 |
public abstract static class FixComputer { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
547 |
private final char shortcut; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
548 |
private final boolean showMenu; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
549 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
550 |
/** |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
551 |
* Construct a new FixComputer. {@code shortcut} defines the key which should trigger this FixComputer. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
552 |
* If {@code showMenu} is {@code false}, and this computer returns exactly one {@code Fix}, |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
553 |
* no options will be show to the user, and the given {@code Fix} will be performed. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
554 |
*/ |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
555 |
public FixComputer(char shortcut, boolean showMenu) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
556 |
this.shortcut = shortcut; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
557 |
this.showMenu = showMenu; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
558 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
559 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
560 |
/** |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
561 |
* Compute possible actions for the given code. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
562 |
*/ |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
563 |
public abstract FixResult compute(JShellTool repl, String code, int cursor); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
564 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
565 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
566 |
/** |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
567 |
* A list of {@code Fix}es with a possible error that should be shown to the user. |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
568 |
*/ |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
569 |
public static class FixResult { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
570 |
public final List<Fix> fixes; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
571 |
public final String error; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
572 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
573 |
public FixResult(List<Fix> fixes, String error) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
574 |
this.fixes = fixes; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
575 |
this.error = error; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
576 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
577 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
578 |
|
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
579 |
private static final FixComputer[] FIX_COMPUTERS = new FixComputer[] { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
580 |
new FixComputer('v', false) { //compute "Introduce variable" Fix: |
41996
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
581 |
private void performToVar(ConsoleReader in, String type) throws IOException { |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
582 |
in.redrawLine(); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
583 |
in.setCursorPosition(0); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
584 |
in.putString(type + " = "); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
585 |
in.setCursorPosition(in.getCursorBuffer().cursor - 3); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
586 |
in.flush(); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
587 |
} |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
588 |
|
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
589 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
590 |
public FixResult compute(JShellTool repl, String code, int cursor) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
591 |
String type = repl.analysis.analyzeType(code, cursor); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
592 |
if (type == null) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
593 |
return new FixResult(Collections.emptyList(), null); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
594 |
} |
41996
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
595 |
List<Fix> fixes = new ArrayList<>(); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
596 |
fixes.add(new Fix() { |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
597 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
598 |
public String displayName() { |
36990 | 599 |
return repl.messageFormat("jshell.console.create.variable"); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
600 |
} |
41996
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
601 |
|
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
602 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
603 |
public void perform(ConsoleReader in) throws IOException { |
41996
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
604 |
performToVar(in, type); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
605 |
} |
41996
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
606 |
}); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
607 |
int idx = type.lastIndexOf("."); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
608 |
if (idx > 0) { |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
609 |
String stype = type.substring(idx + 1); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
610 |
QualifiedNames res = repl.analysis.listQualifiedNames(stype, stype.length()); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
611 |
if (res.isUpToDate() && res.getNames().contains(type) |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
612 |
&& !res.isResolvable()) { |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
613 |
fixes.add(new Fix() { |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
614 |
@Override |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
615 |
public String displayName() { |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
616 |
return "import: " + type + ". " + |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
617 |
repl.messageFormat("jshell.console.create.variable"); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
618 |
} |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
619 |
|
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
620 |
@Override |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
621 |
public void perform(ConsoleReader in) throws IOException { |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
622 |
repl.state.eval("import " + type + ";"); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
623 |
in.println("Imported: " + type); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
624 |
performToVar(in, stype); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
625 |
} |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
626 |
}); |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
627 |
} |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
628 |
} |
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
629 |
return new FixResult(fixes, null); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
630 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
631 |
}, |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
632 |
new FixComputer('i', true) { //compute "Add import" Fixes: |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
633 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
634 |
public FixResult compute(JShellTool repl, String code, int cursor) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
635 |
QualifiedNames res = repl.analysis.listQualifiedNames(code, cursor); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
636 |
List<Fix> fixes = new ArrayList<>(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
637 |
for (String fqn : res.getNames()) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
638 |
fixes.add(new Fix() { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
639 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
640 |
public String displayName() { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
641 |
return "import: " + fqn; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
642 |
} |
41996
389212e0746c
8166333: jshell tool: shortcut var does not import its type
rfield
parents:
41934
diff
changeset
|
643 |
|
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
644 |
@Override |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
645 |
public void perform(ConsoleReader in) throws IOException { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
646 |
repl.state.eval("import " + fqn + ";"); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
647 |
in.println("Imported: " + fqn); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
648 |
in.redrawLine(); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
649 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
650 |
}); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
651 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
652 |
if (res.isResolvable()) { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
653 |
return new FixResult(Collections.emptyList(), |
36990 | 654 |
repl.messageFormat("jshell.console.resolvable")); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
655 |
} else { |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
656 |
String error = ""; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
657 |
if (fixes.isEmpty()) { |
36990 | 658 |
error = repl.messageFormat("jshell.console.no.candidate"); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
659 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
660 |
if (!res.isUpToDate()) { |
36990 | 661 |
error += repl.messageFormat("jshell.console.incomplete"); |
36160
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
662 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
663 |
return new FixResult(fixes, error); |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
664 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
665 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
666 |
} |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
667 |
}; |
f42d362d0d17
8131027: JShell API/tool: suggest imports for a class
jlahoda
parents:
33362
diff
changeset
|
668 |
|
33362 | 669 |
private static final class JShellUnixTerminal extends NoInterruptUnixTerminal { |
670 |
||
671 |
private final StopDetectingInputStream input; |
|
672 |
||
673 |
public JShellUnixTerminal(StopDetectingInputStream input) throws Exception { |
|
674 |
this.input = input; |
|
675 |
} |
|
676 |
||
677 |
public boolean isRaw() { |
|
678 |
try { |
|
679 |
return getSettings().get("-a").contains("-icanon"); |
|
680 |
} catch (IOException | InterruptedException ex) { |
|
681 |
return false; |
|
682 |
} |
|
683 |
} |
|
684 |
||
685 |
@Override |
|
686 |
public InputStream wrapInIfNeeded(InputStream in) throws IOException { |
|
687 |
return input.setInputStream(super.wrapInIfNeeded(in)); |
|
688 |
} |
|
689 |
||
690 |
@Override |
|
691 |
public void disableInterruptCharacter() { |
|
692 |
} |
|
693 |
||
694 |
@Override |
|
695 |
public void enableInterruptCharacter() { |
|
696 |
} |
|
697 |
||
698 |
} |
|
699 |
||
700 |
private static final class JShellWindowsTerminal extends WindowsTerminal { |
|
701 |
||
702 |
private final StopDetectingInputStream input; |
|
703 |
||
704 |
public JShellWindowsTerminal(StopDetectingInputStream input) throws Exception { |
|
705 |
this.input = input; |
|
706 |
} |
|
707 |
||
708 |
@Override |
|
709 |
public void init() throws Exception { |
|
710 |
super.init(); |
|
711 |
setAnsiSupported(false); |
|
712 |
} |
|
713 |
||
714 |
@Override |
|
715 |
public InputStream wrapInIfNeeded(InputStream in) throws IOException { |
|
716 |
return input.setInputStream(super.wrapInIfNeeded(in)); |
|
717 |
} |
|
718 |
||
719 |
} |
|
36715
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
720 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
721 |
private static final class TestTerminal extends TerminalSupport { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
722 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
723 |
private final StopDetectingInputStream input; |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
724 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
725 |
public TestTerminal(StopDetectingInputStream input) throws Exception { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
726 |
super(true); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
727 |
setAnsiSupported(false); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
728 |
setEchoEnabled(true); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
729 |
this.input = input; |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
730 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
731 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
732 |
@Override |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
733 |
public InputStream wrapInIfNeeded(InputStream in) throws IOException { |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
734 |
return input.setInputStream(super.wrapInIfNeeded(in)); |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
735 |
} |
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
736 |
|
ae6fa9280e0b
8152296: langtools/test/jdk/jshell/ToolReloadTest.java failing if there is not persisted history
jlahoda
parents:
36501
diff
changeset
|
737 |
} |
43363
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
738 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
739 |
private static final class CheckCompletionKeyMap extends KeyMap { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
740 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
741 |
private final KeyMap del; |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
742 |
private final AtomicBoolean allowSmart; |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
743 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
744 |
public CheckCompletionKeyMap(KeyMap del, AtomicBoolean allowSmart) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
745 |
super(del.getName(), del.isViKeyMap()); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
746 |
this.del = del; |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
747 |
this.allowSmart = allowSmart; |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
748 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
749 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
750 |
@Override |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
751 |
public void bind(CharSequence keySeq, Object function) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
752 |
del.bind(keySeq, function); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
753 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
754 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
755 |
@Override |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
756 |
public void bindIfNotBound(CharSequence keySeq, Object function) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
757 |
del.bindIfNotBound(keySeq, function); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
758 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
759 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
760 |
@Override |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
761 |
public void from(KeyMap other) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
762 |
del.from(other); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
763 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
764 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
765 |
@Override |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
766 |
public Object getAnotherKey() { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
767 |
return del.getAnotherKey(); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
768 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
769 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
770 |
@Override |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
771 |
public Object getBound(CharSequence keySeq) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
772 |
Object res = del.getBound(keySeq); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
773 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
774 |
if (res != Operation.COMPLETE) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
775 |
allowSmart.set(true); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
776 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
777 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
778 |
return res; |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
779 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
780 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
781 |
@Override |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
782 |
public void setBlinkMatchingParen(boolean on) { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
783 |
del.setBlinkMatchingParen(on); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
784 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
785 |
|
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
786 |
@Override |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
787 |
public String toString() { |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
788 |
return "check: " + del.toString(); |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
789 |
} |
a4ed2006a4c5
8153759: jshell tool: Smart completion detection is not reliable
jlahoda
parents:
42843
diff
changeset
|
790 |
} |
33362 | 791 |
} |