public class DefaultCodeFormatter extends CodeFormatter
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEBUG
Debug trace
|
boolean |
previewEnabled |
F_INCLUDE_COMMENTS, K_CLASS_BODY_DECLARATIONS, K_COMPILATION_UNIT, K_EXPRESSION, K_JAVA_DOC, K_MODULE_INFO, K_MULTI_LINE_COMMENT, K_SINGLE_LINE_COMMENT, K_STATEMENTS, K_UNKNOWN| Constructor and Description |
|---|
DefaultCodeFormatter() |
DefaultCodeFormatter(DefaultCodeFormatterOptions options) |
DefaultCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions,
java.util.Map<java.lang.String,java.lang.String> options) |
DefaultCodeFormatter(java.util.Map<java.lang.String,java.lang.String> options) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
createIndentationString(int indentationLevel)
Answers the string that corresponds to the indentation to the given indentation level or an empty string
if the indentation cannot be computed.
|
TextEdit |
format(int kind,
java.lang.String source,
int offset,
int length,
int indentationLevel,
java.lang.String lineSeparator)
Format
source,
and returns a text edit that correspond to the difference between the given
string and the formatted string. |
TextEdit |
format(int kind,
java.lang.String source,
IRegion[] regions,
int indentationLevel,
java.lang.String lineSeparator)
Format
source,
and returns a text edit that correspond to the difference between the given string and the formatted string. |
void |
setOptions(java.util.Map<java.lang.String,java.lang.String> options)
Sets the formatting options for this formatter.
|
public static boolean DEBUG
public boolean previewEnabled
public DefaultCodeFormatter()
public DefaultCodeFormatter(DefaultCodeFormatterOptions options)
public DefaultCodeFormatter(java.util.Map<java.lang.String,java.lang.String> options)
public DefaultCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, java.util.Map<java.lang.String,java.lang.String> options)
public java.lang.String createIndentationString(int indentationLevel)
CodeFormatterThis method needs to be overridden in a subclass.
The default implementation returns an empty string.
createIndentationString in class CodeFormatterindentationLevel - the given indentation levelpublic TextEdit format(int kind,
java.lang.String source,
int offset,
int length,
int indentationLevel,
java.lang.String lineSeparator)
CodeFormattersource,
and returns a text edit that correspond to the difference between the given
string and the formatted string.
It returns null if the given string cannot be formatted.
If the offset position is matching a whitespace, the result can include whitespaces. It would be up to the caller to get rid of preceding whitespaces.
format in class CodeFormatterkind - Use to specify the kind of the code snippet to format. It can
be any of these:
CodeFormatter.K_EXPRESSIONCodeFormatter.K_STATEMENTSCodeFormatter.K_CLASS_BODY_DECLARATIONSCodeFormatter.K_COMPILATION_UNITCodeFormatter.K_MODULE_INFOCodeFormatter.K_UNKNOWNCodeFormatter.K_SINGLE_LINE_COMMENTCodeFormatter.K_MULTI_LINE_COMMENTCodeFormatter.K_JAVA_DOCCodeFormatter.K_COMPILATION_UNIT and since 3.6 for other
kinds unrelated to comments, the CodeFormatter.F_INCLUDE_COMMENTS flag can be
used to format comments on the fly (see the flag documentation for more
detailed explanation).source - the source to formatoffset - the given offset to start recording the edits (inclusive).length - the given length to stop recording the edits (exclusive).indentationLevel - the initial indentation level, used
to shift left/right the entire source fragment. An initial indentation
level of zero or below has no effect.lineSeparator - the line separator to use in formatted source,
if set to null, then the platform default one will be used.CodeFormatter.format(int, java.lang.String, int, int, int, java.lang.String)public TextEdit format(int kind,
java.lang.String source,
IRegion[] regions,
int indentationLevel,
java.lang.String lineSeparator)
source,
and returns a text edit that correspond to the difference between the given string and the formatted string.
It returns null if the given string cannot be formatted.
If an offset position is matching a whitespace, the result can include whitespaces. It would be up to the caller to get rid of preceding whitespaces.
No region in regions must overlap with any other region in regions.
Each region must be within source. There must be at least one region. Regions must be sorted
by their offsets, smaller offset first.
format in class CodeFormatterkind - Use to specify the kind of the code snippet to format. It can
be any of these:
CodeFormatter.K_EXPRESSIONCodeFormatter.K_STATEMENTSCodeFormatter.K_CLASS_BODY_DECLARATIONSCodeFormatter.K_COMPILATION_UNITCodeFormatter.K_MODULE_INFOCodeFormatter.K_UNKNOWNCodeFormatter.K_SINGLE_LINE_COMMENTCodeFormatter.K_MULTI_LINE_COMMENTCodeFormatter.K_JAVA_DOCCodeFormatter.K_COMPILATION_UNIT and since 3.6 for other
kinds unrelated to comments, the CodeFormatter.F_INCLUDE_COMMENTS flag can be
used to format comments on the fly (see the flag documentation for more
detailed explanation).source - the source to formatregions - a set of regions in source to formatindentationLevel - the initial indentation level, used
to shift left/right the entire source fragment. An initial indentation
level of zero or below has no effect.lineSeparator - the line separator to use in formatted source,
if set to null, then the platform default one will be used.public void setOptions(java.util.Map<java.lang.String,java.lang.String> options)
CodeFormatterThe default implementation ignores the options.
setOptions in class CodeFormatteroptions - the options for the formatter