PHPLanguagePreferencePage.spanish and PHPEditorSyntaxPreferencePage.background added...
[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.*;
38 import net.sourceforge.phpdt.internal.compiler.lookup.*;
39
40 public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
41 public TypeBinding resolveType(BlockScope scope) {
42         TypeBinding typeBinding = null;
43         if (enclosingInstance != null) {
44                 TypeBinding enclosingType = enclosingInstance.resolveType(scope);
45                 if (!(enclosingType instanceof ReferenceBinding)) {
46                         scope.problemReporter().illegalPrimitiveOrArrayTypeForEnclosingInstance(enclosingType, enclosingInstance);
47                         throw new CompletionNodeFound();
48                 }
49                 typeBinding = ((SingleTypeReference) type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType);
50                 if (!(typeBinding instanceof ReferenceBinding))
51                         throw new CompletionNodeFound(); // no need to continue if its an array or base type
52                 if (typeBinding.isInterface()) // handle the anonymous class definition case
53                         typeBinding = scope.getJavaLangObject();
54         } else {
55                 typeBinding = type.resolveType(scope);
56                 if (!(typeBinding instanceof ReferenceBinding))
57                         throw new CompletionNodeFound(); // no need to continue if its an array or base type
58         }
59
60         throw new CompletionNodeFound(this, typeBinding, scope);
61 }
62 public String toStringExpression(int tab) {
63         return 
64                 ((this.enclosingInstance == null) ? 
65                         "<CompleteOnAllocationExpression:" :  //$NON-NLS-1$
66                         "<CompleteOnQualifiedAllocationExpression:") +  //$NON-NLS-1$
67                 super.toStringExpression(tab) + ">"; //$NON-NLS-1$
68 }
69 }