站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

FormatSupport (Editor Library) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.lib/1 1.14.0 3

org.netbeans.editor.ext
Class FormatSupport

java.lang.Object
  extended by org.netbeans.editor.ext.FormatSupport
Direct Known Subclasses:
ExtFormatSupport

public class FormatSupport
extends Object

Format support presents a set of operations over the format-writer that is specific for the given set of formatting layers. It presents the way how to extend the low level methods offered by the format-writer. In general there can be more format-layers that use one type of the format-support.


Constructor Summary
FormatSupport(FormatWriter formatWriter)
           
 
Method Summary
 boolean canInsertToken(TokenItem beforeToken)
          Delegation to the same method in format-writer.
 boolean canModifyWhitespace(TokenItem inToken)
          Check whether the given token enables modifying of a whitespace in it.
 boolean canRemoveToken(TokenItem token)
          Whether the token-item can be removed.
 boolean canReplaceToken(TokenItem token)
          Whether the given token can be replaced or not.
 String chainToString(TokenItem token)
          Debug the current state of the chain.
 String chainToString(TokenItem token, int maxDocumentTokens)
           
 FormatTokenPosition changeLineIndent(FormatTokenPosition pos, int indent)
          Change the indentation of the line.
 boolean expandTabs()
           
 TokenItem findFirstToken(TokenItem token)
          Get the first token in chain.
 FormatTokenPosition findLineEnd(FormatTokenPosition pos)
          Get the ending position of the line.
 FormatTokenPosition findLineEndWhitespace(FormatTokenPosition pos)
          Return the ending whitespace on the line or null if there's no such token on the given line.
 FormatTokenPosition findLineFirstNonWhitespace(FormatTokenPosition pos)
          Return the first non-whitespace character on the line or null if there is no non-WS char on the line.
 FormatTokenPosition findLineStart(FormatTokenPosition pos)
          Get the starting position of the line.
 FormatTokenPosition findNextEOL(FormatTokenPosition pos)
          Get the first EOL in forward direction.
 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.
 FormatTokenPosition findNonWhitespace(FormatTokenPosition startPosition, FormatTokenPosition limitPosition, boolean stopOnEOL, boolean backward)
          Get the first non-whitespace position in the given direction.
 FormatTokenPosition findPreviousEOL(FormatTokenPosition pos)
          Get the first EOL in backward direction.
 FormatTokenPosition getFormatStartPosition()
          Delegation to the same method in format-writer.
 FormatWriter getFormatWriter()
          Getter for the format-writer associated with this format-support.
 int getIndentShift()
          Delegation to the same method in format-writer.
 String getIndentString(int indent)
          This delegates to the same method in formatter.
 FormatTokenPosition getLastPosition()
           
 TokenItem getLastToken()
          Delegation to the same method in format-writer.
 int getLineIndent(FormatTokenPosition pos, boolean zeroForWSLine)
          Get the indentation of the line.
 FormatTokenPosition getNextPosition(FormatTokenPosition pos)
          Get the next successive token-position after the given one.
 FormatTokenPosition getNextPosition(FormatTokenPosition pos, Position.Bias bias)
          Get the token-position preceeding the given one.
 FormatTokenPosition getNextPosition(TokenItem token, int offset)
           
 FormatTokenPosition getNextPosition(TokenItem token, int offset, Position.Bias bias)
          Get the next position of the position given by parameters.
 FormatTokenPosition getPosition(TokenItem token, int offset)
          Get the token position that corresponds to the given token and offset.
 FormatTokenPosition getPosition(TokenItem token, int offset, Position.Bias bias)
           
 FormatTokenPosition getPreviousPosition(FormatTokenPosition pos)
          Get the token-position preceeding the given one.
 FormatTokenPosition getPreviousPosition(FormatTokenPosition pos, Position.Bias bias)
          Get the token-position preceeding the given one.
 FormatTokenPosition getPreviousPosition(TokenItem token, int offset)
           
 FormatTokenPosition getPreviousPosition(TokenItem token, int offset, Position.Bias bias)
          Get the previous position of the position given by parameters.
 TokenItem getPreviousToken(TokenItem token)
          Get the previous token or last token if the argument is null.
 boolean getSettingBoolean(String settingName, boolean defaultValue)
           
 boolean getSettingBoolean(String settingName, Boolean defaultValue)
           
 int getSettingInteger(String settingName, int defaultValue)
           
 int getSettingInteger(String settingName, Integer defaultValue)
           
 Object getSettingValue(String settingName)
           
 Object getSettingValue(String settingName, Object defaultValue)
           
 int getShiftWidth()
           
 int getSpacesPerTab()
           
 int getTabSize()
           
 FormatTokenPosition getTextStartPosition()
           
 TokenContextPath getValidWhitespaceTokenContextPath()
          Get the valid whitespace token-context-path by calling getWhitespaceTokenContextPath().
 TokenID getValidWhitespaceTokenID()
          Get the valid whitespace token-id by calling getWhitespaceTokenID().
 int getVisualColumnOffset(FormatTokenPosition pos)
          Get the column-offset of the tokenItem on its line.
 TokenContextPath getWhitespaceTokenContextPath()
          Get the token-context-path that should be assigned to the token that consists of the indentation whitespace only.
 TokenID getWhitespaceTokenID()
          Get the token-id that should be assigned to the token that consists of the indentation whitespace only.
 void insertSpaces(TokenItem beforeToken, int spaceCount)
           
 void insertString(FormatTokenPosition pos, String text)
           
 void insertString(TokenItem token, int offset, String text)
           
 TokenItem insertToken(TokenItem beforeToken, TokenID tokenID, TokenContextPath tokenContextPath, String tokenImage)
          Delegation to the same method in format-writer.
 boolean isAfter(FormatTokenPosition testedPosition, FormatTokenPosition afterPosition)
           
 boolean isAfter(TokenItem testedToken, TokenItem afterToken)
           
 boolean isChainStartPosition(FormatTokenPosition pos)
           
 boolean isIndentOnly()
          Delegation to the same method in format-writer.
 boolean isLineEmpty(FormatTokenPosition pos)
          Check whether there are no tokens except the ending EOL on the given line.
 boolean isLineWhite(FormatTokenPosition pos)
          Check whether there are only the whitespace tokens on the given line.
 boolean isRestartFormat()
          Delegation to the same method in format-writer.
 boolean isWhitespace(FormatTokenPosition pos)
           
 boolean isWhitespace(TokenItem token, int offset)
          Decide whether the character at the given offset in the given token is whitespace.
 void remove(FormatTokenPosition pos, int length)
           
 void remove(TokenItem token, int offset, int length)
           
 void removeToken(TokenItem token)
          Remove the token-item from the chain.
 void removeTokenChain(TokenItem startToken, TokenItem endToken)
          Remove all the tokens between start and end token inclusive.
 void replaceToken(TokenItem originalToken, TokenID tokenID, TokenContextPath tokenContextPath, String tokenImage)
          Replace the given token with the new token.
 void setIndentShift(int indentShift)
          Delegation to the same method in format-writer.
 void setRestartFormat(boolean restartFormat)
          Delegation to the same method in format-writer.
 TokenItem splitEnd(TokenItem token, int endLength, TokenID newTokenID, TokenContextPath newTokenContextPath)
           
 TokenItem splitStart(TokenItem token, int startLength, TokenID newTokenID, TokenContextPath newTokenContextPath)
           
 boolean tokenEquals(TokenItem compareToken, TokenID withTokenID)
          Compare token-id of the compare-token with the given token-id.
 boolean tokenEquals(TokenItem compareToken, TokenID withTokenID, TokenContextPath withTokenContextPath)
          Compare token-id of the compare-token with the given token-id and token-context-path.
 boolean tokenEquals(TokenItem compareToken, TokenID withTokenID, TokenContextPath withTokenContextPath, String withTokenImage)
          Compare token-id of the compare-token with the given token-id and given token-text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatSupport

