KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > codeassist > complete > CompletionOnMessageSend


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.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 org.eclipse.jdt.internal.compiler.ast.*;
36 import org.eclipse.jdt.internal.compiler.lookup.*;
37
38 public class CompletionOnMessageSend extends MessageSend {
39
40     public TypeBinding resolveType(BlockScope scope) {
41         if (arguments != null) {
42             int argsLength = arguments.length;
43             for (int a = argsLength; --a >= 0;)
44                 arguments[a].resolveType(scope);
45         }
46         
47         if (receiver.isImplicitThis())
48             throw new CompletionNodeFound(this, null, scope);
49
50         this.actualReceiverType = receiver.resolveType(scope);
51         if (this.actualReceiverType == null || this.actualReceiverType.isBaseType())
52             throw new CompletionNodeFound();
53
54         if (this.actualReceiverType.isArrayType())
55             this.actualReceiverType = scope.getJavaLangObject();
56         throw new CompletionNodeFound(this, this.actualReceiverType, scope);
57     }
58
59     public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
60
61         output.append("<CompleteOnMessageSend:"); //$NON-NLS-1$
62
if (!receiver.isImplicitThis()) receiver.printExpression(0, output).append('.');
63         if (this.typeArguments != null) {
64             output.append('<');
65             int max = typeArguments.length - 1;
66             for (int j = 0; j < max; j++) {
67                 typeArguments[j].print(0, output);
68                 output.append(", ");//$NON-NLS-1$
69
}
70             typeArguments[max].print(0, output);
71             output.append('>');
72         }
73         output.append(selector).append('(');
74         if (arguments != null) {
75             for (int i = 0; i < arguments.length; i++) {
76                 if (i > 0) output.append(", "); //$NON-NLS-1$
77
arguments[i].printExpression(0, output);
78             }
79         }
80         return output.append(")>"); //$NON-NLS-1$
81
}
82 }
83
Popular Tags