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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.codeassist.select;
14 * Selection node build by the parser in any case it was intending to
15 * reduce a single name reference containing the assist identifier.
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;
40 public class SelectionOnSingleNameReference extends SingleNameReference {
41 public SelectionOnSingleNameReference(char[] source, long pos) {
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);
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);
62 scope.problemReporter().invalidType(this, (TypeBinding) binding);
64 scope.problemReporter().unresolvableReference(this, binding);
66 throw new SelectionNodeFound();
69 throw new SelectionNodeFound(binding);
71 public String toStringExpression() {
72 return "<SelectOnName:" + super.toStringExpression() + ">"; //$NON-NLS-2$ //$NON-NLS-1$