Skip to main content
summaryrefslogtreecommitdiffstats
blob: e8d7eb5ec587a1821e4d84ac7a88330891463fef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*******************************************************************************
 * Copyright (c) 2000, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.jsdt.internal.codeassist.complete;

/*
 * Completion node build by the parser in any case it was intending to
 * reduce a type reference containing the completion identifier as a single
 * name reference.
 * e.g.
 *
 *	class X extends Obj[cursor]
 *
 *	---> class X extends <CompleteOnType:Obj>
 *
 * The source range of the completion node denotes the source range
 * which should be replaced by the completion.
 */

import org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode;
import org.eclipse.wst.jsdt.internal.compiler.ast.SingleTypeReference;
import org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference;
import org.eclipse.wst.jsdt.internal.compiler.lookup.BlockScope;
import org.eclipse.wst.jsdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.wst.jsdt.internal.compiler.lookup.Scope;
import org.eclipse.wst.jsdt.internal.compiler.lookup.TypeBinding;

public class CompletionOnSingleTypeReference extends SingleTypeReference {
	public static final int K_TYPE = 0;
	public static final int K_CLASS = 1;
	public static final int K_INTERFACE = 2;
	public static final int K_EXCEPTION = 3;
	
	private int kind = K_TYPE;
	public boolean isCompletionNode;
	public boolean isConstructorType;
	public CompletionOnFieldType fieldTypeCompletionNode;
	
	public CompletionOnSingleTypeReference(char[] source, long pos) {
		this(source, pos, K_TYPE);
	}
	public CompletionOnSingleTypeReference(char[] source, long pos, int kind) {
		super(source, pos);
		isCompletionNode = true;
		this.kind = kind;
	}
	public void aboutToResolve(Scope scope) {
		getTypeBinding(scope);
	}
	/*
	 * No expansion of the completion reference into an array one
	 */
	public TypeReference copyDims(int dim){
		return this;
	}
	protected TypeBinding getTypeBinding(Scope scope) {
	    if (this.fieldTypeCompletionNode != null) {
			throw new CompletionNodeFound(this.fieldTypeCompletionNode, scope);
	    }
		if(isCompletionNode) {
			throw new CompletionNodeFound(this, scope);
		} else {
			return super.getTypeBinding(scope);
		}
	}
	public boolean isClass(){
		return this.kind == K_CLASS;
	}
	public boolean isInterface(){
		return this.kind == K_INTERFACE;
	}
	public boolean isException(){
		return this.kind == K_EXCEPTION;
	}
	public boolean isSuperType(){
		return this.kind == K_CLASS || this.kind == K_INTERFACE;
	}
	
	public StringBuffer printExpression(int indent, StringBuffer output){
		switch (this.kind) {
			case K_CLASS :
				output.append("<CompleteOnClass:");//$NON-NLS-1$
				break;
			case K_INTERFACE :
				output.append("<CompleteOnInterface:");//$NON-NLS-1$
				break;
			case K_EXCEPTION :
				output.append("<CompleteOnException:");//$NON-NLS-1$
				break;
			default :
				output.append("<CompleteOnType:");//$NON-NLS-1$
				break;
		}
		return output.append(token).append('>');
	}
	
	public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
	    if (this.fieldTypeCompletionNode != null) {
			throw new CompletionNodeFound(this.fieldTypeCompletionNode, scope);
	    }
		if(isCompletionNode) {
			throw new CompletionNodeFound(this, enclosingType, scope);
		} else {
			return super.resolveTypeEnclosing(scope, enclosingType);
		}
	}
	
	/**
	 * @see org.eclipse.wst.jsdt.internal.compiler.ast.Expression#resolve(org.eclipse.wst.jsdt.internal.compiler.lookup.BlockScope)
	 */
	public void resolve(BlockScope scope) {
		super.resolve(scope);
		
		throw new CompletionNodeFound(this, scope);
	}
	
	/**
	 * @see org.eclipse.wst.jsdt.internal.compiler.ast.TypeReference#resolveType(org.eclipse.wst.jsdt.internal.compiler.lookup.BlockScope, boolean)
	 */
	public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
		super.resolveType(scope, checkBounds);
		
		throw new CompletionNodeFound(this, scope);
	}
	
	/**
	 * 
	 * @see org.eclipse.wst.jsdt.internal.compiler.ast.Expression#resolveForAllocation(org.eclipse.wst.jsdt.internal.compiler.lookup.BlockScope, org.eclipse.wst.jsdt.internal.compiler.ast.ASTNode)
	 */
	public TypeBinding resolveForAllocation(BlockScope scope, ASTNode location) {
		return this.resolveType(scope);
	}
}

Back to the top