com.intellij.formatting
Class Spacing

java.lang.Object
  extended by com.intellij.formatting.Spacing

public abstract class Spacing
extends java.lang.Object

The spacing setting for a formatting model block. Indicates the number of spaces and/or line breaks that should be inserted between the specified children of the specified block.

See Also:
Block.getSpacing(Block, Block)

Constructor Summary
Spacing()
           
 
Method Summary
static Spacing createDependentLFSpacing(int minSpaces, int maxSpaces, TextRange dependance, boolean keepLineBreaks, int keepBlankLines)
          Creates a spacing setting instance which inserts a line break if the specified text range also contains a line break.
static Spacing createKeepingFirstColumnSpacing(int minSpaces, int maxSpaces, boolean keepLineBreaks, int keepBlankLines)
          Creates a spacing setting instance that keeps the second child on the first column if it was there before the formatting, but may indent the second child if it was not in the first column.
static Spacing createSafeSpacing(boolean keepLineBreaks, int keepBlankLines)
          Creates a spacing setting instance which preserves the presence of spaces between the blocks but, if spaces are present, may insert or delete the spaces.
static Spacing createSpacing(int minSpaces, int maxSpaces, int minLineFeeds, boolean keepLineBreaks, int keepBlankLines)
          Creates a regular spacing setting instance.
static Spacing getReadOnlySpacing()
          Returns a spacing setting instance indicating that no line breaks or spaces can be inserted or removed by the formatter between the specified two blocks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Spacing

public Spacing()
Method Detail

createSpacing

public static Spacing createSpacing(int minSpaces,
                                    int maxSpaces,
                                    int minLineFeeds,
                                    boolean keepLineBreaks,
                                    int keepBlankLines)
Creates a regular spacing setting instance.

Parameters:
minSpaces - The minimum number of spaces that should be present between the blocks to which the spacing setting instance is related. Spaces are inserted if there are less than this amount of spaces in the document.
maxSpaces - The maximum number of spaces that should be present between the blocks to which the spacing setting instance is related, or Integer.MAX_VALUE if the number of spaces is not limited. Spaces are deleted if there are more than this amount of spaces in the document.
minLineFeeds - The minimum number of line breaks that should be present between the blocks to which the spacing setting instance is related.
keepLineBreaks - Whether the existing line breaks between the blocks should be preserved.
keepBlankLines - Whether the existing blank lines between the blocks should be preserved.
Returns:
the spacing setting instance.

getReadOnlySpacing

public static Spacing getReadOnlySpacing()
Returns a spacing setting instance indicating that no line breaks or spaces can be inserted or removed by the formatter between the specified two blocks.

Returns:
the spacing setting instance.

createDependentLFSpacing

public static Spacing createDependentLFSpacing(int minSpaces,
                                               int maxSpaces,
                                               TextRange dependance,
                                               boolean keepLineBreaks,
                                               int keepBlankLines)
Creates a spacing setting instance which inserts a line break if the specified text range also contains a line break. Used for formatting rules like the "next line if wrapped" brace placement.

Parameters:
minSpaces - The minimum number of spaces that should be present between the blocks to which the spacing setting instance is related. Spaces are inserted if there are less than this amount of spaces in the document.
maxSpaces - The maximum number of spaces that should be present between the blocks to which the spacing setting instance is related, or Integer.MAX_VALUE if the number of spaces is not limited. Spaces are deleted if there are more than this amount of spaces in the document.
dependance - The text range checked for the presense of line breaks.
keepLineBreaks - Whether the existing line breaks between the blocks should be preserved.
keepBlankLines - Whether the existing blank lines between the blocks should be preserved.
Returns:
the spacing setting instance.

createSafeSpacing

public static Spacing createSafeSpacing(boolean keepLineBreaks,
                                        int keepBlankLines)
Creates a spacing setting instance which preserves the presence of spaces between the blocks but, if spaces are present, may insert or delete the spaces. Used, for example, for HTML formatting where the presence of a whitespace is significant but the specific number of whitespaces at a given location is not.

Parameters:
keepLineBreaks - Whether the existing line breaks between the blocks should be preserved.
keepBlankLines - Whether the existing blank lines between the blocks should be preserved.
Returns:
the spacing setting instance.

createKeepingFirstColumnSpacing

public static Spacing createKeepingFirstColumnSpacing(int minSpaces,
                                                      int maxSpaces,
                                                      boolean keepLineBreaks,
                                                      int keepBlankLines)
Creates a spacing setting instance that keeps the second child on the first column if it was there before the formatting, but may indent the second child if it was not in the first column. Used for implementing the "Keep when Reformatting | Comment in first column" setting.

Parameters:
minSpaces - The minimum number of spaces that should be present between the blocks to which the spacing setting instance is related. Spaces are inserted if there are less than this amount of spaces in the document.
maxSpaces - The maximum number of spaces that should be present between the blocks to which the spacing setting instance is related, or Integer.MAX_VALUE if the number of spaces is not limited. Spaces are deleted if there are more than this amount of spaces in the document.
keepLineBreaks - Whether the existing line breaks between the blocks should be preserved.
keepBlankLines - Whether the existing blank lines between the blocks should be preserved.
Returns:
the spacing setting instance.