KickJava   Java API By Example, From Geeks To Geeks.

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


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 a single
16  * name reference.
17  * e.g.
18  *
19  * class X extends Obj[cursor]
20  *
21  * ---> class X extends <CompleteOnType: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 CompletionOnSingleTypeReference extends SingleTypeReference {
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 boolean isCompletionNode;
38 public boolean isConstructorType;
39 public CompletionOnFieldType fieldTypeCompletionNode;
40
41 public CompletionOnSingleTypeReference(char[] source, long pos) {
42     this(source, pos, K_TYPE);
43 }
44 public CompletionOnSingleTypeReference(char[] source, long pos, int kind) {
45     super(source, pos);
46     isCompletionNode = true;
47     this.kind = kind;
48 }
49 public void aboutToResolve(Scope scope) {
50     getTypeBinding(scope);
51 }
52 /*
53  * No expansion of the completion reference into an array one
54  */

55 public TypeReference copyDims(int dim){
56     return this;
57 }
58 protected TypeBinding getTypeBinding(Scope scope) {
59     if (this.fieldTypeCompletionNode != null) {
60         throw new CompletionNodeFound(this.fieldTypeCompletionNode, scope);
61     }
62     if(isCompletionNode) {
63         throw new CompletionNodeFound(this, scope);
64     } else {
65         return super.getTypeBinding(scope);
66     }
67 }
68 public boolean isClass(){
69     return this.kind == K_CLASS;
70 }
71 public boolean isInterface(){
72     return this.kind == K_INTERFACE;
73 }
74 public boolean isException(){
75     return this.kind == K_EXCEPTION;
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     return output.append(token).append('>');
96 }
97 public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
98     if (this.fieldTypeCompletionNode != null) {
99         throw new CompletionNodeFound(this.fieldTypeCompletionNode, scope);
100     }
101     if(isCompletionNode) {
102         throw new CompletionNodeFound(this, enclosingType, scope);
103     } else {
104         return super.resolveTypeEnclosing(scope, enclosingType);
105     }
106 }
107 }
108
Popular Tags