KickJava   Java API By Example, From Geeks To Geeks.

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


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 single name reference containing the assist identifier.
16  * e.g.
17  *
18  * class X {
19  * void foo() {
20  * [start]ba[end]
21  * }
22  * }
23  *
24  * ---> class X {
25  * void foo() {
26  * <SelectOnName:ba>
27  * }
28  * }
29  *
30  */

31
32 import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
33 import org.eclipse.jdt.internal.compiler.lookup.Binding;
34 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
35 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
36 import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding;
37 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
38 import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
39 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
40  
41 public class SelectionOnSingleNameReference extends SingleNameReference {
42 public SelectionOnSingleNameReference(char[] source, long pos) {
43     super(source, pos);
44 }
45 public TypeBinding resolveType(BlockScope scope) {
46     if (this.actualReceiverType != null) {
47         this.binding = scope.getField(this.actualReceiverType, token, this);
48         if (this.binding != null && this.binding.isValidBinding()) {
49             throw new SelectionNodeFound(binding);
50         }
51     }
52     // it can be a package, type, member type, local variable or field
53
binding = scope.getBinding(token, Binding.VARIABLE | Binding.TYPE | Binding.PACKAGE, this, true /*resolve*/);
54     if (!binding.isValidBinding()) {
55         if (binding instanceof ProblemFieldBinding) {
56             // tolerate some error cases
57
if (binding.problemId() == ProblemReasons.NotVisible
58                     || binding.problemId() == ProblemReasons.InheritedNameHidesEnclosingName
59                     || binding.problemId() == ProblemReasons.NonStaticReferenceInConstructorInvocation
60                     || binding.problemId() == ProblemReasons.NonStaticReferenceInStaticContext){
61                 throw new SelectionNodeFound(binding);
62             }
63             scope.problemReporter().invalidField(this, (FieldBinding) binding);
64         } else if (binding instanceof ProblemReferenceBinding) {
65             // tolerate some error cases
66
if (binding.problemId() == ProblemReasons.NotVisible){
67                 throw new SelectionNodeFound(binding);
68             }
69             scope.problemReporter().invalidType(this, (TypeBinding) binding);
70         } else {
71             scope.problemReporter().unresolvableReference(this, binding);
72         }
73         throw new SelectionNodeFound();
74     }
75
76     throw new SelectionNodeFound(binding);
77 }
78 public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
79     output.append("<SelectOnName:"); //$NON-NLS-1$
80
return super.printExpression(0, output).append('>');
81 }
82 }
83
Popular Tags