49 */ |
49 */ |
50 public abstract CompletionInfo analyzeCompletion(String input); |
50 public abstract CompletionInfo analyzeCompletion(String input); |
51 |
51 |
52 /** |
52 /** |
53 * Compute possible follow-ups for the given input. |
53 * Compute possible follow-ups for the given input. |
54 * Uses information from the current <code>JShell</code> state, including |
54 * Uses information from the current {@code JShell} state, including |
55 * type information, to filter the suggestions. |
55 * type information, to filter the suggestions. |
56 * @param input the user input, so far |
56 * @param input the user input, so far |
57 * @param cursor the current position of the cursors in the given {@code input} text |
57 * @param cursor the current position of the cursors in the given {@code input} text |
58 * @param anchor outgoing parameter - when an option will be completed, the text between |
58 * @param anchor outgoing parameter - when an option will be completed, the text between |
59 * the anchor and cursor will be deleted and replaced with the given option |
59 * the anchor and cursor will be deleted and replaced with the given option |
95 * Internal only constructor |
95 * Internal only constructor |
96 */ |
96 */ |
97 SourceCodeAnalysis() {} |
97 SourceCodeAnalysis() {} |
98 |
98 |
99 /** |
99 /** |
100 * The result of <code>analyzeCompletion(String input)</code>. |
100 * The result of {@code analyzeCompletion(String input)}. |
101 * Describes the completeness and position of the first snippet in the given input. |
101 * Describes the completeness and position of the first snippet in the given input. |
102 */ |
102 */ |
103 public static class CompletionInfo { |
103 public static class CompletionInfo { |
|
104 |
|
105 private final Completeness completeness; |
|
106 private final int unitEndPos; |
|
107 private final String source; |
|
108 private final String remaining; |
104 |
109 |
105 CompletionInfo(Completeness completeness, int unitEndPos, String source, String remaining) { |
110 CompletionInfo(Completeness completeness, int unitEndPos, String source, String remaining) { |
106 this.completeness = completeness; |
111 this.completeness = completeness; |
107 this.unitEndPos = unitEndPos; |
112 this.unitEndPos = unitEndPos; |
108 this.source = source; |
113 this.source = source; |
109 this.remaining = remaining; |
114 this.remaining = remaining; |
110 } |
115 } |
111 |
116 |
112 /** |
117 /** |
113 * The analyzed completeness of the input. |
118 * The analyzed completeness of the input. |
114 */ |
119 * |
115 public final Completeness completeness; |
120 * @return an enum describing the completeness of the input string. |
116 |
121 */ |
117 /** |
122 public Completeness completeness() { |
118 * The end of the first unit of source. |
123 return completeness; |
119 */ |
124 } |
120 public final int unitEndPos; |
125 |
121 |
126 /** |
122 /** |
127 * Input remaining after the complete part of the source. |
123 * Source code for the first unit of code input. For example, first |
128 * |
124 * statement, or first method declaration. Trailing semicolons will |
129 * @return the portion of the input string that remains after the |
125 * be added, as needed |
130 * complete Snippet |
126 */ |
131 */ |
127 public final String source; |
132 public String remaining() { |
128 |
133 return remaining; |
129 /** |
134 } |
130 * Input remaining after the source |
135 |
131 */ |
136 /** |
132 public final String remaining; |
137 * Source code for the first Snippet of code input. For example, first |
|
138 * statement, or first method declaration. Trailing semicolons will be |
|
139 * added, as needed. |
|
140 * |
|
141 * @return the source of the first encountered Snippet |
|
142 */ |
|
143 public String source() { |
|
144 return source; |
|
145 } |
|
146 |
|
147 /** |
|
148 * The end of the first Snippet of source. |
|
149 * |
|
150 * @return the position of the end of the first Snippet in the input. |
|
151 */ |
|
152 public int unitEndPos() { |
|
153 return unitEndPos; |
|
154 } |
133 } |
155 } |
134 |
156 |
135 /** |
157 /** |
136 * Describes the completeness of the given input. |
158 * Describes the completeness of the given input. |
137 */ |
159 */ |
179 * The input is considered complete because evaluating is the best |
201 * The input is considered complete because evaluating is the best |
180 * mechanism to get error information. |
202 * mechanism to get error information. |
181 */ |
203 */ |
182 UNKNOWN(true); |
204 UNKNOWN(true); |
183 |
205 |
184 /** |
206 private final boolean isComplete; |
185 * Is the first snippet of source complete. For example, "x=" is not |
|
186 * complete, but "x=2" is complete, even though a subsequent line could |
|
187 * make it "x=2+2". Already erroneous code is marked complete. |
|
188 */ |
|
189 public final boolean isComplete; |
|
190 |
207 |
191 Completeness(boolean isComplete) { |
208 Completeness(boolean isComplete) { |
192 this.isComplete = isComplete; |
209 this.isComplete = isComplete; |
193 } |
210 } |
|
211 |
|
212 /** |
|
213 * Indicates whether the first snippet of source is complete. |
|
214 * For example, "{@code x=}" is not |
|
215 * complete, but "{@code x=2}" is complete, even though a subsequent line could |
|
216 * make it "{@code x=2+2}". Already erroneous code is marked complete. |
|
217 * |
|
218 * @return {@code true} if the input is or begins a complete Snippet; |
|
219 * otherwise {@code false} |
|
220 */ |
|
221 public boolean isComplete() { |
|
222 return isComplete; |
|
223 } |
194 } |
224 } |
195 |
225 |
196 /** |
226 /** |
197 * A candidate for continuation of the given user's input. |
227 * A candidate for continuation of the given user's input. |
198 */ |
228 */ |
199 public static class Suggestion { |
229 public static class Suggestion { |
200 |
230 |
|
231 private final String continuation; |
|
232 private final boolean matchesType; |
|
233 |
201 /** |
234 /** |
202 * Create a {@code Suggestion} instance. |
235 * Create a {@code Suggestion} instance. |
|
236 * |
203 * @param continuation a candidate continuation of the user's input |
237 * @param continuation a candidate continuation of the user's input |
204 * @param isSmart is the candidate "smart" |
238 * @param matchesType does the candidate match the target type |
205 */ |
239 */ |
206 public Suggestion(String continuation, boolean isSmart) { |
240 public Suggestion(String continuation, boolean matchesType) { |
207 this.continuation = continuation; |
241 this.continuation = continuation; |
208 this.isSmart = isSmart; |
242 this.matchesType = matchesType; |
209 } |
243 } |
210 |
244 |
211 /** |
245 /** |
212 * The candidate continuation of the given user's input. |
246 * The candidate continuation of the given user's input. |
213 */ |
247 * |
214 public final String continuation; |
248 * @return the continuation string |
215 |
249 */ |
216 /** |
250 public String continuation() { |
217 * Is it an input continuation that matches the target type and is thus more |
251 return continuation; |
218 * likely to be the desired continuation. A smart continuation |
252 } |
219 * is preferred. |
253 |
220 */ |
254 /** |
221 public final boolean isSmart; |
255 * Indicates whether input continuation matches the target type and is thus |
|
256 * more likely to be the desired continuation. A matching continuation is |
|
257 * preferred. |
|
258 * |
|
259 * @return {@code true} if this suggested continuation matches the |
|
260 * target type; otherwise {@code false} |
|
261 */ |
|
262 public boolean matchesType() { |
|
263 return matchesType; |
|
264 } |
222 } |
265 } |
223 |
266 |
224 /** |
267 /** |
225 * List of possible qualified names. |
268 * List of possible qualified names. |
226 */ |
269 */ |
257 public int getSimpleNameLength() { |
300 public int getSimpleNameLength() { |
258 return simpleNameLength; |
301 return simpleNameLength; |
259 } |
302 } |
260 |
303 |
261 /** |
304 /** |
262 * Whether the result is based on up to date data. The |
305 * Indicates whether the result is based on up to date data. The |
263 * {@link SourceCodeAnalysis#listQualifiedNames(java.lang.String, int) listQualifiedNames} |
306 * {@link SourceCodeAnalysis#listQualifiedNames(java.lang.String, int) listQualifiedNames} |
264 * method may return before the classpath is fully inspected, in which case this method will |
307 * method may return before the classpath is fully inspected, in which case this method will |
265 * return {@code false}. If the result is based on a fully inspected classpath, this method |
308 * return {@code false}. If the result is based on a fully inspected classpath, this method |
266 * will return {@code true}. |
309 * will return {@code true}. |
267 * |
310 * |
268 * @return true iff the results is based on up-to-date data |
311 * @return {@code true} if the result is based on up-to-date data; |
|
312 * otherwise {@code false} |
269 */ |
313 */ |
270 public boolean isUpToDate() { |
314 public boolean isUpToDate() { |
271 return upToDate; |
315 return upToDate; |
272 } |
316 } |
273 |
317 |
274 /** |
318 /** |
275 * Whether the given simple name in the original code refers to a resolvable element. |
319 * Indicates whether the given simple name in the original code refers |
276 * |
320 * to a resolvable element. |
277 * @return true iff the given simple name in the original code refers to a resolvable element |
321 * |
|
322 * @return {@code true} if the given simple name in the original code |
|
323 * refers to a resolvable element; otherwise {@code false} |
278 */ |
324 */ |
279 public boolean isResolvable() { |
325 public boolean isResolvable() { |
280 return resolvable; |
326 return resolvable; |
281 } |
327 } |
282 |
328 |