PHPLanguagePreferencePage.spanish and PHPEditorSyntaxPreferencePage.background added...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / select / SelectionOnQualifiedNameReference.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 qualified name reference containing the assist identifier.
16  * e.g.
17  *
18  *      class X {
19  *    Y y;
20  *    void foo() {
21  *      y.fred.[start]ba[end]
22  *    }
23  *  }
24  *
25  *      ---> class X {
26  *         Y y;
27  *         void foo() {
28  *           <SelectOnName:y.fred.ba>
29  *         }
30  *       }
31  *
32  */
33
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;
42
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) {
46         super(
47                 CharOperation.arrayConcat(previousIdentifiers, selectionIdentifier),
48                 (int) (positions[0] >>> 32),
49                 (int) positions[positions.length - 1]);
50         this.sourcePositions = positions;
51 }
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);
63                         }
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);
69                         }
70                         scope.problemReporter().invalidType(this, (TypeBinding) binding);
71                 } else {
72                         scope.problemReporter().unresolvableReference(this, binding);
73                 }
74                 throw new SelectionNodeFound();
75         }
76         throw new SelectionNodeFound(binding);
77 }
78 public String toStringExpression() {
79
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]);
83                 if (i != length - 1)
84                         buffer.append("."); //$NON-NLS-1$
85         }
86         buffer.append(">"); //$NON-NLS-1$
87         return buffer.toString();
88 }
89 }