/** * Removes the common number of indents from all lines. If a line * only consists out of white space it is ignored. * @param lines the lines * @param tabWidth the size of one tab in space equivalents * @param indentWidth the size of the indent in space equivalents * * @since 3.1 */ public static void trimIndentation(String[] lines, int tabWidth, int indentWidth) { trimIndentation(lines, tabWidth, indentWidth, true); }
/** * Removes the common number of indents from all lines. If a line * only consists out of white space it is ignored. * * @since 3.1 */ public static void trimIndentation(String[] lines, int tabWidth, int indentWidth) { trimIndentation(lines, tabWidth, indentWidth, true); }
/** * Removes the common number of indents from all lines. If a line * only consists out of white space it is ignored. * @param lines the lines * @param project the java project from which to get the formatter * preferences, or <code>null</code> for global preferences * @since 3.1 */ public static void trimIndentation(String[] lines, IJavaProject project) { trimIndentation(lines, CodeFormatterUtil.getTabWidth(project), CodeFormatterUtil.getIndentWidth(project), true); } /**
/** * Removes the common number of indents from all lines. If a line * only consists out of white space it is ignored. * @param project the java project from which to get the formatter * preferences, or <code>null</code> for global preferences * @since 3.1 */ public static void trimIndentation(String[] lines, IJavaProject project) { trimIndentation(lines, CodeFormatterUtil.getTabWidth(project), CodeFormatterUtil.getIndentWidth(project), true); } /**
public static String trimIndentation(String source, IJavaProject project, boolean considerFirstLine) { return trimIndentation(source, CodeFormatterUtil.getTabWidth(project), CodeFormatterUtil.getIndentWidth(project), considerFirstLine); }
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; }
/** * Removes the common number of indents from all lines. If a line * only consists out of white space it is ignored. If <code> * considerFirstLine</code> is false the first line will be ignored. * * @param project the java project from which to get the formatter * preferences, or <code>null</code> for global preferences * @since 3.1 */ public static void trimIndentation(String[] lines, IJavaProject project, boolean considerFirstLine) { trimIndentation(lines, CodeFormatterUtil.getTabWidth(project), CodeFormatterUtil.getIndentWidth(project), considerFirstLine); }
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())); }
private static String getSourceOfDeclararationNode(IJavaElement elem, ICompilationUnit cu) throws JavaModelException, CoreException { Assert.isTrue(elem.getElementType() != IJavaElement.IMPORT_CONTAINER); if (elem instanceof ISourceReference) { ISourceReference reference= (ISourceReference) elem; String source= reference.getSource(); if (source != null) return Strings.trimIndentation(source, cu.getJavaProject(), false); } return ""; //$NON-NLS-1$ } }
private static String getSourceOfDeclararationNode(IJavaElement elem, ICompilationUnit cu) throws JavaModelException, CoreException { Assert.isTrue(elem.getElementType() != IJavaElement.IMPORT_CONTAINER); if (elem instanceof ISourceReference) { ISourceReference reference= (ISourceReference) elem; String source= reference.getSource(); if (source != null) return Strings.trimIndentation(source, cu.getJavaProject(), false); } return ""; //$NON-NLS-1$ } }
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 String getUpdatedMember(IDocument document, BodyDeclaration declaration) throws BadLocationException { ITrackedNodePosition trackedPosition= (ITrackedNodePosition) declaration.getProperty(TRACKED_POSITION_PROPERTY); return Strings.trimIndentation(document.get(trackedPosition.getStartPosition(), trackedPosition.getLength()), fPreferences.tabWidth, fPreferences.indentWidth, false); }
private String getUpdatedMember(IDocument document, BodyDeclaration declaration) throws BadLocationException { ITrackedNodePosition trackedPosition= (ITrackedNodePosition) declaration.getProperty(TRACKED_POSITION_PROPERTY); return Strings.trimIndentation(document.get(trackedPosition.getStartPosition(), trackedPosition.getLength()), fPreferences.tabWidth, fPreferences.indentWidth, false); }
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; }