JDT codeassist module, nothing changed yet
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / codeassist / select / SelectionOnQualifiedAllocationExpression.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/codeassist/select/SelectionOnQualifiedAllocationExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/codeassist/select/SelectionOnQualifiedAllocationExpression.java
new file mode 100644 (file)
index 0000000..d679001
--- /dev/null
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Common Public License v0.5 
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ ******************************************************************************/
+package net.sourceforge.phpdt.internal.codeassist.select;
+
+/*
+ * Selection node build by the parser in any case it was intending to
+ * reduce an allocation expression containing the cursor.
+ * If the allocation expression is not qualified, the enclosingInstance field
+ * is null.
+ * e.g.
+ *
+ *     class X {
+ *    void foo() {
+ *      new [start]Bar[end](1, 2)
+ *    }
+ *  }
+ *
+ *     ---> class X {
+ *         void foo() {
+ *           <SelectOnAllocationExpression:new Bar(1, 2)>
+ *         }
+ *       }
+ *
+ */
+
+import net.sourceforge.phpdt.internal.compiler.ast.AnonymousLocalTypeDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.ConstructorDeclaration;
+import net.sourceforge.phpdt.internal.compiler.ast.QualifiedAllocationExpression;
+import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
+import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons;
+import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
+public class SelectionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
+public SelectionOnQualifiedAllocationExpression() {
+}
+public SelectionOnQualifiedAllocationExpression(AnonymousLocalTypeDeclaration anonymous) {
+       anonymousType = anonymous ;
+}
+public TypeBinding resolveType(BlockScope scope) {
+       super.resolveType(scope);
+
+       // tolerate some error cases
+       if (binding == null || 
+                       !(binding.isValidBinding() || 
+                               binding.problemId() == ProblemReasons.NotVisible))
+               throw new SelectionNodeFound();
+       if (anonymousType == null)
+               throw new SelectionNodeFound(binding);
+
+       // if selecting a type for an anonymous type creation, we have to
+       // find its target super constructor (if extending a class) or its target 
+       // super interface (if extending an interface)
+       if (anonymousType.binding.superInterfaces == NoSuperInterfaces) {
+               // find the constructor binding inside the super constructor call
+               ConstructorDeclaration constructor = (ConstructorDeclaration) anonymousType.declarationOf(binding);
+               throw new SelectionNodeFound(constructor.constructorCall.binding);
+       } else {
+               // open on the only superinterface
+               throw new SelectionNodeFound(anonymousType.binding.superInterfaces[0]);
+       }
+}
+public String toStringExpression(int tab) {
+       return 
+               ((this.enclosingInstance == null) ? 
+                       "<SelectOnAllocationExpression:" :  //$NON-NLS-1$
+                       "<SelectOnQualifiedAllocationExpression:") +  //$NON-NLS-1$
+               super.toStringExpression(tab) + ">"; //$NON-NLS-1$
+}
+}