Block oldBody= oldMethod.getBody(); String oldBodySource= getBufferText(oldBody, method.getCompilationUnit()); String[] lines= Strings.convertIntoLines(oldBodySource); Strings.trimIndentation(lines, CodeFormatterUtil.getTabWidth(), false); oldBodySource= Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(method)); Block newBody= (Block)targetRewrite.createStringPlaceholder(oldBodySource, ASTNode.BLOCK); newMethod.setBody(newBody);
try { final IDocument document= new Document(method.getCompilationUnit().getBuffer().getContents()); final ASTRewrite rewriter= ASTRewrite.create(body.getAST()); final ITrackedNodePosition position= rewriter.track(body); body.accept(new TypeMapper(rewriter, mapping)); rewriter.rewriteAST(document, null).apply(document, TextEdit.NONE); String content= document.get(position.getStartPosition(), position.getLength()); String[] lines= Strings.convertIntoLines(content); Strings.trimIndentation(lines, CodeFormatterUtil.getTabWidth(), false); content= Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(method)); newMethod.setBody((Block) targetRewrite.createStringPlaceholder(content, ASTNode.BLOCK)); } catch (MalformedTreeException exception) { JavaPlugin.log(exception); } catch (BadLocationException exception) { JavaPlugin.log(exception); }
	private static void copyBodyOfPushedDownMethod(OldASTRewrite targetRewrite, IMethod method, MethodDeclaration oldMethod, MethodDeclaration newMethod) throws JavaModelException {		if (oldMethod.getBody() == null){			newMethod.setBody(null);			return;		}		Block oldBody= oldMethod.getBody();		String oldBodySource= getBufferText(oldBody, method.getCompilationUnit());		String[] lines= Strings.convertIntoLines(oldBodySource);		Strings.trimIndentation(lines, CodeFormatterUtil.getTabWidth(), false);		oldBodySource= Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(method));		Block newBody= (Block)targetRewrite.createStringPlaceholder(oldBodySource, ASTNode.BLOCK);		newMethod.setBody(newBody);	}