Temporarily replace new Project Wizard until errors in old one investigated..
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / complete / CompletionOnQualifiedAllocationExpression.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.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 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;
42
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();
51                 }
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();
57         } else {
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
61         }
62
63         throw new CompletionNodeFound(this, typeBinding, scope);
64 }
65 public String toStringExpression(int tab) {
66         return 
67                 ((this.enclosingInstance == null) ? 
68                         "<CompleteOnAllocationExpression:" :  //$NON-NLS-1$
69                         "<CompleteOnQualifiedAllocationExpression:") +  //$NON-NLS-1$
70                 super.toStringExpression(tab) + ">"; //$NON-NLS-1$
71 }
72 }