135d5d7a00a8c480aab9f2d927cc631966504719
[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.QualifiedTypeReference;
28 import net.sourceforge.phpdt.internal.compiler.ast.TypeReference;
29 import net.sourceforge.phpdt.internal.compiler.lookup.Binding;
30 import net.sourceforge.phpdt.internal.compiler.lookup.Scope;
31 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
32
33 public class CompletionOnQualifiedTypeReference extends QualifiedTypeReference {
34         public char[] completionIdentifier;
35 public CompletionOnQualifiedTypeReference(char[][] previousIdentifiers, char[] completionIdentifier, long[] positions) {
36         super(previousIdentifiers, positions);
37         this.completionIdentifier = completionIdentifier;
38 }
39 public void aboutToResolve(Scope scope) {
40         getTypeBinding(scope);
41 }
42 /*
43  * No expansion of the completion reference into an array one
44  */
45 public TypeReference copyDims(int dim){
46         return this;
47 }
48 public TypeBinding getTypeBinding(Scope scope) {
49         // it can be a package, type or member type
50         Binding binding = scope.parent.getTypeOrPackage(tokens); // step up from the ClassScope
51         if (!binding.isValidBinding()) {
52                 scope.problemReporter().invalidType(this, (TypeBinding) binding);
53                 throw new CompletionNodeFound();
54         }
55
56         throw new CompletionNodeFound(this, binding, scope);
57 }
58 public String toStringExpression(int tab) {
59
60         StringBuffer buffer = new StringBuffer();
61         buffer.append("<CompleteOnType:"); //$NON-NLS-1$
62         for (int i = 0; i < tokens.length; i++) {
63                 buffer.append(tokens[i]);
64                 buffer.append("."); //$NON-NLS-1$
65         }
66         buffer.append(completionIdentifier).append(">"); //$NON-NLS-1$
67         return buffer.toString();
68 }
69 }