public FormatSupport(FormatWriter formatWriter)
Method Detail

getFormatWriter

public FormatWriter getFormatWriter()
Getter for the format-writer associated with this format-support.


getTabSize

public int getTabSize()

getShiftWidth

public int getShiftWidth()

expandTabs

public boolean expandTabs()

getSpacesPerTab

public int getSpacesPerTab()

getSettingValue

public Object getSettingValue(String settingName)

getSettingValue

public Object getSettingValue(String settingName,
                              Object defaultValue)

getSettingBoolean

public boolean getSettingBoolean(String settingName,
                                 Boolean defaultValue)

getSettingBoolean

public boolean getSettingBoolean(String settingName,
                                 boolean defaultValue)

getSettingInteger

public int getSettingInteger(String settingName,
                             Integer defaultValue)

getSettingInteger

public int getSettingInteger(String settingName,
                             int defaultValue)

isIndentOnly

public final boolean isIndentOnly()
Delegation to the same method in format-writer.


getFormatStartPosition

public FormatTokenPosition getFormatStartPosition()
Delegation to the same method in format-writer.


getTextStartPosition

public FormatTokenPosition getTextStartPosition()

findFirstToken

public TokenItem findFirstToken(TokenItem token)
Get the first token in chain.


getLastToken

public TokenItem getLastToken()
Delegation to the same method in format-writer.


