01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.codeassist.complete;
11:
12: /*
13: * Completion node build by the parser in any case it was intending to
14: * reduce a explicit constructor call containing the cursor.
15: * e.g.
16: *
17: * class X {
18: * X() {
19: * this(1, 2, [cursor]
20: * }
21: * }
22: *
23: * ---> class X {
24: * X() {
25: * <CompleteOnExplicitConstructorCall:this(1, 2)>
26: * }
27: * }
28: *
29: * The source range is always of length 0.
30: * The arguments of the constructor call are all the arguments defined
31: * before the cursor.
32: */
33:
34: import org.eclipse.jdt.internal.compiler.ast.*;
35: import org.eclipse.jdt.internal.compiler.lookup.*;
36:
37: public class CompletionOnExplicitConstructorCall extends
38: ExplicitConstructorCall {
39:
40: public CompletionOnExplicitConstructorCall(int accessMode) {
41: super (accessMode);
42: }
43:
44: public StringBuffer printStatement(int tab, StringBuffer output) {
45:
46: printIndent(tab, output);
47: output.append("<CompleteOnExplicitConstructorCall:"); //$NON-NLS-1$
48: if (this .qualification != null)
49: this .qualification.printExpression(0, output).append('.');
50: if (this .accessMode == This) {
51: output.append("this("); //$NON-NLS-1$
52: } else {
53: output.append("super("); //$NON-NLS-1$
54: }
55: if (this .arguments != null) {
56: for (int i = 0; i < this .arguments.length; i++) {
57: if (i > 0)
58: output.append(", "); //$NON-NLS-1$
59: this .arguments[i].printExpression(0, output);
60: }
61: }
62: return output.append(")>;"); //$NON-NLS-1$
63: }
64:
65: public void resolve(BlockScope scope) {
66:
67: ReferenceBinding receiverType = scope.enclosingSourceType();
68:
69: if (this .arguments != null) {
70: int argsLength = this .arguments.length;
71: for (int a = argsLength; --a >= 0;)
72: this .arguments[a].resolveType(scope);
73: }
74:
75: if (this .accessMode != This && receiverType != null) {
76: if (receiverType.isHierarchyInconsistent())
77: throw new CompletionNodeFound();
78: receiverType = receiverType.super class();
79: }
80: if (receiverType == null)
81: throw new CompletionNodeFound();
82: else
83: throw new CompletionNodeFound(this, receiverType, scope);
84: }
85: }
|