public abstract class Indent
extends java.lang.Object
'indent relative to direct parent'
flag. It specified anchor parent block
to use to apply indent.
Consider the following situation:
return a == 0 && (b == 0 || c == 0);Here is the following blocks hierarchy (going from child to parent):
'|| c == 0`
;'b == 0 || c == 0'
;'(b == 0 || c == 0)'
;'a == 0 && (b == 0 || c == 0)'
;'return a == 0 && (b == 0 || c == 0)'
;'|| c == 0'
and '&& (b == 0 || c == 0)'
is 'return a == 0 && (b == 0 || c == 0)'
. That means that the code above is formatted as follows:
return a == 0 && (b == 0 || c == 0);In contrast, it's possible to specify that direct parent block that starts on a line before target child block is used as an anchor. Initial formatting example illustrates such approach. Enforcing indent to children It's possible to configure indent to enforce parent block indent to its children that start new line. Consider the following situation:
foo("test", new Runnable() { public void run() { } }, new Runnable() { public void run() { } } );We want the first
'new Runnable() {...}'
block here to be indented to the method expression list element. However, formatter
uses indents only if the block starts new line. Here the block doesn't start new line ('new Runnable() ...'
), hence
we need to define 'enforce indent to children'
flag in order to instruct formatter to apply parent indent to the sub-blocks.Modifier and Type | Class and Description |
---|---|
static class |
Indent.Type |
Constructor and Description |
---|
Indent() |
Modifier and Type | Method and Description |
---|---|
static Indent |
getAbsoluteLabelIndent()
Returns the "absolute label" indent instance, indicating that the block will be
indented by the number of spaces indicated in the "Project Code Style | General |
Label indent" setting from the leftmost column in the document.
|
static Indent |
getAbsoluteNoneIndent()
Returns the "absolute none" indent instance, indicating that the block will
be placed at the leftmost column in the document.
|
static Indent |
getContinuationIndent()
Returns the "continuation" indent instance, indicating that the block will be indented by
the number of spaces indicated in the "Project Code Style | General | Continuation indent"
setting relative to its parent block.
|
static Indent |
getContinuationIndent(boolean relativeToDirectParent)
Returns the "continuation" indent instance, indicating that the block will be indented by
the number of spaces indicated in the "Project Code Style | General | Continuation indent"
setting relative to its parent block and given
'relative to direct parent' flag. |
static Indent |
getContinuationWithoutFirstIndent()
Returns the "continuation without first" indent instance, indicating that the block will
be indented by the number of spaces indicated in the "Project Code Style | General | Continuation indent"
setting relative to its parent block, unless this block is the first of the children of its
parent having the same indent type.
|
static Indent |
getContinuationWithoutFirstIndent(boolean relativeToDirectParent)
Returns the "continuation without first" indent instance, indicating that the block will
be indented by the number of spaces indicated in the "Project Code Style | General | Continuation indent"
setting relative to its parent block, unless this block is the first of the children of its
parent having the same indent type.
|
static Indent |
getIndent(Indent.Type type,
boolean relativeToDirectParent,
boolean enforceIndentToChildren)
Base factory method for
Indent objects construction, i.e. |
static Indent |
getIndent(Indent.Type type,
int spaces,
boolean relativeToDirectParent,
boolean enforceIndentToChildren)
Base factory method for
Indent objects construction, i.e. |
static Indent |
getLabelIndent()
Returns the "label" indent instance, indicating that the block will be indented by
the number of spaces indicated in the "Project Code Style | General | Label indent"
setting relative to its parent block.
|
static Indent |
getNoneIndent()
Returns the standard "empty indent" instance, indicating that the block is not
indented relative to its parent block.
|
static Indent |
getNormalIndent()
Returns an instance of a regular indent, with the width specified
in "Project Code Style | General | Indent".
|
static Indent |
getNormalIndent(boolean relativeToDirectParent)
Returns an instance of a regular indent, with the width specified
in "Project Code Style | General | Indent" and given
'relative to direct parent' flag |
static Indent |
getSmartIndent(Indent.Type type) |
static Indent |
getSpaceIndent(int spaces)
Returns an indent with the specified width.
|
static Indent |
getSpaceIndent(int spaces,
boolean relativeToDirectParent)
Returns an indent with the specified width and given
'relative to direct parent' flag. |
abstract Indent.Type |
getType() |
public abstract Indent.Type getType()
public static Indent getNormalIndent()
'relative'
to it's direct parent blockgetNormalIndent(boolean)
public static Indent getNormalIndent(boolean relativeToDirectParent)
'relative to direct parent'
flagrelativeToDirectParent
- flag the indicates if current indent object anchors direct block parent (feel free
to get more information about that at class-level javadoc)public static Indent getNoneIndent()
public static Indent getAbsoluteNoneIndent()
public static Indent getAbsoluteLabelIndent()
public static Indent getLabelIndent()
public static Indent getContinuationIndent()
'relative'
to it's direct parent blockgetContinuationIndent(boolean)
public static Indent getContinuationIndent(boolean relativeToDirectParent)
'relative to direct parent'
flag.relativeToDirectParent
- flag the indicates if current indent object anchors direct block parent (feel free
to get more information about that at class-level javadoc)public static Indent getContinuationWithoutFirstIndent()
'relative'
to it's direct parent blockgetContinuationWithoutFirstIndent(boolean)
public static Indent getContinuationWithoutFirstIndent(boolean relativeToDirectParent)
'relative to direct parent'
flag.relativeToDirectParent
- flag the indicates if current indent object anchors direct block parent (feel free
to get more information about that at class-level javadoc)public static Indent getSpaceIndent(int spaces)
'relative'
to it's direct parent blockspaces
- the number of spaces in the indent.getSpaceIndent(int, boolean)
public static Indent getSpaceIndent(int spaces, boolean relativeToDirectParent)
'relative to direct parent'
flag.spaces
- the number of spaces in the indentrelativeToDirectParent
- flag the indicates if current indent object anchors direct block parent (feel free
to get more information about that at class-level javadoc)public static Indent getIndent(Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren)
Indent
objects construction, i.e. all other methods may be expressed in terms of this method.type
- indent typerelativeToDirectParent
- flag the indicates if current indent object anchors direct block parent (feel free
to get more information about that at class-level javadoc)enforceIndentToChildren
- flag the indicates if current indent object should be enforced for multiline block children
(feel free to get more information about that at class-level javadoc)public static Indent getIndent(Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren)
Indent
objects construction, i.e. all other methods may be expressed in terms of this method.type
- indent typespaces
- the number of spaces in the indentrelativeToDirectParent
- flag the indicates if current indent object anchors direct block parent (feel free
to get more information about that at class-level javadoc)enforceIndentToChildren
- flag the indicates if current indent object should be enforced for multiline block children
(feel free to get more information about that at class-level javadoc)public static Indent getSmartIndent(Indent.Type type)