Bug 386587 - [refactoring] pull-up refactoring cannot handle callout
bindings
- support creation of new callout bindings
- support removal of callout declarations
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IMethodNode.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IMethodNode.java
new file mode 100644
index 0000000..1fa760e
--- /dev/null
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/IMethodNode.java
@@ -0,0 +1,29 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2012 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.jdt.core.dom;
+
+import java.util.List;
+
+/**
+ * Generalization over MethodDeclaration and MethodSpec
+ * @since 3.9
+ */
+public interface IMethodNode {
+	List parameters();
+	List typeParameters();
+	Type getReturnType2();
+	void setReturnType2(Type type);
+}
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java
index 2c602db..1548d20 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodDeclaration.java
@@ -66,7 +66,11 @@
  * @since 2.0
  * @noinstantiate This class is not intended to be instantiated by clients.
  */
-public class MethodDeclaration extends BodyDeclaration {
+public class MethodDeclaration extends BodyDeclaration
+//{ObjectTeams: allow generalization with MethodSpec:
+								implements IMethodNode
+// SH}
+{
 
 	/**
 	 * The "javadoc" structural property of this node type (child type: {@link Javadoc}).
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodSpec.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodSpec.java
index 5d55907..1137ae9 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodSpec.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodSpec.java
@@ -41,7 +41,7 @@
  *
  * @author jsv
  */
-public class MethodSpec extends MethodMappingElement
+public class MethodSpec extends MethodMappingElement implements IMethodNode
 {
 	/**
 	 * The "signature" structural property of this node type.
diff --git a/org.eclipse.jdt.core/scripts/.gitignore b/org.eclipse.jdt.core/scripts/.gitignore
new file mode 100644
index 0000000..26c9132
--- /dev/null
+++ b/org.eclipse.jdt.core/scripts/.gitignore
@@ -0,0 +1,2 @@
+/backup
+/output
diff --git a/plugins/org.eclipse.objectteams.otdt.refactoring/plugin.xml b/plugins/org.eclipse.objectteams.otdt.refactoring/plugin.xml
index 82b1d21..f553c90 100644
--- a/plugins/org.eclipse.objectteams.otdt.refactoring/plugin.xml
+++ b/plugins/org.eclipse.objectteams.otdt.refactoring/plugin.xml
@@ -39,6 +39,11 @@
                icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
          </team>
          <team
+               activation="NONE"
+               class="org.eclipse.objectteams.otdt.internal.refactoring.adaptor.pullup.PullUpAdaptor.PullUpRefactoringProcessorRole"
+               icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
+         </team>
+         <team
                activation="ALL_THREADS"
                class="org.eclipse.objectteams.otdt.internal.refactoring.adaptor.RenameTypeAdaptor"
                icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
diff --git a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/pullup/ChangeManagerDetails.java b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/pullup/ChangeManagerDetails.java
new file mode 100644
index 0000000..646cc60
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/pullup/ChangeManagerDetails.java
@@ -0,0 +1,58 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2012 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.refactoring.adaptor.pullup;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;
+import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext;
+import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;
+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
+import org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment;
+import org.eclipse.jdt.internal.corext.refactoring.structure.TypeVariableMaplet;
+import org.eclipse.jdt.internal.corext.refactoring.structure.TypeVariableUtil;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * Data class to mediate data flows between callins in team PullUpAdaptor.
+ */
+@SuppressWarnings("restriction")
+class ChangeManagerDetails {
+
+	RefactoringStatus status;
+	CompilationUnitRewrite rewrite;
+	AbstractTypeDeclaration declaration;
+	ImportRewriteContext context;
+	CompilationUnitRewrite sourceRewrite;
+	TypeVariableMaplet[] mapping;
+	Map<IMember, IncomingMemberVisibilityAdjustment> adjustments;
+	IProgressMonitor monitor;
+
+	public ChangeManagerDetails(CompilationUnitRewrite sourceRewrite, CompilationUnitRewrite rewrite, IType declaringType, IType destinationType, RefactoringStatus status, IProgressMonitor monitor) throws JavaModelException {
+		this.rewrite = rewrite;
+		this.sourceRewrite = sourceRewrite;
+		this.declaration = ASTNodeSearchUtil.getAbstractTypeDeclarationNode(destinationType, rewrite.getRoot());
+		this.context= new ContextSensitiveImportRewriteContext(declaration, rewrite.getImportRewrite());
+		this.mapping= TypeVariableUtil.subTypeToSuperType(declaringType, destinationType);
+		this.status = status;
+		this.monitor = monitor;
+	}
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/pullup/PullUpAdaptor.java b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/pullup/PullUpAdaptor.java
index a12cff2..f9ce0d2 100644
--- a/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/pullup/PullUpAdaptor.java
+++ b/plugins/org.eclipse.objectteams.otdt.refactoring/src/org/eclipse/objectteams/otdt/internal/refactoring/adaptor/pullup/PullUpAdaptor.java
@@ -28,6 +28,7 @@
 import org.eclipse.core.runtime.Assert;

 import org.eclipse.core.runtime.CoreException;

 import org.eclipse.core.runtime.IProgressMonitor;

+import org.eclipse.core.runtime.SubProgressMonitor;

 import org.eclipse.jdt.core.Flags;

 import org.eclipse.jdt.core.ICompilationUnit;

 import org.eclipse.jdt.core.IField;

@@ -39,22 +40,7 @@
 import org.eclipse.jdt.core.ITypeHierarchy;

 import org.eclipse.jdt.core.JavaCore;

 import org.eclipse.jdt.core.JavaModelException;

-import org.eclipse.jdt.core.dom.ASTNode;

-import org.eclipse.jdt.core.dom.ASTParser;

-import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;

-import org.eclipse.jdt.core.dom.CalloutMappingDeclaration;

-import org.eclipse.jdt.core.dom.CompilationUnit;

-import org.eclipse.jdt.core.dom.IBinding;

-import org.eclipse.jdt.core.dom.ITypeBinding;

-import org.eclipse.jdt.core.dom.MarkerAnnotation;

-import org.eclipse.jdt.core.dom.MethodDeclaration;

-import org.eclipse.jdt.core.dom.MethodSpec;

-import org.eclipse.jdt.core.dom.Modifier;

-import org.eclipse.jdt.core.dom.Name;

-import org.eclipse.jdt.core.dom.NodeFinder;

-import org.eclipse.jdt.core.dom.SimpleName;

-import org.eclipse.jdt.core.dom.SingleVariableDeclaration;

-import org.eclipse.jdt.core.dom.Type;

+import org.eclipse.jdt.core.dom.*;

 import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;

 import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext;

@@ -78,8 +64,11 @@
 import org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment;

 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

 import org.eclipse.jdt.internal.corext.util.JdtFlags;

+import org.eclipse.jdt.internal.corext.util.Messages;

 import org.eclipse.jdt.internal.corext.util.SearchUtils;

 import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;

+import org.eclipse.jdt.ui.JavaElementLabels;

+import org.eclipse.ltk.core.refactoring.GroupCategorySet;

 import org.eclipse.ltk.core.refactoring.RefactoringStatus;

 import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;

 import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;

@@ -104,7 +93,9 @@
 import org.eclipse.osgi.util.NLS;

 

 import base org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;

+import base org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;

 import base org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor;

+import base org.eclipse.jdt.internal.corext.refactoring.structure.HierarchyProcessor;

 import base org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor;

 import base org.eclipse.jdt.internal.corext.refactoring.structure.ReferenceFinderUtil;

 
@@ -114,9 +105,15 @@
  */

 @SuppressWarnings({ "restriction", "decapsulation" }) // private base classes

 public team class PullUpAdaptor {

-

-	public class PullUpRefactoringProcessorRole playedBy PullUpRefactoringProcessor {

+	

+	protected team class PullUpRefactoringProcessorRole playedBy PullUpRefactoringProcessor {

 		

+

+		public ChangeManagerDetails changeManagerDetails; // set when this team is activated (see #createChangeManager())

+

+

+		// callout (constant):

+		GroupCategorySet getSET_PULL_UP() -> get GroupCategorySet SET_PULL_UP;

 		// callouts (fields):

 		void setFCachedSkippedSuperTypes(Set<IType> fCachedSkippedSuperTypes) 

 																-> set Set<IType> fCachedSkippedSuperTypes;

@@ -569,10 +566,92 @@
 			targetRewrite.getASTRewrite().getListRewrite(destination, destination.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, destination.bodyDeclarations()), targetRewrite.createCategorizedGroupDescription(RefactoringCoreMessages.PullUpRefactoring_add_abstract_method, SET_PULL_UP));

 		}

 

+		createChangeManager <- replace createChangeManager;

+		@SuppressWarnings("inferredcallout")

+		callin void createChangeManager(IProgressMonitor monitor, RefactoringStatus status) throws CoreException {

+			IType destinationType = getDestinationType();

+			IType declaringType = getDeclaringType();

+			this.changeManagerDetails = new ChangeManagerDetails(getCompilationUnitRewrite(fCompilationUnitRewrites, declaringType.getCompilationUnit()),

+																 getCompilationUnitRewrite(fCompilationUnitRewrites, destinationType.getCompilationUnit()),

+																 declaringType,

+																 destinationType, 

+																 status,

+																 monitor);

+			within (this)

+				base.createChangeManager(monitor, status);

+		}

+

+		/** during createChangeManager we add callouts to the declaration nodes to be removed. */

+		protected team class HierarchyProcRole playedBy HierarchyProcessor {

+			// Note: when defined in role PullUpRefactoringProcessorRole this currently triggers a VerifyError

+			

+			// === for removal of old callout declarations: ===

+			List<ASTNode> getDeclarationNodes(CompilationUnit cuNode, List<IMember> members) 

+			<- replace  List<ASTNode> getDeclarationNodes(CompilationUnit cuNode, List<IMember> members);

+				

+			static callin List<ASTNode> getDeclarationNodes(CompilationUnit cuNode, List<IMember> members)

+					throws JavaModelException 

+			{

+				List<ASTNode> result = base.getDeclarationNodes(cuNode, members);

+				for (IMember member : members) {

+					ASTNode node= null;

+					if (member instanceof AbstractCalloutMapping)

+						node= getCalloutDeclarationNode((IMethod) member, cuNode);

+					if (node != null)

+						result.add(node);

+				}

+				return result;

+			}

+		}

+

+		/** during createChangeManager we intercept the visibility adjustments: */

+		protected class Adjustor playedBy MemberVisibilityAdjustor {

+			setAdjustments <- after setAdjustments;

+

+			private void setAdjustments(Map<IMember, IncomingMemberVisibilityAdjustment> map) {

+				PullUpRefactoringProcessorRole.this.changeManagerDetails.adjustments = map;

+			}

+		}

+

+		/** during createChangeManager we hook into getMethodDeclarationNode to handle callouts, too: */

+		protected class CalloutUtil playedBy ASTNodeSearchUtil {

+			getMethodDeclarationNode <- replace getMethodDeclarationNode

+				base when (!PullUpRefactoringProcessorRole.this.isExecutingCallin());  // inhibit callin trigger during getDeclarationNodes()

+

+			@SuppressWarnings("basecall")

+			static callin MethodDeclaration getMethodDeclarationNode(IMethod iMethod, CompilationUnit compilationUnit) throws JavaModelException {

+				if (iMethod instanceof AbstractCalloutMapping) {

+					// cf block inside org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor.createChangeManager()

+					// which starts "} else if (member instanceof IMethod) {":

+					CalloutMappingDeclaration oldCallout = getCalloutDeclarationNode(iMethod, compilationUnit);

+					if (oldCallout != null) {

+						CompilationUnitRewrite sourceRewriter = PullUpRefactoringProcessorRole.this.changeManagerDetails.sourceRewrite;

+						CompilationUnitRewrite rewrite = PullUpRefactoringProcessorRole.this.changeManagerDetails.rewrite;

+						AbstractTypeDeclaration declaration = PullUpRefactoringProcessorRole.this.changeManagerDetails.declaration;

+						ImportRewriteContext context = PullUpRefactoringProcessorRole.this.changeManagerDetails.context;

+						RefactoringStatus status = PullUpRefactoringProcessorRole.this.changeManagerDetails.status;

+						TypeVariableMaplet[] mapping = PullUpRefactoringProcessorRole.this.changeManagerDetails.mapping;

+						Map<IMember, IncomingMemberVisibilityAdjustment> adjustments = PullUpRefactoringProcessorRole.this.changeManagerDetails.adjustments;

+						ASTRewrite rewriter = rewrite.getASTRewrite();

+						IProgressMonitor subsub = PullUpRefactoringProcessorRole.this.changeManagerDetails.monitor;

+						

+						if (JdtFlags.isStatic(iMethod) && getDestinationType().isInterface())

+							status.merge(RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.PullUpRefactoring_moving_static_method_to_interface, new String[] { JavaElementLabels.getTextLabel(iMethod, JavaElementLabels.ALL_FULLY_QUALIFIED)}), JavaStatusContext.create(iMethod)));

+						CalloutMappingDeclaration newMethod= createNewCalloutDeclarationNode(sourceRewriter, rewrite, iMethod, oldCallout, mapping, adjustments, new SubProgressMonitor(subsub, 1), status);

+						rewriter.getListRewrite(declaration, declaration.getBodyDeclarationsProperty()).insertAt(newMethod, ASTNodes.getInsertionIndex(newMethod, declaration.bodyDeclarations()), rewrite.createCategorizedGroupDescription(RefactoringCoreMessages.HierarchyRefactoring_add_member, getSET_PULL_UP()));

+						ImportRewriteUtil.addImports(rewrite, context, oldCallout, new HashMap<Name, String>(), new HashMap<Name, String>(), false);

+

+					}

+					return null;

+				}

+				return base.getMethodDeclarationNode(iMethod, compilationUnit);

+			}

+		}

+		

 		// ==== COPY&PASTE from base class, use MethodSpec as a template rather then MethodDeclaration: ====

 		

 		@SuppressWarnings("inferredcallout")

-		protected void copyReturnType(ASTRewrite rewrite, ICompilationUnit unit, MethodSpec oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping) throws JavaModelException {

+		protected void copyReturnType(ASTRewrite rewrite, ICompilationUnit unit, MethodSpec oldMethod, IMethodNode newMethod, TypeVariableMaplet[] mapping) throws JavaModelException {

 			Type newReturnType= null;

 			if (mapping.length > 0)

 				newReturnType= createPlaceholderForType(oldMethod.getReturnType2(), unit, mapping, rewrite);

@@ -582,7 +661,7 @@
 		}

 

 		@SuppressWarnings("inferredcallout")

-		protected void copyParameters(ASTRewrite rewrite, ICompilationUnit unit, MethodSpec oldMethod, MethodDeclaration newMethod, TypeVariableMaplet[] mapping) throws JavaModelException {

+		protected void copyParameters(ASTRewrite rewrite, ICompilationUnit unit, MethodSpec oldMethod, IMethodNode newMethod, TypeVariableMaplet[] mapping) throws JavaModelException {

 			SingleVariableDeclaration newDeclaration= null;

 			for (int index= 0, size= oldMethod.parameters().size(); index < size; index++) {

 				final SingleVariableDeclaration oldDeclaration= (SingleVariableDeclaration) oldMethod.parameters().get(index);

@@ -593,6 +672,61 @@
 				newMethod.parameters().add(newDeclaration);

 			}

 		}

+

+		@SuppressWarnings("inferredcallout")

+		CalloutMappingDeclaration createNewCalloutDeclarationNode(CompilationUnitRewrite sourceRewrite, CompilationUnitRewrite targetRewrite, 

+				IMethod sourceMethod, CalloutMappingDeclaration oldCallout, TypeVariableMaplet[] mapping, Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, IProgressMonitor monitor, RefactoringStatus status) 

+				throws JavaModelException 

+		{

+			final ASTRewrite rewrite= targetRewrite.getASTRewrite();

+			final AST ast= rewrite.getAST();

+			final CalloutMappingDeclaration newCallout= ast.newCalloutMappingDeclaration();

+// TODO: copy parameter mappings:

+//			if (!getDestinationType().isInterface())

+//				copyBodyOfPulledUpMethod(sourceRewrite, targetRewrite, sourceMethod, oldCallout, newMethod, mapping, monitor);

+			copyJavadocNode(rewrite, oldCallout, newCallout);

+			int modifiers= getModifiersWithUpdatedVisibility(sourceMethod, sourceMethod.getFlags(), adjustments, monitor, true, status);

+

+// TODO

+//			copyAnnotations(oldCallout, newMethod);

+			newCallout.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers));

+			newCallout.setRoleMappingElement(createNewMethodSpec(ast, rewrite, mapping, (MethodSpec) oldCallout.getRoleMappingElement()));

+			MethodMappingElement baseMappingElement = oldCallout.getBaseMappingElement();

+			if (baseMappingElement instanceof MethodSpec) {

+				newCallout.setBaseMappingElement(createNewMethodSpec(ast, rewrite, mapping, (MethodSpec) baseMappingElement));

+			} else {

+				newCallout.setBaseMappingElement(createNewFieldSpec(ast, rewrite, mapping, (FieldAccessSpec) baseMappingElement));

+				newCallout.bindingOperator().setBindingModifier(ast.newModifier(oldCallout.bindingOperator().bindingModifier().getKeyword()));

+			}

+			newCallout.setSignatureFlag(oldCallout.hasSignature());

+			return newCallout;

+		}

+		MethodSpec createNewMethodSpec(AST ast, ASTRewrite rewrite, TypeVariableMaplet[] mapping, MethodSpec oldMethodSpec) throws JavaModelException {

+			MethodSpec newMethodSpec = ast.newMethodSpec();

+			newMethodSpec.setName(((SimpleName) ASTNode.copySubtree(ast, oldMethodSpec.getName())));

+			if (oldMethodSpec.hasSignature()) {

+				copyReturnType(rewrite, getDeclaringType().getCompilationUnit(), oldMethodSpec, newMethodSpec, mapping);

+				copyParameters(rewrite, getDeclaringType().getCompilationUnit(), oldMethodSpec, newMethodSpec, mapping);

+				newMethodSpec.setSignatureFlag(oldMethodSpec.hasSignature());

+//				copyTypeParameters(oldMethodSpec, newMethodSpec);

+			}

+			return newMethodSpec;

+		}

+		@SuppressWarnings("inferredcallout")

+		FieldAccessSpec createNewFieldSpec(AST ast, ASTRewrite rewrite, TypeVariableMaplet[] mapping, FieldAccessSpec oldFieldSpec) throws JavaModelException {

+			FieldAccessSpec newFieldSpec = ast.newFieldAccessSpec();

+			newFieldSpec.setName(((SimpleName) ASTNode.copySubtree(ast, oldFieldSpec.getName())));

+			if (oldFieldSpec.hasSignature()) {

+				Type newFielType= null;

+				if (mapping.length > 0)

+					newFielType= createPlaceholderForType(oldFieldSpec.getFieldType(), getDeclaringType().getCompilationUnit(), mapping, rewrite);

+				else

+					newFielType= createPlaceholderForType(oldFieldSpec.getFieldType(), getDeclaringType().getCompilationUnit(), rewrite);

+				newFieldSpec.setFieldType(newFielType);

+				newFieldSpec.setSignatureFlag(oldFieldSpec.hasSignature());

+			}

+			return newFieldSpec;

+		}

 	}

 

 	static CalloutMappingDeclaration getCalloutDeclarationNode(IMethod iMethod, CompilationUnit cuNode) throws JavaModelException {

@@ -668,6 +802,8 @@
 			try {

 				base.checkOTMember(member, monitor);

 			} catch (JavaModelException jme) {

+				// when a MethodDeclarationMatch reports a SourceMethod representation actually a callout mapping

+				// the method answers that it doesn't exist, that's what we intercept here:

 				if (jme.getJavaModelStatus().isDoesNotExist()) {

 					IType type = member.getDeclaringType();

 					IOTType ottype = OTModelManager.getOTElement(type);

diff --git a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java
index ef46137..cafbe24 100644
--- a/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java
+++ b/testplugins/org.eclipse.objectteams.otdt.ui.tests.refactoring/src/org/eclipse/objectteams/otdt/ui/tests/refactoring/pullup/PullUpTests.java
@@ -20,6 +20,7 @@
  **********************************************************************/
 package org.eclipse.objectteams.otdt.ui.tests.refactoring.pullup;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -52,6 +53,7 @@
  * 
  * @author Johannes Gebauer
  */
+@SuppressWarnings("restriction")
 public class PullUpTests extends RefactoringTest {
 	private static final String REFACTORING_PATH = "PullUp/";
 
@@ -81,19 +83,6 @@
 		return cus;
 	}
 
-	private String createInputTestFileName(ICompilationUnit[] cus, int idx) {
-		return getInputTestFileName(getSimpleNameOfCu(cus[idx].getElementName()));
-	}
-
-	private String createOutputTestFileName(ICompilationUnit[] cus, int idx) {
-		return getOutputTestFileName(getSimpleNameOfCu(cus[idx].getElementName()));
-	}
-
-	private String getSimpleNameOfCu(String compUnit) {
-		int dot = compUnit.lastIndexOf('.');
-		return compUnit.substring(0, dot);
-	}
-
 	private void setTargetClass(PullUpRefactoringProcessor processor, int targetClassIndex) throws JavaModelException {
 		IType[] possibleClasses = getPossibleTargetClasses(processor);
 		processor.setDestinationType(getPossibleTargetClasses(processor)[possibleClasses.length - 1 - targetClassIndex]);
@@ -104,8 +93,8 @@
 	}
 
 	private static IMethod[] getMethods(IMember[] members) {
-		List l = Arrays.asList(JavaElementUtil.getElementsOfType(members, IJavaElement.METHOD));
-		return (IMethod[]) l.toArray(new IMethod[l.size()]);
+		List<IJavaElement> l = Arrays.asList(JavaElementUtil.getElementsOfType(members, IJavaElement.METHOD));
+		return l.toArray(new IMethod[l.size()]);
 	}
 
 	private static PullUpRefactoringProcessor createRefactoringProcessor(IMember[] methods) throws JavaModelException {
@@ -150,10 +139,13 @@
 
 			setTargetClass(processor, targetClassIndex);
 
+			List<IMethod> methodList = new ArrayList<>();
 			if (deleteAllInSourceType)
-				processor.setDeletedMethods(methods);
+				methodList.addAll(Arrays.asList(methods));
 			if (deleteAllMatchingMethods)
-				processor.setDeletedMethods(getMethods(processor.getMatchingElements(new NullProgressMonitor(), false)));
+				methodList.addAll(Arrays.asList(getMethods(processor.getMatchingElements(new NullProgressMonitor(), false))));
+			if (!methodList.isEmpty())
+				processor.setDeletedMethods(methodList.toArray(new IMethod[methodList.size()]));
 
 			RefactoringStatus checkInputResult = ref.checkFinalConditions(new NullProgressMonitor());
 			assertTrue("precondition was supposed to pass", !checkInputResult.hasError());