KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > codeassist > CompletionRequestorWrapper


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.internal.codeassist;
12
13 import org.eclipse.jdt.core.CompletionProposal;
14 import org.eclipse.jdt.core.CompletionRequestor;
15 import org.eclipse.jdt.core.Flags;
16 import org.eclipse.jdt.core.Signature;
17 import org.eclipse.jdt.core.compiler.CharOperation;
18 import org.eclipse.jdt.core.compiler.IProblem;
19
20 /**
21  * This CompletionRequetor wrap the old requestor ICOmpletionRequestor
22  * @since 3.1
23  * @deprecated
24  */

25 public class CompletionRequestorWrapper extends CompletionRequestor {
26     private static boolean DECODE_SIGNATURE = false;
27     
28     private org.eclipse.jdt.core.ICompletionRequestor requestor;
29     public CompletionRequestorWrapper(org.eclipse.jdt.core.ICompletionRequestor requestor) {
30         this.requestor = requestor;
31     }
32     
33     public void accept(CompletionProposal proposal) {
34         switch(proposal.getKind()) {
35             case CompletionProposal.KEYWORD:
36                 this.requestor.acceptKeyword(
37                         proposal.getName(),
38                         proposal.getReplaceStart(),
39                         proposal.getReplaceEnd(),
40                         proposal.getRelevance());
41                 break;
42             case CompletionProposal.PACKAGE_REF:
43                 if(DECODE_SIGNATURE) {
44                     this.requestor.acceptPackage(
45                             proposal.getDeclarationSignature(),
46                             proposal.getCompletion(),
47                             proposal.getReplaceStart(),
48                             proposal.getReplaceEnd(),
49                             proposal.getRelevance());
50                 } else {
51                     this.requestor.acceptPackage(
52                             proposal.getPackageName(),
53                             proposal.getCompletion(),
54                             proposal.getReplaceStart(),
55                             proposal.getReplaceEnd(),
56                             proposal.getRelevance());
57                 }
58                 break;
59             case CompletionProposal.TYPE_REF:
60                 if((proposal.getFlags() & Flags.AccEnum) != 0) {
61                     // does not exist for old requestor
62
} else if((proposal.getFlags() & Flags.AccInterface) != 0) {
63                     if(DECODE_SIGNATURE) {
64                         this.requestor.acceptInterface(
65                                 proposal.getDeclarationSignature(),
66                                 Signature.getSignatureSimpleName(proposal.getSignature()),
67                                 proposal.getCompletion(),
68                                 proposal.getFlags() & ~Flags.AccInterface,
69                                 proposal.getReplaceStart(),
70                                 proposal.getReplaceEnd(),
71                                 proposal.getRelevance());
72                     } else {
73                         this.requestor.acceptInterface(
74                                 proposal.getPackageName() == null ? CharOperation.NO_CHAR : proposal.getPackageName(),
75                                 proposal.getTypeName(),
76                                 proposal.getCompletion(),
77                                 proposal.getFlags() & ~Flags.AccInterface,
78                                 proposal.getReplaceStart(),
79                                 proposal.getReplaceEnd(),
80                                 proposal.getRelevance());
81                     }
82                 } else {
83                     if(DECODE_SIGNATURE) {
84                         this.requestor.acceptClass(
85                                 proposal.getDeclarationSignature(),
86                                 Signature.getSignatureSimpleName(proposal.getSignature()),
87                                 proposal.getCompletion(),
88                                 proposal.getFlags(),
89                                 proposal.getReplaceStart(),
90                                 proposal.getReplaceEnd(),
91                                 proposal.getRelevance());
92                     } else {
93                         this.requestor.acceptClass(
94                                 proposal.getPackageName() == null ? CharOperation.NO_CHAR : proposal.getPackageName(),
95                                 proposal.getTypeName(),
96                                 proposal.getCompletion(),
97                                 proposal.getFlags(),
98                                 proposal.getReplaceStart(),
99                                 proposal.getReplaceEnd(),
100                                 proposal.getRelevance());
101                     }
102                 }
103                 break;
104             case CompletionProposal.FIELD_REF:
105                 if(DECODE_SIGNATURE) {
106                     this.requestor.acceptField(
107                             Signature.getSignatureQualifier(proposal.getDeclarationSignature()),
108                             Signature.getSignatureSimpleName(proposal.getDeclarationSignature()),
109                             proposal.getName(),
110                             Signature.getSignatureQualifier(proposal.getSignature()),
111                             Signature.getSignatureSimpleName(proposal.getSignature()),
112                             proposal.getCompletion(),
113                             proposal.getFlags(),
114                             proposal.getReplaceStart(),
115                             proposal.getReplaceEnd(),
116                             proposal.getRelevance()
117                     );
118                 } else {
119                     this.requestor.acceptField(
120                             proposal.getDeclarationPackageName() == null ? CharOperation.NO_CHAR : proposal.getDeclarationPackageName(),
121                             proposal.getDeclarationTypeName() == null ? CharOperation.NO_CHAR : proposal.getDeclarationTypeName(),
122                             proposal.getName(),
123                             proposal.getPackageName() == null ? CharOperation.NO_CHAR : proposal.getPackageName(),
124                             proposal.getTypeName() == null ? CharOperation.NO_CHAR : proposal.getTypeName(),
125                             proposal.getCompletion(),
126                             proposal.getFlags(),
127                             proposal.getReplaceStart(),
128                             proposal.getReplaceEnd(),
129                             proposal.getRelevance()
130                     );
131                 }
132                 break;
133             case CompletionProposal.METHOD_REF:
134                 if(DECODE_SIGNATURE) {
135                     this.requestor.acceptMethod(
136                             Signature.getSignatureQualifier(proposal.getDeclarationSignature()),
137                             Signature.getSignatureSimpleName(proposal.getDeclarationSignature()),
138                             proposal.getName(),
139                             getParameterPackages(proposal.getSignature()),
140                             getParameterTypes(proposal.getSignature()),
141                             proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal.findParameterNames(null),
142                             Signature.getSignatureQualifier(Signature.getReturnType(proposal.getSignature())),
143                             Signature.getSignatureSimpleName(Signature.getReturnType(proposal.getSignature())),
144                             proposal.getCompletion(),
145                             proposal.getFlags(),
146                             proposal.getReplaceStart(),
147                             proposal.getReplaceEnd(),
148                             proposal.getRelevance()
149                         );
150                 } else {
151                     this.requestor.acceptMethod(
152                             proposal.getDeclarationPackageName() == null ? CharOperation.NO_CHAR : proposal.getDeclarationPackageName(),
153                             proposal.getDeclarationTypeName() == null ? CharOperation.NO_CHAR : proposal.getDeclarationTypeName(),
154                             proposal.getName(),
155                             proposal.getParameterPackageNames() == null ? CharOperation.NO_CHAR_CHAR : proposal.getParameterPackageNames(),
156                             proposal.getParameterTypeNames() == null ? CharOperation.NO_CHAR_CHAR : proposal.getParameterTypeNames(),
157                             proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal.findParameterNames(null),
158                             proposal.getPackageName() == null ? CharOperation.NO_CHAR : proposal.getPackageName(),
159                             proposal.getTypeName() == null ? CharOperation.NO_CHAR : proposal.getTypeName(),
160                             proposal.getCompletion(),
161                             proposal.getFlags(),
162                             proposal.getReplaceStart(),
163                             proposal.getReplaceEnd(),
164                             proposal.getRelevance()
165                     );
166                 }
167                 break;
168             case CompletionProposal.METHOD_DECLARATION:
169                 if(DECODE_SIGNATURE) {
170                     this.requestor.acceptMethodDeclaration(
171                             Signature.getSignatureQualifier(proposal.getDeclarationSignature()),
172                             Signature.getSignatureSimpleName(proposal.getDeclarationSignature()),
173                             proposal.getName(),
174                             getParameterPackages(proposal.getSignature()),
175                             getParameterTypes(proposal.getSignature()),
176                             proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal.findParameterNames(null),
177                             Signature.getSignatureQualifier(Signature.getReturnType(proposal.getSignature())),
178                             Signature.getSignatureSimpleName(Signature.getReturnType(proposal.getSignature())),
179                             proposal.getCompletion(),
180                             proposal.getFlags(),
181                             proposal.getReplaceStart(),
182                             proposal.getReplaceEnd(),
183                             proposal.getRelevance()
184                     );
185                 } else {
186                     this.requestor.acceptMethodDeclaration(
187                             proposal.getDeclarationPackageName(),
188                             proposal.getDeclarationTypeName(),
189                             proposal.getName(),
190                             proposal.getParameterPackageNames() == null ? CharOperation.NO_CHAR_CHAR : proposal.getParameterPackageNames(),
191                             proposal.getParameterTypeNames() == null ? CharOperation.NO_CHAR_CHAR : proposal.getParameterTypeNames(),
192                             proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal.findParameterNames(null),
193                             proposal.getPackageName(),
194                             proposal.getTypeName(),
195                             proposal.getCompletion(),
196                             proposal.getFlags(),
197                             proposal.getReplaceStart(),
198                             proposal.getReplaceEnd(),
199                             proposal.getRelevance()
200                     );
201                 }
202                 break;
203             case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
204                 if(DECODE_SIGNATURE) {
205                     this.requestor.acceptAnonymousType(
206                             Signature.getSignatureQualifier(proposal.getDeclarationSignature()),
207                             Signature.getSignatureSimpleName(proposal.getDeclarationSignature()),
208                             getParameterPackages(proposal.getSignature()),
209                             getParameterTypes(proposal.getSignature()),
210                             proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal.findParameterNames(null),
211                             proposal.getCompletion(),
212                             proposal.getFlags(),
213                             proposal.getReplaceStart(),
214                             proposal.getReplaceEnd(),
215                             proposal.getRelevance()
216                         );
217                 } else {
218                     this.requestor.acceptAnonymousType(
219                         proposal.getDeclarationPackageName(),
220                         proposal.getDeclarationTypeName(),
221                         proposal.getParameterPackageNames() == null ? CharOperation.NO_CHAR_CHAR : proposal.getParameterPackageNames(),
222                         proposal.getParameterTypeNames() == null ? CharOperation.NO_CHAR_CHAR : proposal.getParameterTypeNames(),
223                         proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal.findParameterNames(null),
224                         proposal.getCompletion(),
225                         proposal.getFlags(),
226                         proposal.getReplaceStart(),
227                         proposal.getReplaceEnd(),
228                         proposal.getRelevance()
229                     );
230                 }
231                 break;
232             case CompletionProposal.LABEL_REF :
233                 this.requestor.acceptLabel(
234                     proposal.getCompletion(),
235                     proposal.getReplaceStart(),
236                     proposal.getReplaceEnd(),
237                     proposal.getRelevance()
238                 );
239                 break;
240             case CompletionProposal.LOCAL_VARIABLE_REF:
241                 if(DECODE_SIGNATURE) {
242                     this.requestor.acceptLocalVariable(
243                             proposal.getCompletion(),
244                             Signature.getSignatureQualifier(proposal.getSignature()),
245                             Signature.getSignatureSimpleName(proposal.getSignature()),
246                             proposal.getFlags(),
247                             proposal.getReplaceStart(),
248                             proposal.getReplaceEnd(),
249                             proposal.getRelevance()
250                     );
251                 } else {
252                     this.requestor.acceptLocalVariable(
253                             proposal.getCompletion(),
254                             proposal.getPackageName() == null ? CharOperation.NO_CHAR : proposal.getPackageName(),
255                             proposal.getTypeName(),
256                             proposal.getFlags(),
257                             proposal.getReplaceStart(),
258                             proposal.getReplaceEnd(),
259                             proposal.getRelevance()
260                     );
261                 }
262                 break;
263             case CompletionProposal.VARIABLE_DECLARATION:
264                 if(DECODE_SIGNATURE) {
265                     this.requestor.acceptLocalVariable(
266                             proposal.getCompletion(),
267                             Signature.getSignatureQualifier(proposal.getSignature()),
268                             Signature.getSignatureSimpleName(proposal.getSignature()),
269                             proposal.getFlags(),
270                             proposal.getReplaceStart(),
271                             proposal.getReplaceEnd(),
272                             proposal.getRelevance()
273                         );
274                 } else {
275                     this.requestor.acceptLocalVariable(
276                         proposal.getCompletion(),
277                         proposal.getPackageName(),
278                         proposal.getTypeName(),
279                         proposal.getFlags(),
280                         proposal.getReplaceStart(),
281                         proposal.getReplaceEnd(),
282                         proposal.getRelevance()
283                     );
284                 }
285                 break;
286             case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
287                 if(this.requestor instanceof IExtendedCompletionRequestor) {
288                     IExtendedCompletionRequestor r = (IExtendedCompletionRequestor) this.requestor;
289                     if(DECODE_SIGNATURE) {
290                         r.acceptPotentialMethodDeclaration(
291                                 Signature.getSignatureQualifier(proposal.getDeclarationSignature()),
292                                 Signature.getSignatureSimpleName(proposal.getDeclarationSignature()),
293                                 proposal.getName(),
294                                 proposal.getReplaceStart(),
295                                 proposal.getReplaceEnd(),
296                                 proposal.getRelevance()
297                         );
298                     } else {
299                         r.acceptPotentialMethodDeclaration(
300                                 proposal.getDeclarationPackageName(),
301                                 proposal.getDeclarationTypeName(),
302                                 proposal.getName(),
303                                 proposal.getReplaceStart(),
304                                 proposal.getReplaceEnd(),
305                                 proposal.getRelevance()
306                         );
307                     }
308                 }
309                 break;
310                 
311         }
312     }
313     
314     public void completionFailure(IProblem problem) {
315         this.requestor.acceptError(problem);
316     }
317     
318     private char[][] getParameterPackages(char[] methodSignature) {
319         char[][] parameterQualifiedTypes = Signature.getParameterTypes(methodSignature);
320         int length = parameterQualifiedTypes == null ? 0 : parameterQualifiedTypes.length;
321         char[][] parameterPackages = new char[length][];
322         for(int i = 0; i < length; i++) {
323             parameterPackages[i] = Signature.getSignatureQualifier(parameterQualifiedTypes[i]);
324         }
325
326         return parameterPackages;
327     }
328     
329     private char[][] getParameterTypes(char[] methodSignature) {
330         char[][] parameterQualifiedTypes = Signature.getParameterTypes(methodSignature);
331         int length = parameterQualifiedTypes == null ? 0 : parameterQualifiedTypes.length;
332         char[][] parameterPackages = new char[length][];
333         for(int i = 0; i < length; i++) {
334             parameterPackages[i] = Signature.getSignatureSimpleName(parameterQualifiedTypes[i]);
335         }
336
337         return parameterPackages;
338     }
339 }
340
Popular Tags