50d998e00a95dcc438812967d9ba023434f9edcc
[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.*;
36 import net.sourceforge.phpdt.internal.compiler.lookup.*;
37
38 public class CompletionOnExplicitConstructorCall extends ExplicitConstructorCall {
39 public CompletionOnExplicitConstructorCall(int accessMode) {
40         super(accessMode);
41 }
42 public void resolve(BlockScope scope) {
43         ReferenceBinding receiverType = scope.enclosingSourceType();
44
45         if (accessMode != This && receiverType != null) {
46                 if (receiverType.isHierarchyInconsistent())
47                         throw new CompletionNodeFound();
48                 receiverType = receiverType.superclass();
49         }
50         if (receiverType == null)
51                 throw new CompletionNodeFound();
52         else
53                 throw new CompletionNodeFound(this, receiverType, scope);
54 }
55 public String toString(int tab) {
56         String s = tabString(tab);
57         s += "<CompleteOnExplicitConstructorCall:"; //$NON-NLS-1$
58         if (qualification != null)
59                 s = s + qualification.toStringExpression() + "."; //$NON-NLS-1$
60         if (accessMode == This) {
61                 s = s + "this("; //$NON-NLS-1$
62         } else {
63                 s = s + "super("; //$NON-NLS-1$
64         }
65         if (arguments != null) {
66                 for (int i = 0; i < arguments.length; i++) {
67                         s += arguments[i].toStringExpression();
68                         if (i != arguments.length - 1) {
69                                 s += ", "; //$NON-NLS-1$
70                         }
71                 };
72         }
73         s += ")>"; //$NON-NLS-1$
74         return s;
75 }
76 }