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

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

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

public final class Indent
extends Object

Reindentation of a single or multiple lines in the document means fixing of the line's indent only but does not do any other code beautification.
The following pattern should be used:

 indent.lock();
 try {
     doc.atomicLock();
     try {
         indent.reindent(...);
     } finally {
         doc.atomicUnlock();
     }
 } finally {
     indent.unlock();
 }
 


Method Summary
static Indent get(Document doc)
          Get the indentation for the given document.
 int indentNewLine(int offset)
          Creates new line at offset and reindents it.
 void lock()
          Clients should call this method before acquiring of document's write lock.
 void reindent(int offset)
          Correct indentation on a single line determined by the given offset.
 void reindent(int startOffset, int endOffset)
          Correct indentation of all lines in the given offset range.
 void unlock()
          Clients should call this method after releasing of document's write lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static Indent get(Document doc)
Get the indentation for the given document.

Parameters:
doc - non-null document.
Returns:
non-null indentation.

lock

public void lock()
Clients should call this method before acquiring of document's write lock.
The following pattern should be used:
 indent.lock();
 try {
     doc.atomicLock();
     try {
         indent.reindent(...);
     } finally {
         doc.atomicUnlock();
     }
 } finally {
     indent.unlock();
 }
 


unlock

public void unlock()
Clients should call this method after releasing of document's write lock.
The following pattern should be used:
 indent.lock();
 try {
     doc.atomicLock();
     try {
         indent.reindent(...);
     } finally {
         doc.atomicUnlock();
     }
 } finally {
     indent.unlock();
 }
 


reindent

public void reindent(int offset)
              throws BadLocationException
Correct indentation on a single line determined by the given offset.
Typically it is called after newline gets inserted or when a line is reindented explicitly (e.g. by pressing TAB key in emacs mode).
This method will fallback to the editor formatting infrastructure in case there are no registered indent or reformat factories.

Parameters:
offset - >=0 any offset on the line to be reformatted.
Throws:
BadLocationException - in case the indenter attempted to insert/remove at an invalid offset or e.g. into a guarded section.

reindent

public void reindent(int startOffset,
                     int endOffset)
              throws BadLocationException
Correct indentation of all lines in the given offset range.
This method will fallback to the editor formatting infrastructure in case there are no registered indent or reformat factories.

Parameters:
startOffset - >=0 any offset on a first line to be reformatted.
endOffset - >=startOffset any offset (including end offset) on a last line to be reformatted.
Throws:
BadLocationException - in case the indenter attempted to insert/remove at an invalid offset or e.g. into a guarded section.

indentNewLine

public int indentNewLine(int offset)
                  throws BadLocationException
Creates new line at offset and reindents it.

This method will insert a line break (ie EOL character) at the specified offset and then reindent the newly created line. The method will return the offset of the indented beginning of the new line. That is the offset where the new text should appear when typing in the document.

Parameters:
offset - The document offset where the new line will be created.
Returns:
The offset of the first non-white character (or the EOL character) on the new line. This is basically where the caret should be moved to.
Throws:
BadLocationException
Since:
1.10

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

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