KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > codeassist > complete > CompletionOnParameterizedQualifiedTypeReference


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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.complete;
12
13 /*
14  * Completion node build by the parser in any case it was intending to
15  * reduce a type reference containing the completion identifier as part
16  * of a parameterized qualified name.
17  * e.g.
18  *
19  * class X extends Y<Z>.W[cursor]
20  *
21  * ---> class X extends <CompleteOnType:Y<Z>.W>
22  *
23  * The source range of the completion node denotes the source range
24  * which should be replaced by the completion.
25  */

26
27 import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
28 import org.eclipse.jdt.internal.compiler.ast.TypeReference;
29 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
30 import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
31 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
32
33
34 public class CompletionOnParameterizedQualifiedTypeReference extends ParameterizedQualifiedTypeReference {
35     public static final int K_TYPE = 0;
36     public static final int K_CLASS = 1;
37     public static final int K_INTERFACE = 2;
38     public static final int K_EXCEPTION = 3;
39     
40     private int kind = K_TYPE;
41     public char[] completionIdentifier;
42     /**
43      * @param tokens
44      * @param typeArguments
45      * @param positions
46      */

47     public CompletionOnParameterizedQualifiedTypeReference(char[][] tokens, TypeReference[][] typeArguments, char[] completionIdentifier, long[] positions) {
48         this(tokens, typeArguments, completionIdentifier, positions, K_TYPE);
49     }
50     
51     /**
52      * @param tokens
53      * @param typeArguments
54      * @param positions
55      * @param kind
56      */

57     public CompletionOnParameterizedQualifiedTypeReference(char[][] tokens, TypeReference[][] typeArguments, char[] completionIdentifier, long[] positions, int kind) {
58         super(tokens, typeArguments, 0, positions);
59         this.completionIdentifier = completionIdentifier;
60         this.kind = kind;
61     }
62     
63     public boolean isClass(){
64         return this.kind == K_CLASS;
65     }
66     
67     public boolean isInterface(){
68         return this.kind == K_INTERFACE;
69     }
70     
71     public boolean isException(){
72         return this.kind == K_EXCEPTION;
73     }
74     
75     public boolean isSuperType(){
76         return this.kind == K_CLASS || this.kind == K_INTERFACE;
77     }
78     
79     public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
80         super.resolveType(scope, checkBounds);
81         throw new CompletionNodeFound(this, this.resolvedType, scope);
82     }
83     
84     public TypeBinding resolveType(ClassScope scope) {
85         super.resolveType(scope);
86         throw new CompletionNodeFound(this, this.resolvedType, scope);
87     }
88     
89     public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
90         switch (this.kind) {
91             case K_CLASS :
92                 output.append("<CompleteOnClass:");//$NON-NLS-1$
93
break;
94             case K_INTERFACE :
95                 output.append("<CompleteOnInterface:");//$NON-NLS-1$
96
break;
97             case K_EXCEPTION :
98                 output.append("<CompleteOnException:");//$NON-NLS-1$
99
break;
100             default :
101                 output.append("<CompleteOnType:");//$NON-NLS-1$
102
break;
103         }
104         int length = tokens.length;
105         for (int i = 0; i < length - 1; i++) {
106             output.append(tokens[i]);
107             TypeReference[] typeArgument = typeArguments[i];
108             if (typeArgument != null) {
109                 output.append('<');
110                 int max = typeArgument.length - 1;
111                 for (int j = 0; j < max; j++) {
112                     typeArgument[j].print(0, output);
113                     output.append(", ");//$NON-NLS-1$
114
}
115                 typeArgument[max].print(0, output);
116                 output.append('>');
117             }
118             output.append('.');
119         }
120         output.append(tokens[length - 1]);
121         TypeReference[] typeArgument = typeArguments[length - 1];
122         if (typeArgument != null) {
123             output.append('<');
124             int max = typeArgument.length - 1;
125             for (int j = 0; j < max; j++) {
126                 typeArgument[j].print(0, output);
127                 output.append(", ");//$NON-NLS-1$
128
}
129             typeArgument[max].print(0, output);
130             output.append('>');
131         }
132         output.append('.').append(completionIdentifier).append('>');
133         return output;
134     }
135 }
136
Popular Tags