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

org.netbeans.modules.editor.indent.spi
Class Context

java.lang.Object
  extended by org.netbeans.modules.editor.indent.spi.Context

public final class Context
extends Object

Context information for both indentation and reformatting.
A common class allows to conveniently share code between indentation and reformatting. isIndent() allows to check whether the actual processing is indentation or reformatting.


Nested Class Summary
static class Context.Region
          Description of the region where the indentation/reformatting should operate.
 
Method Summary
 int caretOffset()
          Return offset of the caret passed to the indentation infrastructure.
 Document document()
          Document for which the reformatting or indenting is being done.
 int endOffset()
          Starting offset of the area to be reformatted or reindented.
 Lookup getLookup()
          Returns lookup which is merge of lookups provided by individual formatters involved in formatting given document.
 List<Context.Region> indentRegions()
          Get list of regions for the given mime-path where the indent or reformat task should operate.
 boolean isIndent()
           
 int lineIndent(int lineStartOffset)
          Determine indent on the given line as a number of spaces.
 int lineStartOffset(int offset)
          Determine start of the line for the given offset.
 String mimePath()
          Get mimePath of this context as string.
 void modifyIndent(int lineStartOffset, int newIndent)
          Modify indent of the line at the offset passed as the parameter.
 void setCaretOffset(int offset)
          Override the offset at which the caret should be placed after the indentation is finished.
 int startOffset()
          Starting offset of the area to be reformatted or reindented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getLookup

public Lookup getLookup()
Returns lookup which is merge of lookups provided by individual formatters involved in formatting given document. This method returns a valid non-null value only after formatting was started, that is in and after IndentTask.reindent() or ReformatTask.reformat().

Returns:
merge lookup provided by individual formatters; will be null before formatting starts
Since:
org.netbeans.modules.editor.indent/2 1.12

document

public Document document()
Document for which the reformatting or indenting is being done.


mimePath

public String mimePath()
Get mimePath of this context as string.
The indent or reformat task should only care about indentation of the code that belongs to this mime path.

Returns:
non-null mime path string.

startOffset

public int startOffset()
Starting offset of the area to be reformatted or reindented.
The value gets updated accordingly when the reformatter performs modifications in the affected area.


endOffset

public int endOffset()
Starting offset of the area to be reformatted or reindented.
The value gets updated accordingly when the reformatter performs modifications in the affected area.


lineStartOffset

public int lineStartOffset(int offset)
                    throws BadLocationException
Determine start of the line for the given offset.

Parameters:
offset - offset in a document being formatted.
Returns:
offset of start of the line.
Throws:
BadLocationException - if the given offset is not within corresponding document's bounds.

lineIndent

public int lineIndent(int lineStartOffset)
               throws BadLocationException
Determine indent on the given line as a number of spaces.

Parameters:
lineStartOffset - start offset of a line where the indent is being determined.
Returns:
indent on the given line. Possible tabs are translated into space count accordingly.
Throws:
BadLocationException - if the given lineStartOffset is not within corresponding document's bounds.

modifyIndent

public void modifyIndent(int lineStartOffset,
                         int newIndent)
                  throws BadLocationException
Modify indent of the line at the offset passed as the parameter.

Parameters:
lineStartOffset - start offset of a line where the indent is being modified.
newIndent - new indent as a number of spaces. The method will possibly use tabs according to the indentation settings for the given document.
Throws:
BadLocationException - if the given lineStartOffset is not within corresponding document's bounds.

caretOffset

public int caretOffset()
Return offset of the caret passed to the indentation infrastructure.
Since it's maintained as a swing position the offset will increase by subsequent modifications by the underlying indent task(s).
If a particular task wishes to modify the offset explicitly it can do so by setCaretOffset(int).

Returns:
current caret offset.

setCaretOffset

public void setCaretOffset(int offset)
                    throws BadLocationException
Override the offset at which the caret should be placed after the indentation is finished.
This is only relevant for indentation not for reformatting.

Parameters:
offset - new offset where the caret should be placed.
Throws:
BadLocationException - if the given offset is outside of underlying document bounds.
See Also:
caretOffset()

indentRegions

public List<Context.Region> indentRegions()
Get list of regions for the given mime-path where the indent or reformat task should operate.
The region boundaries are held as positions so they should update by subsequent inserts/removals.

Returns:
non-null list of regions.

isIndent

public boolean isIndent()

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

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