author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 52938 | 5ff7480c9e28 |
permissions | -rw-r--r-- |
32241 | 1 |
/* |
52938 | 2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
32241 | 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.nashorn.tools.jjs; |
|
27 |
||
32318
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
28 |
import java.io.File; |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
29 |
import java.io.PrintWriter; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
30 |
import java.util.ArrayList; |
32241 | 31 |
import java.util.List; |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
32 |
import java.util.Objects; |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
33 |
import java.util.regex.Pattern; |
52938 | 34 |
|
35 |
import jdk.internal.org.jline.reader.Candidate; |
|
36 |
import jdk.internal.org.jline.reader.Completer; |
|
37 |
import jdk.internal.org.jline.reader.LineReader; |
|
38 |
import jdk.internal.org.jline.reader.ParsedLine; |
|
39 |
import jdk.internal.org.jline.reader.UserInterruptException; |
|
32241 | 40 |
import jdk.nashorn.api.tree.AssignmentTree; |
41 |
import jdk.nashorn.api.tree.BinaryTree; |
|
42 |
import jdk.nashorn.api.tree.CompilationUnitTree; |
|
43 |
import jdk.nashorn.api.tree.CompoundAssignmentTree; |
|
44 |
import jdk.nashorn.api.tree.ConditionalExpressionTree; |
|
45 |
import jdk.nashorn.api.tree.ExpressionTree; |
|
46 |
import jdk.nashorn.api.tree.ExpressionStatementTree; |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
47 |
import jdk.nashorn.api.tree.FunctionCallTree; |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
48 |
import jdk.nashorn.api.tree.IdentifierTree; |
32241 | 49 |
import jdk.nashorn.api.tree.InstanceOfTree; |
50 |
import jdk.nashorn.api.tree.MemberSelectTree; |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
51 |
import jdk.nashorn.api.tree.NewTree; |
32241 | 52 |
import jdk.nashorn.api.tree.SimpleTreeVisitorES5_1; |
53 |
import jdk.nashorn.api.tree.Tree; |
|
54 |
import jdk.nashorn.api.tree.UnaryTree; |
|
55 |
import jdk.nashorn.api.tree.Parser; |
|
56 |
import jdk.nashorn.api.scripting.NashornException; |
|
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
57 |
import jdk.nashorn.tools.PartialParser; |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
58 |
import jdk.nashorn.internal.objects.NativeSyntaxError; |
32241 | 59 |
import jdk.nashorn.internal.objects.Global; |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
60 |
import jdk.nashorn.internal.runtime.ECMAException; |
32241 | 61 |
import jdk.nashorn.internal.runtime.Context; |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
62 |
import jdk.nashorn.internal.runtime.ScriptEnvironment; |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
63 |
import jdk.nashorn.internal.runtime.ScriptFunction; |
32241 | 64 |
import jdk.nashorn.internal.runtime.ScriptRuntime; |
65 |
||
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
66 |
/** |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
67 |
* A simple source completer for nashorn. Handles code completion for |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
68 |
* expressions as well as handles incomplete single line code. |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
69 |
*/ |
52938 | 70 |
final class NashornCompleter { |
32241 | 71 |
private final Context context; |
72 |
private final Global global; |
|
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
73 |
private final ScriptEnvironment env; |
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
74 |
private final PartialParser partialParser; |
32314
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
75 |
private final PropertiesHelper propsHelper; |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
76 |
private final ScriptFunction fileChooserFunc; |
32241 | 77 |
private final Parser parser; |
32318
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
78 |
private static final boolean BACKSLASH_FILE_SEPARATOR = File.separatorChar == '\\'; |
32241 | 79 |
|
32314
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
80 |
NashornCompleter(final Context context, final Global global, |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
81 |
final PartialParser partialParser, final PropertiesHelper propsHelper, |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
82 |
final ScriptFunction fileChooserFunc) { |
32241 | 83 |
this.context = context; |
84 |
this.global = global; |
|
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
85 |
this.env = context.getEnv(); |
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
86 |
this.partialParser = partialParser; |
32314
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
87 |
this.propsHelper = propsHelper; |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
88 |
this.fileChooserFunc = fileChooserFunc; |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
89 |
this.parser = createParser(env); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
90 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
91 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
92 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
93 |
/** |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
94 |
* Is this a ECMAScript SyntaxError thrown for parse issue at the given line and column? |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
95 |
* |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
96 |
* @param exp Throwable to check |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
97 |
* @param line line number to check |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
98 |
* @param column column number to check |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
99 |
* |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
100 |
* @return true if the given Throwable is a ECMAScript SyntaxError at given line, column |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
101 |
*/ |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
102 |
boolean isSyntaxErrorAt(final Throwable exp, final int line, final int column) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
103 |
if (exp instanceof ECMAException) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
104 |
final ECMAException eexp = (ECMAException)exp; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
105 |
if (eexp.getThrown() instanceof NativeSyntaxError) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
106 |
return isParseErrorAt(eexp.getCause(), line, column); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
107 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
108 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
109 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
110 |
return false; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
111 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
112 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
113 |
/** |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
114 |
* Is this a parse error at the given line and column? |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
115 |
* |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
116 |
* @param exp Throwable to check |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
117 |
* @param line line number to check |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
118 |
* @param column column number to check |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
119 |
* |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
120 |
* @return true if the given Throwable is a parser error at given line, column |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
121 |
*/ |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
122 |
boolean isParseErrorAt(final Throwable exp, final int line, final int column) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
123 |
if (exp instanceof NashornException) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
124 |
final NashornException nexp = (NashornException)exp; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
125 |
return nexp.getLineNumber() == line && nexp.getColumnNumber() == column; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
126 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
127 |
return false; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
128 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
129 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
130 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
131 |
/** |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
132 |
* Read more lines of code if we got SyntaxError at EOF and we can it fine by |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
133 |
* by reading more lines of code from the user. This is used for multiline editing. |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
134 |
* |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
135 |
* @param firstLine First line of code from the user |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
136 |
* @param exp Exception thrown by evaluting first line code |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
137 |
* @param in Console to get read more lines from the user |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
138 |
* @param prompt Prompt to be printed to read more lines from the user |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
139 |
* @param err PrintWriter to print any errors in the proecess of reading |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
140 |
* |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
141 |
* @return Complete code read from the user including the first line. This is null |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
142 |
* if any error or the user discarded multiline editing by Ctrl-C. |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
143 |
*/ |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
144 |
String readMoreLines(final String firstLine, final Exception exp, final Console in, |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
145 |
final String prompt, final PrintWriter err) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
146 |
int line = 1; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
147 |
final StringBuilder buf = new StringBuilder(firstLine); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
148 |
while (true) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
149 |
buf.append('\n'); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
150 |
String curLine = null; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
151 |
try { |
52938 | 152 |
curLine = in.readLine(prompt, prompt); |
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
153 |
buf.append(curLine); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
154 |
line++; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
155 |
} catch (final Throwable th) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
156 |
if (th instanceof UserInterruptException) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
157 |
// Ctrl-C from user - discard the whole thing silently! |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
158 |
return null; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
159 |
} else { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
160 |
// print anything else -- but still discard the code |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
161 |
err.println(th); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
162 |
if (env._dump_on_error) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
163 |
th.printStackTrace(err); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
164 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
165 |
return null; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
166 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
167 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
168 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
169 |
final String allLines = buf.toString(); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
170 |
try { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
171 |
parser.parse("<shell>", allLines, null); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
172 |
} catch (final Exception pexp) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
173 |
// Do we have a parse error at the end of current line? |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
174 |
// If so, read more lines from the console. |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
175 |
if (isParseErrorAt(pexp, line, curLine.length())) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
176 |
continue; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
177 |
} else { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
178 |
// print anything else and bail out! |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
179 |
err.println(pexp); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
180 |
if (env._dump_on_error) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
181 |
pexp.printStackTrace(err); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
182 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
183 |
return null; |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
184 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
185 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
186 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
187 |
// We have complete parseable code! |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
188 |
return buf.toString(); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
189 |
} |
32241 | 190 |
} |
191 |
||
38488 | 192 |
public boolean isComplete(String input) { |
193 |
try { |
|
194 |
parser.parse("<shell>", input, null); |
|
195 |
} catch (final Exception pexp) { |
|
196 |
// Do we have a parse error at the end of current line? |
|
197 |
// If so, read more lines from the console. |
|
198 |
int line = input.split("\n").length; |
|
199 |
int lastLineLen = input.length() - (input.lastIndexOf("\n") + 1); |
|
200 |
||
201 |
if (isParseErrorAt(pexp, line, lastLineLen)) { |
|
202 |
return false; |
|
203 |
} |
|
204 |
} |
|
205 |
return true; |
|
206 |
} |
|
207 |
||
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
208 |
// Pattern to match a unfinished member selection expression. object part and "." |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
209 |
// but property name missing pattern. |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
210 |
private static final Pattern SELECT_PROP_MISSING = Pattern.compile(".*\\.\\s*"); |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
211 |
|
32318
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
212 |
// Pattern to match load call |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
213 |
private static final Pattern LOAD_CALL = Pattern.compile("\\s*load\\s*\\(\\s*"); |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
214 |
|
52938 | 215 |
public int complete(String test, int cursor, List<Candidate> candidates) { |
32241 | 216 |
// check that cursor is at the end of test string. Do not complete in the middle! |
217 |
if (cursor != test.length()) { |
|
218 |
return cursor; |
|
219 |
} |
|
220 |
||
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
221 |
// get the start of the last expression embedded in the given code |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
222 |
// using the partial parsing support - so that we can complete expressions |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
223 |
// inside statements, function call argument lists, array index etc. |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
224 |
final int exprStart = partialParser.getLastExpressionStart(context, test); |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
225 |
if (exprStart == -1) { |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
226 |
return cursor; |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
227 |
} |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
228 |
|
32241 | 229 |
|
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
230 |
// extract the last expression string |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
231 |
final String exprStr = test.substring(exprStart); |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
232 |
|
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
233 |
// do we have an incomplete member selection expression that misses property name? |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
234 |
final boolean endsWithDot = SELECT_PROP_MISSING.matcher(exprStr).matches(); |
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
235 |
|
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
236 |
// If this is an incomplete member selection, then it is not legal code. |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
237 |
// Make it legal by adding a random property name "x" to it. |
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
238 |
final String completeExpr = endsWithDot? exprStr + "x" : exprStr; |
32241 | 239 |
|
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
240 |
final ExpressionTree topExpr = getTopLevelExpression(parser, completeExpr); |
32241 | 241 |
if (topExpr == null) { |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
242 |
// Special case for load call that looks like "load(" with optional whitespaces. |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
243 |
// If we have a fileChooserFunc then call it, so that the user can select a file. |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
244 |
if (fileChooserFunc != null && LOAD_CALL.matcher(test).matches()) { |
32319
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
245 |
String name = readFileName(context.getErr()); |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
246 |
if (name != null) { |
32318
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
247 |
// handle '\' file separator |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
248 |
if (BACKSLASH_FILE_SEPARATOR) { |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
249 |
name = name.replace("\\", "\\\\"); |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
250 |
} |
52938 | 251 |
candidates.add(createCandidate("\"" + name + "\")")); |
32318
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
252 |
return cursor + name.length() + 3; |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
253 |
} |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
254 |
} |
3279b026c98a
8134309: load call argument completion could be done with file chooser
sundar
parents:
32317
diff
changeset
|
255 |
|
32241 | 256 |
// did not parse to be a top level expression, no suggestions! |
257 |
return cursor; |
|
258 |
} |
|
259 |
||
260 |
||
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
261 |
// Find 'right most' expression of the top level expression |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
262 |
final Tree rightMostExpr = getRightMostExpression(topExpr); |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
263 |
if (rightMostExpr instanceof MemberSelectTree) { |
52938 | 264 |
return completeMemberSelect(exprStr, cursor, candidates, (MemberSelectTree)rightMostExpr, endsWithDot); |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
265 |
} else if (rightMostExpr instanceof IdentifierTree) { |
52938 | 266 |
return completeIdentifier(exprStr, cursor, candidates, (IdentifierTree)rightMostExpr); |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
267 |
} else { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
268 |
// expression that we cannot handle for completion |
32241 | 269 |
return cursor; |
270 |
} |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
271 |
} |
32241 | 272 |
|
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
273 |
// Internals only below this point |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
274 |
|
32319
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
275 |
// read file name from the user using by showing a swing file chooser diablog |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
276 |
private String readFileName(final PrintWriter err) { |
32319
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
277 |
try { |
47492
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
278 |
final Object res = ScriptRuntime.apply(fileChooserFunc, null); |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
279 |
return res instanceof String? (String)res : null; |
560fab171dc7
8190698: jjs tool of jdk.scripting.nashorn.shell module should not statically depend on java.desktop
sundar
parents:
47216
diff
changeset
|
280 |
} catch (final Exception e) { |
32319
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
281 |
err.println(e); |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
282 |
if (Main.DEBUG) { |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
283 |
e.printStackTrace(); |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
284 |
} |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
285 |
} |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
286 |
return null; |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
287 |
} |
3f22ddeabc0e
8134381: load completion should not use swing from non UI thread
sundar
parents:
32318
diff
changeset
|
288 |
|
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
289 |
// fill properties of the incomplete member expression |
52938 | 290 |
private int completeMemberSelect(final String exprStr, final int cursor, final List<Candidate> candidates, |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
291 |
final MemberSelectTree select, final boolean endsWithDot) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
292 |
final ExpressionTree objExpr = select.getExpression(); |
32245
80164edf8a10
8133872: Expression completion should work on contexts where an expression is accepted
sundar
parents:
32243
diff
changeset
|
293 |
final String objExprCode = exprStr.substring((int)objExpr.getStartPosition(), (int)objExpr.getEndPosition()); |
32241 | 294 |
|
295 |
// try to evaluate the object expression part as a script |
|
296 |
Object obj = null; |
|
297 |
try { |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
298 |
obj = context.eval(global, objExprCode, global, "<suggestions>"); |
32314
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
299 |
} catch (Exception exp) { |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
300 |
// throw away the exception - this is during tab-completion |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
301 |
if (Main.DEBUG) { |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
302 |
exp.printStackTrace(); |
8f7d23d3b1ad
8134255: Implement tab-completion for java package prefixes and package names
sundar
parents:
32245
diff
changeset
|
303 |
} |
32241 | 304 |
} |
305 |
||
306 |
if (obj != null && obj != ScriptRuntime.UNDEFINED) { |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
307 |
if (endsWithDot) { |
32241 | 308 |
// no user specified "prefix". List all properties of the object |
52938 | 309 |
propsHelper.getProperties(obj).stream().map(this::createCandidate).forEach(candidates::add); |
32241 | 310 |
return cursor; |
311 |
} else { |
|
312 |
// list of properties matching the user specified prefix |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
313 |
final String prefix = select.getIdentifier(); |
52938 | 314 |
propsHelper.getProperties(obj, prefix).stream().map(this::createCandidate).forEach(candidates::add); |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
315 |
return cursor - prefix.length(); |
32241 | 316 |
} |
317 |
} |
|
318 |
||
319 |
return cursor; |
|
320 |
} |
|
321 |
||
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
322 |
// fill properties for the given (partial) identifer |
52938 | 323 |
private int completeIdentifier(final String test, final int cursor, final List<Candidate> candidates, |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
324 |
final IdentifierTree ident) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
325 |
final String name = ident.getName(); |
52938 | 326 |
propsHelper.getProperties(global, name).stream().map(this::createCandidate).forEach(candidates::add); |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
327 |
return cursor - name.length(); |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
328 |
} |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
329 |
|
32241 | 330 |
// returns ExpressionTree if the given code parses to a top level expression. |
331 |
// Or else returns null. |
|
332 |
private ExpressionTree getTopLevelExpression(final Parser parser, final String code) { |
|
333 |
try { |
|
334 |
final CompilationUnitTree cut = parser.parse("<code>", code, null); |
|
335 |
final List<? extends Tree> stats = cut.getSourceElements(); |
|
336 |
if (stats.size() == 1) { |
|
337 |
final Tree stat = stats.get(0); |
|
338 |
if (stat instanceof ExpressionStatementTree) { |
|
339 |
return ((ExpressionStatementTree)stat).getExpression(); |
|
340 |
} |
|
341 |
} |
|
342 |
} catch (final NashornException ignored) { |
|
343 |
// ignore any parser error. This is for completion anyway! |
|
344 |
// And user will get that error later when the expression is evaluated. |
|
345 |
} |
|
346 |
||
347 |
return null; |
|
348 |
} |
|
349 |
||
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
350 |
// get the right most expreesion of the given expression |
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
351 |
private Tree getRightMostExpression(final ExpressionTree expr) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
352 |
return expr.accept(new SimpleTreeVisitorES5_1<Tree, Void>() { |
32241 | 353 |
@Override |
354 |
public Tree visitAssignment(final AssignmentTree at, final Void v) { |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
355 |
return getRightMostExpression(at.getExpression()); |
32241 | 356 |
} |
357 |
||
358 |
@Override |
|
359 |
public Tree visitCompoundAssignment(final CompoundAssignmentTree cat, final Void v) { |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
360 |
return getRightMostExpression(cat.getExpression()); |
32241 | 361 |
} |
362 |
||
363 |
@Override |
|
364 |
public Tree visitConditionalExpression(final ConditionalExpressionTree cet, final Void v) { |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
365 |
return getRightMostExpression(cet.getFalseExpression()); |
32241 | 366 |
} |
367 |
||
368 |
@Override |
|
369 |
public Tree visitBinary(final BinaryTree bt, final Void v) { |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
370 |
return getRightMostExpression(bt.getRightOperand()); |
32241 | 371 |
} |
372 |
||
373 |
@Override |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
374 |
public Tree visitIdentifier(final IdentifierTree ident, final Void v) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
375 |
return ident; |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
376 |
} |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
377 |
|
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
378 |
|
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
379 |
@Override |
32241 | 380 |
public Tree visitInstanceOf(final InstanceOfTree it, final Void v) { |
381 |
return it.getType(); |
|
382 |
} |
|
383 |
||
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
384 |
|
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
385 |
@Override |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
386 |
public Tree visitMemberSelect(final MemberSelectTree select, final Void v) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
387 |
return select; |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
388 |
} |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
389 |
|
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
390 |
@Override |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
391 |
public Tree visitNew(final NewTree nt, final Void v) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
392 |
final ExpressionTree call = nt.getConstructorExpression(); |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
393 |
if (call instanceof FunctionCallTree) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
394 |
final ExpressionTree func = ((FunctionCallTree)call).getFunctionSelect(); |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
395 |
// Is this "new Foo" or "new obj.Foo" with no user arguments? |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
396 |
// If so, we may be able to do completion of constructor name. |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
397 |
if (func.getEndPosition() == nt.getEndPosition()) { |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
398 |
return func; |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
399 |
} |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
400 |
} |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
401 |
return null; |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
402 |
} |
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
403 |
|
32241 | 404 |
@Override |
405 |
public Tree visitUnary(final UnaryTree ut, final Void v) { |
|
32243
422ccb5d8437
8133812: identifier and member expression completion handling is not uniform
sundar
parents:
32241
diff
changeset
|
406 |
return getRightMostExpression(ut.getExpression()); |
32241 | 407 |
} |
408 |
}, null); |
|
409 |
} |
|
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
410 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
411 |
// create a Parser instance that uses compatible command line options of the |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
412 |
// current ScriptEnvironment being used for REPL. |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
413 |
private static Parser createParser(final ScriptEnvironment env) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
414 |
final List<String> args = new ArrayList<>(); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
415 |
if (env._const_as_var) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
416 |
args.add("--const-as-var"); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
417 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
418 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
419 |
if (env._no_syntax_extensions) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
420 |
args.add("-nse"); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
421 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
422 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
423 |
if (env._scripting) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
424 |
args.add("-scripting"); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
425 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
426 |
|
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
427 |
if (env._strict) { |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
428 |
args.add("-strict"); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
429 |
} |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
430 |
|
39662
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
38488
diff
changeset
|
431 |
if (env._es6) { |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
38488
diff
changeset
|
432 |
args.add("--language=es6"); |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
38488
diff
changeset
|
433 |
} |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
38488
diff
changeset
|
434 |
|
32317
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
435 |
return Parser.create(args.toArray(new String[0])); |
2b653e4e7d65
8134279: jjs should support multiple line input to complete incomplete code
sundar
parents:
32314
diff
changeset
|
436 |
} |
52938 | 437 |
|
438 |
private Candidate createCandidate(String value) { |
|
439 |
return new Candidate(value, value, null, null, null, null, false); |
|
440 |
} |
|
32241 | 441 |
} |