KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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 import org.eclipse.jdt.internal.compiler.ast.MessageSend;
14 import org.eclipse.jdt.internal.compiler.ast.NameReference;
15 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
16 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
17
18 public class CompletionOnMessageSendName extends MessageSend {
19     public CompletionOnMessageSendName(char[] selector, int start, int end) {
20         super();
21         this.selector = selector;
22         this.sourceStart = start;
23         this.sourceEnd = end;
24         this.nameSourcePosition = end;
25     }
26
27     public TypeBinding resolveType(BlockScope scope) {
28         
29         if (receiver.isImplicitThis())
30             throw new CompletionNodeFound();
31
32         this.actualReceiverType = receiver.resolveType(scope);
33         if (this.actualReceiverType == null || this.actualReceiverType.isBaseType() || this.actualReceiverType.isArrayType())
34             throw new CompletionNodeFound();
35         
36         // resolve type arguments
37
if (this.typeArguments != null) {
38             int length = this.typeArguments.length;
39             this.genericTypeArguments = new TypeBinding[length];
40             for (int i = 0; i < length; i++) {
41                 this.genericTypeArguments[i] = this.typeArguments[i].resolveType(scope, true /* check bounds*/);
42             }
43         }
44     
45         if(this.receiver instanceof NameReference) {
46             throw new CompletionNodeFound(this, ((NameReference)this.receiver).binding, scope);
47         } else if(this.receiver instanceof MessageSend) {
48             throw new CompletionNodeFound(this, ((MessageSend)this.receiver).binding, scope);
49         }
50         throw new CompletionNodeFound(this, this.actualReceiverType, scope);
51     }
52     
53     public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
54
55         output.append("<CompleteOnMessageSendName:"); //$NON-NLS-1$
56
if (!receiver.isImplicitThis()) receiver.printExpression(0, output).append('.');
57         if (this.typeArguments != null) {
58             output.append('<');
59             int max = typeArguments.length - 1;
60             for (int j = 0; j < max; j++) {
61                 typeArguments[j].print(0, output);
62                 output.append(", ");//$NON-NLS-1$
63
}
64             typeArguments[max].print(0, output);
65             output.append('>');
66         }
67         output.append(selector).append('(');
68         return output.append(")>"); //$NON-NLS-1$
69
}
70 }
71
Popular Tags