|
org.netbeans.modules.editor.lib/1 1.14.0 3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.Writer
org.netbeans.editor.ext.FormatWriter
public final class FormatWriter
Formatting writter accepts the input-text, formats it and writes the output to the underlying writer. The data written to the writer are immediately splitted into token-items and the chain of token-items is created from them. Then the writer then waits for the flush() or close() method call which then makes the real formatting. The formatting is done through going through the format-layers registered in ExtFormatter and asking them for formatting. These layers go through the chain and possibly add or remove the tokens as necessary. The good thing is that the layers can ask the tokens before those written to the writer. In that case they will get the tokens from the document at point the formatting should be done. The advantage is that the chain is compact so the border between the tokens written to the writer and those that come from the document is invisible.
Field Summary | |
---|---|
static boolean |
debug
Whether debug messages should be displayed |
static boolean |
debugModify
Whether debug messages should be displayed |
Fields inherited from class java.io.Writer |
---|
lock |
Method Summary | |
---|---|
boolean |
canInsertToken(TokenItem beforeToken)
Check whether a new token can be inserted into the chain before the given token-item. |
boolean |
canModifyToken(TokenItem token,
int offset)
Whether the token can be modified either by insertion or removal at the given offset. |
boolean |
canRemoveToken(TokenItem token)
Whether the token-item can be removed. |
boolean |
canSplitEnd(TokenItem token,
int endLength)
|
boolean |
canSplitStart(TokenItem token,
int startLength)
|
String |
chainToString(TokenItem token)
|
String |
chainToString(TokenItem token,
int maxDocumentTokens)
Debug the current state of the chain. |
void |
checkChain()
Check the chain whether it's OK. |
void |
close()
|
TokenItem |
findFirstToken(TokenItem token)
Find the first token in the chain. |
TokenItem |
findNonEmptyToken(TokenItem token,
boolean backward)
Check whether the given token has empty text and if so start searching for token with non-empty text in the given direction. |
void |
flush()
|
Document |
getDocument()
Get the document being formatted |
FormatTokenPosition |
getFormatStartPosition()
Get the first token that should be formatted. |
ExtFormatter |
getFormatter()
|
int |
getIndentShift()
|
TokenItem |
getLastToken()
Get the last token in the chain. |
int |
getOffset()
Get the starting offset of the formatting |
FormatTokenPosition |
getPosition(TokenItem token,
int offset,
Position.Bias bias)
Get the token-position that corresponds to the given offset inside the given token. |
FormatTokenPosition |
getTextStartPosition()
Get the first position that doesn't belong to the document. |
void |
insertString(TokenItem token,
int offset,
String text)
Insert the text at the offset inside the given token. |
TokenItem |
insertToken(TokenItem beforeToken,
TokenID tokenID,
TokenContextPath tokenContextPath,
String tokenImage)
Create a new token-item and insert it before the token-item given as parameter. |
boolean |
isAfter(FormatTokenPosition testedPosition,
FormatTokenPosition afterPosition)
Checks whether the tested position is after some other position. |
boolean |
isAfter(TokenItem testedToken,
TokenItem afterToken)
It checks whether the tested token is after some other token in the chain. |
boolean |
isChainModified()
Return the flag that is set automatically if the new removal or insertion into chain occurs. |
boolean |
isChainStartPosition(FormatTokenPosition pos)
Check whether this is the first position in the chain of tokens. |
boolean |
isIndentOnly()
Whether the purpose of this writer is to find the proper indentation instead of formatting the tokens. |
boolean |
isRestartFormat()
Return whether the layer requested to restart the format. |
void |
remove(TokenItem token,
int offset,
int length)
Remove the length of the characters at the given offset inside the given token. |
void |
removeToken(TokenItem token)
Remove the token-item from the chain. |
void |
setChainModified(boolean chainModified)
|
void |
setIndentOnly(boolean indentOnly)
Sets whether the purpose of this writer is to find the proper indentation instead of formatting the tokens. |
void |
setIndentShift(int indentShift)
|
void |
setRestartFormat(boolean restartFormat)
|
TokenItem |
splitEnd(TokenItem token,
int endLength,
TokenID newTokenID,
TokenContextPath newTokenContextPath)
Create the additional token from the text at the end of the given token. |
TokenItem |
splitStart(TokenItem token,
int startLength,
TokenID newTokenID,
TokenContextPath newTokenContextPath)
Create the additional token from the text at the start of the given token. |
void |
write(char[] cbuf,
int off,
int len)
|
void |
write(char[] cbuf,
int off,
int len,
int[] saveOffsets,
Position.Bias[] saveBiases)
|
Methods inherited from class java.io.Writer |
---|
append, append, append, write, write, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final boolean debug
public static final boolean debugModify
Method Detail |
---|
public final ExtFormatter getFormatter()
public final Document getDocument()
public final int getOffset()
public final boolean isIndentOnly()
public void setIndentOnly(boolean indentOnly)
isIndentOnly()
public FormatTokenPosition getFormatStartPosition()
public FormatTokenPosition getTextStartPosition()
public TokenItem getLastToken()
public TokenItem findFirstToken(TokenItem token)
token
- token from which the search for previous tokens will
start. It can be null in which case the last document token or last
token are attempted instead.public boolean isAfter(TokenItem testedToken, TokenItem afterToken)
testedToken
- token to test (whether it's after afterToken or not)afterToken
- token to be compared to the testedToken
public boolean isAfter(FormatTokenPosition testedPosition, FormatTokenPosition afterPosition)
public TokenItem findNonEmptyToken(TokenItem token, boolean backward)
token
- token to start to search from. If it has zero
length, the search for non-empty token is performed in the given
direction.public boolean canInsertToken(TokenItem beforeToken)
beforeToken
- token-item before which
the new token-item is about to be inserted. It can
be null to append the new token to the end of the chain.public TokenItem insertToken(TokenItem beforeToken, TokenID tokenID, TokenContextPath tokenContextPath, String tokenImage)
beforeToken
- token-item before which
the new token-item is about to be inserted. It can
be null to append the new token to the end of the chain.tokenID
- token-id of the new token-itemtokenContextPath
- token-context-path of the new token-itemtokenImage
- image of the new token-itempublic boolean canRemoveToken(TokenItem token)
public void removeToken(TokenItem token)
public boolean canSplitStart(TokenItem token, int startLength)
public TokenItem splitStart(TokenItem token, int startLength, TokenID newTokenID, TokenContextPath newTokenContextPath)
token
- token being split.startLength
- length of the text at the begining of the token
for which the additional token will be created.tokenID
- token-id that will be assigned to the new tokentokenContextPath
- token-context-path that will be assigned
to the new tokenpublic boolean canSplitEnd(TokenItem token, int endLength)
public TokenItem splitEnd(TokenItem token, int endLength, TokenID newTokenID, TokenContextPath newTokenContextPath)
token
- token being split.endLength
- length of the text at the end of the token
for which the additional token will be created.tokenID
- token-id that will be assigned to the new tokentokenContextPath
- token-context-path that will be assigned
to the new tokenpublic boolean canModifyToken(TokenItem token, int offset)
public void insertString(TokenItem token, int offset, String text)
token
- token in which the text is inserted.offset
- offset at which the text will be inserted.text
- text that will be inserted at the offset.public void remove(TokenItem token, int offset, int length)
token
- token in which the text is removed.offset
- offset at which the text will be removed.length
- length of the removed text.public FormatTokenPosition getPosition(TokenItem token, int offset, Position.Bias bias)
token
- token in which the position is created.offset
- inside the token at which the position
will be created.bias
- forward or backward biaspublic boolean isChainStartPosition(FormatTokenPosition pos)
public void write(char[] cbuf, int off, int len) throws IOException
IOException
public void write(char[] cbuf, int off, int len, int[] saveOffsets, Position.Bias[] saveBiases) throws IOException
IOException
public boolean isChainModified()
public void setChainModified(boolean chainModified)
public boolean isRestartFormat()
public void setRestartFormat(boolean restartFormat)
public int getIndentShift()
public void setIndentShift(int indentShift)
public void flush() throws IOException
IOException
public void close() throws IOException
IOException
public void checkChain()
public String chainToString(TokenItem token)
public String chainToString(TokenItem token, int maxDocumentTokens)
token
- mark this token as current one. It can be null.maxDocumentTokens
- how many document tokens should be shown.
|
org.netbeans.modules.editor.lib/1 1.14.0 3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |