Class TokenUtils


  • public final class TokenUtils
    extends java.lang.Object
    Utility methods for dealing with tokens.
    Version:
    1.0
    • Constructor Detail

      • TokenUtils

        private TokenUtils()
    • Method Detail

      • getSubTokenList

        public static TokenUtils.TokenSubList getSubTokenList​(Token tokenList,
                                                              int pos,
                                                              javax.swing.text.TabExpander e,
                                                              RSyntaxTextArea textArea,
                                                              float x0)
        Modifies the passed-in token list to start at the specified offset. For example, if the token list covered positions 20-60 in the document (inclusive) like so:
           [token1] -> [token2] -> [token3] -> [token4]
           20     30   31     40   41     50   51     60
         
        and you used this method to make the token list start at position 44, then the token list would be modified to be the following:
           [part-of-old-token3] -> [token4]
           44                 50   51     60
         
        Tokens that come before the specified position are forever lost, and the token containing that position is made to begin at that position if necessary. All token types remain the same as they were originally.

        This method can be useful if you are only interested in part of a token list (i.e., the line it represents), but you don't want to modify the token list yourself.

        Parameters:
        tokenList - The list to make start at the specified position. This parameter is modified.
        pos - The position at which the new token list is to start. If this position is not in the passed-in token list, the returned token list will either be null or the unpaintable token(s) at the end of the passed-in token list.
        e - How to expand tabs.
        textArea - The text area from which the token list came.
        x0 - The initial x-pixel position of the old token list.
        Returns:
        Information about the "sub" token list. This will be null if pos was not a valid offset into the token list.
        See Also:
        getSubTokenList(Token, int, TabExpander, RSyntaxTextArea, float, TokenImpl)
      • getSubTokenList

        public static TokenUtils.TokenSubList getSubTokenList​(Token tokenList,
                                                              int pos,
                                                              javax.swing.text.TabExpander e,
                                                              RSyntaxTextArea textArea,
                                                              float x0,
                                                              TokenImpl tempToken)
        Modifies the passed-in token list to start at the specified offset. For example, if the token list covered positions 20-60 in the document (inclusive) like so:
           [token1] -> [token2] -> [token3] -> [token4]
           20     30   31     40   41     50   51     60
         
        and you used this method to make the token list start at position 44, then the token list would be modified to be the following:
           [part-of-old-token3] -> [token4]
           44                 50   51     60
         
        Tokens that come before the specified position are forever lost, and the token containing that position is made to begin at that position if necessary. All token types remain the same as they were originally.

        This method can be useful if you are only interested in part of a token list (i.e., the line it represents), but you don't want to modify the token list yourself.

        Parameters:
        tokenList - The list to make start at the specified position. This parameter is modified.
        pos - The position at which the new token list is to start. If this position is not in the passed-in token list, the returned token list will either be null or the unpaintable token(s) at the end of the passed-in token list.
        e - How to expand tabs.
        textArea - The text area from which the token list came.
        x0 - The initial x-pixel position of the old token list.
        tempToken - A temporary token to use when creating the token list result. This may be null but callers can pass in a "buffer" token for performance if desired.
        Returns:
        Information about the "sub" token list. This will be null if pos was not a valid offset into the token list.
        See Also:
        getSubTokenList(Token, int, TabExpander, RSyntaxTextArea, float)
      • getWhiteSpaceTokenLength

        public static int getWhiteSpaceTokenLength​(Token t,
                                                   int tabSize,
                                                   int curOffs)
        Returns the length, in characters, of a whitespace token, taking tabs into account.
        Parameters:
        t - The token. This should be of type TokenTypes.WHITESPACE.
        tabSize - The tab size in the editor.
        curOffs - The offset of the token in the current line.
        Returns:
        The length of the token, in characters.
      • isBlankOrAllWhiteSpace

        public static boolean isBlankOrAllWhiteSpace​(Token t)
        Returns whether a token list is null, empty, all whitespace, just comment token(s), or any combination of those.
        Parameters:
        t - The token.
        Returns:
        Whether the token list starting with that token is null, empty, whitespace or comment tokens.
        See Also:
        isBlankOrAllWhiteSpaceWithoutComments(Token)
      • isBlankOrAllWhiteSpaceWithoutComments

        public static boolean isBlankOrAllWhiteSpaceWithoutComments​(Token t)
        Returns whether a token list is null, empty, or all whitespace token(s).
        Parameters:
        t - The token.
        Returns:
        Whether the token list starting with that token is null, empty, or all whitespace token(s).
        See Also:
        isBlankOrAllWhiteSpace(Token)
      • tokenToHtml

        public static java.lang.String tokenToHtml​(RSyntaxTextArea textArea,
                                                   Token token)
        Generates HTML that renders a token with the style used in an RSTA instance. Note this HTML is not concise. It is a straightforward implementation to be used to generate markup used in copy/paste and dnd scenarios.
        Parameters:
        textArea - The text area whose styles to use.
        token - The token to get equivalent HTML for.
        Returns:
        The HTML.