9589df271b81eda3d8331482bdf7ba3e548f0bbb
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / select / SelectionOnSingleNameReference.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.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 net.sourceforge.phpdt.internal.compiler.ast.SingleNameReference;
33 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
34 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
35 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemFieldBinding;
36 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
37 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReferenceBinding;
38 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
39  
40 public class SelectionOnSingleNameReference extends SingleNameReference {
41 public SelectionOnSingleNameReference(char[] source, long pos) {
42         super(source, pos);
43 }
44 public TypeBinding resolveType(BlockScope scope) {
45         // it can be a package, type, member type, local variable or field
46         binding = scope.getBinding(token, VARIABLE | TYPE | PACKAGE, this);
47         if (!binding.isValidBinding()) {
48                 if (binding instanceof ProblemFieldBinding) {
49                         // tolerate some error cases
50                         if (binding.problemId() == ProblemReasons.NotVisible
51                                         || binding.problemId() == ProblemReasons.InheritedNameHidesEnclosingName
52                                         || binding.problemId() == ProblemReasons.NonStaticReferenceInConstructorInvocation
53                                         || binding.problemId() == ProblemReasons.NonStaticReferenceInStaticContext){
54                                 throw new SelectionNodeFound(binding);
55                         }
56                         scope.problemReporter().invalidField(this, (FieldBinding) binding);
57                 } else if (binding instanceof ProblemReferenceBinding) {
58                         // tolerate some error cases
59                         if (binding.problemId() == ProblemReasons.NotVisible){
60                                 throw new SelectionNodeFound(binding);
61                         }                       
62                         scope.problemReporter().invalidType(this, (TypeBinding) binding);
63                 } else {
64                         scope.problemReporter().unresolvableReference(this, binding);
65                 }
66                 throw new SelectionNodeFound();
67         }
68
69         throw new SelectionNodeFound(binding);
70 }
71 public String toStringExpression() {
72         return "<SelectOnName:" + super.toStringExpression() + ">"; //$NON-NLS-2$ //$NON-NLS-1$
73 }
74 }