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.complete;
14 * Completion node build by the parser in any case it was intending to
15 * reduce a qualified name reference containing the completion identifier.
28 * <CompleteOnName:y.fred.ba>
32 * The source range of the completion node denotes the source range
33 * which should be replaced by the completion.
36 import net.sourceforge.phpdt.internal.compiler.ast.*;
37 import net.sourceforge.phpdt.internal.compiler.lookup.*;
39 public class CompletionOnQualifiedNameReference extends QualifiedNameReference {
40 public char[] completionIdentifier;
41 public long[] sourcePositions; // positions of each token, the last one being the positions of the completion identifier
42 public CompletionOnQualifiedNameReference(char[][] previousIdentifiers, char[] completionIdentifier, long[] positions) {
43 super(previousIdentifiers, (int) (positions[0] >>> 32), (int) positions[positions.length - 1]);
44 this.completionIdentifier = completionIdentifier;
45 this.sourcePositions = positions;
47 public CompletionOnQualifiedNameReference(char[][] previousIdentifiers, char[] completionIdentifier, int sourceStart, int sourceEnd) {
48 super(previousIdentifiers, sourceStart, sourceEnd);
49 this.completionIdentifier = completionIdentifier;
50 this.sourcePositions = new long[] {((long)sourceStart << 32) + sourceEnd};
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 scope.problemReporter().invalidField(this, (FieldBinding) binding);
58 } else if (binding instanceof ProblemReferenceBinding) {
59 scope.problemReporter().invalidType(this, (TypeBinding) binding);
61 scope.problemReporter().unresolvableReference(this, binding);
63 throw new CompletionNodeFound();
66 throw new CompletionNodeFound(this, binding, scope);
68 public String toStringExpression() {
70 StringBuffer buffer = new StringBuffer("<CompleteOnName:"); //$NON-NLS-1$
71 for (int i = 0; i < tokens.length; i++) {
72 buffer.append(tokens[i]);
73 buffer.append("."); //$NON-NLS-1$
75 buffer.append(completionIdentifier).append(">"); //$NON-NLS-1$
76 return buffer.toString();