KickJava   Java API By Example, From Geeks To Geeks.

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


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 an access to a member (field reference or message send)
16  * containing the completion identifier.
17  * e.g.
18  *
19  * class X {
20  * void foo() {
21  * bar().fred[cursor]
22  * }
23  * }
24  *
25  * ---> class X {
26  * void foo() {
27  * <CompleteOnMemberAccess:bar().fred>
28  * }
29  * }
30  *
31  * The source range of the completion node denotes the source range
32  * which should be replaced by the completion.
33  */

34
35 import org.eclipse.jdt.internal.compiler.ast.*;
36 import org.eclipse.jdt.internal.compiler.lookup.*;
37
38 public class CompletionOnMemberAccess extends FieldReference {
39     
40     public boolean isInsideAnnotation;
41     
42     public CompletionOnMemberAccess(char[] source, long pos, boolean isInsideAnnotation) {
43         
44         super(source, pos);
45         this.isInsideAnnotation = isInsideAnnotation;
46     }
47     
48     public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
49
50         output.append("<CompleteOnMemberAccess:"); //$NON-NLS-1$
51
return super.printExpression(0, output).append('>');
52     }
53
54     public TypeBinding resolveType(BlockScope scope) {
55         
56         this.receiverType = receiver.resolveType(scope);
57         
58         if (this.receiverType == null && receiver instanceof MessageSend) {
59             MessageSend messageSend = (MessageSend) receiver;
60             if(messageSend.receiver instanceof ThisReference) {
61                 Expression[] arguments = messageSend.arguments;
62                 int length = arguments == null ? 0 : arguments.length;
63                 TypeBinding[] argBindings = new TypeBinding[length];
64                 for (int i = 0; i < length; i++) {
65                     argBindings[i] = arguments[i].resolvedType;
66                     if(argBindings[i] == null || !argBindings[i].isValidBinding()) {
67                         throw new CompletionNodeFound();
68                     }
69                 }
70                     
71                 ProblemMethodBinding problemMethodBinding = new ProblemMethodBinding(messageSend.selector, argBindings, ProblemReasons.NotFound);
72                 throw new CompletionNodeFound(this, problemMethodBinding, scope);
73             }
74         }
75         
76         if (this.receiverType == null || this.receiverType.isBaseType())
77             throw new CompletionNodeFound();
78         else
79             throw new CompletionNodeFound(this, this.receiverType, scope);
80         // array types are passed along to find the length field
81
}
82 }
83
Popular Tags