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

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

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

Built on November 22 2009.  |  Portions Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.