getLastPosition

public FormatTokenPosition getLastPosition()

canInsertToken

public boolean canInsertToken(TokenItem beforeToken)
Delegation to the same method in format-writer.


insertToken

public TokenItem insertToken(TokenItem beforeToken,
                             TokenID tokenID,
                             TokenContextPath tokenContextPath,
                             String tokenImage)
Delegation to the same method in format-writer.


insertSpaces

public void insertSpaces(TokenItem beforeToken,
                         int spaceCount)

canRemoveToken

public boolean canRemoveToken(TokenItem token)
Whether the token-item can be removed. It can be removed only in case it doesn't come from the document's text and it wasn't yet written to the underlying writer.


removeToken

public void removeToken(TokenItem token)
Remove the token-item from the chain. It can be removed only in case it doesn't come from the document's text and it wasn't yet written to the underlying writer.


removeTokenChain

public void removeTokenChain(TokenItem startToken,
                             TokenItem endToken)
Remove all the tokens between start and end token inclusive.


splitStart

public TokenItem splitStart(TokenItem token,
                            int startLength,
                            TokenID newTokenID,
                            TokenContextPath newTokenContextPath)

splitEnd

public TokenItem splitEnd(TokenItem token,
                          int endLength,
                          TokenID newTokenID,
                          TokenContextPath newTokenContextPath)

insertString

public void insertString(TokenItem token,
                         int offset,
                         String text)

insertString

public void insertString(FormatTokenPosition pos,
                         String text)

remove

public void remove(TokenItem token,
                   int offset,
                   int length)

remove

public void remove(FormatTokenPosition pos,
                   int length)

findNonEmptyToken

public 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. If there's no non-empty token in the given direction the method returns null.


getPosition

public FormatTokenPosition getPosition(TokenItem token,
                                       int offset)
Get the token position that corresponds to the given token and offset.

Parameters:
token - token for which the token-position is being created.
offset - offset inside the token.

getPosition

public FormatTokenPosition getPosition(TokenItem token,
                                       int offset,
                                       Position.Bias bias)

getNextPosition

public FormatTokenPosition getNextPosition(TokenItem token,
                                           int offset,
                                           Position.Bias bias)
Get the next position of the position given by parameters. It can be either just offset increasing but it can be movement to the next token for the token boundary.

Returns:
next token-position or null for the EOT position

getPreviousPosition

public FormatTokenPosition getPreviousPosition(TokenItem token,
                                               int offset,
                                               Position.Bias bias)
Get the previous position of the position given by parameters. It can be either just offset decreasing but it can be movement to the previous token for the token boundary.

Returns:
next token-position or null for the first position in the chain

getPreviousPosition

public FormatTokenPosition getPreviousPosition(FormatTokenPosition pos)
Get the token-position preceeding the given one. Use the same bias like the given position has.


getPreviousPosition

public FormatTokenPosition getPreviousPosition(FormatTokenPosition pos,
                                               Position.Bias bias)
Get the token-position preceeding the given one.

Parameters:
bias - bias that the returned position will have.

getPreviousPosition

public FormatTokenPosition getPreviousPosition(TokenItem token,
                                               int offset)

getNextPosition

