1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.codeassist.complete;
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
22 * new Bar(1, 2, [cursor]
28 * <CompleteOnAllocationExpression:new Bar(1, 2)>
32 * The source range is always of length 0.
33 * The arguments of the allocation expression are all the arguments defined
37 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedAllocationExpression;
38 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
39 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
40 import net.sourceforge.phpdt.internal.compiler.lookup.ReferenceBinding;
41 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
43 public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
44 public TypeBinding resolveType(BlockScope scope) {
45 TypeBinding typeBinding = null;
46 if (enclosingInstance != null) {
47 TypeBinding enclosingType = enclosingInstance.resolveType(scope);
48 if (!(enclosingType instanceof ReferenceBinding)) {
49 scope.problemReporter().illegalPrimitiveOrArrayTypeForEnclosingInstance(enclosingType, enclosingInstance);
50 throw new CompletionNodeFound();
52 typeBinding = ((SingleTypeReference) type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType);
53 if (!(typeBinding instanceof ReferenceBinding))
54 throw new CompletionNodeFound(); // no need to continue if its an array or base type
55 if (typeBinding.isInterface()) // handle the anonymous class definition case
56 typeBinding = scope.getJavaLangObject();
58 typeBinding = type.resolveType(scope);
59 if (!(typeBinding instanceof ReferenceBinding))
60 throw new CompletionNodeFound(); // no need to continue if its an array or base type
63 throw new CompletionNodeFound(this, typeBinding, scope);
65 public String toStringExpression(int tab) {
67 ((this.enclosingInstance == null) ?
68 "<CompleteOnAllocationExpression:" : //$NON-NLS-1$
69 "<CompleteOnQualifiedAllocationExpression:") + //$NON-NLS-1$
70 super.toStringExpression(tab) + ">"; //$NON-NLS-1$