a62d389c39a3d93cf53eb74d9b9443e74487cbe6
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / complete / CompletionOnQualifiedTypeReference.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.complete;
12
13 /*
14  * Completion node build by the parser in any case it was intending to
15  * reduce a type reference containing the completion identifier as part
16  * of a qualified name.
17  * e.g.
18  *
19  *      class X extends java.lang.Obj[cursor]
20  *
21  *      ---> class X extends <CompleteOnType:java.lang.Obj>
22  *
23  * The source range of the completion node denotes the source range
24  * which should be replaced by the completion.
25  */
26  
27 import net.sourceforge.phpdt.internal.compiler.ast.*;
28 import net.sourceforge.phpdt.internal.compiler.lookup.*;
29
30 public class CompletionOnQualifiedTypeReference extends QualifiedTypeReference {
31         public char[] completionIdentifier;
32 public CompletionOnQualifiedTypeReference(char[][] previousIdentifiers, char[] completionIdentifier, long[] positions) {
33         super(previousIdentifiers, positions);
34         this.completionIdentifier = completionIdentifier;
35 }
36 public void aboutToResolve(Scope scope) {
37         getTypeBinding(scope);
38 }
39 /*
40  * No expansion of the completion reference into an array one
41  */
42 public TypeReference copyDims(int dim){
43         return this;
44 }
45 public TypeBinding getTypeBinding(Scope scope) {
46         // it can be a package, type or member type
47         Binding binding = scope.parent.getTypeOrPackage(tokens); // step up from the ClassScope
48         if (!binding.isValidBinding()) {
49                 scope.problemReporter().invalidType(this, (TypeBinding) binding);
50                 throw new CompletionNodeFound();
51         }
52
53         throw new CompletionNodeFound(this, binding, scope);
54 }
55 public String toStringExpression(int tab) {
56
57         StringBuffer buffer = new StringBuffer();
58         buffer.append("<CompleteOnType:"); //$NON-NLS-1$
59         for (int i = 0; i < tokens.length; i++) {
60                 buffer.append(tokens[i]);
61                 buffer.append("."); //$NON-NLS-1$
62         }
63         buffer.append(completionIdentifier).append(">"); //$NON-NLS-1$
64         return buffer.toString();
65 }
66 }