Lines 10-17
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.codeassist; |
11 |
package org.eclipse.jdt.internal.codeassist; |
12 |
|
12 |
|
|
|
13 |
import org.eclipse.jdt.core.CompletionContext; |
14 |
import org.eclipse.jdt.core.ICompilationUnit; |
15 |
import org.eclipse.jdt.core.IField; |
16 |
import org.eclipse.jdt.core.IJavaElement; |
17 |
import org.eclipse.jdt.core.ILocalVariable; |
18 |
import org.eclipse.jdt.core.IMember; |
19 |
import org.eclipse.jdt.core.IMethod; |
13 |
import org.eclipse.jdt.core.ITypeRoot; |
20 |
import org.eclipse.jdt.core.ITypeRoot; |
|
|
21 |
import org.eclipse.jdt.core.Signature; |
14 |
import org.eclipse.jdt.core.WorkingCopyOwner; |
22 |
import org.eclipse.jdt.core.WorkingCopyOwner; |
|
|
23 |
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnJavadoc; |
15 |
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser; |
24 |
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser; |
16 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
25 |
import org.eclipse.jdt.internal.compiler.ast.ASTNode; |
17 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
26 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
Lines 23-29
Link Here
|
23 |
* Internal completion context |
32 |
* Internal completion context |
24 |
* @since 3.1 |
33 |
* @since 3.1 |
25 |
*/ |
34 |
*/ |
26 |
public class InternalCompletionContext { |
35 |
public class InternalCompletionContext extends CompletionContext { |
27 |
protected char[][] expectedTypesSignatures; |
36 |
protected char[][] expectedTypesSignatures; |
28 |
protected char[][] expectedTypesKeys; |
37 |
protected char[][] expectedTypesKeys; |
29 |
protected int javadoc; |
38 |
protected int javadoc; |
Lines 106-109
Link Here
|
106 |
this.tokenEnd = 0; |
115 |
this.tokenEnd = 0; |
107 |
} |
116 |
} |
108 |
} |
117 |
} |
|
|
118 |
|
119 |
/** |
120 |
* Returns the innermost enclosing Java element which contains the completion location or <code>null</code> if this element cannot be computed. |
121 |
* The returned Java element and all Java elements in the same compilation unit which can be navigated to from the returned Java element are special Java elements: |
122 |
* <ul> |
123 |
* <li>they are based on the current content of the compilation unit's buffer, they are not the result of a reconcile operation</li> |
124 |
* <li>they are not updated if the buffer changes.</li> |
125 |
* <li>they do not contain local types which are not visible from the completion location.</li> |
126 |
* <li>they do not give information about categories. {@link IMember#getCategories()} will return an empty array</li> |
127 |
* </ul> |
128 |
* |
129 |
* Reasons for returning <code>null</code> include: |
130 |
* <ul> |
131 |
* <li>the compilation unit no longer exists</li> |
132 |
* <li>the completion occurred in a binary type. However this restriction might be relaxed in the future.</li> |
133 |
* </ul> |
134 |
* |
135 |
* @return the innermost enclosing Java element which contains the completion location or <code>null</code> if this element cannot be computed. |
136 |
* |
137 |
* @exception UnsupportedOperationException if the context is not an extended context |
138 |
* |
139 |
* @since 3.4 |
140 |
*/ |
141 |
public IJavaElement getEnclosingElement() { |
142 |
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$ |
143 |
|
144 |
if (this.extendedContext == null) return null; |
145 |
|
146 |
return this.extendedContext.getEnclosingElement(); |
147 |
} |
148 |
|
149 |
/** |
150 |
* Return keys of expected types of a potential completion proposal at the completion position. |
151 |
* |
152 |
* It's not mandatory to a completion proposal to respect this expectation. |
153 |
* |
154 |
* @return keys of expected types of a potential completion proposal at the completion position or |
155 |
* <code>null</code> if there is no expected types. |
156 |
* |
157 |
* @see org.eclipse.jdt.core.dom.ASTParser#createASTs(ICompilationUnit[], String[], org.eclipse.jdt.core.dom.ASTRequestor, org.eclipse.core.runtime.IProgressMonitor) |
158 |
*/ |
159 |
public char[][] getExpectedTypesKeys() { |
160 |
return this.expectedTypesKeys; |
161 |
} |
162 |
|
163 |
/** |
164 |
* Return signatures of expected types of a potential completion proposal at the completion position. |
165 |
* |
166 |
* It's not mandatory to a completion proposal to respect this expectation. |
167 |
* |
168 |
* @return signatures expected types of a potential completion proposal at the completion position or |
169 |
* <code>null</code> if there is no expected types. |
170 |
* |
171 |
* @see Signature |
172 |
*/ |
173 |
public char[][] getExpectedTypesSignatures() { |
174 |
return this.expectedTypesSignatures; |
175 |
} |
176 |
|
177 |
/** |
178 |
* Returns the offset position in the source file buffer |
179 |
* after which code assist is requested. |
180 |
* |
181 |
* @return offset position in the source file buffer |
182 |
* @since 3.2 |
183 |
*/ |
184 |
public int getOffset() { |
185 |
return this.offset; |
186 |
} |
187 |
|
188 |
/** |
189 |
* Returns the completed token. |
190 |
* This token is either the identifier or Java language keyword |
191 |
* or the string literal under, immediately preceding, |
192 |
* the original request offset. If the original request offset |
193 |
* is not within or immediately after an identifier or keyword or |
194 |
* a string literal then the returned value is <code>null</code>. |
195 |
* |
196 |
* @return completed token or <code>null</code> |
197 |
* @since 3.2 |
198 |
*/ |
199 |
public char[] getToken() { |
200 |
return this.token; |
201 |
} |
202 |
|
203 |
/** |
204 |
* Returns the character index of the end (exclusive) of the subrange |
205 |
* in the source file buffer containing the |
206 |
* relevant token. When there is no relevant token, the |
207 |
* range is empty |
208 |
* (<code>getTokenEnd() == getTokenStart() - 1</code>). |
209 |
* |
210 |
* @return character index of token end position (exclusive) |
211 |
* @since 3.2 |
212 |
*/ |
213 |
// TODO (david) https://bugs.eclipse.org/bugs/show_bug.cgi?id=132558 |
214 |
public int getTokenEnd() { |
215 |
return this.tokenEnd; |
216 |
} |
217 |
|
218 |
/** |
219 |
* Returns the kind of completion token being proposed. |
220 |
* <p> |
221 |
* The set of different kinds of completion token is |
222 |
* expected to change over time. It is strongly recommended |
223 |
* that clients do <b>not</b> assume that the kind is one of the |
224 |
* ones they know about, and code defensively for the |
225 |
* possibility of unexpected future growth. |
226 |
* </p> |
227 |
* |
228 |
* @return the kind; one of the kind constants declared on |
229 |
* this class whose name starts with <code>TOKEN_KIND</code>, |
230 |
* or possibly a kind unknown to the caller |
231 |
* @since 3.2 |
232 |
*/ |
233 |
public int getTokenKind() { |
234 |
return this.tokenKind; |
235 |
} |
236 |
|
237 |
/** |
238 |
* Returns the location of completion token being proposed. |
239 |
* The returned location is a bit mask which can contain some values |
240 |
* of the constants declared on this class whose name starts with <code>TL</code>, |
241 |
* or possibly values unknown to the caller. |
242 |
* |
243 |
* <p> |
244 |
* The set of different location values is expected to change over time. |
245 |
* It is strongly recommended that clients do <b>not</b> assume that |
246 |
* the location contains only known value, and code defensively for |
247 |
* the possibility of unexpected future growth. |
248 |
* </p> |
249 |
* |
250 |
* @return the location |
251 |
* |
252 |
* @since 3.4 |
253 |
*/ |
254 |
public int getTokenLocation() { |
255 |
return this.tokenLocation; |
256 |
} |
257 |
|
258 |
/** |
259 |
* Returns the character index of the start of the |
260 |
* subrange in the source file buffer containing the |
261 |
* relevant token being completed. This |
262 |
* token is either the identifier or Java language keyword |
263 |
* under, or immediately preceding, the original request |
264 |
* offset. If the original request offset is not within |
265 |
* or immediately after an identifier or keyword, then the |
266 |
* position returned is original request offset and the |
267 |
* token range is empty. |
268 |
* |
269 |
* @return character index of token start position (inclusive) |
270 |
* @since 3.2 |
271 |
*/ |
272 |
public int getTokenStart() { |
273 |
return this.tokenStart; |
274 |
} |
275 |
|
276 |
/** |
277 |
* Return the elements which are visible from the completion location and which can be assigned to the given type. |
278 |
* An element is assignable if its type can be assigned to a variable |
279 |
* of the given type, as specified in section 5.2 of <em>The Java Language |
280 |
* Specification, Third Edition</em> (JLS3). |
281 |
* A visible element is either: |
282 |
* <ul> |
283 |
* <li>a {@link ILocalVariable} - the element type is {@link ILocalVariable#getTypeSignature()}</li> |
284 |
* <li>a {@link IField} - the element type is {@link IField#getTypeSignature()}</li> |
285 |
* <li>a {@link IMethod} - the element type is {@link IMethod#getReturnType()}</li> |
286 |
* </ul> |
287 |
* |
288 |
* Returned elements defined in the completed compilation unit are special Java elements: |
289 |
* <ul> |
290 |
* <li>they are based on the current content of the compilation unit's buffer, they are not the result of a reconcile operation</li> |
291 |
* <li>they are not updated if the buffer changes.</li> |
292 |
* <li>they do not contain local types which are not visible from the completion location.</li> |
293 |
* <li>they do not give information about categories. {@link IMember#getCategories()} will return an empty array</li> |
294 |
* </ul> |
295 |
* |
296 |
* Note the array can be empty if: |
297 |
* <ul> |
298 |
* <li>the compilation unit no longer exists</li> |
299 |
* <li>the completion occurred in a binary type. However this restriction might be relaxed in the future.</li> |
300 |
* </ul> |
301 |
* |
302 |
* @param typeSignature elements which can be assigned to this type are returned. |
303 |
* If <code>null</code> there is no constraint on the type of the returned elements. |
304 |
* |
305 |
* @return elements which are visible from the completion location and which can be assigned to the given type. |
306 |
* |
307 |
* @exception UnsupportedOperationException if the context is not an extended context |
308 |
* |
309 |
* @see #isExtended() |
310 |
* |
311 |
* @since 3.4 |
312 |
*/ |
313 |
public IJavaElement[] getVisibleElements(String typeSignature) { |
314 |
if (!this.isExtended) throw new UnsupportedOperationException("Operation only supported in extended context"); //$NON-NLS-1$ |
315 |
|
316 |
if (this.extendedContext == null) return new IJavaElement[0]; |
317 |
|
318 |
return this.extendedContext.getVisibleElements(typeSignature); |
319 |
} |
320 |
|
321 |
/** |
322 |
* Returns whether this completion context is an extended context. |
323 |
* Some methods of this context can be used only if this context is an extended context but an extended context consumes more memory. |
324 |
* |
325 |
* @return <code>true</code> if this completion context is an extended context. |
326 |
* |
327 |
* @since 3.4 |
328 |
*/ |
329 |
public boolean isExtended() { |
330 |
return this.isExtended; |
331 |
} |
332 |
|
333 |
/** |
334 |
* Tell user whether completion takes place in a javadoc comment or not. |
335 |
* |
336 |
* @return boolean true if completion takes place in a javadoc comment, false otherwise. |
337 |
* @since 3.2 |
338 |
*/ |
339 |
public boolean isInJavadoc() { |
340 |
return this.javadoc != 0; |
341 |
} |
342 |
|
343 |
/** |
344 |
* Tell user whether completion takes place in a formal reference of a javadoc tag or not. |
345 |
* Tags with formal reference are: |
346 |
* <ul> |
347 |
* <li>@see</li> |
348 |
* <li>@throws</li> |
349 |
* <li>@exception</li> |
350 |
* <li>{@link Object}</li> |
351 |
* <li>{@linkplain Object}</li> |
352 |
* <li>{@value} when compiler compliance is set at leats to 1.5</li> |
353 |
* </ul> |
354 |
* |
355 |
* @return boolean true if completion takes place in formal reference of a javadoc tag, false otherwise. |
356 |
* @since 3.2 |
357 |
*/ |
358 |
public boolean isInJavadocFormalReference() { |
359 |
return (this.javadoc & CompletionOnJavadoc.FORMAL_REFERENCE) != 0; |
360 |
} |
361 |
|
362 |
/** |
363 |
* Tell user whether completion takes place in text area of a javadoc comment or not. |
364 |
* |
365 |
* @return boolean true if completion takes place in a text area of a javadoc comment, false otherwise. |
366 |
* @since 3.2 |
367 |
*/ |
368 |
public boolean isInJavadocText() { |
369 |
return (this.javadoc & CompletionOnJavadoc.TEXT) != 0; |
370 |
} |
109 |
} |
371 |
} |