Class DefaultCodeFormatter
-
Field Summary
FieldsFields inherited from class org.aspectj.org.eclipse.jdt.core.formatter.CodeFormatter
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 Summary
ConstructorsConstructorDescriptionDefaultCodeFormatter(Map<String, String> options) DefaultCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, String> options) -
Method Summary
Modifier and TypeMethodDescriptioncreateIndentationString(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.org.eclipse.text.edits.TextEditFormatsource, and returns a text edit that correspond to the difference between the given string and the formatted string.org.eclipse.text.edits.TextEditformat(int kind, String source, org.eclipse.jface.text.IRegion[] regions, int indentationLevel, String lineSeparator) Formatsource, and returns a text edit that correspond to the difference between the given string and the formatted string.voidsetOptions(Map<String, String> options) Sets the formatting options for this formatter.
-
Field Details
-
DEBUG
public static boolean DEBUGDebug trace -
previewEnabled
public boolean previewEnabled
-
-
Constructor Details
-
DefaultCodeFormatter
public DefaultCodeFormatter() -
DefaultCodeFormatter
-
DefaultCodeFormatter
-
DefaultCodeFormatter
public DefaultCodeFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, String> options)
-
-
Method Details
-
createIndentationString
Description copied from class:CodeFormatterAnswers the string that corresponds to the indentation to the given indentation level or an empty string if the indentation cannot be computed.This method needs to be overridden in a subclass.
The default implementation returns an empty string.
- Overrides:
createIndentationStringin classCodeFormatter- Parameters:
indentationLevel- the given indentation level- Returns:
- the string corresponding to the right indentation level
-
format
public org.eclipse.text.edits.TextEdit format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator) Description copied from class:CodeFormatterFormatsource, 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.
- Specified by:
formatin classCodeFormatter- Parameters:
kind- 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_DOC
CodeFormatter.K_COMPILATION_UNITand since 3.6 for other kinds unrelated to comments, theCodeFormatter.F_INCLUDE_COMMENTSflag 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 tonull, then the platform default one will be used.- Returns:
- the text edit
- See Also:
-
format
public org.eclipse.text.edits.TextEdit format(int kind, String source, org.eclipse.jface.text.IRegion[] regions, int indentationLevel, String lineSeparator) Formatsource, 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
regionsmust overlap with any other region inregions. Each region must be within source. There must be at least one region. Regions must be sorted by their offsets, smaller offset first.- Specified by:
formatin classCodeFormatter- Parameters:
kind- 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_DOC
CodeFormatter.K_COMPILATION_UNITand since 3.6 for other kinds unrelated to comments, theCodeFormatter.F_INCLUDE_COMMENTSflag 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 tonull, then the platform default one will be used.- Returns:
- the text edit
-
setOptions
Description copied from class:CodeFormatterSets the formatting options for this formatter.The default implementation ignores the options.
- Overrides:
setOptionsin classCodeFormatter- Parameters:
options- the options for the formatter
-