deleted: export="true"
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / select / SelectionOnQualifiedAllocationExpression.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.codeassist.select;
12
13 /*
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
17  * is null.
18  * e.g.
19  *
20  *      class X {
21  *    void foo() {
22  *      new [start]Bar[end](1, 2)
23  *    }
24  *  }
25  *
26  *      ---> class X {
27  *         void foo() {
28  *           <SelectOnAllocationExpression:new Bar(1, 2)>
29  *         }
30  *       }
31  *
32  */
33
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;
40  
41 public class SelectionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
42 public SelectionOnQualifiedAllocationExpression() {
43 }
44 public SelectionOnQualifiedAllocationExpression(AnonymousLocalTypeDeclaration anonymous) {
45         anonymousType = anonymous ;
46 }
47 public TypeBinding resolveType(BlockScope scope) {
48         super.resolveType(scope);
49
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);
57
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);
65         } else {
66                 // open on the only superinterface
67                 throw new SelectionNodeFound(anonymousType.binding.superInterfaces[0]);
68         }
69 }
70 public String toStringExpression(int tab) {
71         return 
72                 ((this.enclosingInstance == null) ? 
73                         "<SelectOnAllocationExpression:" :  //$NON-NLS-1$
74                         "<SelectOnQualifiedAllocationExpression:") +  //$NON-NLS-1$
75                 super.toStringExpression(tab) + ">"; //$NON-NLS-1$
76 }
77 }