private static int indexOfIndent(CharSequence line, int numberOfIndentUnits, int tabWidth, int indentWidth) { int spaceEquivalents= numberOfIndentUnits * indentWidth; int size= line.length(); int result= -1; int blanks= 0; for (int i= 0; i < size && blanks < spaceEquivalents; i++) { char c= line.charAt(i); if (c == '\t') { blanks = calculateSpaceEquivalents(tabWidth, blanks); } else if (isIndentChar(c)) { blanks++; } else { break; } result= i; } if (blanks < spaceEquivalents) return -1; return result + 1; }
/** * Change the indent of, possible muti-line, code range. The current indent is removed, a new indent added. * The first line of the code will not be changed. (It is considered to have no indent as it might start in * the middle of a line) * @since 3.1 */ public static String changeIndent(String code, int codeIndentLevel, int tabWidth, int indentWidth, String newIndent, String lineDelim) { return IndentManipulation.changeIndent(code, codeIndentLevel, tabWidth, indentWidth, newIndent, lineDelim); }
/** * Returns that part of the indentation of <code>line</code> that makes up * a multiple of indentation units. * * @param line the line to scan * @param tabWidth the size of one tab in space equivalents * @param indentWidth the size of the indent in space equivalents * @return the indent part of <code>line</code>, but no odd spaces * @since 3.1 */ public static String getIndentString(String line, int tabWidth, int indentWidth) { return IndentManipulation.extractIndentString(line, tabWidth, indentWidth); }
public ASTRewriteFormatter(NodeInfoStore placeholders, RewriteEventStore eventStore, Map options, String lineDelimiter) { this.placeholders= placeholders; this.eventStore= eventStore; this.options= options; this.lineDelimiter= lineDelimiter; this.tabWidth= IndentManipulation.getTabWidth(options); this.indentWidth= IndentManipulation.getIndentWidth(options); }
public ReplaceEdit[] getModifications(String source) { List result= new ArrayList(); int destIndentLevel= IndentManipulation.measureIndentUnits(this.destinationIndent, this.tabWidth, this.indentWidth); if (destIndentLevel == this.sourceIndentLevel) { return (ReplaceEdit[])result.toArray(new ReplaceEdit[result.size()]); } return IndentManipulation.getChangeIndentEdits(source, this.sourceIndentLevel, this.tabWidth, this.indentWidth, this.destinationIndent); } }
private String removeIndentAndNewLines(String code, ICompilationUnit cu) throws JavaModelException { IJavaProject project = cu.getJavaProject(); Map options = project.getOptions(true/*inherit JavaCore options*/); int tabWidth = IndentManipulation.getTabWidth(options); int indentWidth = IndentManipulation.getIndentWidth(options); int indent = IndentManipulation.measureIndentUnits(code, tabWidth, indentWidth); int firstNonWhiteSpace = -1; int length = code.length(); while (firstNonWhiteSpace < length-1) if (!ScannerHelper.isWhitespace(code.charAt(++firstNonWhiteSpace))) break; int lastNonWhiteSpace = length; while (lastNonWhiteSpace > 0) if (!ScannerHelper.isWhitespace(code.charAt(--lastNonWhiteSpace))) break; String lineDelimiter = cu.findRecommendedLineSeparator(); return IndentManipulation.changeIndent(code.substring(firstNonWhiteSpace, lastNonWhiteSpace+1), indent, tabWidth, indentWidth, "", lineDelimiter); //$NON-NLS-1$ } /*
final private String getIndentOfLine(int pos) { int line= getLineInformation().getLineOfOffset(pos); if (line >= 0) { char[] cont= getContent(); int lineStart= getLineInformation().getLineOffset(line); int i= lineStart; while (i < cont.length && IndentManipulation.isIndentChar(this.content[i])) { i++; } return new String(cont, lineStart, i - lineStart); } return Util.EMPTY_STRING; }
private int getCurrentLineStart(String str, int pos) { for (int i= pos - 1; i>= 0; i--) { char ch= str.charAt(i); if (IndentManipulation.isLineDelimiterChar(ch)) { return i+1; } } return 0; }
/** * Removes the given number of indents from the line. Asserts that the given line * has the requested number of indents. If <code>indentsToRemove <= 0</code> * the line is returned. * * @since 3.1 */ public static String trimIndent(String line, int indentsToRemove, int tabWidth, int indentWidth) { return IndentManipulation.trimIndent(line, indentsToRemove, tabWidth, indentWidth); }
/** * Returns the indent of the given string in indentation units. Odd spaces * are not counted. * * @param line the text line * @param tabWidth the width of the '\t' character in space equivalents * @param indentWidth the width of one indentation unit in space equivalents * @since 3.1 */ public static int computeIndentUnits(String line, int tabWidth, int indentWidth) { return IndentManipulation.measureIndentUnits(line, tabWidth, indentWidth); }
/** * Computes the visual length of the indentation of a * <code>CharSequence</code>, counting a tab character as the size until * the next tab stop and every other whitespace character as one. * * @param line the string to measure the indent of * @param tabSize the visual size of a tab in space equivalents * @return the visual length of the indentation of <code>line</code> * @since 3.1 */ public static int measureIndentLength(CharSequence line, int tabSize) { return IndentManipulation.measureIndentInSpaces(line, tabSize); }
ReplaceEdit[] edits = IndentManipulation.getChangeIndentEdits(unformatted, 0, this.tabWidth, this.indentWidth, indentString); edit= new MultiTextEdit(); edit.addChild(new InsertEdit(0, indentString));
public AbstractSourceFileLocator(IPackageFragmentRoot root) { this.root = root; final Map<?, ?> options = root.getJavaProject().getOptions(true); this.tabWidth = IndentManipulation.getTabWidth(options); }
private String removeIndentAndNewLines(String code, ICompilationUnit cu) throws JavaModelException { IJavaProject project = cu.getJavaProject(); Map options = project.getOptions(true/*inherit JavaCore options*/); int tabWidth = IndentManipulation.getTabWidth(options); int indentWidth = IndentManipulation.getIndentWidth(options); int indent = IndentManipulation.measureIndentUnits(code, tabWidth, indentWidth); int firstNonWhiteSpace = -1; int length = code.length(); while (firstNonWhiteSpace < length-1) if (!ScannerHelper.isWhitespace(code.charAt(++firstNonWhiteSpace))) break; int lastNonWhiteSpace = length; while (lastNonWhiteSpace > 0) if (!ScannerHelper.isWhitespace(code.charAt(--lastNonWhiteSpace))) break; String lineDelimiter = cu.findRecommendedLineSeparator(); return IndentManipulation.changeIndent(code.substring(firstNonWhiteSpace, lastNonWhiteSpace+1), indent, tabWidth, indentWidth, "", lineDelimiter); //$NON-NLS-1$ } /*
private int findTagNameEnd(TagElement tagNode) { if (tagNode.getTagName() != null) { char[] cont= getContent(); int len= cont.length; int i= tagNode.getStartPosition(); while (i < len && !IndentManipulation.isIndentChar(cont[i])) { i++; } return i; } return tagNode.getStartPosition(); }
@Override public ReplaceEdit[] getModifications(String source) { List result= new ArrayList(); int destIndentLevel= IndentManipulation.measureIndentUnits(this.destinationIndent, this.tabWidth, this.indentWidth); if (destIndentLevel == this.sourceIndentLevel) { return (ReplaceEdit[])result.toArray(new ReplaceEdit[result.size()]); } return IndentManipulation.getChangeIndentEdits(source, this.sourceIndentLevel, this.tabWidth, this.indentWidth, this.destinationIndent); } }
private int getCurrentLineStart(String str, int pos) { for (int i= pos - 1; i>= 0; i--) { char ch= str.charAt(i); if (IndentManipulation.isLineDelimiterChar(ch)) { return i+1; } } return 0; }
public ASTRewriteFormatter(NodeInfoStore placeholders, RewriteEventStore eventStore, Map options, String lineDelimiter) { this.placeholders= placeholders; this.eventStore= eventStore; this.options= options == null ? JavaCore.getOptions() : (Map) new HashMap(options); this.options.put( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RESOURCES_IN_TRY, DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_NEXT_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT)); this.lineDelimiter= lineDelimiter; this.tabWidth= IndentManipulation.getTabWidth(options); this.indentWidth= IndentManipulation.getIndentWidth(options); }
/** * Removes the given number of indents from the line. Asserts that the given line * has the requested number of indents. If <code>indentsToRemove <= 0</code> * the line is returned. * @param line the line * @param indentsToRemove the indents to remove * @param tabWidth the tab width * @param indentWidth the indent width * @return the trimmed line * * @since 3.1 */ public static String trimIndent(String line, int indentsToRemove, int tabWidth, int indentWidth) { return IndentManipulation.trimIndent(line, indentsToRemove, tabWidth, indentWidth); }
public int computeIndentUnits(String line) { return IndentManipulation.measureIndentUnits(line, this.tabWidth, this.indentWidth); }