java.lang.Object
com.intellij.formatting.Indent
- Direct Known Subclasses:
IndentImpl
The indent setting for a formatting model block. Indicates how the block is indented
relative to its parent block.
Relative indents
Number of factory methods of this class use
'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.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IndentReturns 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 IndentReturns the "absolute none" indent instance, indicating that the block will be placed at the leftmost column in the document.static IndentReturns 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 IndentgetContinuationIndent(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 IndentReturns 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 IndentgetContinuationWithoutFirstIndent(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 IndentgetIndent(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren) Base factory method forIndentobjects construction, i.e.static IndentgetIndent(@NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren) Base factory method forIndentobjects construction, i.e.static IndentReturns 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 IndentReturns the standard "empty indent" instance, indicating that the block is not indented relative to its parent block.static IndentReturns an instance of a regular indent, with the width specified in "Project Code Style | General | Indent".static IndentgetNormalIndent(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'flagstatic IndentgetSmartIndent(Indent.Type type) static IndentgetSpaceIndent(int spaces) Returns an indent with the specified width.static IndentgetSpaceIndent(int spaces, boolean relativeToDirectParent) Returns an indent with the specified width and given'relative to direct parent'flag.abstract Indent.TypegetType()
-
Constructor Details
-
Indent
public Indent()
-
-
Method Details
-
getType
-
getNormalIndent
Returns an instance of a regular indent, with the width specified in "Project Code Style | General | Indent". Note: returned indent is not set to be'relative'to it's direct parent block- Returns:
- the indent instance.
- See Also:
-
getNormalIndent
Returns an instance of a regular indent, with the width specified in "Project Code Style | General | Indent" and given'relative to direct parent'flag- Parameters:
relativeToDirectParent- flag the indicates if current indent object anchors direct block parent (feel free to get more information about that at class-level javadoc)- Returns:
- newly created indent instance configured in accordance with the given parameter
-
getNoneIndent
Returns the standard "empty indent" instance, indicating that the block is not indented relative to its parent block.- Returns:
- the empty indent instance.
-
getAbsoluteNoneIndent
Returns the "absolute none" indent instance, indicating that the block will be placed at the leftmost column in the document.- Returns:
- the indent instance.
-
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.- Returns:
- the indent instance.
-
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.- Returns:
- the indent instance.
-
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. Note: returned indent is not set to be'relative'to it's direct parent block- Returns:
- the indent instance.
- See Also:
-
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 and given'relative to direct parent'flag.- Parameters:
relativeToDirectParent- flag the indicates if current indent object anchors direct block parent (feel free to get more information about that at class-level javadoc)- Returns:
- newly created indent instance configured in accordance with the given parameter
-
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. This is used for things like parameter lists, where the first parameter does not have any indent and the remaining parameters are indented by the continuation indent. Note: returned indent is not set to be'relative'to it's direct parent block- Returns:
- the indent instance.
- See Also:
-
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. This is used for things like parameter lists, where the first parameter does not have any indent and the remaining parameters are indented by the continuation indent and given'relative to direct parent'flag.- Parameters:
relativeToDirectParent- flag the indicates if current indent object anchors direct block parent (feel free to get more information about that at class-level javadoc)- Returns:
- newly created indent instance configured in accordance with the given parameter
-
getSpaceIndent
Returns an indent with the specified width. Note: returned indent is not set to be'relative'to it's direct parent block- Parameters:
spaces- the number of spaces in the indent.- Returns:
- the indent instance.
- See Also:
-
getSpaceIndent
Returns an indent with the specified width and given'relative to direct parent'flag.- Parameters:
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)- Returns:
- newly created indent instance configured in accordance with the given parameter
-
getIndent
public static Indent getIndent(@NotNull @NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren) Base factory method forIndentobjects construction, i.e. all other methods may be expressed in terms of this method.- Parameters:
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)- Returns:
- newly created indent configured in accordance with the given arguments
-
getIndent
public static Indent getIndent(@NotNull @NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren) Base factory method forIndentobjects construction, i.e. all other methods may be expressed in terms of this method.- Parameters:
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)- Returns:
- newly created indent configured in accordance with the given arguments
-
getSmartIndent
-