public FormatTokenPosition getNextPosition(FormatTokenPosition pos)
Get the next successive token-position after the given one. Use the same bias like the given position has.


getNextPosition

public FormatTokenPosition getNextPosition(FormatTokenPosition pos,
                                           Position.Bias bias)
Get the token-position preceeding the given one.

Parameters:
bias - bias that the returned position will have.

getNextPosition

public FormatTokenPosition getNextPosition(TokenItem token,
                                           int offset)

isAfter

public boolean isAfter(TokenItem testedToken,
                       TokenItem afterToken)

isAfter

public boolean isAfter(FormatTokenPosition testedPosition,
                       FormatTokenPosition afterPosition)

isChainStartPosition

public boolean isChainStartPosition(FormatTokenPosition pos)

canReplaceToken

public boolean canReplaceToken(TokenItem token)
Whether the given token can be replaced or not. It's identical to whether the token can be removed.


replaceToken

public void replaceToken(TokenItem originalToken,
                         TokenID tokenID,
                         TokenContextPath tokenContextPath,
                         String tokenImage)
Replace the given token with the new token.

Parameters:
originalToken - original token to be replaced.
tokenID - token-id of the new token-item
tokenContextPath - token-context-path of the new token-item
tokenImage - token-text of the new token-item

isRestartFormat

public boolean isRestartFormat()
Delegation to the same method in format-writer.


setRestartFormat

public void setRestartFormat(boolean restartFormat)
Delegation to the same method in format-writer.


getIndentShift

public int getIndentShift()
Delegation to the same method in format-writer.


setIndentShift

public void setIndentShift(int indentShift)
Delegation to the same method in format-writer.


tokenEquals

public boolean tokenEquals(TokenItem compareToken,
                           TokenID withTokenID)
Compare token-id of the compare-token with the given token-id. Token text and token-context-path are ignored in comparison.

Parameters:
compareToken - token to compare
withTokenID - token-id with which the token's token-id is compared
Returns:
true if the token-ids match, false otherwise

tokenEquals

public boolean tokenEquals(TokenItem compareToken,
                           TokenID withTokenID,
                           TokenContextPath withTokenContextPath)
Compare token-id of the compare-token with the given token-id and token-context-path. Token text is ignored in comparison.

Parameters:
compareToken - token to compare
withTokenID - token-id with which the token's token-id is compared.
withTokenContextPath - token-context-path to which the token's token-context-path is compared.
Returns:
true if the token-ids match, false otherwise

tokenEquals

public boolean tokenEquals(TokenItem compareToken,
                           TokenID withTokenID,
                           TokenContextPath withTokenContextPath,
                           String withTokenImage)
Compare token-id of the compare-token with the given token-id and given token-text.

Parameters:
compareToken - token to compare
withTokenID - token-id with which the token's token-id is compared. It can be null in which case the token-id is ignored from comparison.
withTokenContextPath - token-context-path to which the token's token-context-path is compared. It can be null in which case the token-context-path is ignored from comparison.
withTokenImage - token-text with which the token's token-text is compared. It can be null in which case the token-text is ignored from comparison.
Returns:
true if the token-ids and token-texts match, false otherwise

isWhitespace

public boolean isWhitespace(TokenItem token,
                            int offset)
Decide whether the character at the given offset in the given token is whitespace.


isWhitespace

public boolean isWhitespace(FormatTokenPosition pos)

findLineStart

public FormatTokenPosition findLineStart(FormatTokenPosition pos)
Get the starting position of the line. It searches for the new-line character in backward direction and returns the position of the character following the new-line character or the first character of the first token in the chain.

Parameters:
pos - any token-position on the line.

findLineEnd

public FormatTokenPosition findLineEnd(FormatTokenPosition pos)
Get the ending position of the line. It searches for the new-line character and returns the position of it or the position after the last character of the last token in the chain.

Parameters:
pos - any token-position on the line.

findLineFirstNonWhitespace

public FormatTokenPosition findLineFirstNonWhitespace(FormatTokenPosition pos)
Return the first non-whitespace character on the line or null if there is no non-WS char on the line.


findLineEndWhitespace

