0882c74953dc213dcddc3aae607d9f1c1a6e7fa5
[phpeclipse.git] /
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 message send containing the cursor.
16  * e.g.
17  *
18  *      class X {
19  *    void foo() {
20  *      this.bar(1, 2, [cursor]
21  *    }
22  *  }
23  *
24  *      ---> class X {
25  *         void foo() {
26  *           <CompleteOnMessageSend:this.bar(1, 2)>
27  *         }
28  *       }
29  *
30  * The source range is always of length 0.
31  * The arguments of the message send 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 CompletionOnMessageSend extends MessageSend {
39
40         public TypeBinding resolveType(BlockScope scope) {
41                 if (receiver == ThisReference.ThisImplicit)
42                         throw new CompletionNodeFound(this, null, scope);
43
44                 TypeBinding receiverType = receiver.resolveType(scope);
45                 if (receiverType == null || receiverType.isBaseType())
46                         throw new CompletionNodeFound();
47
48                 if (receiverType.isArrayType())
49                         receiverType = scope.getJavaLangObject();
50                 throw new CompletionNodeFound(this, receiverType, scope);
51         }
52
53         public String toStringExpression() {
54
55                 String s = "<CompleteOnMessageSend:"; //$NON-NLS-1$
56                 if (receiver != ThisReference.ThisImplicit)
57                         s = s + receiver.toStringExpression() + "."; //$NON-NLS-1$
58                 s = s + new String(selector) + "("; //$NON-NLS-1$
59                 if (arguments != null) {
60                         for (int i = 0; i < arguments.length; i++) {
61                                 s += arguments[i].toStringExpression();
62                                 if (i != arguments.length - 1) {
63                                         s += ", "; //$NON-NLS-1$
64                                 }
65                         };
66                 }
67                 s = s + ")>"; //$NON-NLS-1$
68                 return s;
69         }
70 }