KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > CompletionContext


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.core;
12
13 import org.eclipse.jdt.internal.codeassist.InternalCompletionContext;
14 import org.eclipse.jdt.internal.codeassist.complete.CompletionOnJavadoc;
15
16 /**
17  * Completion context.
18  *
19  * Represent the context in which the completion occurs.
20  * <p>
21  * This class is not intended to be instantiated or subclassed by clients.
22  * </p>
23  *
24  * @see CompletionRequestor#acceptContext(CompletionContext)
25  * @since 3.1
26  */

27 public final class CompletionContext extends InternalCompletionContext {
28
29     /**
30      * The completion token is unknown.
31      * @since 3.2
32      */

33     public static final int TOKEN_KIND_UNKNOWN = 0;
34     
35     /**
36      * The completion token is a name.
37      * @since 3.2
38      */

39     public static final int TOKEN_KIND_NAME = 1;
40     /**
41      * The completion token is a string literal.
42      * The string literal ends quote can be not present the source.
43      * <code>"foo"</code> or <code>"foo</code>.
44      * @since 3.2
45      */

46     
47     public static final int TOKEN_KIND_STRING_LITERAL = 2;
48     /**
49      * Tell user whether completion takes place in a javadoc comment or not.
50      *
51      * @return boolean true if completion takes place in a javadoc comment, false otherwise.
52      * @since 3.2
53      */

54     public boolean isInJavadoc() {
55         return this.javadoc != 0;
56     }
57
58     /**
59      * Tell user whether completion takes place in text area of a javadoc comment or not.
60      *
61      * @return boolean true if completion takes place in a text area of a javadoc comment, false otherwise.
62      * @since 3.2
63      */

64     public boolean isInJavadocText() {
65         return (this.javadoc & CompletionOnJavadoc.TEXT) != 0;
66     }
67
68     /**
69      * Tell user whether completion takes place in a formal reference of a javadoc tag or not.
70      * Tags with formal reference are:
71      * <ul>
72      * <li>&#64;see</li>
73      * <li>&#64;throws</li>
74      * <li>&#64;exception</li>
75      * <li>{&#64;link Object}</li>
76      * <li>{&#64;linkplain Object}</li>
77      * <li>{&#64;value} when compiler compliance is set at leats to 1.5</li>
78      * </ul>
79      *
80      * @return boolean true if completion takes place in formal reference of a javadoc tag, false otherwise.
81      * @since 3.2
82      */

83     public boolean isInJavadocFormalReference() {
84         return (this.javadoc & CompletionOnJavadoc.FORMAL_REFERENCE) != 0;
85     }
86
87     /**
88      * Return signatures of expected types of a potential completion proposal at the completion position.
89      *
90      * It's not mandatory to a completion proposal to respect this expectation.
91      *
92      * @return signatures expected types of a potential completion proposal at the completion position or
93      * <code>null</code> if there is no expected types.
94      *
95      * @see Signature
96      */

97     public char[][] getExpectedTypesSignatures() {
98         return this.expectedTypesSignatures;
99     }
100     /**
101      * Return keys of expected types of a potential completion proposal at the completion position.
102      *
103      * It's not mandatory to a completion proposal to respect this expectation.
104      *
105      * @return keys of expected types of a potential completion proposal at the completion position or
106      * <code>null</code> if there is no expected types.
107      *
108      * @see org.eclipse.jdt.core.dom.ASTParser#createASTs(ICompilationUnit[], String[], org.eclipse.jdt.core.dom.ASTRequestor, org.eclipse.core.runtime.IProgressMonitor)
109      */

110     public char[][] getExpectedTypesKeys() {
111         return this.expectedTypesKeys;
112     }
113     
114     /**
115      * Returns the completed token.
116      * This token is either the identifier or Java language keyword
117      * or the string literal under, immediately preceding,
118      * the original request offset. If the original request offset
119      * is not within or immediately after an identifier or keyword or
120      * a string literal then the returned value is <code>null</code>.
121      *
122      * @return completed token or <code>null</code>
123      * @since 3.2
124      */

125     public char[] getToken() {
126         return this.token;
127     }
128     
129     /**
130      * Returns the kind of completion token being proposed.
131      * <p>
132      * The set of different kinds of completion token is
133      * expected to change over time. It is strongly recommended
134      * that clients do <b>not</b> assume that the kind is one of the
135      * ones they know about, and code defensively for the
136      * possibility of unexpected future growth.
137      * </p>
138      *
139      * @return the kind; one of the kind constants declared on
140      * this class whose name starts with <code>TOKEN_KIND</code>,
141      * or possibly a kind unknown to the caller
142      * @since 3.2
143      */

144     public int getTokenKind() {
145         return this.tokenKind;
146     }
147     
148     /**
149      * Returns the character index of the start of the
150      * subrange in the source file buffer containing the
151      * relevant token being completed. This
152      * token is either the identifier or Java language keyword
153      * under, or immediately preceding, the original request
154      * offset. If the original request offset is not within
155      * or immediately after an identifier or keyword, then the
156      * position returned is original request offset and the
157      * token range is empty.
158      *
159      * @return character index of token start position (inclusive)
160      * @since 3.2
161      */

162     public int getTokenStart() {
163         return this.tokenStart;
164     }
165     
166     /**
167      * Returns the character index of the end (exclusive) of the subrange
168      * in the source file buffer containing the
169      * relevant token. When there is no relevant token, the
170      * range is empty
171      * (<code>getTokenEnd() == getTokenStart() - 1</code>).
172      *
173      * @return character index of token end position (exclusive)
174      * @since 3.2
175      */

176     // TODO (david) https://bugs.eclipse.org/bugs/show_bug.cgi?id=132558
177
public int getTokenEnd() {
178         return this.tokenEnd;
179     }
180     
181     /**
182      * Returns the offset position in the source file buffer
183      * after which code assist is requested.
184      *
185      * @return offset position in the source file buffer
186      * @since 3.2
187      */

188     public int getOffset() {
189         return this.offset;
190     }
191     
192     public String JavaDoc toString() {
193         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
194         
195         buffer.append("completion offset="); //$NON-NLS-1$
196
buffer.append(this.offset);
197         buffer.append('\n');
198         
199         buffer.append("completion range=["); //$NON-NLS-1$
200
buffer.append(this.tokenStart);
201         buffer.append(", "); //$NON-NLS-1$
202
buffer.append(this.tokenEnd);
203         buffer.append("]\n"); //$NON-NLS-1$
204

205         buffer.append("completion token="); //$NON-NLS-1$
206
String JavaDoc string = "null"; //$NON-NLS-1$
207
if(token == null) {
208             buffer.append(string);
209         } else {
210             buffer.append('\"');
211             buffer.append(this.token);
212             buffer.append('\"');
213         }
214         buffer.append('\n');
215         
216         buffer.append("expectedTypesSignatures="); //$NON-NLS-1$
217
if(this.expectedTypesSignatures == null) {
218             buffer.append(string);
219         } else {
220             buffer.append('{');
221             for (int i = 0; i < this.expectedTypesSignatures.length; i++) {
222                 if(i > 0) buffer.append(',');
223                 buffer.append(this.expectedTypesSignatures[i]);
224                 
225             }
226             buffer.append('}');
227         }
228         buffer.append('\n');
229         
230         buffer.append("expectedTypesKeys="); //$NON-NLS-1$
231
if(expectedTypesSignatures == null) {
232             buffer.append(string);
233         } else {
234             buffer.append('{');
235             for (int i = 0; i < this.expectedTypesKeys.length; i++) {
236                 if(i > 0) buffer.append(',');
237                 buffer.append(this.expectedTypesKeys[i]);
238                 
239             }
240             buffer.append('}');
241         }
242         buffer.append('\n');
243             
244         return buffer.toString();
245     }
246 }
247
Popular Tags