gt: 			Block newBody= ast.newBlock();
context: /*******************************************************************************
   * Copyright (c) 2006, 2017 IBM Corporation and others.
   * 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
   *
   * Contributors:
   *     IBM Corporation - initial API and implementation
   *******************************************************************************/
  package org.eclipse.jdt.internal.corext.refactoring.code;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.eclipse.core.runtime.Assert;
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.core.runtime.OperationCanceledException;
  import org.eclipse.core.runtime.SubProgressMonitor;
  
  import org.eclipse.core.resources.IFile;
  import org.eclipse.core.resources.IResource;
  
  import org.eclipse.text.edits.MalformedTreeException;
  import org.eclipse.text.edits.MultiTextEdit;
  import org.eclipse.text.edits.TextEdit;
  import org.eclipse.text.edits.TextEditGroup;
  
  import org.eclipse.jface.text.BadLocationException;
  import org.eclipse.jface.text.Document;
  import org.eclipse.jface.text.IDocument;
  
  import org.eclipse.ltk.core.refactoring.Change;
  import org.eclipse.ltk.core.refactoring.Refactoring;
  import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
  import org.eclipse.ltk.core.refactoring.RefactoringStatus;
  import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker;
  
  import org.eclipse.jdt.core.Flags;
  import org.eclipse.jdt.core.ICompilationUnit;
  import org.eclipse.jdt.core.IJavaElement;
  import org.eclipse.jdt.core.IJavaProject;
  import org.eclipse.jdt.core.IMethod;
  import org.eclipse.jdt.core.IOrdinaryClassFile;
  import org.eclipse.jdt.core.IType;
  import org.eclipse.jdt.core.ITypeHierarchy;
  import org.eclipse.jdt.core.ITypeRoot;
  import org.eclipse.jdt.core.JavaModelException;
  import org.eclipse.jdt.core.dom.AST;
  import org.eclipse.jdt.core.dom.ASTNode;
  import org.eclipse.jdt.core.dom.ASTParser;
  import org.eclipse.jdt.core.dom.Block;
  import org.eclipse.jdt.core.dom.BodyDeclaration;
  import org.eclipse.jdt.core.dom.CompilationUnit;
  import org.eclipse.jdt.core.dom.ExpressionStatement;
  import org.eclipse.jdt.core.dom.IBinding;
  import org.eclipse.jdt.core.dom.IMethodBinding;
  import org.eclipse.jdt.core.dom.MethodDeclaration;
  import org.eclipse.jdt.core.dom.MethodInvocation;
  import org.eclipse.jdt.core.dom.Modifier;
  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.rewrite.ASTRewrite;
  import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
  import org.eclipse.jdt.core.refactoring.CompilationUnitChange;
  import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor;
  
  import org.eclipse.jdt.internal.corext.refactoring.Checks;
  import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment;
  import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments;
  import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringDescriptorUtil;
  import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
  import org.eclipse.jdt.internal.corext.refactoring.base.JavaStatusContext;
  import org.eclipse.jdt.internal.corext.refactoring.base.ReferencesInBinaryContext;
  import org.eclipse.jdt.internal.corext.refactoring.binary.StubCreator;
  import org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange;
  import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser;
  import org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager;
  import org.eclipse.jdt.internal.corext.util.Messages;
  
  import org.eclipse.jdt.ui.JavaElementLabels;
  
  import org.eclipse.jdt.internal.ui.JavaPlugin;
  import org.eclipse.jdt.internal.corext.dom.IASTSharedValues;
  import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
  import org.eclipse.jdt.internal.ui.viewsupport.BindingLabelProvider;
  
  public class ReplaceInvocationsRefactoring extends Refactoring {
  
  	private static final String ID_REPLACE_INVOCATIONS= "org.eclipse.jdt.ui.replace.invocations"; //$NON-NLS-1$
  	private static final String ATTRIBUTE_MODE= "mode"; //$NON-NLS-1$
  
  	public static class Mode {
  		private Mode() {
  		}
  		public static final Mode REPLACE_ALL= new Mode();
  		public static final Mode REPLACE_SINGLE= new Mode();
  	}
  
  	private final ITypeRoot fSelectionTypeRoot;
  	/**
  	 * only set if initial mode is REPLACE_SINGLE
  	 */
  	private final int fSelectionStart;
  	/**
  	 * only set if initial mode is REPLACE_SINGLE
  	 */
  	private final int fSelectionLength;
  
  	private ASTNode fSelectionNode;
  	/**
  	 * only set after checkInitialConditions
  	 */
  	private IMethod fMethod;
  
  	private String fBody;
  	private String[] fParameterNames;
  
  	private SourceProvider fSourceProvider; // resolved once in checkInitialConditions
  	private TargetProvider fTargetProvider; // flexible
  
  	private TextChangeManager fChangeManager;
  	private IMethodBinding fMethodBinding;
  
  	public ReplaceInvocationsRefactoring(ITypeRoot typeRoot, int offset, int length) {
  		fSelectionTypeRoot= typeRoot;
  		fSelectionStart= offset;
  		fSelectionLength= length;
  	}
  
  	public ReplaceInvocationsRefactoring(IMethod method) {
  		fMethod= method;
  		fSelectionTypeRoot= method.getTypeRoot();
  		fSelectionStart= -1;
  		fSelectionLength= -1;
  	}
  
      public ReplaceInvocationsRefactoring(JavaRefactoringArguments arguments, RefactoringStatus status) {
     		this(null, 0, 0);
     		RefactoringStatus initializeStatus= initialize(arguments);
     		status.merge(initializeStatus);
      }
  
  	@Override
  	public String getName() {
  		return RefactoringCoreMessages.ReplaceInvocationsRefactoring_name;
  	}
  
  	/*
  	 * Only to be called after {@link #checkInitialConditions(IProgressMonitor)}
  	 */
  	public boolean canReplaceSingle() {
  		return fSelectionNode instanceof MethodInvocation;
  	}
  
  	/*
  	 * Only to be called after {@link #checkInitialConditions(IProgressMonitor)}
  	 */
  	public RefactoringStatus setCurrentMode(Mode mode) throws JavaModelException {
  		if (fTargetProvider.isSingle() == (mode == Mode.REPLACE_SINGLE))
  			return new RefactoringStatus();
  		Assert.isTrue(canReplaceSingle());
  		if (mode == Mode.REPLACE_SINGLE) {
  			fTargetProvider= TargetProvider.create((ICompilationUnit) fSelectionTypeRoot, (MethodInvocation) fSelectionNode);
  		} else {
  			fTargetProvider= TargetProvider.create(fSourceProvider.getDeclaration());
  		}
  		return fTargetProvider.checkActivation();
  	}
  
  	public void setBody(String body, String[] parameterNames) {
  		//TODO: validate parameter name count and body
  		fBody= body;
  		fParameterNames= parameterNames;
  	}
  
  	@Override
  	public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  		// TargetProvider must get an untampered AST with original invocation node
  		// SourceProvider must get a tweaked AST with method body / parameter names replaced
  
  		RefactoringStatus result= new RefactoringStatus();
  
  		if (fMethod == null) {
  			if (! (fSelectionTypeRoot instanceof ICompilationUnit))
  				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReplaceInvocationsRefactoring_cannot_replace_in_binary);
  
  			ICompilationUnit cu= (ICompilationUnit) fSelectionTypeRoot;
  			CompilationUnit root= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(cu, true);
  			fSelectionNode= getTargetNode(cu, root, fSelectionStart, fSelectionLength);
  			if (fSelectionNode == null)
  				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReplaceInvocationsRefactoring_select_method_to_apply);
  
  			if (fSelectionNode.getNodeType() == ASTNode.METHOD_DECLARATION) {
  				MethodDeclaration methodDeclaration= (MethodDeclaration) fSelectionNode;
  				fTargetProvider= TargetProvider.create(methodDeclaration);
  				fMethodBinding= methodDeclaration.resolveBinding();
  			} else {
  				MethodInvocation methodInvocation= (MethodInvocation) fSelectionNode;
  				fTargetProvider= TargetProvider.create(cu, methodInvocation);
  				fMethodBinding= methodInvocation.resolveMethodBinding();
  			}
  			if (fMethodBinding == null)
  				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
  			fMethod= (IMethod) fMethodBinding.getJavaElement();
  
  		} else {
  			ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
  			parser.setProject(fMethod.getJavaProject());
  			IBinding[] bindings= parser.createBindings(new IJavaElement[] { fMethod }, null);
  			fMethodBinding= (IMethodBinding) bindings[0];
  			if (fMethodBinding == null)
  				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
  
  			fTargetProvider= TargetProvider.create(fMethodBinding);
  		}
  
  		result.merge(fTargetProvider.checkActivation());
  		return result;
  	}
  
  	private SourceProvider resolveSourceProvider(IMethodBinding methodBinding, RefactoringStatus status) throws JavaModelException {
  		final IMethod method= (IMethod) methodBinding.getJavaElement();
  
  		ITypeRoot typeRoot;
  		IDocument source;
  		CompilationUnit methodDeclarationAstRoot;
  
  		ICompilationUnit methodCu= (method).getCompilationUnit();
  		if (methodCu != null) {
  			typeRoot= methodCu;
  			ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
  			parser.setSource(methodCu);
  			parser.setFocalPosition(method.getNameRange().getOffset());
  			CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null);
  			MethodDeclaration methodDecl= (MethodDeclaration) NodeFinder.perform(compilationUnit, method.getNameRange()).getParent();
  			AST ast= compilationUnit.getAST();
  			ASTRewrite rewrite= ASTRewrite.create(ast);
  