public FormatTokenPosition findLineEndWhitespace(FormatTokenPosition pos)
Return the ending whitespace on the line or null if there's no such token on the given line.


findPreviousEOL

public FormatTokenPosition findPreviousEOL(FormatTokenPosition pos)
Get the first EOL in backward direction. The current position is ignored by the search.

Returns:
first EOL in backward direction or null if there is no such token.

findNextEOL

public FormatTokenPosition findNextEOL(FormatTokenPosition pos)
Get the first EOL in forward direction.

Parameters:
pos - starting token-position that is ignored by the search so it can be even EOL.
Returns:
first EOL token-position in the forward direction or null if there is no such token.

isLineEmpty

public boolean isLineEmpty(FormatTokenPosition pos)
Check whether there are no tokens except the ending EOL on the given line.

Parameters:
pos - any position on the line

isLineWhite

public boolean isLineWhite(FormatTokenPosition pos)
Check whether there are only the whitespace tokens on the given line.

Parameters:
token - any token on the line. It doesn't have to be the first one.

getVisualColumnOffset

public int getVisualColumnOffset(FormatTokenPosition pos)
Get the column-offset of the tokenItem on its line. The tabs are expanded according to the tab-size.


findNonWhitespace

public FormatTokenPosition findNonWhitespace(FormatTokenPosition startPosition,
                                             FormatTokenPosition limitPosition,
                                             boolean stopOnEOL,
                                             boolean backward)
Get the first non-whitespace position in the given direction.

Parameters:
startPosition - position at which the search starts. For the backward search the character right at startPosition is not considered as part of the search.
limitPosition - the token where the search will be broken reporting that nothing was found. It can be null to search till the end or begining of the chain (depending on direction). For forward search the char at the limitPosition is not considered to be part of search, but for backward search it is.
stopOnEOL - whether stop and return EOL position or continue search if EOL token is found.
backward - whether search in backward direction.
Returns:
first non-whitespace position or EOL or null if all the tokens till the begining of the chain are whitespaces.

getPreviousToken

public TokenItem getPreviousToken(TokenItem token)
Get the previous token or last token if the argument is null.


getWhitespaceTokenID

public TokenID getWhitespaceTokenID()
Get the token-id that should be assigned to the token that consists of the indentation whitespace only. This method should be overriden in the descendants.


getValidWhitespaceTokenID

public TokenID getValidWhitespaceTokenID()
Get the valid whitespace token-id by calling getWhitespaceTokenID(). Throw IllegalStateException if the whitespace-token-id is null.


getWhitespaceTokenContextPath

public TokenContextPath getWhitespaceTokenContextPath()
Get the token-context-path that should be assigned to the token that consists of the indentation whitespace only. This method should be overriden in the descendants.


getValidWhitespaceTokenContextPath

public TokenContextPath getValidWhitespaceTokenContextPath()
Get the valid whitespace token-context-path by calling getWhitespaceTokenContextPath(). Throw IllegalStateException if the whitespace-token-id is null.


canModifyWhitespace

public boolean canModifyWhitespace(TokenItem inToken)
Check whether the given token enables modifying of a whitespace in it. This method should be overriden in the descendants.


getIndentString

public String getIndentString(int indent)
This delegates to the same method in formatter.


getLineIndent

public int getLineIndent(FormatTokenPosition pos,
                         boolean zeroForWSLine)
Get the indentation of the line.

Parameters:
formatTokenPosition - any position on the line. It doesn't have to be the first one.
zeroForWSLine - If set to true the method will return zero in case the line consist of whitespace only. If false the method will return the indentation even for whitespace lines.

changeLineIndent

public FormatTokenPosition changeLineIndent(FormatTokenPosition pos,
                                            int indent)
Change the indentation of the line. This method should be always called for all the lines because it ensures that the indentation will contain exactly the characters from the indentation string.

Parameters:
pos - any position on the line being checked.
indent - the indentation for the line.
Returns:
some position on the line

chainToString

public String chainToString(TokenItem token)
Debug the current state of the chain.

Parameters:
token - mark this token as current one. It can be null.

chainToString

public String chainToString(TokenItem token,
                            int maxDocumentTokens)

org.netbeans.modules.editor.lib/1 1.14.0 3

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.