public final class IndentManipulation extends Object
Modifier and Type | Method and Description |
---|---|
static String |
changeIndent(String code,
int indentUnitsToRemove,
int tabWidth,
int indentWidth,
String newIndentString,
String lineDelim)
Change the indent of a, possible multiple line, code string.
|
static String |
extractIndentString(String line,
int tabWidth,
int indentWidth)
Returns the leading indentation string of the given line.
|
static ReplaceEdit[] |
getChangeIndentEdits(String source,
int indentUnitsToRemove,
int tabWidth,
int indentWidth,
String newIndentString)
Returns the text edits retrieved after changing the indentation of a, possible multi-line, code string.
|
static int |
getIndentWidth(Map options)
Returns the tab width as configured in the given map.
|
static int |
getTabWidth(Map options)
Returns the tab width as configured in the given map.
|
static boolean |
isIndentChar(char ch)
Returns
true if the given character is an indentation character. |
static boolean |
isLineDelimiterChar(char ch)
Returns
true if the given character is a line delimiter character. |
static int |
measureIndentInSpaces(CharSequence line,
int tabWidth)
Returns the indentation of the given line in space equivalents.
|
static int |
measureIndentUnits(CharSequence line,
int tabWidth,
int indentWidth)
Returns the indentation of the given line in indentation units.
|
static String |
trimIndent(String line,
int indentUnitsToRemove,
int tabWidth,
int indentWidth)
Removes the given number of indentation units from a given line.
|
public static boolean isIndentChar(char ch)
true
if the given character is an indentation character. Indentation character are all whitespace characters
except the line delimiter characters.ch
- the given charactertrue
if this the character is a indent character, false
otherwisepublic static boolean isLineDelimiterChar(char ch)
true
if the given character is a line delimiter character.ch
- the given charactertrue
if this the character is a line delimiter character, false
otherwisepublic static int measureIndentUnits(CharSequence line, int tabWidth, int indentWidth)
line
up to the first
non-whitespace character.line
- the string to measure the indent oftabWidth
- the width of one tab character in space equivalentsindentWidth
- the width of one indentation unit in space equivalentsIllegalArgumentException
- if:
indentWidth
is lower than zerotabWidth
is lower than zeroline
is nullpublic static int measureIndentInSpaces(CharSequence line, int tabWidth)
Tab characters are counted using the given tabWidth
and every other indent
character as one. This method analyzes the content of line
up to the first
non-whitespace character.
line
- the string to measure the indent oftabWidth
- the width of one tab in space equivalentsIllegalArgumentException
- if:
line
is nulltabWidth
is lower than zeropublic static String extractIndentString(String line, int tabWidth, int indentWidth)
line
- the line to scantabWidth
- the size of one tab in space equivalentsindentWidth
- the width of one indentation unit in space equivalentsline
, but no odd spacesIllegalArgumentException
- if:
indentWidth
is lower than zerotabWidth
is lower than zeroline
is nullpublic static String trimIndent(String line, int indentUnitsToRemove, int tabWidth, int indentWidth)
indentsToRemove <= 0 or indent == 0
the line is returned.line
- the line to trimtabWidth
- the width of one tab in space equivalentsindentWidth
- the width of one indentation unit in space equivalentsIllegalArgumentException
- if:
indentWidth
is lower than zerotabWidth
is lower than zeroline
is nullpublic static String changeIndent(String code, int indentUnitsToRemove, int tabWidth, int indentWidth, String newIndentString, String lineDelim)
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).
code
- the code to change the indent ofindentUnitsToRemove
- the number of indent units to remove from each line (except the first) of the given codetabWidth
- the size of one tab in space equivalentsindentWidth
- the width of one indentation unit in space equivalentsnewIndentString
- the new indent string to be added to all lines (except the first)lineDelim
- the new line delimiter to be used. The returned code will contain only this line delimiter.IllegalArgumentException
- if:
indentWidth
is lower than zerotabWidth
is lower than zerocode
is nullindentUnitsToRemove
is lower than zeronewIndentString
is nulllineDelim
is nullpublic static ReplaceEdit[] getChangeIndentEdits(String source, int indentUnitsToRemove, int tabWidth, int indentWidth, String newIndentString)
The given number of indent units is removed, and a new indent string is 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).
source
- The code to change the indent ofindentUnitsToRemove
- the number of indent units to remove from each line (except the first) of the given codetabWidth
- the size of one tab in space equivalentsindentWidth
- the width of one indentation unit in space equivalentsnewIndentString
- the new indent string to be added to all lines (except the first)IllegalArgumentException
- if:
indentWidth
is lower than zerotabWidth
is lower than zerosource
is nullindentUnitsToRemove
is lower than zeronewIndentString
is nullpublic static int getTabWidth(Map options)
Use IJavaProject.getOptions(boolean)
to get the most current project options.
options
- the map to get the formatter settings from.IllegalArgumentException
- if the given options
is nullpublic static int getIndentWidth(Map options)
Use IJavaProject.getOptions(boolean)
to get the most current project options.
options
- the map to get the formatter settings fromIllegalArgumentException
- if the given options
is null
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.