public class CoreFormatterUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
allowBackwardAlignment(LeafBlockWrapper first,
LeafBlockWrapper second,
java.util.Map<AbstractBlockWrapper,java.util.Set<AbstractBlockWrapper>> alignmentMappings)
It's possible to configure alignment in a way to allow
AlignmentFactory.createAlignment(boolean, Alignment.Anchor) backward shift}. |
static FormattingModel |
buildModel(FormattingModelBuilder builder,
PsiElement element,
CodeStyleSettings settings,
FormattingMode mode) |
static FormattingModel |
buildModel(FormattingModelBuilder builder,
PsiElement element,
TextRange range,
CodeStyleSettings settings,
FormattingMode mode) |
static AlignmentImpl |
getAlignment(AbstractBlockWrapper block)
Checks if there is an
AlignmentImpl object that should be used during adjusting
white space of the given block. |
static LeafBlockWrapper |
getFirstLeaf(AbstractBlockWrapper block) |
static IndentData |
getIndent(CommonCodeStyleSettings.IndentOptions options,
AbstractBlockWrapper block,
int tokenBlockStartOffset)
Calculates indent for the given block and target start offset according to the given indent options.
|
static AbstractBlockWrapper |
getIndentedParentBlock(AbstractBlockWrapper block)
Tries to find the closest block that starts before the given block and contains line feeds.
|
static int |
getStartColumn(LeafBlockWrapper block)
Calculates number of non-line feed symbols before the given wrapped block.
|
public static FormattingModel buildModel(FormattingModelBuilder builder, PsiElement element, TextRange range, CodeStyleSettings settings, FormattingMode mode)
public static FormattingModel buildModel(FormattingModelBuilder builder, PsiElement element, CodeStyleSettings settings, FormattingMode mode)
public static AlignmentImpl getAlignment(AbstractBlockWrapper block)
AlignmentImpl
object that should be used during adjusting
white space
of the given block.block
- target blocknull
otherwisepublic static int getStartColumn(LeafBlockWrapper block)
whitespace11 block11 whitespace12 block12 whitespace21 block21 whitespace22 block22Suppose this method is called with the wrapped
'block22'
and 'whitespace21'
contains line feeds but 'whitespace22'
is not. This method returns number of symbols
from 'whitespace21'
after its last line feed symbol plus number of symbols at
block21
plus number of symbols at whitespace22
.block
- target wrapped block to be used at a boundary during counting non-line feed symbols to the left of itpublic static AbstractBlockWrapper getIndentedParentBlock(AbstractBlockWrapper block)
null
otherwisepublic static boolean allowBackwardAlignment(LeafBlockWrapper first, LeafBlockWrapper second, java.util.Map<AbstractBlockWrapper,java.util.Set<AbstractBlockWrapper>> alignmentMappings)
AlignmentFactory.createAlignment(boolean, Alignment.Anchor)
backward shift}.
Example:
class Test { int i; StringBuilder buffer; }It's possible that blocks
'i'
and 'buffer'
should be aligned. As formatter processes document from
start to end that means that requirement to shift block 'i'
to the right is discovered only during
'buffer'
block processing. I.e. formatter returns to the previously processed block ('i'
), modifies
its white space and continues from that location (performs 'backward' shift).
Here is one very important moment - there is a possible case that formatting blocks are configured in a way that they are
combined in explicit cyclic graph.
Example:
blah(bleh(blih, bloh), bluh);Consider that pairs of blocks
'blih'; 'bloh'
and 'bleh', 'bluh'
should be aligned
and backward shift is possible for them. Here is how formatter works:
'blih'
block. Current document state:
blah(bleh(blih, bloh), bluh);
'blih'
block and backward shift is allowed, hence,
'blih'
block is moved to the right and processing contnues from it. Current document state:
blah( bleh(blih, bloh), bluh);
'blih'
block, hence, it's moved
to the right:
blah( bleh(blih, bloh), bluh);
first
- the first aligned blocksecond
- the second aligned blockalignmentMappings
- block aligned mappings infotrue
if backward alignment is possible; false
otherwisepublic static IndentData getIndent(CommonCodeStyleSettings.IndentOptions options, AbstractBlockWrapper block, int tokenBlockStartOffset)
options
- indent options to useblock
- target wrapped blocktokenBlockStartOffset
- target wrapped block offsetpublic static LeafBlockWrapper getFirstLeaf(AbstractBlockWrapper block)