KickJava   Java API By Example, From Geeks To Geeks.

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


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 allocation expression containing the cursor.
16  * If the allocation expression is not qualified, the enclosingInstance field
17  * is null.
18  * e.g.
19  *
20  * class X {
21  * void foo() {
22  * new Bar(1, 2, [cursor]
23  * }
24  * }
25  *
26  * ---> class X {
27  * void foo() {
28  * <CompleteOnAllocationExpression:new Bar(1, 2)>
29  * }
30  * }
31  *
32  * The source range is always of length 0.
33  * The arguments of the allocation expression are all the arguments defined
34  * before the cursor.
35  */

36
37 import org.eclipse.jdt.internal.compiler.ast.*;
38 import org.eclipse.jdt.internal.compiler.lookup.*;
39
40 public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
41 public TypeBinding resolveType(BlockScope scope) {
42     if (arguments != null) {
43         int argsLength = arguments.length;
44         for (int a = argsLength; --a >= 0;)
45             arguments[a].resolveType(scope);
46     }
47     
48     if (enclosingInstance != null) {
49         TypeBinding enclosingType = enclosingInstance.resolveType(scope);
50         if (enclosingType == null || !(enclosingType instanceof ReferenceBinding)) {
51             throw new CompletionNodeFound();
52         }
53         this.resolvedType = ((SingleTypeReference) type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType);
54         if (!(this.resolvedType instanceof ReferenceBinding))
55             throw new CompletionNodeFound(); // no need to continue if its an array or base type
56
if (this.resolvedType.isInterface()) // handle the anonymous class definition case
57
this.resolvedType = scope.getJavaLangObject();
58     } else {
59         this.resolvedType = type.resolveType(scope, true /* check bounds*/);
60         if (!(this.resolvedType instanceof ReferenceBinding))
61             throw new CompletionNodeFound(); // no need to continue if its an array or base type
62
}
63
64     throw new CompletionNodeFound(this, this.resolvedType, scope);
65 }
66 public StringBuffer JavaDoc printExpression(int indent, StringBuffer JavaDoc output) {
67     if (this.enclosingInstance == null)
68         output.append("<CompleteOnAllocationExpression:" ); //$NON-NLS-1$
69
else
70         output.append("<CompleteOnQualifiedAllocationExpression:"); //$NON-NLS-1$
71
return super.printExpression(indent, output).append('>');
72 }
73 }
74
Popular Tags