public class JavaClassHelper
extends java.lang.Object
what is the boxed type for a primitive type
is this a numeric type.
Constructor and Description |
---|
JavaClassHelper() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canCoerce(java.lang.Class numberClassToBeCoerced,
java.lang.Class numberClassToCoerceTo)
Determines if a number can be coerced upwards to another number class without loss.
|
static java.lang.Number |
coerceBoxed(java.lang.Number numToCoerce,
java.lang.Class resultBoxedType)
Coerce the given number to the given type, assuming the type is a Boxed type.
|
static CodegenExpression |
coerceNumberBoxedToBoxedCodegen(CodegenExpression exprReturningBoxed,
java.lang.Class fromTypeBoxed,
java.lang.Class targetTypeBoxed) |
static CodegenExpression |
coerceNumberToBoxedCodegen(CodegenExpression expr,
java.lang.Class fromType,
java.lang.Class targetTypeBoxed) |
static java.util.Set<java.lang.reflect.Field> |
findAnnotatedFields(java.lang.Class targetClass,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
static java.util.Set<java.lang.reflect.Method> |
findAnnotatedMethods(java.lang.Class targetClass,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
static java.lang.reflect.Method |
findRequiredMethod(java.lang.Class clazz,
java.lang.String methodName) |
static java.lang.Object |
getAnnotationHook(java.lang.annotation.Annotation[] annotations,
HookType hookType,
java.lang.Class interfaceExpected,
EngineImportService engineImportService)
Returns an instance of a hook as specified by an annotation.
|
static java.util.List<java.lang.annotation.Annotation> |
getAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
java.lang.annotation.Annotation[] annotations) |
static java.lang.Class |
getArithmaticCoercionType(java.lang.Class typeOne,
java.lang.Class typeTwo)
Returns the coercion type for the 2 numeric types for use in arithmatic.
|
static java.lang.Class |
getArrayType(java.lang.Class resultType) |
static java.lang.String |
getBoxedClassName(java.lang.String className)
Returns for the class name given the class name of the boxed (wrapped) type if
the class name is one of the Java primitive types.
|
static java.lang.Class |
getBoxedType(java.lang.Class clazz)
Returns the boxed class for the given class, or the class itself if already boxed or not a primitive type.
|
static java.lang.Class |
getClassForName(java.lang.String className,
ClassForNameProvider classForNameProvider)
Returns the class given a fully-qualified class name.
|
static java.lang.Class |
getClassForSimpleName(java.lang.String className,
ClassForNameProvider classForNameProvider)
Returns the boxed class for the given classname, recognizing all primitive and abbreviations,
uppercase and lowercase.
|
static java.lang.Class |
getClassInClasspath(java.lang.String classname,
ClassForNameProvider classForNameProvider) |
static java.lang.String |
getClassLoaderId(java.lang.ClassLoader classLoader) |
static java.lang.String |
getClassNameFullyQualPretty(java.lang.Class clazz) |
static java.lang.String |
getClassNameFullyQualPrettyWithClassloader(java.lang.Class clazz) |
static java.util.Map<java.lang.String,java.lang.Object> |
getClassObjectFromPropertyTypeNames(java.util.Properties properties,
ClassForNameProvider classForNameProvider) |
static java.lang.Class |
getCommonCoercionType(java.lang.Class[] types)
Determines a common denominator type to which one or more types can be casted or coerced.
|
static java.lang.Class |
getCompareToCoercionType(java.lang.Class typeOne,
java.lang.Class typeTwo)
Returns for 2 classes to be compared via relational operator the Class type of
common comparison.
|
static java.lang.Class |
getComponentTypeOutermost(java.lang.Class clazz) |
static java.lang.Class |
getGenericFieldType(java.lang.reflect.Field field,
boolean isAllowNull)
Returns the generic type parameter of a return value by a field.
|
static java.lang.Class |
getGenericFieldTypeMap(java.lang.reflect.Field field,
boolean isAllowNull)
Returns the generic type parameter of a return value by a field or method.
|
static java.lang.Class |
getGenericReturnType(java.lang.reflect.Method method,
boolean isAllowNull)
Returns the generic type parameter of a return value by a method.
|
static java.lang.Class |
getGenericReturnType(java.lang.reflect.Method method,
java.lang.reflect.Field field,
boolean isAllowNull)
Returns the generic type parameter of a return value by a field or method.
|
static java.lang.Class |
getGenericReturnTypeMap(java.lang.reflect.Method method,
boolean isAllowNull)
Returns the second generic type parameter of a return value by a field or method.
|
static java.lang.Class |
getGenericReturnTypeMap(java.lang.reflect.Method method,
java.lang.reflect.Field field,
boolean isAllowNull)
Returns the second generic type parameter of a return value by a field or method.
|
static java.lang.Class |
getGenericType(java.lang.reflect.Type t,
int index) |
static java.lang.String |
getMessageInvocationTarget(java.lang.String statementName,
java.lang.reflect.Method method,
java.lang.String classOrPropertyName,
java.lang.Object[] args,
java.lang.Throwable targetException) |
static java.lang.reflect.Method |
getMethodByName(java.lang.Class clazz,
java.lang.String methodName) |
static int |
getNumberOfDimensions(java.lang.Class clazz) |
static java.lang.String |
getParameterAsString(java.lang.Class param)
Returns a parameter as a string text, allowing null values to represent a null
select expression type.
|
static java.lang.String |
getParameterAsString(java.lang.Class[] parameters)
Returns a comma-separated parameter type list in readable form,
considering arrays and null-type parameters.
|
static java.lang.Class |
getPrimitiveClassForName(java.lang.String typeName)
Returns the class for a Java primitive type name, ignoring case, and considering String as a primitive.
|
static java.lang.Class |
getPrimitiveType(java.lang.Class clazz)
Returns the un-boxed class for the given class, or the class itself if already un-boxed or not a primitive type.
|
static java.lang.String |
getSimpleNameForClass(java.lang.Class clazz) |
static void |
getSuper(java.lang.Class clazz,
java.util.Set<java.lang.Class> result)
Populates all interface and superclasses for the given class, recursivly.
|
static java.lang.Class[] |
getSuperInterfaces(java.lang.Class clazz) |
static void |
getSuperInterfaces(java.lang.Class clazz,
java.util.Set<java.lang.Class> result) |
static java.lang.Object |
instantiate(java.lang.Class implementedOrExtendedClass,
java.lang.Class clazz)
Checks that the given class implements or extends the required interface (first parameter),
and instantiates an object.
|
static java.lang.Object |
instantiate(java.lang.Class implementedOrExtendedClass,
java.lang.String className,
ClassForNameProvider classForNameProvider)
Looks up the given class and checks that it implements or extends the required interface,
and instantiates an object.
|
static boolean |
isAnnotationListed(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
java.lang.annotation.Annotation[] annotations) |
static boolean |
isArrayTypeCompatible(java.lang.Class target,
java.lang.Class provided) |
static boolean |
isAssignmentCompatible(java.lang.Class invocationType,
java.lang.Class declarationType)
Returns true if 2 classes are assignment compatible.
|
static boolean |
isBigNumberType(java.lang.Class clazz)
Returns true if the type is one of the big number types, i.e.
|
static boolean |
isBoolean(java.lang.Class clazz)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isCollectionMapOrArray(java.lang.Class returnType) |
static boolean |
isDatetimeClass(java.lang.Class inputType) |
static boolean |
isFloatingPointClass(java.lang.Class clazz)
Returns true if the supplied type is a floating point number.
|
static boolean |
isFloatingPointNumber(java.lang.Number number)
Returns true if the Number instance is a floating point number.
|
static boolean |
isFragmentableType(java.lang.Class propertyType)
Returns true if the Class is a fragmentable type, i.e.
|
static Pair<java.lang.String,java.lang.Boolean> |
isGetArrayType(java.lang.String type) |
static boolean |
isImplementsCharSequence(java.lang.Class type) |
static boolean |
isImplementsInterface(java.lang.Class clazz,
java.lang.Class interfaceClass)
Method to check if a given class, and its superclasses and interfaces (deep), implement a given interface.
|
static boolean |
isJavaBuiltinDataType(java.lang.Class clazz)
Returns true if the class passed in is a Java built-in data type (primitive or wrapper) including String and 'null'.
|
static boolean |
isNumeric(java.lang.Class clazz)
Determines if the class passed in is one of the numeric classes.
|
static boolean |
isNumericNonFP(java.lang.Class clazz)
Determines if the class passed in is one of the numeric classes and not a floating point.
|
static boolean |
isSignatureCompatible(java.lang.Class<?>[] one,
java.lang.Class<?>[] two) |
static boolean |
isSimpleNameFullyQualfied(java.lang.String simpleClassName,
java.lang.String fullyQualifiedClassname)
Returns true if the simple class name is the class name of the fully qualified classname.
|
static boolean |
isSubclassOrImplementsInterface(java.lang.Class extendorOrImplementor,
java.lang.Class extendedOrImplemented)
Method to check if a given class, and its superclasses and interfaces (deep), implement a given interface or extend a given class.
|
static java.lang.Object |
parse(java.lang.Class clazz,
java.lang.String text)
Parse the String using the given Java built-in class for parsing.
|
static java.lang.String |
printInstance(java.lang.Object instance,
boolean fullyQualified) |
static java.lang.Object |
resolveIdentAsEnumConst(java.lang.String constant,
EngineImportService engineImportService,
boolean isAnnotation)
Resolve a string constant as a possible enumeration value, returning null if not resolved.
|
static void |
setFieldForAnnotation(java.lang.Object target,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation,
java.lang.Object value) |
static java.lang.Class[] |
takeFirstN(java.lang.Class[] classes,
int numToTake) |
static java.lang.reflect.Type[] |
takeFirstN(java.lang.reflect.Type[] types,
int numToTake) |
static void |
writeInstance(java.io.StringWriter writer,
java.lang.Object instance,
boolean fullyQualified) |
static void |
writeInstance(java.io.StringWriter writer,
java.lang.String title,
java.lang.Object instance) |
public static boolean isImplementsCharSequence(java.lang.Class type)
public static boolean isArrayTypeCompatible(java.lang.Class target, java.lang.Class provided)
public static boolean isCollectionMapOrArray(java.lang.Class returnType)
public static java.lang.Class getBoxedType(java.lang.Class clazz)
clazz
- is the class to return the boxed class forpublic static java.lang.String getParameterAsString(java.lang.Class[] parameters)
parameters
- is the parameter types to renderpublic static java.lang.String getParameterAsString(java.lang.Class param)
param
- is the parameter typepublic static java.lang.Class getPrimitiveType(java.lang.Class clazz)
clazz
- is the class to return the unboxed (or primitive) class forpublic static boolean isNumeric(java.lang.Class clazz)
clazz
- to checkpublic static boolean isNumericNonFP(java.lang.Class clazz)
clazz
- to checkpublic static boolean isAssignmentCompatible(java.lang.Class invocationType, java.lang.Class declarationType)
invocationType
- type to assign fromdeclarationType
- type to assign topublic static boolean isBoolean(java.lang.Class clazz)
clazz
- to checkpublic static java.lang.Class getArithmaticCoercionType(java.lang.Class typeOne, java.lang.Class typeTwo) throws CoercionException
typeOne
- is the first typetypeTwo
- is the second typeCoercionException
- if types don't allow coercionpublic static java.lang.Number coerceBoxed(java.lang.Number numToCoerce, java.lang.Class resultBoxedType)
Meant for statement compile-time use, not for runtime use.
numToCoerce
- is the number to coerce to the given typeresultBoxedType
- is the boxed result type to returnpublic static CodegenExpression coerceNumberBoxedToBoxedCodegen(CodegenExpression exprReturningBoxed, java.lang.Class fromTypeBoxed, java.lang.Class targetTypeBoxed)
public static CodegenExpression coerceNumberToBoxedCodegen(CodegenExpression expr, java.lang.Class fromType, java.lang.Class targetTypeBoxed)
public static boolean isFloatingPointNumber(java.lang.Number number)
number
- to checkpublic static boolean isFloatingPointClass(java.lang.Class clazz)
clazz
- to checkpublic static java.lang.Class getCompareToCoercionType(java.lang.Class typeOne, java.lang.Class typeTwo) throws CoercionException
typeOne
- is the first typetypeTwo
- is the second typeCoercionException
- if the types cannot be comparedpublic static boolean isBigNumberType(java.lang.Class clazz)
clazz
- to checkpublic static boolean canCoerce(java.lang.Class numberClassToBeCoerced, java.lang.Class numberClassToCoerceTo)
Clients must pass in two classes that are numeric types.
Any number class can be coerced to double, while only double cannot be coerced to float. Any non-floating point number can be coerced to long. Integer can be coerced to Byte and Short even though loss is possible, for convenience.
numberClassToBeCoerced
- the number class to be coercednumberClassToCoerceTo
- the number class to coerce topublic static java.lang.String getBoxedClassName(java.lang.String className)
className
- is a class name, a Java primitive type or other classpublic static boolean isJavaBuiltinDataType(java.lang.Class clazz)
clazz
- to checkpublic static java.lang.Class getCommonCoercionType(java.lang.Class[] types) throws CoercionException
Null values are allowed as part of the input and indicate a 'null' constant value in an expression tree. Such as value doesn't have any type and can be ignored in determining a result type.
For numeric types, determines a coercion type that all types can be converted to via the method getArithmaticCoercionType.
Indicates that there is no common denominator type by throwing CoercionException
.
types
- is an array of one or more types, which can be Java built-in (primitive or wrapper)
or user typesCoercionException
- when no coercion type could be determinedpublic static java.lang.Class getClassForName(java.lang.String className, ClassForNameProvider classForNameProvider) throws java.lang.ClassNotFoundException
className
- is the fully-qualified class name, java primitive types included.classForNameProvider
- lookup of class for class namejava.lang.ClassNotFoundException
- if the class cannot be foundpublic static java.lang.Class getClassForSimpleName(java.lang.String className, ClassForNameProvider classForNameProvider) throws EventAdapterException
Recognizes "int" as Integer.class and "strIng" as String.class, and "Integer" as Integer.class, and so on.
className
- is the name to recognizeclassForNameProvider
- lookup of class for class nameEventAdapterException
- is throw if the class cannot be identifiedpublic static java.lang.String getSimpleNameForClass(java.lang.Class clazz)
public static java.lang.Class getPrimitiveClassForName(java.lang.String typeName)
typeName
- is a potential primitive Java type, or some other type namepublic static java.lang.Object parse(java.lang.Class clazz, java.lang.String text)
clazz
- is the class to parse the value totext
- is the text to parsepublic static boolean isImplementsInterface(java.lang.Class clazz, java.lang.Class interfaceClass)
clazz
- to check, including all its superclasses and their interfaces and extendsinterfaceClass
- is the interface class to look forpublic static boolean isSubclassOrImplementsInterface(java.lang.Class extendorOrImplementor, java.lang.Class extendedOrImplemented)
extendorOrImplementor
- is the class to inspects its extends and implements clausesextendedOrImplemented
- is the potential interface, or superclass, to checkpublic static java.lang.Object instantiate(java.lang.Class implementedOrExtendedClass, java.lang.String className, ClassForNameProvider classForNameProvider) throws ClassInstantiationException
implementedOrExtendedClass
- is the class that the looked-up class should extend or implementclassName
- of the class to load, check type and instantiateclassForNameProvider
- lookup of class for class nameClassInstantiationException
- if the type does not match or the class cannot be loaded or an object instantiatedpublic static java.lang.Object instantiate(java.lang.Class implementedOrExtendedClass, java.lang.Class clazz) throws ClassInstantiationException
implementedOrExtendedClass
- is the class that the looked-up class should extend or implementclazz
- to check type and instantiateClassInstantiationException
- if the type does not match or the class cannot be loaded or an object instantiatedpublic static void getSuper(java.lang.Class clazz, java.util.Set<java.lang.Class> result)
clazz
- to reflect uponresult
- set of classes to populatepublic static boolean isSimpleNameFullyQualfied(java.lang.String simpleClassName, java.lang.String fullyQualifiedClassname)
This method does not verify validity of class and package names, it uses simple string compare inspecting the trailing part of the fully qualified class name.
simpleClassName
- simple class namefullyQualifiedClassname
- fully qualified class name contains package name and simple class namepublic static boolean isFragmentableType(java.lang.Class propertyType)
propertyType
- type to checkpublic static java.lang.Class[] getSuperInterfaces(java.lang.Class clazz)
public static void getSuperInterfaces(java.lang.Class clazz, java.util.Set<java.lang.Class> result)
public static java.lang.Class getGenericReturnType(java.lang.reflect.Method method, java.lang.reflect.Field field, boolean isAllowNull)
method
- method or null if fieldfield
- field or null if methodisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static java.lang.Class getGenericReturnTypeMap(java.lang.reflect.Method method, java.lang.reflect.Field field, boolean isAllowNull)
method
- method or null if fieldfield
- field or null if methodisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static java.lang.Class getGenericReturnType(java.lang.reflect.Method method, boolean isAllowNull)
method
- method or null if fieldisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static java.lang.Class getGenericReturnTypeMap(java.lang.reflect.Method method, boolean isAllowNull)
method
- method or null if fieldisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static java.lang.Class getGenericFieldType(java.lang.reflect.Field field, boolean isAllowNull)
field
- field or null if methodisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static java.lang.Class getGenericFieldTypeMap(java.lang.reflect.Field field, boolean isAllowNull)
field
- field or null if methodisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static java.lang.Class getGenericType(java.lang.reflect.Type t, int index)
public static java.lang.Object getAnnotationHook(java.lang.annotation.Annotation[] annotations, HookType hookType, java.lang.Class interfaceExpected, EngineImportService engineImportService) throws ExprValidationException
annotations
- to searchhookType
- type to look forinterfaceExpected
- interface requiredengineImportService
- for resolving referencesExprValidationException
- if instantiation failedpublic static java.lang.Object resolveIdentAsEnumConst(java.lang.String constant, EngineImportService engineImportService, boolean isAnnotation) throws ExprValidationException
constant
- to resolveengineImportService
- for engine-level use to resolve enums, can be nullisAnnotation
- whether we are in an annotationExprValidationException
- if there is an error accessing the enumpublic static java.lang.Class getArrayType(java.lang.Class resultType)
public static java.lang.String getClassNameFullyQualPretty(java.lang.Class clazz)
public static java.lang.String getClassNameFullyQualPrettyWithClassloader(java.lang.Class clazz)
public static java.lang.String getClassLoaderId(java.lang.ClassLoader classLoader)
public static java.lang.reflect.Method getMethodByName(java.lang.Class clazz, java.lang.String methodName)
public static java.lang.String printInstance(java.lang.Object instance, boolean fullyQualified)
public static void writeInstance(java.io.StringWriter writer, java.lang.Object instance, boolean fullyQualified)
public static void writeInstance(java.io.StringWriter writer, java.lang.String title, java.lang.Object instance)
public static java.lang.String getMessageInvocationTarget(java.lang.String statementName, java.lang.reflect.Method method, java.lang.String classOrPropertyName, java.lang.Object[] args, java.lang.Throwable targetException)
public static boolean isDatetimeClass(java.lang.Class inputType)
public static java.util.Map<java.lang.String,java.lang.Object> getClassObjectFromPropertyTypeNames(java.util.Properties properties, ClassForNameProvider classForNameProvider)
public static java.lang.Class getClassInClasspath(java.lang.String classname, ClassForNameProvider classForNameProvider)
public static boolean isSignatureCompatible(java.lang.Class<?>[] one, java.lang.Class<?>[] two)
public static java.lang.reflect.Method findRequiredMethod(java.lang.Class clazz, java.lang.String methodName)
public static java.util.List<java.lang.annotation.Annotation> getAnnotations(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.annotation.Annotation[] annotations)
public static boolean isAnnotationListed(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass, java.lang.annotation.Annotation[] annotations)
public static java.util.Set<java.lang.reflect.Field> findAnnotatedFields(java.lang.Class targetClass, java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public static java.util.Set<java.lang.reflect.Method> findAnnotatedMethods(java.lang.Class targetClass, java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public static void setFieldForAnnotation(java.lang.Object target, java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Object value)
public static Pair<java.lang.String,java.lang.Boolean> isGetArrayType(java.lang.String type)
public static java.lang.Class[] takeFirstN(java.lang.Class[] classes, int numToTake)
public static java.lang.reflect.Type[] takeFirstN(java.lang.reflect.Type[] types, int numToTake)
public static java.lang.Class getComponentTypeOutermost(java.lang.Class clazz)
public static int getNumberOfDimensions(java.lang.Class clazz)