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.select;
14 * Selection 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 [start]Bar[end](1, 2)
28 * <SelectOnAllocationExpression:new Bar(1, 2)>
34 import net.sourceforge.phpdt.internal.compiler.ast.AnonymousLocalTypeDeclaration;
35 import net.sourceforge.phpdt.internal.compiler.ast.ConstructorDeclaration;
36 import net.sourceforge.phpdt.internal.compiler.ast.QualifiedAllocationExpression;
37 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
38 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
39 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
41 public class SelectionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
42 public SelectionOnQualifiedAllocationExpression() {
44 public SelectionOnQualifiedAllocationExpression(AnonymousLocalTypeDeclaration anonymous) {
45 anonymousType = anonymous ;
47 public TypeBinding resolveType(BlockScope scope) {
48 super.resolveType(scope);
50 // tolerate some error cases
51 if (binding == null ||
52 !(binding.isValidBinding() ||
53 binding.problemId() == ProblemReasons.NotVisible))
54 throw new SelectionNodeFound();
55 if (anonymousType == null)
56 throw new SelectionNodeFound(binding);
58 // if selecting a type for an anonymous type creation, we have to
59 // find its target super constructor (if extending a class) or its target
60 // super interface (if extending an interface)
61 if (anonymousType.binding.superInterfaces == NoSuperInterfaces) {
62 // find the constructor binding inside the super constructor call
63 ConstructorDeclaration constructor = (ConstructorDeclaration) anonymousType.declarationOf(binding);
64 throw new SelectionNodeFound(constructor.constructorCall.binding);
66 // open on the only superinterface
67 throw new SelectionNodeFound(anonymousType.binding.superInterfaces[0]);
70 public String toStringExpression(int tab) {
72 ((this.enclosingInstance == null) ?
73 "<SelectOnAllocationExpression:" : //$NON-NLS-1$
74 "<SelectOnQualifiedAllocationExpression:") + //$NON-NLS-1$
75 super.toStringExpression(tab) + ">"; //$NON-NLS-1$