public class Types extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areEquivalent(String left,
String right)
Checks if two type names are equal after removing the generic part.
|
static int |
getArrayDimension(String name)
Returns the dimension of the array.
|
static String |
getArraySuffix(String type)
Get the array suffix.
|
static String |
getDefaultValue(Class<?> clazz)
Returns the default value for a given class according to the Java Language Specification.
|
static String |
getDefaultValue(String type)
Returns the default value for a given type according to the Java Language Specification.
|
static String |
getGenerics(String type)
Returns the generic part of a given type.
|
static String |
getGenericsTypeParameter(String type) |
static String |
getPackage(String typeName)
Extracts the package part of a given type name.
|
static boolean |
isArray(String type)
Checks if the given type is an array.
|
static boolean |
isBasicType(String type)
Checks if the give type is a basic type, so it's either primitive or one of the primitive wrapper classes.
|
static boolean |
isGeneric(String type)
Checks if the given type is generic.
|
static boolean |
isJavaLang(String type)
Checks if the given type is part of the
java.lang package. |
static boolean |
isPrimitive(String type)
Checks if the given type is primitive according to the Java Language Specification.
|
static boolean |
isQualified(String typeName)
Checks if the given type name is qualified, that means that it contains at least one '.'.
|
static boolean |
isSimpleName(String name)
Checks if the given name is a simple name, so not full qualified.
|
static <O extends JavaType<O>> |
rebuildGenericNameWithArrays(String resolvedTypeName,
Type<O> type) |
static String[] |
splitGenerics(String typeName)
Returns the available generics as a String array.
|
static String |
stripArray(String type)
Strips the array from a given type.
|
static String |
stripGenerics(String type)
Removes the generics part of a given type.
|
static String[] |
tokenizeClassName(String className)
Splits the given class name into is parts which are separated by a '.'.
|
static Class<?> |
toPrimitive(String type) |
static String |
toResolvedType(String type,
Importer<?> importer)
Resolves the given type including generics.
|
static String |
toSimpleName(String type)
Calculates the simple name of the given type including all generics.
|
static boolean |
validateGenerics(String type)
Checks if the generics are valid of this given type.
|
public static boolean areEquivalent(String left, String right)
nullString.equals(Object) returns
trueString.equals(Object) returns
trueleft - the first type (maybe null)right - the second type (maybe null)true if the above conditions are fulfilled, false otherwiseNullPointerException - if one of the arguments isnullpublic static String toSimpleName(String type)
type - the type to convertNullPointerException - if the type is nullIllegalArgumentException - if the generic part couldn't be parsedpublic static String toResolvedType(String type, Importer<?> importer)
NOTE: This method won't import anything.
type - the type to resolveimporter - the importer to use to check for existing importsNullPointerException - if the type and/or the importer are nullpublic static String[] tokenizeClassName(String className)
className - the class name to tokenizeNullPointerException - if the class name is nullpublic static boolean isQualified(String typeName)
typeName - the type name to checktrue, if the type is qualified, false otherwiseNullPointerException - if the type name is nullpublic static String getPackage(String typeName)
typeName - the type name to extract the package fromNullPointerException - if the type name is nullpublic static boolean isSimpleName(String name)
false is returned.name - the name to checktrue, if the name is simple, false otherwise or if the name is no valid java identifierNullPointerException - if the name is nullpublic static boolean isJavaLang(String type)
java.lang package. For this, the type is first transformed to a
simple type.
The consequence is that the following will return true: isJavaLang("test.String"), because
String is part of java.lang.
type - the type to checktrue, if the simple name of the type is part of java.lang, false otherwiseNullPointerException - if the type name is nullpublic static boolean isBasicType(String type)
type - the type to checktrue if this type is basic, false otherwiseNullPointerException - if the type name is nullpublic static boolean isGeneric(String type)
type - the type to checktrue if this type is generic, false otherwiseNullPointerException - if the given type is nullpublic static boolean validateGenerics(String type)
type - the type to checktrue, if the generics are valid, false otherwiseNullPointerException - if the given type is nullpublic static String stripGenerics(String type)
type - the type where the generics should be removedNullPointerException - if the given type is nullpublic static String getGenerics(String type)
getGenerics("A<B>") returns "<B>".type - the type to get the generics fromNullPointerException - if the given type is nullpublic static boolean isArray(String type)
type - the type to checktrue, if the type is an array, false otherwiseNullPointerException - if the given type is nullpublic static String stripArray(String type)
type - the type to remove the array fromNullPointerException - if the given type is nullpublic static boolean isPrimitive(String type)
type - the type to checktrue if this type is primitive, false otherwiseNullPointerException - if the given type is nullpublic static int getArrayDimension(String name)
name - an array type, e.g.: byte[] or [Ljava.lang.Boolean;NullPointerException - if the given name is nullpublic static String getArraySuffix(String type)
getArraySuffix("String[][]") will return [][].type - the type to get the array suffix frompublic static <O extends JavaType<O>> String rebuildGenericNameWithArrays(String resolvedTypeName, Type<O> type)
public static String getDefaultValue(Class<?> clazz)
clazz - the class of the typeNullPointerException - if the given class is nullpublic static String getDefaultValue(String type)
type - the typeNullPointerException - if the given type is nullpublic static String[] splitGenerics(String typeName)
splitGenerics("Foo<Bar<A>, Bar<B>>") returns an array with Bar<A> and Bar<B>.typeName - the generic type to splitnull)NullPointerException - if the given type is nullCopyright © 2019 JBoss by Red Hat. All rights reserved.