public class TokenUtils extends java.lang.Object
IToken
s.Modifier and Type | Field and Description |
---|---|
static java.util.EnumSet<ETokenType> |
ALWAYS_CASE_SENSITIVE_TOKEN_TYPES
Set of token types that always have to be treated case-sensitive, e.g.
|
Constructor and Description |
---|
TokenUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
calculateEndLineByCountingLines(IToken token)
Calculates the zero-based end line of the specified token by counting the
lines of the text contained within.
|
static int |
estimateEndLineByLookahead(IToken token,
IToken nextToken)
Estimates the zero-based end line of the specified token by looking where the
provided next token begins.
|
static Pair<TokenPattern,TokenPatternMatch> |
getMatchingPattern(java.util.Collection<TokenPattern> patterns,
java.util.List<IToken> tokens)
Returns the first matching pattern and the match or null if no pattern
matches.
|
static int |
getTokenLineCount(java.util.EnumSet<ETokenType.ETokenClass> tokenClassesToPreserve,
java.util.List<IToken> tokens,
java.util.Set<java.lang.Integer> coveredLines)
Creates a representation of the tokens that contains only the tokens
specified in the parameter.
|
static boolean |
isCommentToken(IToken token)
Returns true if a given token is a comment token.
|
static boolean |
isEqualTypeAndText(IToken t1,
IToken t2)
Checks if the given tokens are of equal type and have the equal text.
|
public static final java.util.EnumSet<ETokenType> ALWAYS_CASE_SENSITIVE_TOKEN_TYPES
public TokenUtils()
public static int estimateEndLineByLookahead(IToken token, IToken nextToken)
This method is more efficient than
calculateEndLineByCountingLines(IToken)
, but not as precise.
token
- the token whose end line should be calculated.nextToken
- the lookahead token.public static int calculateEndLineByCountingLines(IToken token)
This method is less efficient than
estimateEndLineByLookahead(IToken, IToken)
, but always yields the
correct result.
token
- the token whose end line should be calculated.public static boolean isEqualTypeAndText(IToken t1, IToken t2)
null
-safe.true
if both tokens are null
or if both
tokens are of the same ETokenType
and have the same text,
false
otherwise.public static Pair<TokenPattern,TokenPatternMatch> getMatchingPattern(java.util.Collection<TokenPattern> patterns, java.util.List<IToken> tokens)
public static boolean isCommentToken(IToken token)
public static int getTokenLineCount(java.util.EnumSet<ETokenType.ETokenClass> tokenClassesToPreserve, java.util.List<IToken> tokens, java.util.Set<java.lang.Integer> coveredLines)
coveredLines
- the method will only count lines that are not already in the given
set. The set will afterwards contain all lines covered by the
remaining tokens.