public class Types
extends Object
Registry of token type constants and type hierarchy definitions for the concrete syntax tree (CST) system. Provides constants for lexical tokens (literals, keywords, operators), semantic types, type classifications, and utility methods for type checking and querying. All Token, CSTNode, and Reduction nodes reference types from this class to identify their syntactic and semantic meaning.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static boolean |
canMean(int actual, int preferred)Determines if a type can be interpreted as another type. |
|
public static String |
getDescription(int type)Returns a human-readable description of the specified token type. |
|
public static Collection<String> |
getKeywords()Returns an unmodifiable collection of all recognized keywords. |
|
public static int |
getPrecedence(int type, boolean throwIfInvalid)Returns the operator precedence level for the specified type. |
|
public static String |
getText(int type)Returns the text representation for the specified token type. |
|
public static boolean |
isAssignment(int type)Returns true if the specified type represents an assignment operator.
|
|
public static boolean |
isKeyword(String text)Returns true if the specified text is a recognized keyword. |
|
public static int |
lookup(String text, int filter)Returns the token type for the specified symbol or keyword text. |
|
public static int |
lookupKeyword(String text)Returns the token type for the specified keyword text. |
|
public static int |
lookupSymbol(String text)Returns the token type for the specified symbol text. |
|
public static void |
makePostfix(CSTNode node, boolean throwIfInvalid)Converts an operator node's meaning to a postfix operator variant. |
|
public static void |
makePrefix(CSTNode node, boolean throwIfInvalid)Converts an operator node's meaning to a prefix operator variant. |
|
public static boolean |
ofType(int specific, int general)Determines if a specific type belongs to a general type category through the type hierarchy. |
Alias for EQUAL.
Alias for EQUAL.
Alias for MULTIPLY.
Determines if a type can be interpreted as another type. This is orthogonal to ofType(int, int) and is used for semantic flexibility (e.g., an identifier can be viewed as a class name).
actual - the actual type being checkedpreferred - the desired interpretationtrue if the actual type can be reinterpreted as the preferred type Returns a human-readable description of the specified token type.
Useful for error messages and debugging. For example, PLUS might return "+".
type - the token type constant"<>" if the type has no descriptionReturns an unmodifiable collection of all recognized keywords.
Returns the operator precedence level for the specified type.
Lower precedence values bind tighter (evaluate first). For example,
multiplication (MULTIPLY) has higher precedence than addition (PLUS).
type - the operator type to checkthrowIfInvalid - if true, throws GroovyBugError for non-operators;
if false, returns -1 for non-operatorsReturns the text representation for the specified token type. For symbols and keywords, this is the canonical text (e.g., "def", "+", "->").
type - a token type constant from this class Returns true if the specified type represents an assignment operator.
Assignment operators include simple assignment (=) and compound assignments
(+=, -=, *=, etc.).
type - the token type to checktrue if the type is an assignment operator Returns true if the specified text is a recognized keyword.
text - the text to checktrue if the text is a keywordReturns the token type for the specified symbol or keyword text. Returns UNKNOWN if the text is not found. Optionally filters the result by type (e.g., restrict to keywords only).
text - the text to look up (e.g., "def", "+", "if")filter - a type filter (KEYWORD, SYMBOL, or UNKNOWN for no filter)Returns the token type for the specified keyword text. Only matches keywords, not symbols.
text - the keyword text (e.g., "def", "if", "class")Returns the token type for the specified symbol text. Only matches symbols (operators, delimiters), not keywords.
text - the symbol text (e.g., "+", "-", "{", ".") Converts an operator node's meaning to a postfix operator variant.
For example, converts PLUS_PLUS to POSTFIX_PLUS_PLUS.
node - the node whose meaning is to be modifiedthrowIfInvalid - if true, throws GroovyBugError if the type cannot be converted Converts an operator node's meaning to a prefix operator variant.
For example, converts PLUS to PREFIX_PLUS.
node - the node whose meaning is to be modifiedthrowIfInvalid - if true, throws GroovyBugError if the type cannot be converted Determines if a specific type belongs to a general type category through the type hierarchy.
For example, ofType(Types.PLUS, Types.MATH_OPERATOR) returns true
because PLUS is classified as a MATH_OPERATOR.
specific - the specific token type to checkgeneral - the general type categorytrue if the specific type is within the general category