org.netbeans.modules.editor.indent/2 1.28

org.netbeans.modules.editor.indent.api
Class IndentUtils

java.lang.Object
  extended by org.netbeans.modules.editor.indent.api.IndentUtils

public final class IndentUtils
extends Object

Utility methods related to indentation and reformatting.


Method Summary
static String createIndentString(Document doc, int indent)
          Create (or get from cache) indentation string for the given indent.
static String createIndentString(int indent, boolean expandTabs, int tabSize)
          Create (or get from cache) indentation string for the given indent while knowing whether tabs are exapnded and tabSize value.
static int indentLevelSize(Document doc)
          Get number of spaces that form a single indentation level.
static boolean isExpandTabs(Document doc)
          Get whether the indentation strings should contain hard tabs '\t' or whether they should only contain spaces.
static int lineIndent(Document doc, int lineStartOffset)
          Get indentation of a line in a document as a number of spaces.
static int lineStartOffset(Document doc, int offset)
          Get start offset of a line in a document.
static int tabSize(Document doc)
          Get number of spaces that visually substitute '\t' character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

indentLevelSize

public static int indentLevelSize(Document doc)
Get number of spaces that form a single indentation level.

Returns:
>=0 size of indentation level in spaces.

tabSize

public static int tabSize(Document doc)
Get number of spaces that visually substitute '\t' character.

Returns:
>=0 size corresponding to '\t' character in spaces.

isExpandTabs

public static boolean isExpandTabs(Document doc)
Get whether the indentation strings should contain hard tabs '\t' or whether they should only contain spaces.

Returns:
true if the tabs should be expanded or false if not.

lineStartOffset

public static int lineStartOffset(Document doc,
                                  int offset)
                           throws BadLocationException
Get start offset of a line in a document.

Parameters:
doc - non-null document.
offset - >= 0 offset anywhere on the line.
Throws:
BadLocationException - for invalid offset

lineIndent

public static int lineIndent(Document doc,
                             int lineStartOffset)
                      throws BadLocationException
Get indentation of a line in a document as a number of spaces.

Parameters:
doc - non-null document.
lineStartOffset - >= 0 start offset of a line in the document.
Throws:
BadLocationException - for invalid offset

createIndentString

public static String createIndentString(Document doc,
                                        int indent)
Create (or get from cache) indentation string for the given indent.
The indentation settings (tab-size etc. are determined based on the given document).

Parameters:
doc - document from which the indentation settings will be retrieved.
indent - >=0 indentation in number of spaces.
Returns:
indentation string containing tabs and spaces according to the document's settings (tab-size etc.).

createIndentString

public static String createIndentString(int indent,
                                        boolean expandTabs,
                                        int tabSize)
Create (or get from cache) indentation string for the given indent while knowing whether tabs are exapnded and tabSize value.

Parameters:
indent - >=0 indentation in number of spaces.
expandTabs - true if no tab characters '\t' should be used for indentation string (only spaces will be used).
tabSize - number of spaces equal to each '\t' character used in indentation string.
This only applies if expandTabs == false.
For example if indent == 20 and tabSize == 8 then indent string would contain two tabs followed by four spaces.
Returns:
indentation string containing tabs and spaces according to the given parameters
Since:
1.22

org.netbeans.modules.editor.indent/2 1.28

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.