Test & fix for Bug 330169 -  [refactoring] Extract method throws NPE if declared lifting arg is involved
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 8b3800b..24b2ec1 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
@@ -14,6 +14,7 @@
 package org.eclipse.jdt.core.dom;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.eclipse.jdt.core.WorkingCopyOwner;
@@ -1840,6 +1841,28 @@
 			if (key != null) {
 				this.bindingTables.bindingKeysToBindings.put(key, variableBinding);
 			}
+//{ObjectTeams: arg w/ declared lifting needs to be registered twice (outside / inside):
+			if (abstractVariableDeclaration.type instanceof LiftingTypeReference) {
+				AST ast = variable.ast;
+				SingleVariableDeclaration realVariable = (SingleVariableDeclaration)variable;
+				LocalDeclaration fakedArgument = ((LiftingTypeReference)abstractVariableDeclaration.type).fakedArgument;
+				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);
+			}
+// SH}
 			return variableBinding;
 		}
 		return null;
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java
index 7703fb6..31e51d9 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java
@@ -17,6 +17,7 @@
 import org.eclipse.jdt.core.util.IModifierConstants;
 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.Initializer;
+import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
 import org.eclipse.jdt.internal.compiler.impl.Constant;
@@ -29,6 +30,7 @@
 import org.eclipse.jdt.internal.core.JavaElement;
 import org.eclipse.jdt.internal.core.LocalVariable;
 import org.eclipse.jdt.internal.core.util.Util;
+import org.eclipse.objectteams.otdt.internal.core.compiler.ast.LiftingTypeReference;
 import org.eclipse.objectteams.otdt.internal.core.compiler.model.FieldModel;
 
 /**
@@ -351,6 +353,18 @@
 		return this.binding.id;
 	}
 
+//{ObjectTeams: arg w/ declared lifting has two ids, answer the max of both:
+	public int getVariableIdMax() {
+		if (!isField()) {
+			LocalDeclaration decl = ((LocalVariableBinding)this.binding).declaration;
+			if (decl != null && decl.type instanceof LiftingTypeReference) {
+				return ((LiftingTypeReference)decl.type).fakedArgument.binding.id;
+			}
+		}
+		return getVariableId(); 
+	}
+// SH}
+
 	/*
 	 * @see IVariableBinding#isParameter()
 	 */