Fix regression in org.eclipse.objectteams.otdt.ui.tests.refactoring.extractmethod.ExtractMethodTests.testDeclaredLifting1():
Even the faked variable declaration must have a non-null parent.
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java
index c8bef90..232ad1f 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java
@@ -1969,7 +1969,12 @@
* @see #getParent
* @since 3.0
*/
+//{ObjectTeams: make overridable:
+/* orig:
final void setParent(ASTNode parent, StructuralPropertyDescriptor property) {
+ :giro */
+ void setParent(ASTNode parent, StructuralPropertyDescriptor property) {
+// SH}
this.ast.modifying();
this.parent = parent;
this.location = property;
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java
index 73a5c89..9d64111 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java
@@ -15,7 +15,6 @@
package org.eclipse.jdt.core.dom;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.eclipse.jdt.core.WorkingCopyOwner;
@@ -1884,21 +1883,15 @@
SingleVariableDeclaration realVariable = (SingleVariableDeclaration)variable;
LocalDeclaration fakedArgument = ((LiftingTypeReference)abstractVariableDeclaration.type).fakedArgument;
if (fakedArgument != null) {
- IVariableBinding fakedBinding = getVariableBinding(fakedArgument.binding, variable);
-
// fake the internal local with role type, while avoiding the internal variable name (_OT$<arg>)
- SingleVariableDeclaration fakedVariable = ast.newSingleVariableDeclaration();
- fakedVariable.setName((SimpleName) variable.getName().clone(ast));
- Type roleType = ((LiftingType)realVariable.getType()).getRoleType();
- fakedVariable.setType((Type) roleType.clone(ast));
- List modifiers = realVariable.modifiers();
- for(Object mod : modifiers)
- fakedVariable.modifiers().add(((Modifier)mod).clone(ast));
-
- this.bindingsToAstNodes.put(fakedBinding, fakedVariable);
- key = fakedBinding.getKey();
- if (key != null)
- this.bindingTables.bindingKeysToBindings.put(key, fakedBinding);
+ SingleVariableDeclaration fakedVariable = realVariable.newFakedRoleVariable((LiftingType) realVariable.getType());
+ if (fakedVariable != null) { // else a faked variable has already been registered
+ IVariableBinding fakedBinding = getVariableBinding(fakedArgument.binding, variable);
+ this.bindingsToAstNodes.put(fakedBinding, fakedVariable);
+ key = fakedBinding.getKey();
+ if (key != null)
+ this.bindingTables.bindingKeysToBindings.put(key, fakedBinding);
+ }
}
}
// SH}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java
index 1a7a888..b135359 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/SingleVariableDeclaration.java
@@ -191,6 +191,32 @@
*/
private Expression optionalInitializer = null;
+//{ObjectTeams: emulation for declared lifting:
+ private SingleVariableDeclaration fakedRoleVariable;
+ public static final ChildPropertyDescriptor FAKED_ROLE_VARIABLE =
+ new ChildPropertyDescriptor(SingleVariableDeclaration.class, "fakedRoleVariable", SingleVariableDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
+
+ @SuppressWarnings("unchecked")
+ SingleVariableDeclaration newFakedRoleVariable(LiftingType liftingType) {
+ if (this.fakedRoleVariable != null)
+ return null;
+ this.fakedRoleVariable = this.ast.newSingleVariableDeclaration();
+ this.fakedRoleVariable.setName((SimpleName) getName().clone(this.ast));
+ Type roleType = liftingType.getRoleType();
+ this.fakedRoleVariable.setType((Type) roleType.clone(this.ast));
+ for(Object mod : this.modifiers)
+ this.fakedRoleVariable.modifiers().add(((Modifier)mod).clone(this.ast));
+ return this.fakedRoleVariable;
+ }
+ @Override
+ void setParent(ASTNode parent, StructuralPropertyDescriptor property) {
+ // we might have one more node that needs a parent:
+ super.setParent(parent, property);
+ if (this.fakedRoleVariable != null)
+ this.fakedRoleVariable.setParent(this, FAKED_ROLE_VARIABLE);
+ }
+// SH}
+
/**
* Creates a new AST node for a variable declaration owned by the given
* AST. By default, the variable declaration has: no modifiers, an