3edfcc6a3ae9c06ea5f1e3c3c5d1a24085c230a8
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / complete / CompletionOnExplicitConstructorCall.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 explicit constructor call containing the cursor.
16  * e.g.
17  *
18  *      class X {
19  *    X() {
20  *      this(1, 2, [cursor]
21  *    }
22  *  }
23  *
24  *      ---> class X {
25  *         X() {
26  *           <CompleteOnExplicitConstructorCall:this(1, 2)>
27  *         }
28  *       }
29  *
30  * The source range is always of length 0.
31  * The arguments of the constructor call are all the arguments defined
32  * before the cursor.
33  */
34
35 import net.sourceforge.phpdt.internal.compiler.ast.ExplicitConstructorCall;
36 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
37 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
38
39 public class CompletionOnExplicitConstructorCall extends ExplicitConstructorCall {
40 public CompletionOnExplicitConstructorCall(int accessMode) {
41         super(accessMode);
42 }
43 public void resolve(BlockScope scope) {
44         ReferenceBinding receiverType = scope.enclosingSourceType();
45
46         if (accessMode != This && receiverType != null) {
47                 if (receiverType.isHierarchyInconsistent())
48                         throw new CompletionNodeFound();
49                 receiverType = receiverType.superclass();
50         }
51         if (receiverType == null)
52                 throw new CompletionNodeFound();
53         else
54                 throw new CompletionNodeFound(this, receiverType, scope);
55 }
56 public String toString(int tab) {
57         String s = tabString(tab);
58         s += "<CompleteOnExplicitConstructorCall:"; //$NON-NLS-1$
59         if (qualification != null)
60                 s = s + qualification.toStringExpression() + "."; //$NON-NLS-1$
61         if (accessMode == This) {
62                 s = s + "this("; //$NON-NLS-1$
63         } else {
64                 s = s + "super("; //$NON-NLS-1$
65         }
66         if (arguments != null) {
67                 for (int i = 0; i < arguments.length; i++) {
68                         s += arguments[i].toStringExpression();
69                         if (i != arguments.length - 1) {
70                                 s += ", "; //$NON-NLS-1$
71                         }
72                 };
73         }
74         s += ")>"; //$NON-NLS-1$
75         return s;
76 }
77 }