com.intellij.formatting
Interface Block


public interface Block

Describes a single block in the FormattingModel.

See Also:
FormattingModel.getRootBlock()

Method Summary
 Alignment getAlignment()
          Returns an alignment object indicating how this block is aligned with other blocks.
 ChildAttributes getChildAttributes(int newChildIndex)
          Returns the alignment and indent attributes which are applied to a new block inserted at the specified position in the list of children of this block.
 Indent getIndent()
          Returns an indent object indicating how this block is indented relative to its parent block.
 Spacing getSpacing(Block child1, Block child2)
          Returns a spacing object indicating what spaces and/or line breaks are added between two specified children of this block.
 java.util.List<Block> getSubBlocks()
          Returns the list of child blocks for the specified block.
 TextRange getTextRange()
          Returns the text range covered by the block.
 Wrap getWrap()
          Returns a wrap object indicating the conditions under which a line break is inserted before this block when formatting, if the block extends beyond the right margin.
 boolean isIncomplete()
          Checks if the current block is incomplete (contains elements that the user will probably type but has not yet typed).
 boolean isLeaf()
          Returns true if the specified block may not contain child blocks.
 

Method Detail

getTextRange

@NotNull
TextRange getTextRange()
Returns the text range covered by the block.

Returns:
the text range.

getSubBlocks

@NotNull
java.util.List<Block> getSubBlocks()
Returns the list of child blocks for the specified block. Important: The same list of blocks must be returned when getSubBlocks() is repeatedly called on a particular Block instance.

Returns:
the child block list.
See Also:
isLeaf()

getWrap

@Nullable
Wrap getWrap()
Returns a wrap object indicating the conditions under which a line break is inserted before this block when formatting, if the block extends beyond the right margin.

Returns:
the wrap object, or null if the line break is never inserted.
See Also:
Wrap.createWrap(WrapType, boolean), Wrap.createChildWrap(Wrap, WrapType, boolean)

getIndent

@Nullable
Indent getIndent()
Returns an indent object indicating how this block is indented relative to its parent block.

Returns:
the indent object, or null if the default indent ("continuation without first") should be used.
See Also:
Indent.getContinuationWithoutFirstIndent()

getAlignment

@Nullable
Alignment getAlignment()
Returns an alignment object indicating how this block is aligned with other blocks. Blocks which return the same alignment object instance from the getAlignment method are aligned with each other.

Returns:
the alignment object instance, or null if no alignment is required for the block.

getSpacing

@Nullable
Spacing getSpacing(Block child1,
                            Block child2)
Returns a spacing object indicating what spaces and/or line breaks are added between two specified children of this block.

Parameters:
child1 - the first child for which spacing is requested.
child2 - the second child for which spacing is requested.
Returns:
the spacing instance, or null if no special spacing is required. If null is returned, the formatter does not insert or delete spaces between the child blocks, but may insert a line break if the line wraps at the position between the child blocks.
See Also:
Spacing.createSpacing(int, int, int, boolean, int), Spacing.getReadOnlySpacing()

getChildAttributes

@NotNull
ChildAttributes getChildAttributes(int newChildIndex)
Returns the alignment and indent attributes which are applied to a new block inserted at the specified position in the list of children of this block. Used for performing automatic indent when Enter is pressed.

Parameters:
newChildIndex - the index where a new child is inserted.
Returns:
the object containing the indent and alignment settings for the new child.

isIncomplete

boolean isIncomplete()
Checks if the current block is incomplete (contains elements that the user will probably type but has not yet typed). For example, a parameter list is incomplete if it does not have the trailing parenthesis, and a statement is incomplete if it does not have the trailing semicolon. Used to determine the block for which getChildAttributes(int) is called when Enter is pressed: if the block immediately before the cursor is incomplete, the method is called for that block; otherwise, the method is called for the parent of that block.

Returns:
true if the block is incomplete, false otherwise.

isLeaf

boolean isLeaf()
Returns true if the specified block may not contain child blocks. Used as an optimization to avoid building the complete formatting model through calls to getSubBlocks().

Returns:
true if the block is a leaf block and may not contain child blocks, false otherwise.