Test & fix for Bug 339823 - [select] base constructor invocation is not selectable
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
index 9897c3b..b4cdbbe 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java
@@ -44,6 +44,8 @@
import org.eclipse.objectteams.otdt.internal.codeassist.SelectionOnParameterMapping;
import org.eclipse.objectteams.otdt.internal.codeassist.SelectionOnTSuperMessageSend;
import org.eclipse.objectteams.otdt.internal.codeassist.SelectionOnTSuperReference;
+import org.eclipse.objectteams.otdt.internal.codeassist.select.SelectionOnBaseAllocationExpression;
+import org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseAllocationExpression;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseCallMessageSend;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.CallinMappingDeclaration;
import org.eclipse.objectteams.otdt.internal.core.compiler.ast.FieldAccessSpec;
@@ -1524,6 +1526,10 @@
return baseCall;
}
@Override
+ protected BaseAllocationExpression newBaseAllocationExpression(int start, int end) {
+ return new SelectionOnBaseAllocationExpression(start, end);
+ }
+ @Override
protected void consumeCallinLabel() {
int assistIdentifierPtr = indexOfAssistIdentifier();
super.consumeCallinLabel();
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/objectteams/otdt/internal/codeassist/select/SelectionOnBaseAllocationExpression.java b/org.eclipse.jdt.core/codeassist/org/eclipse/objectteams/otdt/internal/codeassist/select/SelectionOnBaseAllocationExpression.java
new file mode 100644
index 0000000..6e5083e
--- /dev/null
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/objectteams/otdt/internal/codeassist/select/SelectionOnBaseAllocationExpression.java
@@ -0,0 +1,45 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2011 GK Software AG
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Stephan Herrmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.codeassist.select;
+
+import org.eclipse.jdt.internal.codeassist.select.SelectionNodeFound;
+import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
+import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
+import org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseAllocationExpression;
+
+/**
+ * For code select, a base allocation expression should be mapped to the corresponding
+ * base constructor, which is found via this.expression (an AllocationExpression).
+ *
+ * @author stephan
+ * @since 0.8 (from eclipse.org).
+ */
+public class SelectionOnBaseAllocationExpression extends BaseAllocationExpression {
+
+ public SelectionOnBaseAllocationExpression(int start, int end) {
+ super(start, end);
+ }
+
+ @Override
+ public TypeBinding resolveType(BlockScope scope) {
+ super.resolveType(scope);
+ if (this.expression instanceof AllocationExpression)
+ throw new SelectionNodeFound(((AllocationExpression)this.expression).binding);
+ else
+ throw new SelectionNodeFound(); // see super method on how we can get here.
+ }
+}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index fdbb165..a4822e3 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -4588,7 +4588,7 @@
int end = this.intStack[this.intPtr--];
// code basically taken from classInstanceCreation:
- BaseAllocationExpression alloc = new BaseAllocationExpression(start, end);
+ BaseAllocationExpression alloc = newBaseAllocationExpression(start, end);
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
@@ -4619,6 +4619,9 @@
pushOnExpressionStack(alloc);
}
+protected BaseAllocationExpression newBaseAllocationExpression(int start, int end) {
+ return new BaseAllocationExpression(start, end);
+}
// SH}
protected void consumeExpressionStatement() {