KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > codeassist > select > SelectionOnSingleTypeReference


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.select;
12
13 /*
14  * Selection node build by the parser in any case it was intending to
15  * reduce a type reference containing the selection identifier as a single
16  * name reference.
17  * e.g.
18  *
19  * class X extends [start]Object[end]
20  *
21  * ---> class X extends <SelectOnType:Object>
22  *
23  */

24 import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
25 import org.eclipse.jdt.internal.compiler.lookup.Binding;
26 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
27 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
28 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
29 import org.eclipse.jdt.internal.compiler.lookup.Scope;
30 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
31
32 public class SelectionOnSingleTypeReference extends SingleTypeReference {
33 public SelectionOnSingleTypeReference(char[] source, long pos) {
34     super(source, pos);
35 }
36 public void aboutToResolve(Scope scope) {
37     getTypeBinding(scope.parent); // step up from the ClassScope
38
}
39 protected TypeBinding getTypeBinding(Scope scope) {
40     // it can be a package, type or member type
41
Binding binding = scope.getTypeOrPackage(new char[][] {token});
42     if (!binding.isValidBinding()) {
43         scope.problemReporter().invalidType(this, (TypeBinding) binding);
44         throw new SelectionNodeFound();
45     }
46     throw new SelectionNodeFound(binding);
47 }
48 public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
49
50     return output.append("<SelectOnType:").append(token).append('>');//$NON-NLS-1$
51
}
52 public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
53     super.resolveTypeEnclosing(scope, enclosingType);
54
55         // tolerate some error cases
56
if (this.resolvedType == null ||
57                 !(this.resolvedType.isValidBinding() ||
58                     this.resolvedType.problemId() == ProblemReasons.NotVisible))
59         throw new SelectionNodeFound();
60     else
61         throw new SelectionNodeFound(this.resolvedType);
62 }
63 }
64
Popular Tags