Block oldBody= oldMethod.getBody(); ISourceRange[] superRefOffsert= SourceRange.reverseSortByOffset(findSuperReferenceRanges(method, getSuperclassOfDeclaringClass(pm)));  String oldBodySource= getBufferText(oldBody, getDeclaringCU()); StringBuffer newBodyCodeBuff= new StringBuffer(oldBodySource); for (int i= 0; i < superRefOffsert.length; i++) { ISourceRange range= superRefOffsert[i]; int start= range.getOffset() - oldBody.getStartPosition(); int end= start + range.getLength(); newBodyCodeBuff.replace(start, end, "this");
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 MethodMapper(rewriter, getSuperclassOfDeclaringClass(pm), 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 void copyBodyOfPulledUpMethod(OldASTRewrite targetRewrite, IMethod method, MethodDeclaration oldMethod, MethodDeclaration newMethod, IProgressMonitor pm) throws JavaModelException {		if (oldMethod.getBody() == null){			newMethod.setBody(null);			return;		}		Block oldBody= oldMethod.getBody();		ISourceRange[] superRefOffsert= SourceRange.reverseSortByOffset(findSuperReferenceRanges(method, getSuperclassOfDeclaringClass(pm)));				String oldBodySource= getBufferText(oldBody, getDeclaringCU());		StringBuffer newBodyCodeBuff= new StringBuffer(oldBodySource);		for (int i= 0; i < superRefOffsert.length; i++) {			ISourceRange range= superRefOffsert[i];			int start= range.getOffset() - oldBody.getStartPosition();			int end= start + range.getLength();			newBodyCodeBuff.replace(start, end, "this"); //$NON-NLS-1$		}		String newBodySource= newBodyCodeBuff.toString();		String[] lines= Strings.convertIntoLines(newBodySource);		Strings.trimIndentation(lines, CodeFormatterUtil.getTabWidth(), false);		newBodySource= Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(method));		Block newBody= (Block)targetRewrite.createStringPlaceholder(newBodySource, ASTNode.BLOCK);		newMethod.setBody(newBody);	}