类 Indent

java.lang.Object
com.intellij.formatting.Indent
直接已知子类:
IndentImpl

public abstract class Indent extends Object
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)';

By default formatter applies block indent to the first block ancestor (direct or indirect) that starts on a new line. That means that such an ancestor for both blocks '|| 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.
  • 嵌套类概要

    嵌套类
    修饰符和类型
    说明
    static final class 
     
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static Indent
    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
    Returns the "absolute none" indent instance, indicating that the block will be placed at the leftmost column in the document.
    static Indent
    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
    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(@NotNull Indent.Type type, boolean relativeToDirectParent, boolean enforceIndentToChildren)
    Base factory method for Indent objects construction, i.e. all other methods may be expressed in terms of this method.
    static Indent
    getIndent(@NotNull Indent.Type type, int spaces, boolean relativeToDirectParent, boolean enforceIndentToChildren)
    Base factory method for Indent objects construction, i.e. all other methods may be expressed in terms of this method.
    static Indent
    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
    Returns the standard "empty indent" instance, indicating that the block is not indented relative to its parent block.
    static Indent
    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
     
    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
     

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • Indent

      public Indent()
  • 方法详细资料

    • getType

      public abstract Indent.Type getType()
    • getNormalIndent

      public static Indent 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

      返回:
      the indent instance.
      另请参阅:
    • getNormalIndent

      public 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
      参数:
      relativeToDirectParent - flag the indicates if current indent object anchors direct block parent (feel free to get more information about that at class-level javadoc)
      返回:
      newly created indent instance configured in accordance with the given parameter
    • getNoneIndent

      public static Indent getNoneIndent()
      Returns the standard "empty indent" instance, indicating that the block is not indented relative to its parent block.
      返回:
      the empty indent instance.
    • getAbsoluteNoneIndent

      public static Indent getAbsoluteNoneIndent()
      Returns the "absolute none" indent instance, indicating that the block will be placed at the leftmost column in the document.
      返回:
      the indent instance.
    • getAbsoluteLabelIndent

      public 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.
      返回:
      the indent instance.
    • getLabelIndent

      public 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.
      返回:
      the indent instance.
    • getContinuationIndent

      public 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.

      Note: returned indent is not set to be 'relative' to it's direct parent block

      返回:
      the indent instance.
      另请参阅:
    • getContinuationIndent

      public 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.
      参数:
      relativeToDirectParent - flag the indicates if current indent object anchors direct block parent (feel free to get more information about that at class-level javadoc)
      返回:
      newly created indent instance configured in accordance with the given parameter
    • getContinuationWithoutFirstIndent

      public 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. 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

      返回:
      the indent instance.
      另请参阅:
    • getContinuationWithoutFirstIndent

      public 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. 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.
      参数:
      relativeToDirectParent - flag the indicates if current indent object anchors direct block parent (feel free to get more information about that at class-level javadoc)
      返回:
      newly created indent instance configured in accordance with the given parameter
    • getSpaceIndent

      public static Indent getSpaceIndent(int spaces)
      Returns an indent with the specified width.

      Note: returned indent is not set to be 'relative' to it's direct parent block

      参数:
      spaces - the number of spaces in the indent.
      返回:
      the indent instance.
      另请参阅:
    • getSpaceIndent

      public static Indent getSpaceIndent(int spaces, boolean relativeToDirectParent)
      Returns an indent with the specified width and given 'relative to direct parent' flag.
      参数:
      spaces - the number of spaces in the indent
      relativeToDirectParent - flag the indicates if current indent object anchors direct block parent (feel free to get more information about that at class-level javadoc)
      返回:
      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 for Indent objects construction, i.e. all other methods may be expressed in terms of this method.
      参数:
      type - indent type
      relativeToDirectParent - 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)
      返回:
      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 for Indent objects construction, i.e. all other methods may be expressed in terms of this method.
      参数:
      type - indent type
      spaces - the number of spaces in the indent
      relativeToDirectParent - 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)
      返回:
      newly created indent configured in accordance with the given arguments
    • getSmartIndent

      public static Indent getSmartIndent(Indent.Type type)