static String trimTextBlock(String content, String delimiter, IJavaProject currentProject) { if (content != null) { String[] lines= Strings.convertIntoLines(content); if (lines != null) { Strings.trimIndentation(lines, currentProject); return Strings.concatenate(lines, delimiter); } } return null; }
static String trimTextBlock(String content, String delimiter, IJavaProject currentProject) { if (content != null) { String[] lines= Strings.convertIntoLines(content); if (lines != null) { Strings.trimIndentation(lines, currentProject); return Strings.concatenate(lines, delimiter); } } return null; }
/** * Returns the trimmed source lines. * * @param source the source string, could be <code>null</code> * @param javaElement the java element * @return the trimmed source lines or <code>null</code> */ private String[] getTrimmedSource(String source, IJavaElement javaElement) { if (source == null) return null; source= removeLeadingComments(source); String[] sourceLines= Strings.convertIntoLines(source); Strings.trimIndentation(sourceLines, javaElement.getJavaProject()); return sourceLines; }
private String getAlignedSourceBlock(final ICompilationUnit unit, final String block) { Assert.isNotNull(block); final String[] lines= Strings.convertIntoLines(block); Strings.trimIndentation(lines, unit.getJavaProject(), false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(fType.getJavaProject())); }
private String getAlignedSourceBlock(final ICompilationUnit unit, final String block) { Assert.isNotNull(block); final String[] lines= Strings.convertIntoLines(block); Strings.trimIndentation(lines, unit.getJavaProject(), false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(fType.getJavaProject())); }
/** * Normalizes the indentation of the specified text. * * @param code * the text to normalize * @return the normalized text * @throws JavaModelException * if an error occurs */ protected final String normalizeText(final String code) throws JavaModelException { Assert.isNotNull(code); final String[] lines= Strings.convertIntoLines(code); final IJavaProject project= fSubType.getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(project)); }
/** * Normalizes the indentation of the specified text. * * @param code * the text to normalize * @return the normalized text * @throws JavaModelException * if an error occurs */ protected final String normalizeText(final String code) throws JavaModelException { Assert.isNotNull(code); final String[] lines= Strings.convertIntoLines(code); final IJavaProject project= fSubType.getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(project)); }
protected static String getUnindentedText(final String text, final ICompilationUnit declaringCu) throws JavaModelException { final String[] lines= Strings.convertIntoLines(text); Strings.trimIndentation(lines, declaringCu.getJavaProject(), false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(declaringCu)); }
protected static String getUnindentedText(final String text, final ICompilationUnit declaringCu) throws JavaModelException { final String[] lines= Strings.convertIntoLines(text); Strings.trimIndentation(lines, declaringCu.getJavaProject(), false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed(declaringCu)); }
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException { String[] lines= Strings.convertIntoLines(sourceReference.getSource()); final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference)); }
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException { Assert.isTrue(sourceReference instanceof IJavaElement); String[] lines= Strings.convertIntoLines(sourceReference.getSource()); final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference)); }
private String[] getBlocks(RangeMarker[] markers) throws BadLocationException { String[] result= new String[markers.length]; for (int i= 0; i < markers.length; i++) { RangeMarker marker= markers[i]; String content= fDocument.get(marker.getOffset(), marker.getLength()); String lines[]= Strings.convertIntoLines(content); Strings.trimIndentation(lines, fTypeRoot.getJavaProject(), false); if (fMarkerMode == STATEMENT_MODE && lines.length == 2 && isSingleControlStatementWithoutBlock()) { lines[1]= CodeFormatterUtil.createIndentString(1, fTypeRoot.getJavaProject()) + lines[1]; } result[i]= Strings.concatenate(lines, TextUtilities.getDefaultLineDelimiter(fDocument)); } return result; }
private void setSourceViewerContents(String contents) { if (contents != null) { final IJavaProject project= fProcessor.getDestinationType().getJavaProject(); final String[] lines= Strings.convertIntoLines(contents); if (lines.length > 0) { final int indent= Strings.computeIndentUnits(lines[lines.length - 1], project); contents= Strings.changeIndent(contents, indent, project, "", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } } final IDocument document= (contents == null) ? new Document() : new Document(contents); JavaPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document); fSourceViewer.setDocument(document); }
private String[] getBlocks(RangeMarker[] markers) throws BadLocationException { String[] result= new String[markers.length]; for (int i= 0; i < markers.length; i++) { RangeMarker marker= markers[i]; String content= fDocument.get(marker.getOffset(), marker.getLength()); String lines[]= Strings.convertIntoLines(content); Strings.trimIndentation(lines, fTypeRoot.getJavaProject(), false); if (fMarkerMode == STATEMENT_MODE && lines.length == 2 && isSingleControlStatementWithoutBlock()) { lines[1]= CodeFormatterUtil.createIndentString(1, fTypeRoot.getJavaProject()) + lines[1]; } result[i]= Strings.concatenate(lines, TextUtilities.getDefaultLineDelimiter(fDocument)); } return result; }
private void setSourceViewerContents(String contents) { if (contents != null) { final IJavaProject project= getPullUpRefactoring().getPullUpProcessor().getDestinationType().getJavaProject(); final String[] lines= Strings.convertIntoLines(contents); if (lines.length > 0) { final int indent= Strings.computeIndentUnits(lines[lines.length - 1], project); contents= Strings.changeIndent(contents, indent, project, "", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ } } final IDocument document= (contents == null) ? new Document() : new Document(contents); JavaPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document); fSourceViewer.setDocument(document); }
protected static void copyJavadocNode(final ASTRewrite rewrite, final IMember member, final BodyDeclaration oldDeclaration, final BodyDeclaration newDeclaration) throws JavaModelException { final Javadoc predecessor= oldDeclaration.getJavadoc(); if (predecessor != null) { final IDocument buffer= new Document(member.getCompilationUnit().getBuffer().getContents()); try { final String[] lines= Strings.convertIntoLines(buffer.get(predecessor.getStartPosition(), predecessor.getLength())); Strings.trimIndentation(lines, member.getJavaProject(), false); final Javadoc successor= (Javadoc) rewrite.createStringPlaceholder(Strings.concatenate(lines, TextUtilities.getDefaultLineDelimiter(buffer)), ASTNode.JAVADOC); newDeclaration.setJavadoc(successor); } 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); } }