1 /*******************************************************************************
2  * Copyright (c) 2004, 2019 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.core;
15 
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.jdt.internal.codeassist.InternalCompletionProposal;
18 
19 /**
20  * Completion proposal.
21  * <p>
22  * In typical usage, the user working in a Java code editor issues
23  * a code assist command. This command results in a call to
24  * <code>ICodeAssist.codeComplete(position, completionRequestor)</code>
25  * passing the current position in the source code. The code assist
26  * engine analyzes the code in the buffer, determines what kind of
27  * Java language construct is at that position, and proposes ways
28  * to complete that construct. These proposals are instances of
29  * the class <code>CompletionProposal</code>. These proposals,
30  * perhaps after sorting and filtering, are presented to the user
31  * to make a choice.
32  * </p>
33  * <p>
34  * The proposal is as follows: insert
35  * the {@linkplain #getCompletion() completion string} into the
36  * source file buffer, replacing the characters between
37  * {@linkplain #getReplaceStart() the start}
38  * and {@linkplain #getReplaceEnd() end}. The string
39  * can be arbitrary; for example, it might include not only the
40  * name of a method but a set of parentheses. Moreover, the source
41  * range may include source positions before or after the source
42  * position where <code>ICodeAssist.codeComplete</code> was invoked.
43  * The rest of the information associated with the proposal is
44  * to provide context that may help a user to choose from among
45  * competing proposals.
46  * </p>
47  * <p>
48  * The completion engine creates instances of this class.
49  * </p>
50  *
51  * @see ICodeAssist#codeComplete(int, CompletionRequestor)
52  * @since 3.0
53  * @noinstantiate This class is not intended to be instantiated by clients.
54  * @noextend This class is not intended to be subclassed by clients.
55  */
56 public class CompletionProposal {
57 
58 	/**
59 	 * Completion is a declaration of an anonymous class.
60 	 * This kind of completion might occur in a context like
61 	 * <code>"new List(^;"</code> and complete it to
62 	 * <code>"new List() {}"</code>.
63 	 * <p>
64 	 * The following additional context information is available
65 	 * for this kind of completion proposal at little extra cost:
66 	 * <ul>
67 	 * <li>{@link #getDeclarationSignature()} -
68 	 * the type signature of the type being implemented or subclassed
69 	 * </li>
70 	 * <li>{@link #getDeclarationKey()} -
71 	 * the type unique key of the type being implemented or subclassed
72 	 * </li>
73 	 * <li>{@link #getSignature()} -
74 	 * the method signature of the constructor that is referenced
75 	 * </li>
76 	 * <li>{@link #getKey()} -
77 	 * the method unique key of the constructor that is referenced
78 	 * if the declaring type is not an interface
79 	 * </li>
80 	 * <li>{@link #getFlags()} -
81 	 * the modifiers flags of the constructor that is referenced
82 	 * </li>
83 	 * </ul>
84 	 *
85 	 * @see #getKind()
86 	 */
87 	public static final int ANONYMOUS_CLASS_DECLARATION = 1;
88 
89 	/**
90 	 * Completion is a reference to a field.
91 	 * This kind of completion might occur in a context like
92 	 * <code>"this.ref^ = 0;"</code> and complete it to
93 	 * <code>"this.refcount = 0;"</code>.
94 	 * <p>
95 	 * The following additional context information is available
96 	 * for this kind of completion proposal at little extra cost:
97 	 * <ul>
98 	 * <li>{@link #getDeclarationSignature()} -
99 	 * the type signature of the type that declares the field that is referenced
100 	 * </li>
101 	 * <li>{@link #getFlags()} -
102 	 * the modifiers flags (including ACC_ENUM) of the field that is referenced
103 	 * </li>
104 	 * <li>{@link #getName()} -
105 	 * the simple name of the field that is referenced
106 	 * </li>
107 	 * <li>{@link #getSignature()} -
108 	 * the type signature of the field's type (as opposed to the
109 	 * signature of the type in which the referenced field
110 	 * is declared)
111 	 * </li>
112 	 * </ul>
113 	 *
114 	 * @see #getKind()
115 	 */
116 	public static final int FIELD_REF = 2;
117 
118 	/**
119 	 * Completion is a keyword.
120 	 * This kind of completion might occur in a context like
121 	 * <code>"public cl^ Foo {}"</code> and complete it to
122 	 * <code>"public class Foo {}"</code>.
123 	 * <p>
124 	 * The following additional context information is available
125 	 * for this kind of completion proposal at little extra cost:
126 	 * <ul>
127 	 * <li>{@link #getName()} -
128 	 * the keyword token
129 	 * </li>
130 	 * <li>{@link #getFlags()} -
131 	 * the corresponding modifier flags if the keyword is a modifier
132 	 * </li>
133 	 * </ul>
134 	 *
135 	 * @see #getKind()
136 	 */
137 	public static final int KEYWORD = 3;
138 
139 	/**
140 	 * Completion is a reference to a label.
141 	 * This kind of completion might occur in a context like
142 	 * <code>"break lo^;"</code> and complete it to
143 	 * <code>"break loop;"</code>.
144 	 * <p>
145 	 * The following additional context information is available
146 	 * for this kind of completion proposal at little extra cost:
147 	 * <ul>
148 	 * <li>{@link #getName()} -
149 	 * the simple name of the label that is referenced
150 	 * </li>
151 	 * </ul>
152 	 *
153 	 * @see #getKind()
154 	 */
155 	public static final int LABEL_REF = 4;
156 
157 	/**
158 	 * Completion is a reference to a local variable.
159 	 * This kind of completion might occur in a context like
160 	 * <code>"ke^ = 4;"</code> and complete it to
161 	 * <code>"keys = 4;"</code>.
162 	 * <p>
163 	 * The following additional context information is available
164 	 * for this kind of completion proposal at little extra cost:
165 	 * <ul>
166 	 * <li>{@link #getFlags()} -
167 	 * the modifiers flags of the local variable that is referenced
168 	 * </li>
169 	 * <li>{@link #getName()} -
170 	 * the simple name of the local variable that is referenced
171 	 * </li>
172 	 * <li>{@link #getSignature()} -
173 	 * the type signature of the local variable's type
174 	 * </li>
175 	 * </ul>
176 	 *
177 	 * @see #getKind()
178 	 */
179 	public static final int LOCAL_VARIABLE_REF = 5;
180 
181 	/**
182 	 * Completion is a reference to a method.
183 	 * This kind of completion might occur in a context like
184 	 * <code>"System.out.pr^();"</code> and complete it to
185 	 * <code>""System.out.println();"</code>.
186 	 * <p>
187 	 * The following additional context information is available
188 	 * for this kind of completion proposal at little extra cost:
189 	 * <ul>
190 	 * <li>{@link #getDeclarationSignature()} -
191 	 * the type signature of the type that declares the method that is referenced
192 	 * </li>
193 	 * <li>{@link #getFlags()} -
194 	 * the modifiers flags of the method that is referenced
195 	 * </li>
196 	 * <li>{@link #getName()} -
197 	 * the simple name of the method that is referenced
198 	 * </li>
199 	 * <li>{@link #getSignature()} -
200 	 * the method signature of the method that is referenced
201 	 * </li>
202 	 * </ul>
203 	 *
204 	 * @see #getKind()
205 	 */
206 	public static final int METHOD_REF = 6;
207 
208 	/**
209 	 * Completion is a declaration of a method.
210 	 * This kind of completion might occur in a context like
211 	 * <code>"new List() {si^};"</code> and complete it to
212 	 * <code>"new List() {public int size() {} };"</code>.
213 	 * <p>
214 	 * The following additional context information is available
215 	 * for this kind of completion proposal at little extra cost:
216 	 * <ul>
217 	 * <li>{@link #getDeclarationSignature()} -
218 	 * the type signature of the type that declares the
219 	 * method that is being overridden or implemented
220 	 * </li>
221 	 * <li>{@link #getDeclarationKey()} -
222 	 * the unique of the type that declares the
223 	 * method that is being overridden or implemented
224 	 * </li>
225 	 * <li>{@link #getName()} -
226 	 * the simple name of the method that is being overridden
227 	 * or implemented
228 	 * </li>
229 	 * <li>{@link #getSignature()} -
230 	 * the method signature of the method that is being
231 	 * overridden or implemented
232 	 * </li>
233 	 * <li>{@link #getKey()} -
234 	 * the method unique key of the method that is being
235 	 * overridden or implemented
236 	 * </li>
237 	 * <li>{@link #getFlags()} -
238 	 * the modifiers flags of the method that is being
239 	 * overridden or implemented
240 	 * </li>
241 	 * </ul>
242 	 *
243 	 * @see #getKind()
244 	 */
245 	public static final int METHOD_DECLARATION = 7;
246 
247 	/**
248 	 * Completion is a reference to a package.
249 	 * This kind of completion might occur in a context like
250 	 * <code>"import java.u^.*;"</code> and complete it to
251 	 * <code>"import java.util.*;"</code>.
252 	 * <p>
253 	 * The following additional context information is available
254 	 * for this kind of completion proposal at little extra cost:
255 	 * <ul>
256 	 * <li>{@link #getDeclarationSignature()} -
257 	 * the dot-based package name of the package that is referenced
258 	 * </li>
259 	 * </ul>
260 	 *
261 	 * @see #getKind()
262 	 */
263 	public static final int PACKAGE_REF = 8;
264 
265 	/**
266 	 * Completion is a reference to a type. Any kind of type
267 	 * is allowed, including primitive types, reference types,
268 	 * array types, parameterized types, and type variables.
269 	 * This kind of completion might occur in a context like
270 	 * <code>"public static Str^ key;"</code> and complete it to
271 	 * <code>"public static String key;"</code>.
272 	 * <p>
273 	 * The following additional context information is available
274 	 * for this kind of completion proposal at little extra cost:
275 	 * <ul>
276 	 * <li>{@link #getDeclarationSignature()} -
277 	 * the dot-based package name of the package that contains
278 	 * the type that is referenced
279 	 * </li>
280 	 * <li>{@link #getSignature()} -
281 	 * the type signature of the type that is referenced
282 	 * </li>
283 	 * <li>{@link #getFlags()} -
284 	 * the modifiers flags (including Flags.AccInterface, AccEnum,
285 	 * and AccAnnotation) of the type that is referenced
286 	 * </li>
287 	 * </ul>
288 	 *
289 	 * @see #getKind()
290 	 */
291 	public static final int TYPE_REF = 9;
292 
293 	/**
294 	 * Completion is a declaration of a variable (locals, parameters,
295 	 * fields, etc.).
296 	 * <p>
297 	 * The following additional context information is available
298 	 * for this kind of completion proposal at little extra cost:
299 	 * <ul>
300 	 * <li>{@link #getName()} -
301 	 * the simple name of the variable being declared
302 	 * </li>
303 	 * <li>{@link #getSignature()} -
304 	 * the type signature of the type of the variable
305 	 * being declared
306 	 * </li>
307 	 * <li>{@link #getFlags()} -
308 	 * the modifiers flags of the variable being declared
309 	 * </li>
310 	 * </ul>
311 	 * @see #getKind()
312 	 */
313 	public static final int VARIABLE_DECLARATION = 10;
314 
315 	/**
316 	 * Completion is a declaration of a new potential method.
317 	 * This kind of completion might occur in a context like
318 	 * <code>"new List() {si^};"</code> and complete it to
319 	 * <code>"new List() {public int si() {} };"</code>.
320 	 * <p>
321 	 * The following additional context information is available
322 	 * for this kind of completion proposal at little extra cost:
323 	 * <ul>
324 	 * <li>{@link #getDeclarationSignature()} -
325 	 * the type signature of the type that declares the
326 	 * method that is being created
327 	 * </li>
328 	 * <li>{@link #getName()} -
329 	 * the simple name of the method that is being created
330 	 * </li>
331 	 * <li>{@link #getSignature()} -
332 	 * the method signature of the method that is being
333 	 * created
334 	 * </li>
335 	 * <li>{@link #getFlags()} -
336 	 * the modifiers flags of the method that is being
337 	 * created
338 	 * </li>
339 	 * </ul>
340 	 *
341 	 * @see #getKind()
342      * @since 3.1
343 	 */
344 	public static final int POTENTIAL_METHOD_DECLARATION = 11;
345 
346 	/**
347 	 * Completion is a reference to a method name.
348 	 * This kind of completion might occur in a context like
349 	 * <code>"import p.X.fo^"</code> and complete it to
350 	 * <code>"import p.X.foo;"</code>.
351 	 * <p>
352 	 * The following additional context information is available
353 	 * for this kind of completion proposal at little extra cost:
354 	 * </p>
355 	 * <ul>
356 	 * <li>{@link #getDeclarationSignature()} -
357 	 * the type signature of the type that declares the method that is referenced
358 	 * </li>
359 	 * <li>{@link #getFlags()} -
360 	 * the modifiers flags of the method that is referenced
361 	 * </li>
362 	 * <li>{@link #getName()} -
363 	 * the simple name of the method that is referenced
364 	 * </li>
365 	 * <li>{@link #getSignature()} -
366 	 * the method signature of the method that is referenced
367 	 * </li>
368 	 * </ul>
369 	 *
370 	 * @see #getKind()
371      * @since 3.1
372 	 */
373 	public static final int METHOD_NAME_REFERENCE = 12;
374 
375 	/**
376 	 * Completion is a reference to annotation's attribute.
377 	 * This kind of completion might occur in a context like
378 	 * <code>"@Annot(attr^=value)"</code> and complete it to
379 	 * <code>"@Annot(attribute^=value)"</code>.
380 	 * <p>
381 	 * The following additional context information is available
382 	 * for this kind of completion proposal at little extra cost:
383 	 * <ul>
384 	 * <li>{@link #getDeclarationSignature()} -
385 	 * the type signature of the annotation that declares the attribute that is referenced
386 	 * </li>
387 	 * <li>{@link #getFlags()} -
388 	 * the modifiers flags of the attribute that is referenced
389 	 * </li>
390 	 * <li>{@link #getName()} -
391 	 * the simple name of the attribute that is referenced
392 	 * </li>
393 	 * <li>{@link #getSignature()} -
394 	 * the type signature of the attribute's type (as opposed to the
395 	 * signature of the type in which the referenced attribute
396 	 * is declared)
397 	 * </li>
398 	 * </ul>
399 	 *
400 	 * @see #getKind()
401 	 * @since 3.1
402 	 */
403 	public static final int ANNOTATION_ATTRIBUTE_REF = 13;
404 
405 	/**
406 	 * Completion is a link reference to a field in a javadoc text.
407 	 * This kind of completion might occur in a context like
408 	 * <code>"	* blabla System.o^ blabla"</code> and complete it to
409 	 * <code>"	* blabla {&#64;link System#out } blabla"</code>.
410 	 * <p>
411 	 * The following additional context information is available
412 	 * for this kind of completion proposal at little extra cost:
413 	 * <ul>
414 	 * <li>{@link #getDeclarationSignature()} -
415 	 * the type signature of the type that declares the field that is referenced
416 	 * </li>
417 	 * <li>{@link #getFlags()} -
418 	 * the modifiers flags (including ACC_ENUM) of the field that is referenced
419 	 * </li>
420 	 * <li>{@link #getName()} -
421 	 * the simple name of the field that is referenced
422 	 * </li>
423 	 * <li>{@link #getSignature()} -
424 	 * the type signature of the field's type (as opposed to the
425 	 * signature of the type in which the referenced field
426 	 * is declared)
427 	 * </li>
428 	 * </ul>
429 	 *
430 	 * @see #getKind()
431 	 * @since 3.2
432 	 */
433 	public static final int JAVADOC_FIELD_REF = 14;
434 
435 	/**
436 	 * Completion is a link reference to a method in a javadoc text.
437 	 * This kind of completion might occur in a context like
438 	 * <code>"	* blabla Runtime#get^ blabla"</code> and complete it to
439 	 * <code>"	* blabla {&#64;link Runtime#getRuntime() }"</code>.
440 	 * <p>
441 	 * The following additional context information is available
442 	 * for this kind of completion proposal at little extra cost:
443 	 * <ul>
444 	 * <li>{@link #getDeclarationSignature()} -
445 	 * the type signature of the type that declares the method that is referenced
446 	 * </li>
447 	 * <li>{@link #getFlags()} -
448 	 * the modifiers flags of the method that is referenced
449 	 * </li>
450 	 * <li>{@link #getName()} -
451 	 * the simple name of the method that is referenced
452 	 * </li>
453 	 * <li>{@link #getSignature()} -
454 	 * the method signature of the method that is referenced
455 	 * </li>
456 	 * </ul>
457 	 *
458 	 * @see #getKind()
459 	 * @since 3.2
460 	 */
461 	public static final int JAVADOC_METHOD_REF = 15;
462 
463 	/**
464 	 * Completion is a link reference to a type in a javadoc text.
465 	 * Any kind of type is allowed, including primitive types, reference types,
466 	 * array types, parameterized types, and type variables.
467 	 * This kind of completion might occur in a context like
468 	 * <code>"	* blabla Str^ blabla"</code> and complete it to
469 	 * <code>"	* blabla {&#64;link String } blabla"</code>.
470 	 * <p>
471 	 * The following additional context information is available
472 	 * for this kind of completion proposal at little extra cost:
473 	 * <ul>
474 	 * <li>{@link #getDeclarationSignature()} -
475 	 * the dot-based package name of the package that contains
476 	 * the type that is referenced
477 	 * </li>
478 	 * <li>{@link #getSignature()} -
479 	 * the type signature of the type that is referenced
480 	 * </li>
481 	 * <li>{@link #getFlags()} -
482 	 * the modifiers flags (including Flags.AccInterface, AccEnum,
483 	 * and AccAnnotation) of the type that is referenced
484 	 * </li>
485 	 * </ul>
486 	 *
487 	 * @see #getKind()
488 	 * @since 3.2
489 	 */
490 	public static final int JAVADOC_TYPE_REF = 16;
491 
492 	/**
493 	 * Completion is a value reference to a static field in a javadoc text.
494 	 * This kind of completion might occur in a context like
495 	 * <code>"	* blabla System.o^ blabla"</code> and complete it to
496 	 * <code>"	* blabla {&#64;value System#out } blabla"</code>.
497 	 * <p>
498 	 * The following additional context information is available
499 	 * for this kind of completion proposal at little extra cost:
500 	 * <ul>
501 	 * <li>{@link #getDeclarationSignature()} -
502 	 * the type signature of the type that declares the field that is referenced
503 	 * </li>
504 	 * <li>{@link #getFlags()} -
505 	 * the modifiers flags (including ACC_ENUM) of the field that is referenced
506 	 * </li>
507 	 * <li>{@link #getName()} -
508 	 * the simple name of the field that is referenced
509 	 * </li>
510 	 * <li>{@link #getSignature()} -
511 	 * the type signature of the field's type (as opposed to the
512 	 * signature of the type in which the referenced field
513 	 * is declared)
514 	 * </li>
515 	 * </ul>
516 	 *
517 	 * @see #getKind()
518 	 * @since 3.2
519 	 */
520 	public static final int JAVADOC_VALUE_REF = 17;
521 
522 	/**
523 	 * Completion is a method argument or a class/method type parameter
524 	 * in javadoc param tag.
525 	 * This kind of completion might occur in a context like
526 	 * <code>"	* @param arg^ blabla"</code> and complete it to
527 	 * <code>"	* @param argument blabla"</code>.
528 	 * or
529 	 * <code>"	* @param &lt;T^ blabla"</code> and complete it to
530 	 * <code>"	* @param &lt;TT&gt; blabla"</code>.
531 	 * <p>
532 	 * The following additional context information is available
533 	 * for this kind of completion proposal at little extra cost:
534 	 * <ul>
535 	 * <li>{@link #getDeclarationSignature()} -
536 	 * the type signature of the type that declares the field that is referenced
537 	 * </li>
538 	 * <li>{@link #getFlags()} -
539 	 * the modifiers flags (including ACC_ENUM) of the field that is referenced
540 	 * </li>
541 	 * <li>{@link #getName()} -
542 	 * the simple name of the field that is referenced
543 	 * </li>
544 	 * <li>{@link #getSignature()} -
545 	 * the type signature of the field's type (as opposed to the
546 	 * signature of the type in which the referenced field
547 	 * is declared)
548 	 * </li>
549 	 * </ul>
550 	 *
551 	 * @see #getKind()
552 	 * @since 3.2
553 	 */
554 	public static final int JAVADOC_PARAM_REF = 18;
555 
556 	/**
557 	 * Completion is a javadoc block tag.
558 	 * This kind of completion might occur in a context like
559 	 * <code>"	* @s^ blabla"</code> and complete it to
560 	 * <code>"	* @see blabla"</code>.
561 	 * <p>
562 	 * The following additional context information is available
563 	 * for this kind of completion proposal at little extra cost:
564 	 * <ul>
565 	 * <li>{@link #getDeclarationSignature()} -
566 	 * the type signature of the type that declares the field that is referenced
567 	 * </li>
568 	 * <li>{@link #getFlags()} -
569 	 * the modifiers flags (including ACC_ENUM) of the field that is referenced
570 	 * </li>
571 	 * <li>{@link #getName()} -
572 	 * the simple name of the field that is referenced
573 	 * </li>
574 	 * <li>{@link #getSignature()} -
575 	 * the type signature of the field's type (as opposed to the
576 	 * signature of the type in which the referenced field
577 	 * is declared)
578 	 * </li>
579 	 * </ul>
580 	 *
581 	 * @see #getKind()
582 	 * @since 3.2
583 	 */
584 	public static final int JAVADOC_BLOCK_TAG = 19;
585 
586 	/**
587 	 * Completion is a javadoc inline tag.
588 	 * This kind of completion might occur in a context like
589 	 * <code>"	* Insert @l^ Object"</code> and complete it to
590 	 * <code>"	* Insert {&#64;link Object }"</code>.
591 	 * <p>
592 	 * The following additional context information is available
593 	 * for this kind of completion proposal at little extra cost:
594 	 * <ul>
595 	 * <li>{@link #getDeclarationSignature()} -
596 	 * the type signature of the type that declares the field that is referenced
597 	 * </li>
598 	 * <li>{@link #getFlags()} -
599 	 * the modifiers flags (including ACC_ENUM) of the field that is referenced
600 	 * </li>
601 	 * <li>{@link #getName()} -
602 	 * the simple name of the field that is referenced
603 	 * </li>
604 	 * <li>{@link #getSignature()} -
605 	 * the type signature of the field's type (as opposed to the
606 	 * signature of the type in which the referenced field
607 	 * is declared)
608 	 * </li>
609 	 * </ul>
610 	 *
611 	 * @see #getKind()
612 	 * @since 3.2
613 	 */
614 	public static final int JAVADOC_INLINE_TAG = 20;
615 
616 	/**
617 	 * Completion is an import of reference to a static field.
618 	 * <p>
619 	 * The following additional context information is available
620 	 * for this kind of completion proposal at little extra cost:
621 	 * <ul>
622 	 * <li>{@link #getDeclarationSignature()} -
623 	 * the type signature of the type that declares the field that is imported
624 	 * </li>
625 	 * <li>{@link #getFlags()} -
626 	 * the modifiers flags (including ACC_ENUM) of the field that is imported
627 	 * </li>
628 	 * <li>{@link #getName()} -
629 	 * the simple name of the field that is imported
630 	 * </li>
631 	 * <li>{@link #getSignature()} -
632 	 * the type signature of the field's type (as opposed to the
633 	 * signature of the type in which the referenced field
634 	 * is declared)
635 	 * </li>
636 	 * <li>{@link #getAdditionalFlags()} -
637 	 * the completion flags (including ComletionFlags.StaticImport)
638 	 * of the proposed import
639 	 * </li>
640 	 * </ul>
641 	 *
642 	 * @see #getKind()
643 	 *
644 	 * @since 3.3
645 	 */
646 	public static final int FIELD_IMPORT = 21;
647 
648 	/**
649 	 * Completion is an import of reference to a static method.
650 	 * <p>
651 	 * The following additional context information is available
652 	 * for this kind of completion proposal at little extra cost:
653 	 * <ul>
654 	 * <li>{@link #getDeclarationSignature()} -
655 	 * the type signature of the type that declares the method that is imported
656 	 * </li>
657 	 * <li>{@link #getFlags()} -
658 	 * the modifiers flags of the method that is imported
659 	 * </li>
660 	 * <li>{@link #getName()} -
661 	 * the simple name of the method that is imported
662 	 * </li>
663 	 * <li>{@link #getSignature()} -
664 	 * the method signature of the method that is imported
665 	 * </li>
666 	 * <li>{@link #getAdditionalFlags()} -
667 	 * the completion flags (including ComletionFlags.StaticImport)
668 	 * of the proposed import
669 	 * </li>
670 	 * </ul>
671 	 *
672 	 * @see #getKind()
673 	 *
674 	 * @since 3.3
675 	 */
676 	public static final int METHOD_IMPORT = 22;
677 
678 	/**
679 	 * Completion is an import of reference to a type.
680 	 * Only reference to reference types are allowed.
681 	 * <p>
682 	 * The following additional context information is available
683 	 * for this kind of completion proposal at little extra cost:
684 	 * <ul>
685 	 * <li>{@link #getDeclarationSignature()} -
686 	 * the dot-based package name of the package that contains
687 	 * the type that is imported
688 	 * </li>
689 	 * <li>{@link #getSignature()} -
690 	 * the type signature of the type that is imported
691 	 * </li>
692 	 * <li>{@link #getFlags()} -
693 	 * the modifiers flags (including Flags.AccInterface, AccEnum,
694 	 * and AccAnnotation) of the type that is imported
695 	 * </li>
696 	 * <li>{@link #getAdditionalFlags()} -
697 	 * the completion flags (including ComletionFlags.StaticImport)
698 	 * of the proposed import
699 	 * </li>
700 	 * </ul>
701 	 *
702 	 * @see #getKind()
703 	 *
704 	 * @since 3.3
705 	 */
706 	public static final int TYPE_IMPORT = 23;
707 
708 	/**
709 	 * Completion is a reference to a method with a casted receiver.
710 	 * This kind of completion might occur in a context like
711 	 * <code>"receiver.fo^();"</code> and complete it to
712 	 * <code>""((X)receiver).foo();"</code>.
713 	 * <p>
714 	 * The following additional context information is available
715 	 * for this kind of completion proposal at little extra cost:
716 	 * <ul>
717 	 * <li>{@link #getDeclarationSignature()} -
718 	 * the type signature of the type that declares the method that is referenced
719 	 * </li>
720 	 * <li>{@link #getFlags()} -
721 	 * the modifiers flags of the method that is referenced
722 	 * </li>
723 	 * <li>{@link #getName()} -
724 	 * the simple name of the method that is referenced
725 	 * </li>
726 	 * <li>{@link #getReceiverSignature()} -
727 	 * the type signature of the receiver type. It's the type of the cast expression.
728 	 * </li>
729 	 * <li>{@link #getSignature()} -
730 	 * the method signature of the method that is referenced
731 	 * </li>
732 	 * </ul>
733 	 *
734 	 * @see #getKind()
735 	 *
736 	 * @since 3.4
737 	 */
738 	public static final int METHOD_REF_WITH_CASTED_RECEIVER = 24;
739 
740 	/**
741 	 * Completion is a reference to a field with a casted receiver.
742 	 * This kind of completion might occur in a context like
743 	 * <code>"recevier.ref^ = 0;"</code> and complete it to
744 	 * <code>"((X)receiver).refcount = 0;"</code>.
745 	 * <p>
746 	 * The following additional context information is available
747 	 * for this kind of completion proposal at little extra cost:
748 	 * <ul>
749 	 * <li>{@link #getDeclarationSignature()} -
750 	 * the type signature of the type that declares the field that is referenced
751 	 * </li>
752 	 * <li>{@link #getFlags()} -
753 	 * the modifiers flags (including ACC_ENUM) of the field that is referenced
754 	 * </li>
755 	 * <li>{@link #getName()} -
756 	 * the simple name of the field that is referenced
757 	 * </li>
758 	 * <li>{@link #getReceiverSignature()} -
759 	 * the type signature of the receiver type. It's the type of the cast expression.
760 	 * </li>
761 	 * <li>{@link #getSignature()} -
762 	 * the type signature of the field's type (as opposed to the
763 	 * signature of the type in which the referenced field
764 	 * is declared)
765 	 * </li>
766 	 *
767 	 * </ul>
768 	 *
769 	 * @see #getKind()
770 	 *
771 	 * @since 3.4
772 	 */
773 	public static final int FIELD_REF_WITH_CASTED_RECEIVER = 25;
774 
775 	/**
776 	 * Completion is a reference to a constructor.
777 	 * This kind of completion might occur in a context like
778 	 * <code>"new Lis"</code> and complete it to
779 	 * <code>"new List();"</code> if List is a class that is not abstract.
780 	 * <p>
781 	 * The following additional context information is available
782 	 * for this kind of completion proposal at little extra cost:
783 	 * <ul>
784 	 * <li>{@link #getDeclarationSignature()} -
785 	 * the type signature of the type that declares the constructor that is referenced
786 	 * </li>
787 	 * <li>{@link #getFlags()} -
788 	 * the modifiers flags of the constructor that is referenced
789 	 * </li>
790 	 * <li>{@link #getName()} -
791 	 * the simple name of the constructor that is referenced
792 	 * </li>
793 	 * <li>{@link #getSignature()} -
794 	 * the method signature of the constructor that is referenced
795 	 * </li>
796 	 * </ul>
797 	 * <p>
798 	 * This kind of proposal could require a long computation, so they are computed only if completion operation is called with a {@link IProgressMonitor}
799 	 * (e.g. {@link ICodeAssist#codeComplete(int, CompletionRequestor, IProgressMonitor)}).<br>
800 	 * This kind of proposal is always is only proposals with a {@link #TYPE_REF} required proposal, so this kind of required proposal must be allowed:
801 	 * <code>requestor.setAllowsRequiredProposals(CONSTRUCTOR_INVOCATION, TYPE_REF, true)</code>.
802 	 * </p>
803 	 *
804 	 * @see #getKind()
805 	 * @see CompletionRequestor#setAllowsRequiredProposals(int, int, boolean)
806 	 *
807 	 * @since 3.5
808 	 */
809 	public static final int CONSTRUCTOR_INVOCATION = 26;
810 
811 	/**
812 	 * Completion is a reference of a constructor of an anonymous class.
813 	 * This kind of completion might occur in a context like
814 	 * <code>"new Lis^;"</code> and complete it to
815 	 * <code>"new List() {}"</code> if List is an interface or abstract class.
816 	 * <p>
817 	 * The following additional context information is available
818 	 * for this kind of completion proposal at little extra cost:
819 	 * <ul>
820 	 * <li>{@link #getDeclarationSignature()} -
821 	 * the type signature of the type being implemented or subclassed
822 	 * </li>
823 	 * <li>{@link #getDeclarationKey()} -
824 	 * the type unique key of the type being implemented or subclassed
825 	 * </li>
826 	 * <li>{@link #getSignature()} -
827 	 * the method signature of the constructor that is referenced
828 	 * </li>
829 	 * <li>{@link #getKey()} -
830 	 * the method unique key of the constructor that is referenced
831 	 * if the declaring type is not an interface
832 	 * </li>
833 	 * <li>{@link #getFlags()} -
834 	 * the modifiers flags of the constructor that is referenced
835 	 * </li>
836 	 * </ul>
837 	 * <p>
838 	 * This kind of proposal could require a long computation, so they are computed only if completion operation is called with a {@link IProgressMonitor}
839 	 * (e.g. {@link ICodeAssist#codeComplete(int, CompletionRequestor, IProgressMonitor)})<br>
840 	 * This kind of proposal is always is only proposals with a {@link #TYPE_REF} required proposal, so this kind of required proposal must be allowed:
841 	 * <code>requestor.setAllowsRequiredProposals(CONSTRUCTOR_INVOCATION, TYPE_REF, true)</code>.
842 	 * </p>
843 	 *
844 	 * @see #getKind()
845 	 * @see CompletionRequestor#setAllowsRequiredProposals(int, int, boolean)
846 	 *
847 	 * @since 3.5
848 	 */
849 	public static final int ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION = 27;
850 
851 	/**
852 	 * Completion is a declaration of a module.
853 	 * This kind of completion might occur in a module-info.java file
854 	 * after the keyword <code> "module" </code> as shown below:
855 	 * <code>"module co^"</code> and complete it to
856 	 * <code>"module com.greetings"</code>.
857 	 *
858 	 * @see #getKind()
859 	 * @since 3.14
860 	 */
861 	public static final int MODULE_DECLARATION = 28;
862 
863 	/**
864 	/**
865 	 * Completion is a reference to a module.
866 	 * This kind of completion might occur in a context like
867 	 * <code>"requires com.g^"</code> and complete it to
868 	 * <code>"requires com.greetings"</code> or in
869 	 * <code> "to com.g^"</code> to <code>"to com.greetings</code>
870 	 *
871 	 * @see #getKind()
872 	 * @since 3.14
873 	 */
874 	public static final int MODULE_REF = 29;
875 	/**
876 	 * First valid completion kind.
877 	 *
878 	 * @since 3.1
879 	 */
880 	protected static final int FIRST_KIND = ANONYMOUS_CLASS_DECLARATION;
881 
882 	/**
883 	 * Last valid completion kind.
884 	 *
885 	 * @since 3.1
886 	 */
887 	protected static final int LAST_KIND = MODULE_REF;
888 
889 	/**
890 	 * Creates a basic completion proposal. All instance
891 	 * field have plausible default values unless otherwise noted.
892 	 * <p>
893 	 * Note that the constructors for this class are internal to the
894 	 * Java model implementation. Clients cannot directly create
895 	 * CompletionProposal objects.
896 	 * </p>
897 	 *
898 	 * @param kind one of the kind constants declared on this class
899 	 * @param completionOffset original offset of code completion request
900 	 * @return a new completion proposal
901 	 */
create(int kind, int completionOffset)902 	public static CompletionProposal create(int kind, int completionOffset) {
903 		return new InternalCompletionProposal(kind, completionOffset);
904 	}
905 
906 	/**
907 	 * Returns the completion flags relevant in the context, or
908 	 * <code>CompletionFlags.Default</code> if none.
909 	 * <p>
910 	 * This field is available for the following kinds of
911 	 * completion proposals:
912 	 * <ul>
913 	 * <li><code>FIELD_IMPORT</code> - completion flags
914 	 * of the attribute that is referenced. Completion flags for
915 	 * this proposal kind can only include <code>CompletionFlags.StaticImport</code></li>
916 	 * <li><code>METHOD_IMPORT</code> - completion flags
917 	 * of the attribute that is referenced. Completion flags for
918 	 * this proposal kind can only include <code>CompletionFlags.StaticImport</code></li>
919 	 * <li><code>TYPE_IMPORT</code> - completion flags
920 	 * of the attribute that is referenced. Completion flags for
921 	 * this proposal kind can only include <code>CompletionFlags.StaticImport</code></li>
922 	 * </ul>
923 	 * For other kinds of completion proposals, this method returns
924 	 * <code>CompletionFlags.Default</code>.
925 	 *
926 	 * @return the completion flags, or
927 	 * <code>CompletionFlags.Default</code> if none
928 	 * @see CompletionFlags
929 	 *
930 	 * @since 3.3
931 	 */
getAdditionalFlags()932 	public int getAdditionalFlags() {
933 		return -1; // default overridden by concrete implementation
934 	}
935 
936 	/**
937 	 * Sets the completion flags relevant in the context.
938 	 * <p>
939 	 * If not set, defaults to none.
940 	 * </p>
941 	 * <p>
942 	 * The completion engine creates instances of this class and sets
943 	 * its properties; this method is not intended to be used by other clients.
944 	 * </p>
945 	 *
946 	 * @param additionalFlags the completion flags, or
947 	 * <code>CompletionFlags.Default</code> if none
948 	 *
949 	 * @since 3.3
950 	 */
setAdditionalFlags(int additionalFlags)951 	public void setAdditionalFlags(int additionalFlags) {
952 		// default overridden by concrete implementation
953 	}
954 
955 	/**
956 	 * Returns the kind of completion being proposed.
957 	 * <p>
958 	 * The set of different kinds of completion proposals is
959 	 * expected to change over time. It is strongly recommended
960 	 * that clients do <b>not</b> assume that the kind is one of the
961 	 * ones they know about, and code defensively for the
962 	 * possibility of unexpected future growth.
963 	 * </p>
964 	 *
965 	 * @return the kind; one of the kind constants
966 	 * declared on this class, or possibly a kind unknown
967 	 * to the caller
968 	 */
getKind()969 	public int getKind() {
970 		return -1; // default overridden by concrete implementation
971 	}
972 
973 	/**
974 	 * Returns the character index in the source file buffer
975 	 * where source completion was requested (the
976 	 * <code>offset</code> parameter to
977 	 * <code>ICodeAssist.codeComplete</code> minus one).
978 	 *
979 	 * @return character index in source file buffer
980 	 * @see ICodeAssist#codeComplete(int,CompletionRequestor)
981 	 */
982 	// TODO (david) https://bugs.eclipse.org/bugs/show_bug.cgi?id=132558
getCompletionLocation()983 	public int getCompletionLocation() {
984 		return -1; // default overridden by concrete implementation
985 	}
986 
987 	/**
988 	 * Returns the character index of the start of the
989 	 * subrange in the source file buffer containing the
990 	 * relevant token being completed. This
991 	 * token is either the identifier or Java language keyword
992 	 * under, or immediately preceding, the original request
993 	 * offset. If the original request offset is not within
994 	 * or immediately after an identifier or keyword, then the
995 	 * position returned is original request offset and the
996 	 * token range is empty.
997 	 *
998 	 * @return character index of token start position (inclusive)
999 	 */
getTokenStart()1000 	public int getTokenStart() {
1001 		return -1; // default overridden by concrete implementation
1002 	}
1003 
1004 	/**
1005 	 * Returns the character index of the end (exclusive) of the subrange
1006 	 * in the source file buffer containing the
1007 	 * relevant token. When there is no relevant token, the
1008 	 * range is empty
1009 	 * (<code>getEndToken() == getStartToken()</code>).
1010 	 *
1011 	 * @return character index of token end position (exclusive)
1012 	 */
getTokenEnd()1013 	public int getTokenEnd() {
1014 		return -1; // default overridden by concrete implementation
1015 	}
1016 
1017 	/**
1018 	 * Sets the character indices of the subrange in the
1019 	 * source file buffer containing the relevant token being
1020 	 * completed. This token is either the identifier or
1021 	 * Java language keyword under, or immediately preceding,
1022 	 * the original request offset. If the original request
1023 	 * offset is not within or immediately after an identifier
1024 	 * or keyword, then the source range begins at original
1025 	 * request offset and is empty.
1026 	 * <p>
1027 	 * If not set, defaults to empty subrange at [0,0).
1028 	 * </p>
1029 	 *
1030 	 * @param startIndex character index of token start position (inclusive)
1031 	 * @param endIndex character index of token end position (exclusive)
1032 	 */
setTokenRange(int startIndex, int endIndex)1033 	public void setTokenRange(int startIndex, int endIndex) {
1034 		// default overridden by concrete implementation
1035 	}
1036 
1037 	/**
1038 	 * Returns the proposed sequence of characters to insert into the
1039 	 * source file buffer, replacing the characters at the specified
1040 	 * source range. The string can be arbitrary; for example, it might
1041 	 * include not only the name of a method but a set of parentheses.
1042 	 * <p>
1043 	 * The client must not modify the array returned.
1044 	 * </p>
1045 	 *
1046 	 * @return the completion string
1047 	 */
getCompletion()1048 	public char[] getCompletion() {
1049 		return null; // default overridden by concrete implementation
1050 	}
1051 
1052 	/**
1053 	 * Sets the proposed sequence of characters to insert into the
1054 	 * source file buffer, replacing the characters at the specified
1055 	 * source range. The string can be arbitrary; for example, it might
1056 	 * include not only the name of a method but a set of parentheses.
1057 	 * <p>
1058 	 * If not set, defaults to an empty character array.
1059 	 * </p>
1060 	 * <p>
1061 	 * The completion engine creates instances of this class and sets
1062 	 * its properties; this method is not intended to be used by other clients.
1063 	 * </p>
1064 	 *
1065 	 * @param completion the completion string
1066 	 */
setCompletion(char[] completion)1067 	public void setCompletion(char[] completion) {
1068 		// default overridden by concrete implementation
1069 	}
1070 
1071 	/**
1072 	 * Returns the character index of the start of the
1073 	 * subrange in the source file buffer to be replaced
1074 	 * by the completion string. If the subrange is empty
1075 	 * (<code>getReplaceEnd() == getReplaceStart()</code>),
1076 	 * the completion string is to be inserted at this
1077 	 * index.
1078 	 * <p>
1079 	 * Note that while the token subrange is precisely
1080 	 * specified, the replacement range is loosely
1081 	 * constrained and may not bear any direct relation
1082 	 * to the original request offset. For example,
1083 	 * it would be possible for a type completion to
1084 	 * propose inserting an import declaration at the
1085 	 * top of the compilation unit; or the completion
1086 	 * might include trailing parentheses and
1087 	 * punctuation for a method completion.
1088 	 * </p>
1089 	 *
1090 	 * @return replacement start position (inclusive)
1091 	 */
getReplaceStart()1092 	public int getReplaceStart() {
1093 		return -1; // default overridden by concrete implementation
1094 	}
1095 
1096 	/**
1097 	 * Returns the character index of the end of the
1098 	 * subrange in the source file buffer to be replaced
1099 	 * by the completion string. If the subrange is empty
1100 	 * (<code>getReplaceEnd() == getReplaceStart()</code>),
1101 	 * the completion string is to be inserted at this
1102 	 * index.
1103 	 *
1104 	 * @return replacement end position (exclusive)
1105 	 */
getReplaceEnd()1106 	public int getReplaceEnd() {
1107 		return -1; // default overridden by concrete implementation
1108 	}
1109 
1110 	/**
1111 	 * Sets the character indices of the subrange in the
1112 	 * source file buffer to be replaced by the completion
1113 	 * string. If the subrange is empty
1114 	 * (<code>startIndex == endIndex</code>),
1115 	 * the completion string is to be inserted at this
1116 	 * index.
1117 	 * <p>
1118 	 * If not set, defaults to empty subrange at [0,0).
1119 	 * </p>
1120 	 * <p>
1121 	 * The completion engine creates instances of this class and sets
1122 	 * its properties; this method is not intended to be used by other clients.
1123 	 * </p>
1124 	 *
1125 	 * @param startIndex character index of replacement start position (inclusive)
1126 	 * @param endIndex character index of replacement end position (exclusive)
1127 	 */
setReplaceRange(int startIndex, int endIndex)1128 	public void setReplaceRange(int startIndex, int endIndex) {
1129 		// default overridden by concrete implementation
1130 	}
1131 
1132 	/**
1133 	 * Returns the relative relevance rating of this proposal.
1134 	 *
1135 	 * @return relevance rating of this proposal; ratings are positive; higher means better
1136 	 */
getRelevance()1137 	public int getRelevance() {
1138 		return -1; // default overridden by concrete implementation
1139 	}
1140 
1141 	/**
1142 	 * Sets the relative relevance rating of this proposal.
1143 	 * <p>
1144 	 * If not set, defaults to the lowest possible rating (1).
1145 	 * </p>
1146 	 * <p>
1147 	 * The completion engine creates instances of this class and sets
1148 	 * its properties; this method is not intended to be used by other clients.
1149 	 * </p>
1150 	 *
1151 	 * @param rating relevance rating of this proposal; ratings are positive; higher means better
1152 	 */
setRelevance(int rating)1153 	public void setRelevance(int rating) {
1154 		// default overridden by concrete implementation
1155 	}
1156 
1157 	/**
1158 	 * Returns the type signature or package name or module name (9) of the relevant
1159 	 * declaration in the context, or <code>null</code> if none.
1160 	 * <p>
1161 	 * This field is available for the following kinds of
1162 	 * completion proposals:
1163 	 * <ul>
1164 	 *  <li><code>ANNOTATION_ATTRIBUT_REF</code> - type signature
1165 	 * of the annotation that declares the attribute that is referenced</li>
1166 	 * <li><code>ANONYMOUS_CLASS_DECLARATION</code> - type signature
1167 	 * of the type that is being subclassed or implemented</li>
1168 	 * 	<li><code>FIELD_IMPORT</code> - type signature
1169 	 * of the type that declares the field that is imported</li>
1170 	 *  <li><code>FIELD_REF</code> - type signature
1171 	 * of the type that declares the field that is referenced</li>
1172 	 *  <li><code>FIELD_REF_WITH_CASTED_RECEIVER</code> - type signature
1173 	 * of the type that declares the field that is referenced</li>
1174 	 * 	<li><code>METHOD_IMPORT</code> - type signature
1175 	 * of the type that declares the method that is imported</li>
1176 	 *  <li><code>METHOD_REF</code> - type signature
1177 	 * of the type that declares the method that is referenced</li>
1178 	 *  <li><code>METHOD_REF_WITH_CASTED_RECEIVER</code> - type signature
1179 	 * of the type that declares the method that is referenced</li>
1180 	 * 	<li><code>METHOD_DECLARATION</code> - type signature
1181 	 * of the type that declares the method that is being
1182 	 * implemented or overridden</li>
1183 	 * 	<li><code>MODULE_DECLARATION</code> -
1184 	 * possible name of the module that is being declared</li>
1185 	 * 	<li><code>MODULE_REF</code> -
1186 	 * name of the module that is referenced</li>
1187 	 * 	<li><code>PACKAGE_REF</code> - dot-based package
1188 	 * name of the package that is referenced</li>
1189 	 * 	<li><code>TYPE_IMPORT</code> - dot-based package
1190 	 * name of the package containing the type that is imported</li>
1191 	 *  <li><code>TYPE_REF</code> - dot-based package
1192 	 * name of the package containing the type that is referenced</li>
1193 	 *  <li><code>POTENTIAL_METHOD_DECLARATION</code> - type signature
1194 	 * of the type that declares the method that is being created</li>
1195 	 * </ul>
1196 	 * For kinds of completion proposals, this method returns
1197 	 * <code>null</code>. Clients must not modify the array
1198 	 * returned.
1199 	 *
1200 	 * @return a type signature or a package name or module name (9) (depending
1201 	 * on the kind of completion), or <code>null</code> if none
1202 	 * @see Signature
1203 	 */
getDeclarationSignature()1204 	public char[] getDeclarationSignature() {
1205 		return null; // default overridden by concrete implementation
1206 
1207 	}
1208 
1209 	/**
1210 	 * Returns the key of the relevant
1211 	 * declaration in the context, or <code>null</code> if none.
1212 	 * <p>
1213 	 * This field is available for the following kinds of
1214 	 * completion proposals:
1215 	 * <ul>
1216 	 * <li><code>ANONYMOUS_CLASS_DECLARATION</code> - key
1217 	 * of the type that is being subclassed or implemented</li>
1218 	 * 	<li><code>METHOD_DECLARATION</code> - key
1219 	 * of the type that declares the method that is being
1220 	 * implemented or overridden</li>
1221 	 * </ul>
1222 	 * For kinds of completion proposals, this method returns
1223 	 * <code>null</code>. Clients must not modify the array
1224 	 * returned.
1225 	 *
1226 	 * @return a key, or <code>null</code> if none
1227 	 * @see org.eclipse.jdt.core.dom.ASTParser#createASTs(ICompilationUnit[], String[], org.eclipse.jdt.core.dom.ASTRequestor, IProgressMonitor)
1228      * @since 3.1
1229 	 */
getDeclarationKey()1230 	public char[] getDeclarationKey() {
1231 		return null; // default overridden by concrete implementation
1232 	}
1233 
1234 	/**
1235 	 * Sets the type or package signature or module name (9) of the relevant
1236 	 * declaration in the context, or <code>null</code> if none.
1237 	 * <p>
1238 	 * If not set, defaults to none.
1239 	 * </p>
1240 	 * <p>
1241 	 * The completion engine creates instances of this class and sets
1242 	 * its properties; this method is not intended to be used by other clients.
1243 	 * </p>
1244 	 *
1245 	 * @param signature the type or package signature or module name(9) , or
1246 	 * <code>null</code> if none
1247 	 */
setDeclarationSignature(char[] signature)1248 	public void setDeclarationSignature(char[] signature) {
1249 		// default overridden by concrete implementation
1250 	}
1251 
1252 	/**
1253 	 * Sets the type or package key of the relevant
1254 	 * declaration in the context, or <code>null</code> if none.
1255 	 * <p>
1256 	 * If not set, defaults to none.
1257 	 * </p>
1258 	 * <p>
1259 	 * The completion engine creates instances of this class and sets
1260 	 * its properties; this method is not intended to be used by other clients.
1261 	 * </p>
1262 	 *
1263 	 * @param key the type or package key, or
1264 	 * <code>null</code> if none
1265      * @since 3.1
1266 	 */
setDeclarationKey(char[] key)1267 	public void setDeclarationKey(char[] key) {
1268 		// default overridden by concrete implementation
1269 	}
1270 
1271 	/**
1272 	 * Returns the simple name of the method, field,
1273 	 * member, or variable relevant in the context, or
1274 	 * <code>null</code> if none.
1275 	 * <p>
1276 	 * This field is available for the following kinds of
1277 	 * completion proposals:
1278 	 * <ul>
1279 	 *  <li><code>ANNOTATION_ATTRIBUT_REF</code> - the name of the attribute</li>
1280 	 * 	<li><code>FIELD_IMPORT</code> - the name of the field</li>
1281 	 *  <li><code>FIELD_REF</code> - the name of the field</li>
1282 	 *  <li><code>FIELD_REF_WITH_CASTED_RECEIVER</code> - the name of the field</li>
1283 	 * 	<li><code>KEYWORD</code> - the keyword</li>
1284 	 * 	<li><code>LABEL_REF</code> - the name of the label</li>
1285 	 * 	<li><code>LOCAL_VARIABLE_REF</code> - the name of the local variable</li>
1286 	 * 	<li><code>METHOD_IMPORT</code> - the name of the method</li>
1287 	 *  <li><code>METHOD_REF</code> - the name of the method (the type simple name for constructor)</li>
1288 	 *  <li><code>METHOD_REF_WITH_CASTED_RECEIVER</code> - the name of the method</li>
1289 	 * 	<li><code>METHOD_DECLARATION</code> - the name of the method (the type simple name for constructor)</li>
1290 	 * 	<li><code>VARIABLE_DECLARATION</code> - the name of the variable</li>
1291 	 *  <li><code>POTENTIAL_METHOD_DECLARATION</code> - the name of the method</li>
1292 	 * </ul>
1293 	 * For kinds of completion proposals, this method returns
1294 	 * <code>null</code>. Clients must not modify the array
1295 	 * returned.
1296 	 *
1297 	 * @return the keyword, field, method, local variable, or member
1298 	 * name, or <code>null</code> if none
1299 	 */
getName()1300 	public char[] getName() {
1301 		return null; // default overridden by concrete implementation
1302 	}
1303 
1304 
1305 	/**
1306 	 * Sets the simple name of the method (type simple name for constructor), field,
1307 	 * member, or variable relevant in the context, or
1308 	 * <code>null</code> if none.
1309 	 * <p>
1310 	 * If not set, defaults to none.
1311 	 * </p>
1312 	 * <p>
1313 	 * The completion engine creates instances of this class and sets
1314 	 * its properties; this method is not intended to be used by other clients.
1315 	 * </p>
1316 	 *
1317 	 * @param name the keyword, field, method, local variable,
1318 	 * or member name, or <code>null</code> if none
1319 	 */
setName(char[] name)1320 	public void setName(char[] name) {
1321 		// default overridden by concrete implementation
1322 	}
1323 
1324 	/**
1325 	 * Returns the signature of the method or type
1326 	 * relevant in the context, or <code>null</code> if none.
1327 	 * <p>
1328 	 * This field is available for the following kinds of
1329 	 * completion proposals:
1330 	 * <ul>
1331 	 * <li><code>ANNOTATION_ATTRIBUT_REF</code> - the type signature
1332 	 * of the referenced attribute's type</li>
1333 	 * <li><code>ANONYMOUS_CLASS_DECLARATION</code> - method signature
1334 	 * of the constructor that is being invoked</li>
1335 	 * 	<li><code>FIELD_IMPORT</code> - the type signature
1336 	 * of the referenced field's type</li>
1337 	 *  <li><code>FIELD_REF</code> - the type signature
1338 	 * of the referenced field's type</li>
1339 	 *  <li><code>FIELD_REF_WITH_CASTED_RECEIVER</code> - the type signature
1340 	 * of the referenced field's type</li>
1341 	 * 	<li><code>LOCAL_VARIABLE_REF</code> - the type signature
1342 	 * of the referenced local variable's type</li>
1343 	 * 	<li><code>METHOD_IMPORT</code> - method signature
1344 	 * of the method that is imported</li>
1345 	 *  <li><code>METHOD_REF</code> - method signature
1346 	 * of the method that is referenced</li>
1347 	 *  <li><code>METHOD_REF_WITH_CASTED_RECEIVER</code> - method signature
1348 	 * of the method that is referenced</li>
1349 	 * 	<li><code>METHOD_DECLARATION</code> - method signature
1350 	 * of the method that is being implemented or overridden</li>
1351 	 * 	<li><code>TYPE_IMPORT</code> - type signature
1352 	 * of the type that is imported</li>
1353 	 * 	<li><code>TYPE_REF</code> - type signature
1354 	 * of the type that is referenced</li>
1355 	 * 	<li><code>VARIABLE_DECLARATION</code> - the type signature
1356 	 * of the type of the variable being declared</li>
1357 	 *  <li><code>POTENTIAL_METHOD_DECLARATION</code> - method signature
1358 	 * of the method that is being created</li>
1359 	 * </ul>
1360 	 * For kinds of completion proposals, this method returns
1361 	 * <code>null</code>. Clients must not modify the array
1362 	 * returned.
1363 	 *
1364 	 * @return the signature, or <code>null</code> if none
1365 	 * @see Signature
1366 	 */
getSignature()1367 	public char[] getSignature() {
1368 		return null; // default overridden by concrete implementation
1369 	}
1370 
1371 	/**
1372 	 * Returns the key relevant in the context,
1373 	 * or <code>null</code> if none.
1374 	 * <p>
1375 	 * This field is available for the following kinds of
1376 	 * completion proposals:
1377 	 * <ul>
1378 	 * <li><code>ANONYMOUS_CLASS_DECLARATION</code> - method key
1379 	 * of the constructor that is being invoked, or <code>null</code> if
1380 	 * the declaring type is an interface</li>
1381 	 * 	<li><code>METHOD_DECLARATION</code> - method key
1382 	 * of the method that is being implemented or overridden</li>
1383 	 * </ul>
1384 	 * For kinds of completion proposals, this method returns
1385 	 * <code>null</code>. Clients must not modify the array
1386 	 * returned.
1387 	 *
1388 	 * @return the key, or <code>null</code> if none
1389 	 * @see org.eclipse.jdt.core.dom.ASTParser#createASTs(ICompilationUnit[], String[], org.eclipse.jdt.core.dom.ASTRequestor, IProgressMonitor)
1390      * @since 3.1
1391 	 */
getKey()1392 	public char[] getKey() {
1393 		return null; // default overridden by concrete implementation
1394 	}
1395 
1396 	/**
1397 	 * Sets the signature of the method, field type, member type,
1398 	 * relevant in the context, or <code>null</code> if none.
1399 	 * <p>
1400 	 * If not set, defaults to none.
1401 	 * </p>
1402 	 * <p>
1403 	 * The completion engine creates instances of this class and sets
1404 	 * its properties; this method is not intended to be used by other clients.
1405 	 * </p>
1406 	 *
1407 	 * @param signature the signature, or <code>null</code> if none
1408 	 */
setSignature(char[] signature)1409 	public void setSignature(char[] signature) {
1410 		// default overridden by concrete implementation
1411 	}
1412 
1413 	/**
1414 	 * Sets the key of the method, field type, member type,
1415 	 * relevant in the context, or <code>null</code> if none.
1416 	 * <p>
1417 	 * If not set, defaults to none.
1418 	 * </p>
1419 	 * <p>
1420 	 * The completion engine creates instances of this class and sets
1421 	 * its properties; this method is not intended to be used by other clients.
1422 	 * </p>
1423 	 *
1424 	 * @param key the key, or <code>null</code> if none
1425      * @since 3.1
1426 	 */
setKey(char[] key)1427 	public void setKey(char[] key) {
1428 		// default overridden by concrete implementation
1429 	}
1430 
1431 	/**
1432 	 * Returns the modifier flags relevant in the context, or
1433 	 * <code>Flags.AccDefault</code> if none.
1434 	 * <p>
1435 	 * This field is available for the following kinds of
1436 	 * completion proposals:
1437 	 * <ul>
1438 	 * <li><code>ANNOTATION_ATTRIBUT_REF</code> - modifier flags
1439 	 * of the attribute that is referenced;
1440 	 * <li><code>ANONYMOUS_CLASS_DECLARATION</code> - modifier flags
1441 	 * of the constructor that is referenced</li>
1442 	 * 	<li><code>FIELD_IMPORT</code> - modifier flags
1443 	 * of the field that is imported.</li>
1444 	 *  <li><code>FIELD_REF</code> - modifier flags
1445 	 * of the field that is referenced;
1446 	 * <code>Flags.AccEnum</code> can be used to recognize
1447 	 * references to enum constants
1448 	 * </li>
1449 	 *  <li><code>FIELD_REF_WITH_CASTED_RECEIVER</code> - modifier flags
1450 	 * of the field that is referenced.
1451 	 * </li>
1452 	 * 	<li><code>KEYWORD</code> - modifier flag
1453 	 * corresponding to the modifier keyword</li>
1454 	 * 	<li><code>LOCAL_VARIABLE_REF</code> - modifier flags
1455 	 * of the local variable that is referenced</li>
1456 	 *  <li><code>METHOD_IMPORT</code> - modifier flags
1457 	 * of the method that is imported;
1458 	 *  </li>
1459 	 * 	<li><code>METHOD_REF</code> - modifier flags
1460 	 * of the method that is referenced;
1461 	 * <code>Flags.AccAnnotation</code> can be used to recognize
1462 	 * references to annotation type members
1463 	 * </li>
1464 	 * <li><code>METHOD_REF_WITH_CASTED_RECEIVER</code> - modifier flags
1465 	 * of the method that is referenced.
1466 	 * </li>
1467 	 * <li><code>METHOD_DECLARATION</code> - modifier flags
1468 	 * for the method that is being implemented or overridden</li>
1469 	 * <li><code>TYPE_IMPORT</code> - modifier flags
1470 	 * of the type that is imported; <code>Flags.AccInterface</code>
1471 	 * can be used to recognize references to interfaces,
1472 	 * <code>Flags.AccEnum</code> enum types,
1473 	 * and <code>Flags.AccAnnotation</code> annotation types</li>
1474 	 * <li><code>TYPE_REF</code> - modifier flags
1475 	 * of the type that is referenced; <code>Flags.AccInterface</code>
1476 	 * can be used to recognize references to interfaces,
1477 	 * <code>Flags.AccEnum</code> enum types,
1478 	 * and <code>Flags.AccAnnotation</code> annotation types
1479 	 * </li>
1480 	 * 	<li><code>VARIABLE_DECLARATION</code> - modifier flags
1481 	 * for the variable being declared</li>
1482 	 * 	<li><code>POTENTIAL_METHOD_DECLARATION</code> - modifier flags
1483 	 * for the method that is being created</li>
1484 	 * </ul>
1485 	 * For other kinds of completion proposals, this method returns
1486 	 * <code>Flags.AccDefault</code>.
1487 	 *
1488 	 * @return the modifier flags, or
1489 	 * <code>Flags.AccDefault</code> if none
1490 	 * @see Flags
1491 	 */
getFlags()1492 	public int getFlags() {
1493 		return -1; // default overridden by concrete implementation
1494 	}
1495 
1496 	/**
1497 	 * Sets the modifier flags relevant in the context.
1498 	 * <p>
1499 	 * If not set, defaults to none.
1500 	 * </p>
1501 	 * <p>
1502 	 * The completion engine creates instances of this class and sets
1503 	 * its properties; this method is not intended to be used by other clients.
1504 	 * </p>
1505 	 *
1506 	 * @param flags the modifier flags, or
1507 	 * <code>Flags.AccDefault</code> if none
1508 	 */
setFlags(int flags)1509 	public void setFlags(int flags) {
1510 		// default overridden by concrete implementation
1511 	}
1512 
1513 	/**
1514 	 * Returns the required completion proposals.
1515 	 * The proposal can be apply only if these required completion proposals are also applied.
1516 	 * If the required proposal aren't applied the completion could create completion problems.
1517 	 *
1518 	 * <p>
1519 	 * This field is available for the following kinds of
1520 	 * completion proposals:
1521 	 * <ul>
1522 	 * 	<li><code>FIELD_REF</code> - The allowed required proposals for this kind are:
1523 	 *   <ul>
1524 	 *    <li><code>TYPE_REF</code></li>
1525 	 *    <li><code>TYPE_IMPORT</code></li>
1526 	 *    <li><code>FIELD_IMPORT</code></li>
1527 	 *   </ul>
1528 	 * </li>
1529 	 * 	<li><code>METHOD_REF</code> - The allowed required proposals for this kind are:
1530 	 *   <ul>
1531 	 *    <li><code>TYPE_REF</code></li>
1532 	 *    <li><code>TYPE_IMPORT</code></li>
1533 	 *    <li><code>METHOD_IMPORT</code></li>
1534 	 *   </ul>
1535 	 * </li>
1536 	 * 	<li><code>TYPE_REF</code> - The allowed required proposals for this kind are:
1537 	 *   <ul>
1538 	 *    <li><code>TYPE_REF</code></li>
1539 	 *   </ul>
1540 	 *  </li>
1541 	 *  <li><code>CONSTRUCTOR_INVOCATION</code> - The allowed required proposals for this kind are:
1542 	 *   <ul>
1543 	 *    <li><code>TYPE_REF</code></li>
1544 	 *   </ul>
1545 	 *  </li>
1546 	 *  <li><code>ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION</code> - The allowed required proposals for this kind are:
1547 	 *   <ul>
1548 	 *    <li><code>TYPE_REF</code></li>
1549 	 *   </ul>
1550 	 *  </li>
1551 	 *  <li><code>ANONYMOUS_CLASS_DECLARATION</code> - The allowed required proposals for this kind are:
1552 	 *   <ul>
1553 	 *    <li><code>TYPE_REF</code></li>
1554 	 *   </ul>
1555 	 *  </li>
1556 	 * </ul>
1557 	 * <p>
1558 	 * Other kinds of required proposals will be returned in the future, therefore clients of this
1559 	 * API must allow with {@link CompletionRequestor#setAllowsRequiredProposals(int, int, boolean)}
1560 	 * only kinds which are in this list to avoid unexpected results in the future.
1561 	 * </p>
1562 	 * <p>
1563 	 * A required proposal of a given kind is proposed even if {@link CompletionRequestor#isIgnored(int)}
1564 	 * return <code>true</code> for that kind.
1565 	 * </p>
1566 	 * <p>
1567 	 * A required completion proposal cannot have required completion proposals.
1568 	 * </p>
1569 	 *
1570 	 * @return the required completion proposals, or <code>null</code> if none.
1571 	 *
1572 	 * @see CompletionRequestor#setAllowsRequiredProposals(int, int,boolean)
1573 	 *
1574 	 * @since 3.3
1575 	 */
getRequiredProposals()1576 	public CompletionProposal[] getRequiredProposals() {
1577 		return null; // default overridden by concrete implementation
1578 	}
1579 
1580 
1581 	/**
1582 	 * Sets the list of required completion proposals, or <code>null</code> if none.
1583 	 * <p>
1584 	 * If not set, defaults to none.
1585 	 * </p>
1586 	 * <p>
1587 	 * The completion engine creates instances of this class and sets
1588 	 * its properties; this method is not intended to be used by other clients.
1589 	 * </p>
1590 	 *
1591 	 * @param proposals the list of required completion proposals, or
1592 	 * <code>null</code> if none
1593      * @since 3.3
1594 	 */
setRequiredProposals(CompletionProposal[] proposals)1595 	public void setRequiredProposals(CompletionProposal[] proposals) {
1596 		// default overridden by concrete implementation
1597 	}
1598 
1599 	/**
1600 	 * Finds the method parameter names.
1601 	 * This information is relevant to method reference (and
1602 	 * method declaration proposals). Returns <code>null</code>
1603 	 * if not available or not relevant.
1604 	 * <p>
1605 	 * The client must not modify the array returned.
1606 	 * </p>
1607 	 * <p>
1608 	 * <b>Note that this is an expensive thing to compute, which may require
1609 	 * parsing Java source files, etc. Use sparingly.</b>
1610 	 * </p>
1611 	 *
1612 	 * @param monitor the progress monitor, or <code>null</code> if none
1613 	 * @return the parameter names, or <code>null</code> if none
1614 	 * or not available or not relevant
1615 	 */
findParameterNames(IProgressMonitor monitor)1616 	public char[][] findParameterNames(IProgressMonitor monitor) {
1617 		return null; // default overridden by concrete implementation
1618 	}
1619 
1620 	/**
1621 	 * Sets the method parameter names.
1622 	 * This information is relevant to method reference (and
1623 	 * method declaration proposals).
1624 	 * <p>
1625 	 * The completion engine creates instances of this class and sets
1626 	 * its properties; this method is not intended to be used by other clients.
1627 	 * </p>
1628 	 *
1629 	 * @param parameterNames the parameter names, or <code>null</code> if none
1630 	 */
setParameterNames(char[][] parameterNames)1631 	public void setParameterNames(char[][] parameterNames) {
1632 		// default overridden by concrete implementation
1633 	}
1634 
1635 	/**
1636 	 * Returns the accessibility of the proposal.
1637 	 * <p>
1638 	 * This field is available for the following kinds of
1639 	 * completion proposals:
1640 	 * <ul>
1641 	 * 	<li><code>TYPE_REF</code> - accessibility of the type</li>
1642 	 * </ul>
1643 	 * For these kinds of completion proposals, this method returns
1644 	 * {@link IAccessRule#K_ACCESSIBLE} or {@link IAccessRule#K_DISCOURAGED}
1645 	 * or {@link IAccessRule#K_NON_ACCESSIBLE}.
1646 	 * By default this method return {@link IAccessRule#K_ACCESSIBLE}.
1647 	 *
1648 	 * @see IAccessRule
1649 	 *
1650 	 * @return the accessibility of the proposal
1651 	 *
1652 	 * @since 3.1
1653 	 */
getAccessibility()1654 	public int getAccessibility() {
1655 		return -1; // default overridden by concrete implementation
1656 	}
1657 
1658 	/**
1659 	 * Returns whether this proposal is a constructor.
1660 	 * <p>
1661 	 * This field is available for the following kinds of
1662 	 * completion proposals:
1663 	 * <ul>
1664 	 * <li><code>METHOD_REF</code> - return <code>true</code>
1665 	 * if the referenced method is a constructor</li>
1666 	 * 	<li><code>METHOD_DECLARATION</code> - return <code>true</code>
1667 	 * if the declared method is a constructor</li>
1668 	 * </ul>
1669 	 * For kinds of completion proposals, this method returns
1670 	 * <code>false</code>.
1671 	 *
1672 	 * @return <code>true</code> if the proposal is a constructor.
1673 	 * @since 3.1
1674 	 */
isConstructor()1675 	public boolean isConstructor() {
1676 		return false; // default overridden by concrete implementation
1677 	}
1678 
1679 	/**
1680 	 * Returns the type signature or package name of the relevant
1681 	 * receiver in the context, or <code>null</code> if none.
1682 	 * <p>
1683 	 * This field is available for the following kinds of
1684 	 * completion proposals:
1685 	 * <ul>
1686 	 *  <li><code>FIELD_REF_WITH_CASTED_RECEIVER</code> - type signature
1687 	 * of the type that cast the receiver of the field that is referenced</li>
1688 	 *  <li><code>METHOD_REF_WITH_CASTED_RECEIVER</code> - type signature
1689 	 * of the type that cast the receiver of the method that is referenced</li>
1690 	 * </ul>
1691 	 * For kinds of completion proposals, this method returns
1692 	 * <code>null</code>. Clients must not modify the array
1693 	 * returned.
1694 	 *
1695 	 * @return a type signature or a package name (depending
1696 	 * on the kind of completion), or <code>null</code> if none
1697 	 * @see Signature
1698 	 *
1699 	 * @since 3.4
1700 	 */
getReceiverSignature()1701 	public char[] getReceiverSignature() {
1702 		return null; // default overridden by concrete implementation
1703 	}
1704 
1705 	/**
1706 	 * Returns the character index of the start of the
1707 	 * subrange in the source file buffer containing the
1708 	 * relevant receiver of the member being completed. This
1709 	 * receiver is an expression.
1710 	 *
1711 	 * <p>
1712 	 * This field is available for the following kinds of
1713 	 * completion proposals:
1714 	 * <ul>
1715 	 *  <li><code>FIELD_REF_WITH_CASTED_RECEIVER</code></li>
1716 	 *  <li><code>METHOD_REF_WITH_CASTED_RECEIVER</code></li>
1717 	 * </ul>
1718 	 * For kinds of completion proposals, this method returns <code>0</code>.
1719 	 *
1720 	 * @return character index of receiver start position (inclusive)
1721 	 *
1722 	 * @since 3.4
1723 	 */
getReceiverStart()1724 	public int getReceiverStart() {
1725 		return -1; // default overridden by concrete implementation
1726 	}
1727 
1728 	/**
1729 	 * Returns the character index of the end (exclusive) of the subrange
1730 	 * in the source file buffer containing the
1731 	 * relevant receiver of the member being completed.
1732 	 *
1733 	 * * <p>
1734 	 * This field is available for the following kinds of
1735 	 * completion proposals:
1736 	 * <ul>
1737 	 *  <li><code>FIELD_REF_WITH_CASTED_RECEIVER</code></li>
1738 	 *  <li><code>METHOD_REF_WITH_CASTED_RECEIVER</code></li>
1739 	 * </ul>
1740 	 * For kinds of completion proposals, this method returns <code>0</code>.
1741 	 *
1742 	 * @return character index of receiver end position (exclusive)
1743 	 *
1744 	 * @since 3.4
1745 	 */
getReceiverEnd()1746 	public int getReceiverEnd() {
1747 		return -1; // default overridden by concrete implementation
1748 	}
1749 
1750 	/**
1751 	 * Sets the type or package signature of the relevant
1752 	 * receiver in the context, or <code>null</code> if none.
1753 	 * <p>
1754 	 * If not set, defaults to none.
1755 	 * </p>
1756 	 * <p>
1757 	 * The completion engine creates instances of this class and sets
1758 	 * its properties; this method is not intended to be used by other clients.
1759 	 * </p>
1760 	 *
1761 	 * @param signature the type or package signature, or
1762 	 * <code>null</code> if none
1763 	 *
1764 	 * @since 3.4
1765 	 */
setReceiverSignature(char[] signature)1766 	public void setReceiverSignature(char[] signature) {
1767 		// default overridden by concrete implementation
1768 	}
1769 
1770 	/**
1771 	 * Sets the character indices of the subrange in the
1772 	 * source file buffer containing the relevant receiver
1773 	 * of the member being completed.
1774 	 *
1775 	 * <p>
1776 	 * If not set, defaults to empty subrange at [0,0).
1777 	 * </p>
1778 	 *
1779 	 * @param startIndex character index of receiver start position (inclusive)
1780 	 * @param endIndex character index of receiver end position (exclusive)
1781 	 *
1782 	 * @since 3.4
1783 	 */
setReceiverRange(int startIndex, int endIndex)1784 	public void setReceiverRange(int startIndex, int endIndex) {
1785 		// default overridden by concrete implementation
1786 	}
1787 
1788 	/**
1789 	 * Returns whether it is safe to use the '<>' (diamond) operator in place of explicitly specifying
1790 	 * type arguments for this proposal.
1791 	 *
1792 	 * <p>
1793 	 * This is only relevant for source level 1.7 or greater.
1794 	 * </p>
1795 	 *
1796 	 * @param coreContext the completion context associated with the proposal
1797 	 * @since 3.7.1
1798 	 * @return <code>true</code> if it is safe to use the diamond operator for the constructor invocation,
1799 	 * <code>false</code> otherwise. Also returns <code>false</code> for source levels below 1.7
1800 	 */
canUseDiamond(CompletionContext coreContext)1801 	public boolean canUseDiamond(CompletionContext coreContext) {
1802 		return false; // default overridden by concrete implementation
1803 	}
1804 }
1805