KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 qualified name.
17  * e.g.
18  *
19  * class X extends java.lang.Obj[cursor]
20  *
21  * ---> class X extends <CompleteOnType:java.lang.Obj>
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.*;
28 import org.eclipse.jdt.internal.compiler.lookup.*;
29
30 public class CompletionOnQualifiedTypeReference extends QualifiedTypeReference {
31     public static final int K_TYPE = 0;
32     public static final int K_CLASS = 1;
33     public static final int K_INTERFACE = 2;
34     public static final int K_EXCEPTION = 3;
35     
36     private int kind = K_TYPE;
37     public char[] completionIdentifier;
38 public CompletionOnQualifiedTypeReference(char[][] previousIdentifiers, char[] completionIdentifier, long[] positions) {
39     this(previousIdentifiers, completionIdentifier, positions, K_TYPE);
40 }
41 public CompletionOnQualifiedTypeReference(char[][] previousIdentifiers, char[] completionIdentifier, long[] positions, int kind) {
42     super(previousIdentifiers, positions);
43     this.completionIdentifier = completionIdentifier;
44     this.kind = kind;
45 }
46 public void aboutToResolve(Scope scope) {
47     getTypeBinding(scope);
48 }
49 /*
50  * No expansion of the completion reference into an array one
51  */

52 public TypeReference copyDims(int dim){
53     return this;
54 }
55 protected TypeBinding getTypeBinding(Scope scope) {
56     // it can be a package, type or member type
57
Binding binding = scope.parent.getTypeOrPackage(tokens); // step up from the ClassScope
58
if (!binding.isValidBinding()) {
59         scope.problemReporter().invalidType(this, (TypeBinding) binding);
60         throw new CompletionNodeFound();
61     }
62
63     throw new CompletionNodeFound(this, binding, scope);
64 }
65 public boolean isClass(){
66     return this.kind == K_CLASS;
67 }
68
69 public boolean isInterface(){
70     return this.kind == K_INTERFACE;
71 }
72
73 public boolean isException(){
74     return this.kind == K_EXCEPTION;
75 }
76
77 public boolean isSuperType(){
78     return this.kind == K_CLASS || this.kind == K_INTERFACE;
79 }
80 public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
81     switch (this.kind) {
82         case K_CLASS :
83             output.append("<CompleteOnClass:");//$NON-NLS-1$
84
break;
85         case K_INTERFACE :
86             output.append("<CompleteOnInterface:");//$NON-NLS-1$
87
break;
88         case K_EXCEPTION :
89             output.append("<CompleteOnException:");//$NON-NLS-1$
90
break;
91         default :
92             output.append("<CompleteOnType:");//$NON-NLS-1$
93
break;
94     }
95     for (int i = 0; i < tokens.length; i++) {
96         output.append(tokens[i]);
97         output.append('.');
98     }
99     output.append(completionIdentifier).append('>');
100     return output;
101 }
102 }
103
Popular Tags