public class JavaSymbolResolver extends java.lang.Object implements JavaTokenTypes
This class also provides a service to lookup a symbolic name for a Java token type and the type that goes with a symbolic token type name.
Modifier and Type | Field and Description |
---|---|
private static KeywordDictionary |
keywords
Stores all Java language keywords and provides name to token type
resolution.
|
private static java.util.Map |
nameToType
Stores a list of all types indexed by the symbolic type name.
|
private static java.util.Map |
typeToName
Stores a list of all names indexed by the token type.
|
ANNOTATION, ANON_CTOR, ASSIGN, BEGIN_DOCTAGS, BITWISE_AND, BITWISE_OR, BITWISE_XOR, BLOCK, BLOCK_DEF, BOGUS, BOOL_FALSE, BOOL_TRUE, CAST, CHAR_LITERAL, CLASS_REFERENCE, COMPILE_UNIT, COMPLEMENT, CONSTRUCTOR, CS_BEGIN, CS_CONSTANTS, CS_CONSTRUCTORS, CS_END, CS_INNER_CLASSES, CS_INSTANCE_METHODS, CS_INSTANCE_VARS, CS_STATIC_INITS, CS_STATIC_METHODS, CS_STATIC_VARS, DEC_LITERAL, DECREMENT, DIVIDE, DO_WHILE, DOC_COMMENT, DOC_HTML, DOC_PARAGRAPH, DOC_TEXTRUN, DOCTAG_LINK, DOCTAG_PARAM, DOCTAG_RETURN, ELSE_IF, END_DOCTAGS, EQUALS, EXPRESSION, GT, GTE, INCREMENT, INDENT_GRP, INITIALIZER, KW_ABSTRACT, KW_ASSERT, KW_BOOLEAN, KW_BREAK, KW_BYTE, KW_CASE, KW_CATCH, KW_CHAR, KW_CLASS, KW_CONST, KW_CONTINUE, KW_DEFAULT, KW_DO, KW_DOUBLE, KW_ELSE, KW_ENUM, KW_EXTENDS, KW_FINAL, KW_FINALLY, KW_FLOAT, KW_FOR, KW_GOTO, KW_IF, KW_IMPLEMENTS, KW_IMPORT, KW_INSTANCEOF, KW_INT, KW_INTERFACE, KW_LONG, KW_NATIVE, KW_NEW, KW_PACKAGE, KW_PRIVATE, KW_PROTECTED, KW_PUBLIC, KW_RETURN, KW_SHORT, KW_STATIC, KW_STRICTFP, KW_SUPER, KW_SWITCH, KW_SYNCHRONIZED, KW_THIS, KW_THROW, KW_THROWS, KW_TRANSIENT, KW_TRY, KW_VOID, KW_VOLATILE, KW_WHILE, LABEL, LABEL_DEF, LAMBDA, LBRACKET, LOGICAL_AND, LOGICAL_NOT, LOGICAL_OR, LPARENS, LSHIFT, LT, LTE, MEMBER, METHOD_CALL, METHOD_DECL, METHOD_DEF, MINUS, MINUS_ASSIGN, MODULO, MULTIPLY, NOT_EQ, NULL_LITERAL, NUM_LITERAL, OR_ELSE_IF, PLACEHOLDER, PLUS, PLUS_ASSIGN, REFERENCE, REFERENCE_DEF, RSHIFT, SKIP, SLASH_COMMENT, STAR_COMMENT, STATIC_IMPORT, STATIC_METHOD_CALL, STRING, SYMBOL, TERN_IF_ELSE, THEN, UN_MINUS, UN_PLUS, UNRECOGNIZED, ZERO_RSHIFT
Constructor and Description |
---|
JavaSymbolResolver() |
Modifier and Type | Method and Description |
---|---|
private static void |
buildTokenNameArray()
Assumes all
int type fields in the JavaTokenTypes
interface are unique token types and it adds a bidirectional mapping
(name to type and type to name) for each type using reflection. |
private static void |
initializeKeywordDictionary()
Creates a
Keyword array and initializes that array to
a the list of all recognized Java language keywords. |
static int |
lookupKeyword(java.lang.String symbol)
Lookup a symbol to see if it is a reserved Java keyword.
|
static java.lang.String |
lookupTokenName(int type)
Translates an integer value of a Java token type into the associated
human readable text representation.
|
static int |
lookupTokenType(java.lang.String tokenName)
Translates a text representation of a Java token type into the
actual integer value.
|
static void |
main(java.lang.String[] args)
Simple command line driver to print out the list of Java token types
and the associated symbolic names.
|
private static KeywordDictionary keywords
private static java.util.Map typeToName
private static java.util.Map nameToType
public static int lookupKeyword(java.lang.String symbol)
symbol
- The symbol to lookup in the dictionary.public static int lookupTokenType(java.lang.String tokenName)
tokenName
- The text representation of the token type.public static java.lang.String lookupTokenName(int type)
type
- The integer token type.null
if
no match was found.private static void buildTokenNameArray()
int
type fields in the JavaTokenTypes
interface are unique token types and it adds a bidirectional mapping
(name to type and type to name) for each type using reflection. This
assumes that all 'int' fields are token types AND that all such types
are UNIQUE! This should be a safe assumption since this is the
purpose for that class. The type names used as an index to the types
are stored in lowercase to allow case-insensitive matches.private static void initializeKeywordDictionary()
Keyword
array and initializes that array to
a the list of all recognized Java language keywords. The
initialization is done in-line and the source file is organized in
an easy to maintain column format. A loop then processes this array
and adds each Keyword
into the keyword dictionary.
The following values are needed for each Keyword
object:
See
for more details.Keyword
public static void main(java.lang.String[] args)
args
- All command line arguments are ignored.