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; }
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 String getHoverInfo(IJavaElement[] result) { int nResults= result.length; if (nResults > 1) return null; IJavaElement curr= result[0]; if ((curr instanceof IMember || curr instanceof ILocalVariable || curr instanceof ITypeParameter) && curr instanceof ISourceReference) { try { String source= ((ISourceReference) curr).getSource(); if (source == null) return null; source= removeLeadingComments(source); String delim= StubUtility.getLineDelimiterUsed(result[0]); String[] sourceLines= Strings.convertIntoLines(source); String firstLine= sourceLines[0]; if (!Character.isWhitespace(firstLine.charAt(0))) sourceLines[0]= ""; //$NON-NLS-1$ Strings.trimIndentation(sourceLines, curr.getJavaProject()); if (!Character.isWhitespace(firstLine.charAt(0))) sourceLines[0]= firstLine; source= Strings.concatenate(sourceLines, delim); return source; } catch (JavaModelException ex) { } } return null; }
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)); }
sourceLines[0]= firstLine; return Strings.concatenate(sourceLines, delim);
@Override @Deprecated public String getHoverInfo(ITextViewer textViewer, IRegion region) { IJavaElement[] result= getJavaElementsAt(textViewer, region); fUpwardShiftInLines= 0; fBracketHoverStatus= null; if (result == null || result.length == 0) { return getBracketHoverInfo(textViewer, region); } if (result.length > 1) return null; IJavaElement curr= result[0]; if ((curr instanceof IMember || curr instanceof ILocalVariable || curr instanceof ITypeParameter) && curr instanceof ISourceReference) { try { String source= ((ISourceReference) curr).getSource(); String[] sourceLines= getTrimmedSource(source, curr); if (sourceLines == null) return null; String delim= StubUtility.getLineDelimiterUsed(curr); source= Strings.concatenate(sourceLines, delim); return source; } catch (JavaModelException ex) { //do nothing } } return null; }
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 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; }
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); } }