public final class TokenUtil extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
TOKEN_ID_EXCEPTION_FORMAT
Format for exception message when getting token by given id.
|
private static int[] |
TOKEN_IDS
Array of all token IDs.
|
private static java.lang.String |
TOKEN_NAME_EXCEPTION_FORMAT
Format for exception message when getting token by given name.
|
private static java.util.Map<java.lang.String,java.lang.Integer> |
TOKEN_NAME_TO_VALUE
Maps from a token name to value.
|
private static java.util.Map<java.lang.Integer,java.lang.String> |
TOKEN_VALUE_TO_NAME
Maps from a token value to name.
|
| Modifier | Constructor and Description |
|---|---|
private |
TokenUtil()
Stop instances being created.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areOnSameLine(DetailAST ast1,
DetailAST ast2)
Determines if two ASTs are on the same line.
|
static java.util.Optional<DetailAST> |
findFirstTokenByPredicate(DetailAST root,
java.util.function.Predicate<DetailAST> predicate)
Finds the first
Optional child token of DetailAST root node
which matches the given predicate. |
static void |
forEachChild(DetailAST root,
int type,
java.util.function.Consumer<DetailAST> action)
Performs an action for each child of
DetailAST root node
which matches the given token type. |
static int[] |
getAllTokenIds()
Get all token IDs that are available in TokenTypes.
|
static int |
getIntFromField(java.lang.reflect.Field field,
java.lang.Object object)
Gets the value of a static or instance field of type int or of another primitive type
convertible to type int via a widening conversion.
|
static java.lang.String |
getShortDescription(java.lang.String name)
Returns the short description of a token for a given name.
|
static int |
getTokenId(java.lang.String name)
Returns the ID of a token for a given name.
|
static java.lang.String |
getTokenName(int id)
Returns the name of a token for a given ID.
|
static int |
getTokenTypesTotalNumber()
Get total number of TokenTypes.
|
static java.util.Map<java.lang.Integer,java.lang.String> |
invertMap(java.util.Map<java.lang.String,java.lang.Integer> map)
Inverts a given map by exchanging each entry's key and value.
|
static boolean |
isBooleanLiteralType(int tokenType)
Checks if a token type is a literal true or false.
|
static boolean |
isCommentType(int type)
Is argument comment-related type (SINGLE_LINE_COMMENT,
BLOCK_COMMENT_BEGIN, BLOCK_COMMENT_END, COMMENT_CONTENT).
|
static boolean |
isCommentType(java.lang.String type)
Is argument comment-related type name (SINGLE_LINE_COMMENT,
BLOCK_COMMENT_BEGIN, BLOCK_COMMENT_END, COMMENT_CONTENT).
|
static boolean |
isOfType(DetailAST ast,
int... types)
Determines if the AST belongs to the given types.
|
static boolean |
isOfType(int type,
int... types)
Determines if the token type belongs to the given types.
|
static boolean |
isRootNode(DetailAST ast)
Determines if given AST is a root node, i.e.
|
static boolean |
isTypeDeclaration(int type)
Is type declaration token type (CLASS_DEF, INTERFACE_DEF,
ANNOTATION_DEF, ENUM_DEF, RECORD_DEF).
|
static java.util.Map<java.lang.String,java.lang.Integer> |
nameToValueMapFromPublicIntFields(java.lang.Class<?> cls)
Creates a map of 'field name' to 'field value' from all
public int fields
of a class. |
private static final java.util.Map<java.lang.String,java.lang.Integer> TOKEN_NAME_TO_VALUE
private static final java.util.Map<java.lang.Integer,java.lang.String> TOKEN_VALUE_TO_NAME
private static final int[] TOKEN_IDS
private static final java.lang.String TOKEN_ID_EXCEPTION_FORMAT
private static final java.lang.String TOKEN_NAME_EXCEPTION_FORMAT
private TokenUtil()
public static int getIntFromField(java.lang.reflect.Field field, java.lang.Object object)
field - from which the int should be extractedobject - to extract the int value fromjava.lang.IllegalStateException - if this Field object is enforcing Java language access control
and the underlying field is inaccessibleField.getInt(Object)public static java.util.Map<java.lang.String,java.lang.Integer> nameToValueMapFromPublicIntFields(java.lang.Class<?> cls)
public int fields
of a class.cls - source classpublic static java.util.Map<java.lang.Integer,java.lang.String> invertMap(java.util.Map<java.lang.String,java.lang.Integer> map)
map - source mappublic static int getTokenTypesTotalNumber()
public static int[] getAllTokenIds()
public static java.lang.String getTokenName(int id)
id - the ID of the token name to getjava.lang.IllegalArgumentException - when id is not validpublic static int getTokenId(java.lang.String name)
name - the name of the token ID to getjava.lang.IllegalArgumentException - when id is nullpublic static java.lang.String getShortDescription(java.lang.String name)
name - the name of the token ID to getjava.lang.IllegalArgumentException - when name is unknownpublic static boolean isCommentType(int type)
type - token type.public static boolean isCommentType(java.lang.String type)
type - token type name.public static java.util.Optional<DetailAST> findFirstTokenByPredicate(DetailAST root, java.util.function.Predicate<DetailAST> predicate)
Optional child token of DetailAST root node
which matches the given predicate.root - root node.predicate - predicate.Optional of DetailAST node which matches the predicate.public static void forEachChild(DetailAST root, int type, java.util.function.Consumer<DetailAST> action)
DetailAST root node
which matches the given token type.root - root node.type - token type to match.action - action to perform on the nodes.public static boolean areOnSameLine(DetailAST ast1, DetailAST ast2)
ast1 - the first ASTast2 - the second ASTpublic static boolean isTypeDeclaration(int type)
type - token type.public static boolean isOfType(int type, int... types)
type - the Token Type to checktypes - the acceptable typespublic static boolean isOfType(DetailAST ast, int... types)
ast - the AST node to checktypes - the acceptable typespublic static boolean isRootNode(DetailAST ast)
COMPILATION_UNIT.ast - AST to checkpublic static boolean isBooleanLiteralType(int tokenType)
tokenType - the TokenTypeCopyright © 2001-2022. All Rights Reserved.