public class WhiteSpace
extends java.lang.Object
'white-space'
.
I.e. document text fragment like '\t \t\t\n\t \t'
may be considered as a continuous white space and may be represented as a WhiteSpace
object.
Provides number of properties that describe encapsulated continuous white space:
Provides ability to build string representation of the managed settings taking into consideration user settings for tabulation vs white space usage, tabulation
size etc.
Not thread-safe.Constructor and Description |
---|
WhiteSpace(int startOffset,
boolean isFirst)
Creates new
WhiteSpace object with the given start offset and a flag that shows if current white space is
the first white space. |
Modifier and Type | Method and Description |
---|---|
void |
arrangeLineFeeds(SpacingImpl spaceProperty,
BlockRangesMap helper)
Tries to ensure that number of line feeds managed by the current
WhiteSpace is consistent to the settings
defined at the given spacing property. |
void |
arrangeSpaces(SpacingImpl spaceProperty)
Tries to arrange
spaces property value to belong to
[min ; SpacingImpl.getMaxSpaces() ] bounds defined by the given spacing object
if totalSpaces property value lays out of the same bounds. |
void |
changeEndOffset(int newEndOffset,
FormattingDocumentModel model,
CommonCodeStyleSettings.IndentOptions options)
Applies new end offset to the current object.
|
boolean |
containsLineFeeds()
Allows to get information if target text document continuous 'white space' represented by the current object contained line feed
symbol(s) initially or contains line feed(s) now.
|
boolean |
containsLineFeedsInitially()
Allows to get information if current object contained line feed(s) initially.
|
void |
ensureLineFeed()
Tries to ensure that current
WhiteSpace object contains at least one line feed. |
boolean |
equalsToString(java.lang.CharSequence ws) |
java.lang.String |
generateWhiteSpace(CommonCodeStyleSettings.IndentOptions options)
Builds string that contains line feeds, white spaces and tabulation symbols known to the current
WhiteSpace object. |
java.lang.StringBuilder |
generateWhiteSpace(CommonCodeStyleSettings.IndentOptions indentOptions,
int offset,
IndentInfo indent) |
int |
getEndOffset() |
int |
getIndentOffset() |
int |
getIndentSpaces()
Provides access to the information about indent white spaces at last line of continuous white space text document
fragment represented by the current
WhiteSpace object. |
IndentInside |
getInitialLastLineIndent() |
int |
getLength() |
int |
getLineFeeds()
Provides access to the line feed symbols number at continuous white space text document fragment represented
by the current
WhiteSpace object. |
int |
getSpaces()
Allows to get information about number of 'pure' white space symbols at the last line of continuous white space document
text fragment represented by the current
WhiteSpace object. |
int |
getStartOffset() |
TextRange |
getTextRange() |
int |
getTotalSpaces() |
boolean |
isIsFirstWhiteSpace() |
boolean |
isIsReadOnly() |
boolean |
isIsSafe() |
boolean |
isKeepFirstColumn() |
boolean |
isLineFeedsAreReadOnly() |
boolean |
isReadOnly() |
void |
removeLineFeeds(SpacingImpl spacing,
BlockRangesMap helper)
Tries to ensure that number of line feeds and white spaces managed by the given
WhiteSpace object is the
same as the one defined by the given 'spacing' object. |
WhiteSpace |
setBeforeCodeBlockEnd(boolean isBeforeCodeBlockEnd) |
void |
setForceSkipTabulationsUsage(boolean skip)
There is a possible case that particular indent info is applied to the code block that is not the first block on a line.
|
void |
setIsFirstWhiteSpace(boolean isFirstWhiteSpace) |
void |
setIsReadOnly(boolean isReadOnly) |
void |
setIsSafe(boolean value) |
void |
setKeepFirstColumn(boolean b) |
void |
setLineFeeds(int lineFeeds) |
void |
setLineFeedsAreReadOnly() |
void |
setLineFeedsAreReadOnly(boolean lineFeedsAreReadOnly) |
void |
setReadOnly(boolean isReadOnly) |
void |
setSpaces(int spaces,
int indent)
Tries to apply given values to
spaces and indentSpaces properties accordingly. |
java.lang.String |
toString() |
public WhiteSpace(int startOffset, boolean isFirst)
WhiteSpace
object with the given start offset and a flag that shows if current white space is
the first white space.
Note: end offset
value is the same as the start offset
for
the newly constructed object. changeEndOffset(int, FormattingDocumentModel, CommonCodeStyleSettings.IndentOptions)
should be
called in order to apply desired end offset.startOffset
- start offset to useisFirst
- flag that shows if current white space is the firstpublic void changeEndOffset(int newEndOffset, FormattingDocumentModel model, CommonCodeStyleSettings.IndentOptions options)
lineFeeds
, spaces
,
indentSpaces
and totalSpaces
properties accordingly;
newEndOffset
- new end offset valuemodel
- formatting model that is used to access to the underlying document textoptions
- indent formatting optionspublic java.lang.String generateWhiteSpace(CommonCodeStyleSettings.IndentOptions options)
WhiteSpace
object.options
- indentation formatting optionsWhiteSpace
objectpublic void setSpaces(int spaces, int indent)
spaces
and indentSpaces
properties accordingly.
The action is not guaranteed to be executed (i.e. the it's not guaranteed that target properties return given values after
this method call - see performModification(Runnable)
for more details).
Moreover, the action is guaranteed to be not executed if keepFirstColumn
property
is unset and target document string doesn't contain spaces.spaces
- new value for the spaces
propertyindent
- new value for the getIndentSpaces()
indentSpaces} propertypublic int getStartOffset()
public int getEndOffset()
public void arrangeSpaces(SpacingImpl spaceProperty)
spaces
property value to belong to
[min
; SpacingImpl.getMaxSpaces()
] bounds defined by the given spacing object
if totalSpaces
property value lays out of the same bounds.
The action is not performed if there are line feeds configured for the
current WhiteSpace
object (getSpaces()
!= 0).spaceProperty
- spacing settings holderpublic void arrangeLineFeeds(SpacingImpl spaceProperty, BlockRangesMap helper)
WhiteSpace
is consistent to the settings
defined at the given spacing property.public void setForceSkipTabulationsUsage(boolean skip)
'align fields in columns'
processing:
public class Test {
private Object o;
private int <white space to align>
i;
}
We may not want to use tabulation characters then even if user configured
their usage
because we can't be sure how many visual columns
will be used for tab representation if there are non-white space symbols before it (IJ editor may use different number of columns
for single tabulation symbol representation).
Hence, we can ask current white space object to avoid using tabulation symbols.skip
- indicates if tabulations symbols usage should be suppressedpublic boolean containsLineFeeds()
true
if this object contained line feeds initially or contains them now; false
otherwisecontainsLineFeedsInitially()
public int getTotalSpaces()
public void ensureLineFeed()
WhiteSpace
object contains at least one line feed.public boolean isReadOnly()
public boolean equalsToString(java.lang.CharSequence ws)
ws
- char sequence to checktrue
if given char sequence is equal to the target document text identified by
start/end offsets managed by the current WhiteSpace
object; false
otherwisepublic void setIsSafe(boolean value)
public boolean containsLineFeedsInitially()
changeEndOffset(int, FormattingDocumentModel, CommonCodeStyleSettings.IndentOptions)
end offset appliance}.true
if current object contained line feeds initially; false
otherwisepublic void removeLineFeeds(SpacingImpl spacing, BlockRangesMap helper)
WhiteSpace
object is the
same as the one defined by the given 'spacing'
object.
This method may be considered a shortcut for calling arrangeLineFeeds(SpacingImpl, BlockRangesMap)
and
arrangeSpaces(SpacingImpl)
.public int getIndentOffset()
public int getSpaces()
WhiteSpace
object.
Note: pay special attention to 'last line'
qualification here. Consider the following target continuous
white space document fragment:
' ws11ws12 'ws21'Here
'wsnm'
is a m-th white space symbol at the n-th line. 'Spaces'
property of
WhiteSpace
object for such white-space text has a value not 2 or 3 but 1.public void setKeepFirstColumn(boolean b)
public void setLineFeedsAreReadOnly()
public void setReadOnly(boolean isReadOnly)
public boolean isIsFirstWhiteSpace()
public boolean isIsSafe()
public boolean isKeepFirstColumn()
public boolean isLineFeedsAreReadOnly()
public void setLineFeedsAreReadOnly(boolean lineFeedsAreReadOnly)
public boolean isIsReadOnly()
public void setIsReadOnly(boolean isReadOnly)
public void setIsFirstWhiteSpace(boolean isFirstWhiteSpace)
public java.lang.StringBuilder generateWhiteSpace(CommonCodeStyleSettings.IndentOptions indentOptions, int offset, IndentInfo indent)
public IndentInside getInitialLastLineIndent()
public int getIndentSpaces()
WhiteSpace
object.
'Indent white space'
here is a white space representation of tabulation symbol. User may define that
he or she wants to use particular number of white spaces instead of tabulation
(CommonCodeStyleSettings.IndentOptions#TAB_SIZE
). So, WhiteSpace
object uses corresponding
number of 'indent white spaces' for each tabulation symbol encountered at target continuous white space text document fragment.
Note: pay special attention to 'last line'
qualification here. Consider the following target
continuous white space document fragment:
' \t\t '\t'Let's consider that
'tab size'
is defined as four white spaces (default setting).
'IndentSpaces'
property of WhiteSpace
object for such white-space text has a value not
8 or 12 but 4, i.e. tabulation symbols from last line
only are counted.public int getLength()
public final int getLineFeeds()
WhiteSpace
object.public void setLineFeeds(int lineFeeds)
public WhiteSpace setBeforeCodeBlockEnd(boolean isBeforeCodeBlockEnd)
public TextRange getTextRange()
public java.lang.String toString()
toString
in class java.lang.Object