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 qualified name reference containing the assist identifier.
21 * y.fred.[start]ba[end]
28 * <SelectOnName:y.fred.ba>
34 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedNameReference;
35 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
36 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
37 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemFieldBinding;
38 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
39 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReferenceBinding;
40 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
41 import net.sourceforge.phpdt.internal.compiler.util.CharOperation;
43 public class SelectionOnQualifiedNameReference extends QualifiedNameReference {
44 public long[] sourcePositions; // positions of each token, the last one being the positions of the completion identifier
45 public SelectionOnQualifiedNameReference(char[][] previousIdentifiers, char[] selectionIdentifier, long[] positions) {
47 CharOperation.arrayConcat(previousIdentifiers, selectionIdentifier),
48 (int) (positions[0] >>> 32),
49 (int) positions[positions.length - 1]);
50 this.sourcePositions = positions;
52 public TypeBinding resolveType(BlockScope scope) {
53 // it can be a package, type, member type, local variable or field
54 binding = scope.getBinding(tokens, this);
55 if (!binding.isValidBinding()) {
56 if (binding instanceof ProblemFieldBinding) {
57 // tolerate some error cases
58 if (binding.problemId() == ProblemReasons.NotVisible
59 || binding.problemId() == ProblemReasons.InheritedNameHidesEnclosingName
60 || binding.problemId() == ProblemReasons.NonStaticReferenceInConstructorInvocation
61 || binding.problemId() == ProblemReasons.NonStaticReferenceInStaticContext) {
62 throw new SelectionNodeFound(binding);
64 scope.problemReporter().invalidField(this, (FieldBinding) binding);
65 } else if (binding instanceof ProblemReferenceBinding) {
66 // tolerate some error cases
67 if (binding.problemId() == ProblemReasons.NotVisible){
68 throw new SelectionNodeFound(binding);
70 scope.problemReporter().invalidType(this, (TypeBinding) binding);
72 scope.problemReporter().unresolvableReference(this, binding);
74 throw new SelectionNodeFound();
76 throw new SelectionNodeFound(binding);
78 public String toStringExpression() {
80 StringBuffer buffer = new StringBuffer("<SelectOnName:"); //$NON-NLS-1$
81 for (int i = 0, length = tokens.length; i < length; i++) {
82 buffer.append(tokens[i]);
84 buffer.append("."); //$NON-NLS-1$
86 buffer.append(">"); //$NON-NLS-1$
87 return buffer.toString();