private void copyBodyOfPushedDownMethod(ASTRewrite targetRewrite, IMethod method, MethodDeclaration oldMethod, MethodDeclaration newMethod, TypeVariableMaplet[] mapping) throws JavaModelException { Block body= oldMethod.getBody(); if (body == null) { newMethod.setBody(null); return; } 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 TypeVariableMapper(rewriter, mapping)); rewriter.rewriteAST(document, getDeclaringType().getCompilationUnit().getJavaProject().getOptions(true)).apply(document, TextEdit.NONE); String content= document.get(position.getStartPosition(), position.getLength()); String[] lines= Strings.convertIntoLines(content); Strings.trimIndentation(lines, method.getJavaProject(), 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 copyBodyOfPushedDownMethod(ASTRewrite targetRewrite, IMethod method, MethodDeclaration oldMethod, MethodDeclaration newMethod, TypeVariableMaplet[] mapping) throws JavaModelException { Block body= oldMethod.getBody(); if (body == null) { newMethod.setBody(null); return; } 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 TypeVariableMapper(rewriter, mapping)); rewriter.rewriteAST(document, getDeclaringType().getCompilationUnit().getJavaProject().getOptions(true)).apply(document, TextEdit.NONE); String content= document.get(position.getStartPosition(), position.getLength()); String[] lines= Strings.convertIntoLines(content); Strings.trimIndentation(lines, method.getJavaProject(), 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 copyBodyOfPushedDownMethod(ASTRewrite targetRewrite, IMethod method, MethodDeclaration oldMethod, MethodDeclaration newMethod, TypeVariableMaplet[] mapping) throws JavaModelException { Block body= oldMethod.getBody(); if (body == null) { newMethod.setBody(null); return; } 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 TypeVariableMapper(rewriter, mapping)); rewriter.rewriteAST(document, getDeclaringType().getCompilationUnit().getJavaProject().getOptions(true)).apply(document, TextEdit.NONE); String content= document.get(position.getStartPosition(), position.getLength()); String[] lines= Strings.convertIntoLines(content); Strings.trimIndentation(lines, method.getJavaProject(), 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(final CompilationUnitRewrite sourceRewrite, final CompilationUnitRewrite targetRewrite, final IMethod method, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping, final IProgressMonitor monitor) throws JavaModelException { final Block body= oldMethod.getBody(); if (body == null) { newMethod.setBody(null); return; } try { final IDocument document= new Document(method.getCompilationUnit().getBuffer().getContents()); final ASTRewrite rewrite= ASTRewrite.create(body.getAST()); final ITrackedNodePosition position= rewrite.track(body); body.accept(new PullUpAstNodeMapper(sourceRewrite, targetRewrite, rewrite, getDeclaringSuperTypeHierarchy(monitor).getSuperclass(getDeclaringType()), mapping, oldMethod.resolveBinding())); rewrite.rewriteAST(document, method.getJavaProject().getOptions(true)).apply(document, TextEdit.NONE); String content= document.get(position.getStartPosition(), position.getLength()); final String[] lines= Strings.convertIntoLines(content); Strings.trimIndentation(lines, method.getJavaProject(), false); content= Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(method)); newMethod.setBody((Block) targetRewrite.getASTRewrite().createStringPlaceholder(content, ASTNode.BLOCK)); } catch (MalformedTreeException exception) { JavaPlugin.log(exception); } catch (BadLocationException exception) { JavaPlugin.log(exception); } }
private void copyBodyOfPulledUpMethod(final CompilationUnitRewrite sourceRewrite, final CompilationUnitRewrite targetRewrite, final IMethod method, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping, final IProgressMonitor monitor) throws JavaModelException { final Block body= oldMethod.getBody(); if (body == null) { newMethod.setBody(null); return; } try { final IDocument document= new Document(method.getCompilationUnit().getBuffer().getContents()); final ASTRewrite rewrite= ASTRewrite.create(body.getAST()); final ITrackedNodePosition position= rewrite.track(body); body.accept(new PullUpAstNodeMapper(sourceRewrite, targetRewrite, rewrite, getDeclaringSuperTypeHierarchy(monitor).getSuperclass(getDeclaringType()), mapping, oldMethod.resolveBinding())); rewrite.rewriteAST(document, method.getJavaProject().getOptions(true)).apply(document, TextEdit.NONE); String content= document.get(position.getStartPosition(), position.getLength()); final String[] lines= Strings.convertIntoLines(content); Strings.trimIndentation(lines, method.getJavaProject(), false); content= Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(method)); newMethod.setBody((Block) targetRewrite.getASTRewrite().createStringPlaceholder(content, ASTNode.BLOCK)); } catch (MalformedTreeException exception) { JavaPlugin.log(exception); } catch (BadLocationException exception) { JavaPlugin.log(exception); } }
private void copyBodyOfPulledUpMethod(final CompilationUnitRewrite sourceRewrite, final CompilationUnitRewrite targetRewrite, final IMethod method, final MethodDeclaration oldMethod, final MethodDeclaration newMethod, final TypeVariableMaplet[] mapping, final IProgressMonitor monitor) throws JavaModelException { final Block body= oldMethod.getBody(); if (body == null) { newMethod.setBody(null); return; } try { final IDocument document= new Document(method.getCompilationUnit().getBuffer().getContents()); final ASTRewrite rewrite= ASTRewrite.create(body.getAST()); final ITrackedNodePosition position= rewrite.track(body); body.accept(new PullUpAstNodeMapper(sourceRewrite, targetRewrite, rewrite, getDeclaringSuperTypeHierarchy(monitor).getSuperclass(getDeclaringType()), mapping, oldMethod.resolveBinding())); rewrite.rewriteAST(document, method.getJavaProject().getOptions(true)).apply(document, TextEdit.NONE); String content= document.get(position.getStartPosition(), position.getLength()); final String[] lines= Strings.convertIntoLines(content); Strings.trimIndentation(lines, method.getJavaProject(), false); content= Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(method)); newMethod.setBody((Block) targetRewrite.getASTRewrite().createStringPlaceholder(content, ASTNode.BLOCK)); } catch (MalformedTreeException exception) { JavaPlugin.log(exception); } catch (BadLocationException exception) { JavaPlugin.log(exception); } }