java.lang.Object
org.bzdev.util.JavaIdents
Utility class for checking whether or not strings representing
Java types, identifiers, or type parameters are valid.
The tests are lexical and partially syntactic: a type parameter
such as "? extends Foo" will not check that Foo is a class that has
been defined. Similarly a type such as "Foo[EXPRESSION][]" will not
check that the EXPRESSION uses the correct Java syntax for an
expression. Errors such as a type defined as "1Foo" or an
identifier whose name is "const" will be caught (while not
currently used by Java, "const" is a Java reserved word).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isValidIdentifier
(String token, boolean fullyQualified) Determine if a string represents a valid Java identifier.static boolean
isValidType
(String type) Determine if a string is a valid Java type, including ones with a type parameter.static boolean
isValidTypeParameter
(String token) Determine if a string is a valid Java type parameter.static boolean
isValidTypeParameterList
(String string) Determine if a string is a valid Java type-parameter list.
-
Constructor Details
-
JavaIdents
public JavaIdents()
-
-
Method Details
-
isValidIdentifier
Determine if a string represents a valid Java identifier. The test is a lexical test so that a return value of true does not indicate that a compile-time error will not occur. The test is a lexical test so that a return value of true does not indicate that a compile-time error will not occur.- Parameters:
token
- the string to checkfullyQualified
- true if fully-qualified names are allowed; false if only simple names are allowed.- Returns:
- true if the string 'token' is valid; false otherwise
-
isValidTypeParameterList
Determine if a string is a valid Java type-parameter list. The string must contain the list's opening and closing '<' and '>' delimiters. The test is a lexical test so that a return value of true does not indicate that a compile-time error will not occur.- Parameters:
string
- the string to test- Returns:
- true if 'string' is valid; false otherwise
-
isValidTypeParameter
Determine if a string is a valid Java type parameter. The test accepts any type specification that can occur in a type-parameter list (a comma-separated list delimited by an opening '<'and a closing '>'). Wildcard types are supported. The type must not include the opening '<'and a closing '>' delimiters, and the test is a lexical test so that a return value of true does not indicate that a compile-time error will not occur.- Parameters:
token
- the string to test- Returns:
- true if the string 'token' is valid; false otherwise
-
isValidType
Determine if a string is a valid Java type, including ones with a type parameter. The test is a lexical test so that a return value of true does not indicate that a compile-time error will not occur.- Parameters:
type
- the string to test- Returns:
- true if the string 'type' is valid; false otherwise
-