public abstract class AbstractWhiteSpaceFormattingStrategy extends java.lang.Object implements WhiteSpaceFormattingStrategy
WhiteSpaceFormattingStrategy
implementation that doesn't replace default strategy and doesn't
adjust white space andConstructor and Description |
---|
AbstractWhiteSpaceFormattingStrategy() |
Modifier and Type | Method and Description |
---|---|
boolean |
addWhitespace(ASTNode treePrev,
LeafElement whiteSpaceElement)
Allows to customize addition of the given white space element to the AST referenced by the given node.
|
java.lang.CharSequence |
adjustWhiteSpaceIfNecessary(java.lang.CharSequence whiteSpaceText,
java.lang.CharSequence text,
int startOffset,
int endOffset,
CodeStyleSettings codeStyleSettings,
ASTNode nodeAfter)
Main formatter's duty is to tweak white space symbols (add/remove/modify them).
|
java.lang.CharSequence |
adjustWhiteSpaceIfNecessary(java.lang.CharSequence whiteSpaceText,
PsiElement startElement,
int startOffset,
int endOffset,
CodeStyleSettings codeStyleSettings)
|
boolean |
containsWhitespacesOnly(ASTNode node)
Allows to answer if given node should be treated as white space node.
|
boolean |
replaceDefaultStrategy() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
check
public AbstractWhiteSpaceFormattingStrategy()
public boolean replaceDefaultStrategy()
replaceDefaultStrategy
in interface WhiteSpaceFormattingStrategy
true
if default white space strategy used by formatter should be replaced by the current one;
false
to indicate that current strategy should be used in composition with default strategy
if any, i.e. particular symbols sequence should be considered as white spaces if any of composed
strategies defines sopublic java.lang.CharSequence adjustWhiteSpaceIfNecessary(java.lang.CharSequence whiteSpaceText, java.lang.CharSequence text, int startOffset, int endOffset, CodeStyleSettings codeStyleSettings, ASTNode nodeAfter)
WhiteSpaceFormattingStrategy
'\'
symbol is
used inside multiline expression in case of Python etc.
This method defines a callback that allows to modify white space symbols to use for replacing particular
document symbols sub-sequence if necessary.adjustWhiteSpaceIfNecessary
in interface WhiteSpaceFormattingStrategy
whiteSpaceText
- white space text to use by default for replacing sub-sequence of the given texttext
- target text which region is to be replaced by the given white space symbolsstartOffset
- start offset to use with the given text (inclusive)endOffset
- end offset to use with the given text (exclusive)codeStyleSettings
- the code style settingsnodeAfter
- the AST node following the whitespace, if known[startOffset; endOffset)
sub-sequence of the given textpublic java.lang.CharSequence adjustWhiteSpaceIfNecessary(java.lang.CharSequence whiteSpaceText, PsiElement startElement, int startOffset, int endOffset, CodeStyleSettings codeStyleSettings)
WhiteSpaceFormattingStrategy
WhiteSpaceFormattingStrategy.adjustWhiteSpaceIfNecessary(CharSequence, CharSequence, int, int, com.intellij.psi.codeStyle.CodeStyleSettings, com.intellij.lang.ASTNode)
.
There is a possible case that particular changes are performed to PSI tree and it's not yet synchronized with the underlying
document. Hence, we can't directly work with document char sequence but need to traverse PSI tree instead. I.e. we start with
particular PSI element that contains given start offset and process its right siblings/relatives until given end offset
is reached.adjustWhiteSpaceIfNecessary
in interface WhiteSpaceFormattingStrategy
whiteSpaceText
- white space text to use by default for replacing sub-sequence of the given textstartElement
- PSI element that contains given start offsetstartOffset
- start offset to use with the given text (inclusive)endOffset
- end offset to use with the given text (exclusive)codeStyleSettings
- the code style settings[startOffset; endOffset)
sub-sequence of the given textpublic boolean containsWhitespacesOnly(ASTNode node)
WhiteSpaceFormattingStrategy
containsWhitespacesOnly
in interface WhiteSpaceFormattingStrategy
node
- node to checktrue
if given node should be treated as white space; false
otherwisepublic boolean addWhitespace(ASTNode treePrev, LeafElement whiteSpaceElement)
WhiteSpaceFormattingStrategy
addWhitespace
in interface WhiteSpaceFormattingStrategy
treePrev
- target node to use as an anchor for inserting given white space elementwhiteSpaceElement
- target white space element to inserttrue
if given white space element was added in a custom way during the current method call
processing;
false
as an indicator that given white space element has not been inserted during the
current method call