KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 org.eclipse.jdt.internal.compiler.ast.*;
36 import org.eclipse.jdt.internal.compiler.lookup.*;
37
38 public class CompletionOnExplicitConstructorCall extends ExplicitConstructorCall {
39
40     public CompletionOnExplicitConstructorCall(int accessMode) {
41         super(accessMode);
42     }
43     
44     public StringBuffer JavaDoc printStatement(int tab, StringBuffer JavaDoc output) {
45         
46         printIndent(tab, output);
47         output.append("<CompleteOnExplicitConstructorCall:"); //$NON-NLS-1$
48
if (this.qualification != null) this.qualification.printExpression(0, output).append('.');
49         if (this.accessMode == This) {
50             output.append("this("); //$NON-NLS-1$
51
} else {
52             output.append("super("); //$NON-NLS-1$
53
}
54         if (this.arguments != null) {
55             for (int i = 0; i < this.arguments.length; i++) {
56                 if (i > 0) output.append(", "); //$NON-NLS-1$
57
this.arguments[i].printExpression(0, output);
58             }
59         }
60         return output.append(")>;"); //$NON-NLS-1$
61
}
62
63     public void resolve(BlockScope scope) {
64
65         ReferenceBinding receiverType = scope.enclosingSourceType();
66         
67         if (this.arguments != null) {
68             int argsLength = this.arguments.length;
69             for (int a = argsLength; --a >= 0;)
70                 this.arguments[a].resolveType(scope);
71         }
72     
73         if (this.accessMode != This && receiverType != null) {
74             if (receiverType.isHierarchyInconsistent())
75                 throw new CompletionNodeFound();
76             receiverType = receiverType.superclass();
77         }
78         if (receiverType == null)
79             throw new CompletionNodeFound();
80         else
81             throw new CompletionNodeFound(this, receiverType, scope);
82     }
83 }
84
Popular Tags