public class JavaClassHelper extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
JavaClassHelper.AnnotationConsumer |
Modifier and Type | Field and Description |
---|---|
static String |
APACHE_AVRO_GENERIC_RECORD_CLASSNAME |
Constructor and Description |
---|
JavaClassHelper() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canCoerce(Class<?> numberClassToBeCoerced,
Class<?> numberClassToCoerceTo)
Determines if a number can be coerced upwards to another number class without loss.
|
static Number |
coerceBoxed(Number numToCoerce,
Class<?> resultBoxedType)
Coerce the given number to the given type, assuming the type is a Boxed type.
|
static CodegenExpression |
coerceNumberBoxedToBoxedCodegen(CodegenExpression exprReturningBoxed,
EPTypeClass fromTypeBoxed,
EPTypeClass targetTypeBoxed) |
static CodegenExpression |
coerceNumberToBoxedCodegen(CodegenExpression expr,
EPTypeClass fromType,
EPTypeClass targetTypeBoxed) |
static Set<Field> |
findAnnotatedFields(Class<?> targetClass,
Class<? extends Annotation> annotation) |
static Set<Method> |
findAnnotatedMethods(Class<?> targetClass,
Class<? extends Annotation> annotation) |
static Method |
findRequiredMethod(Class<?> clazz,
String methodName) |
static List<Annotation> |
getAnnotations(Class<? extends Annotation> annotationClass,
Annotation[] annotations) |
static Class<?> |
getArithmaticCoercionType(Class<?> typeOne,
Class<?> typeTwo)
Returns the coercion type for the 2 numeric types for use in arithmatic.
|
static EPTypeClass |
getArithmaticCoercionType(EPTypeClass typeOne,
EPTypeClass typeTwo)
Returns the coercion type for the 2 numeric types for use in arithmatic.
|
static EPTypeClass |
getArrayComponentType(EPTypeClass type) |
static Class<?> |
getArrayComponentTypeInnermost(Class<?> clazz) |
static EPTypeClass |
getArrayComponentTypeInnermost(EPTypeClass type) |
static int |
getArrayDimensions(Class<?> clazz) |
static Class<?> |
getArrayType(Class<?> resultType) |
static Class<?> |
getArrayType(Class<?> resultType,
int numberOfDimensions) |
static EPTypeClass |
getArrayType(EPTypeClass type) |
static EPTypeClass |
getArrayType(EPTypeClass type,
int numDimensions) |
static String |
getBoxedClassName(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 Class<?> |
getBoxedType(Class<?> clazz)
Returns the boxed class for the given class, or the class itself if already boxed or not a primitive type.
|
static EPType |
getBoxedType(EPType type) |
static EPTypeClass |
getBoxedType(EPTypeClass clazz) |
static Class<?> |
getClassForName(String className,
ClassForNameProvider classForNameProvider)
Returns the class given a fully-qualified class name.
|
static Class<?> |
getClassForSimpleName(String className,
ClassForNameProvider classForNameProvider)
Returns the boxed class for the given classname, recognizing all primitive and abbreviations,
uppercase and lowercase.
|
static Class<?> |
getClassInClasspath(String classname,
ClassForNameProvider classForNameProvider) |
static String |
getClassNameNormalized(EPTypeClass clazz) |
static Map<String,Object> |
getClassObjectFromPropertyTypeNames(Properties properties,
ClassForNameProvider classForNameProvider) |
static EPType |
getCommonCoercionType(EPType[] types)
Determines a common denominator type to which one or more types can be casted or coerced.
|
static EPTypeClass |
getCompareToCoercionType(EPType typeOne,
EPType typeTwo)
Returns for 2 classes to be compared via relational operator the Class type of
common comparison.
|
static Class<?> |
getGenericFieldType(Field field,
boolean isAllowNull)
Returns the generic type parameter of a return value by a field.
|
static Class<?> |
getGenericFieldTypeMap(Field field,
boolean isAllowNull)
Returns the generic type parameter of a return value by a field or method.
|
static Class<?> |
getGenericType(Type t,
int index) |
static String |
getMessageInvocationTarget(String optionalStatementName,
String methodName,
Class[] methodParameters,
String classOrPropertyName,
Object[] args,
Throwable targetException) |
static Method |
getMethodByName(Class<?> clazz,
String methodName) |
static void |
getObjectValuePretty(Object value,
StringWriter writer) |
static Class<?> |
getPrimitiveClassForName(String typeName)
Returns the class for a Java primitive type name, ignoring case, and considering String as a primitive.
|
static EPTypeClass |
getPrimitiveType(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 EPTypeClass |
getPrimitiveType(EPTypeClass clazz)
Returns the un-boxed class for the given class, or the class itself if already un-boxed or not a primitive type.
|
static EPTypeClass |
getSecondParameterTypeOrObject(EPTypeClass returnType) |
static String |
getSimpleNameForClass(Class<?> clazz) |
static String |
getSimpleNameForClass(EPTypeClass clazz) |
static EPTypeClass |
getSingleParameterTypeOrObject(EPTypeClass returnType) |
static void |
getSuper(Class<?> clazz,
Set<Class> result)
Populates all interface and superclasses for the given class, recursivly.
|
static Class[] |
getSuperInterfaces(Class<?> clazz) |
static void |
getSuperInterfaces(Class<?> clazz,
Set<Class> result) |
static EPTypeClass |
getTypeClassOrObjectType(EPType evaluationType) |
static Object |
instantiate(Class<?> implementedOrExtendedClass,
Class<?> clazz)
Checks that the given class implements or extends the required interface (first parameter),
and instantiates an object.
|
static <T> T |
instantiate(Class<T> implementedOrExtendedClass,
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(Class<? extends Annotation> annotationClass,
Annotation[] annotations) |
static boolean |
isArrayTypeCompatible(Class<?> target,
Class<?> provided) |
static boolean |
isAssignmentCompatible(Class<?> invocationType,
Class<?> declarationType)
Returns true if 2 classes are assignment compatible.
|
static boolean |
isAssignmentCompatible(EPType invocationType,
Class<?> declarationType) |
static boolean |
isCollectionMapOrArray(EPType returnType) |
static boolean |
isDatetimeClass(Class<?> inputType) |
static boolean |
isDatetimeClass(EPType inputType) |
static boolean |
isFloatingPointClass(Class<?> clazz)
Returns true if the supplied type is a floating point number.
|
static boolean |
isFloatingPointClass(EPType type)
Returns true if the supplied type is a floating point number.
|
static boolean |
isFloatingPointNumber(Number number)
Returns true if the Number instance is a floating point number.
|
static boolean |
isFragmentableType(Class<?> propertyType)
Returns true if the Class is a fragmentable type, i.e.
|
static boolean |
isFragmentableType(EPType type)
Returns true if the Class is a fragmentable type, i.e.
|
static boolean |
isImplementsCharSequence(EPType type) |
static boolean |
isImplementsInterface(Class<?> clazz,
Class<?> interfaceClass)
Method to check if a given class, and its superclasses and interfaces (deep), implement a given interface.
|
static boolean |
isImplementsInterface(EPType type,
Class<?> interfaceClass)
Method to check if a given class, and its superclasses and interfaces (deep), implement a given interface.
|
static boolean |
isJavaBuiltinDataType(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 |
isJavaBuiltinDataType(EPType type)
Returns true if the class passed in is a Java built-in data type (primitive or wrapper) including String and 'null'.
|
static boolean |
isNumeric(Class<?> clazz)
Determines if the class passed in is one of the numeric classes.
|
static boolean |
isNumeric(EPType clazz) |
static boolean |
isNumericNonFP(Class<?> clazz)
Determines if the class passed in is one of the numeric classes and not a floating point.
|
static boolean |
isNumericNonFP(EPType type)
Determines if the type passed in is one of the numeric classes and not a floating point.
|
static boolean |
isSignatureCompatible(Class<?>[] one,
Class<?>[] two) |
static boolean |
isSimpleNameFullyQualfied(String simpleClassName,
String fullyQualifiedClassname)
Returns true if the simple class name is the class name of the fully qualified classname.
|
static boolean |
isSubclassOrImplementsInterface(Class<?> extendorOrImplementor,
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 boolean |
isSubclassOrImplementsInterface(EPType extendorOrImplementor,
Class<?> extendedOrImplemented) |
static boolean |
isSubclassOrImplementsInterface(EPType extendorOrImplementor,
EPTypeClass extendedOrImplemented) |
static boolean |
isType(EPType type,
Class<?> clazz) |
static boolean |
isTypeBoolean(Class<?> clazz)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeBoolean(EPType type)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeDouble(Class<?> clazz)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeDouble(EPType type)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeInteger(Class<?> clazz)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeInteger(EPType type)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeLong(Class<?> clazz)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeLong(EPType type)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeOrNull(EPType type,
Class<?> expected) |
static boolean |
isTypePrimitive(EPType type) |
static boolean |
isTypeString(EPType type)
Determines if the class passed in is a boolean boxed or unboxed type.
|
static boolean |
isTypeVoid(Class<?> clazz) |
static boolean |
isTypeVoid(EPType type) |
static Object |
parse(Class<?> clazz,
String text)
Parse the String using the given Java built-in class for parsing.
|
static String |
printInstance(Object instance,
boolean fullyQualified) |
static void |
setFieldForAnnotation(Object target,
Class<? extends Annotation> annotation,
Object value) |
static Type[] |
takeFirstN(Type[] types,
int numToTake) |
static <T> void |
traverseAnnotations(List<Class> classes,
Class<T> annotationClass,
BiConsumer<Class,T> consumer) |
static void |
writeInstance(StringWriter writer,
Object instance,
boolean fullyQualified) |
static void |
writeInstance(StringWriter writer,
String title,
Object instance) |
public static final String APACHE_AVRO_GENERIC_RECORD_CLASSNAME
public static boolean isImplementsCharSequence(EPType type)
public static boolean isArrayTypeCompatible(Class<?> target, Class<?> provided)
public static boolean isCollectionMapOrArray(EPType returnType)
public static EPTypeClass getBoxedType(EPTypeClass clazz)
public static Class<?> getBoxedType(Class<?> clazz)
clazz
- is the class to return the boxed class forpublic static EPTypeClass getPrimitiveType(Class<?> clazz)
clazz
- is the class to return the unboxed (or primitive) class forpublic static EPTypeClass getPrimitiveType(EPTypeClass clazz)
clazz
- is the class to return the unboxed (or primitive) class forpublic static boolean isNumeric(EPType clazz)
public static boolean isNumeric(Class<?> clazz)
clazz
- to checkpublic static boolean isNumericNonFP(EPType type)
type
- to checkpublic static boolean isNumericNonFP(Class<?> clazz)
clazz
- to checkpublic static boolean isAssignmentCompatible(EPType invocationType, Class<?> declarationType)
public static boolean isAssignmentCompatible(Class<?> invocationType, Class<?> declarationType)
invocationType
- type to assign fromdeclarationType
- type to assign topublic static boolean isTypeBoolean(EPType type)
type
- to checkpublic static boolean isTypeInteger(EPType type)
type
- to checkpublic static boolean isTypeLong(EPType type)
type
- to checkpublic static boolean isTypeDouble(EPType type)
type
- to checkpublic static boolean isTypeString(EPType type)
type
- to checkpublic static boolean isTypePrimitive(EPType type)
public static boolean isTypeBoolean(Class<?> clazz)
clazz
- to checkpublic static boolean isTypeInteger(Class<?> clazz)
clazz
- to checkpublic static boolean isTypeLong(Class<?> clazz)
clazz
- to checkpublic static boolean isTypeDouble(Class<?> clazz)
clazz
- to checkpublic static EPTypeClass getArithmaticCoercionType(EPTypeClass typeOne, EPTypeClass typeTwo) throws CoercionException
typeOne
- is the first typetypeTwo
- is the second typeCoercionException
- if types don't allow coercionpublic static Class<?> getArithmaticCoercionType(Class<?> typeOne, Class<?> typeTwo) throws CoercionException
typeOne
- is the first typetypeTwo
- is the second typeCoercionException
- if types don't allow coercionpublic static Number coerceBoxed(Number numToCoerce, 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, EPTypeClass fromTypeBoxed, EPTypeClass targetTypeBoxed)
public static CodegenExpression coerceNumberToBoxedCodegen(CodegenExpression expr, EPTypeClass fromType, EPTypeClass targetTypeBoxed)
public static boolean isFloatingPointNumber(Number number)
number
- to checkpublic static boolean isFloatingPointClass(EPType type)
type
- to checkpublic static boolean isFloatingPointClass(Class<?> clazz)
clazz
- to checkpublic static EPTypeClass getCompareToCoercionType(EPType typeOne, EPType typeTwo) throws CoercionException
typeOne
- is the first typetypeTwo
- is the second typeCoercionException
- if the types cannot be comparedpublic static boolean canCoerce(Class<?> numberClassToBeCoerced, 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 String getBoxedClassName(String className)
className
- is a class name, a Java primitive type or other classpublic static boolean isJavaBuiltinDataType(EPType type)
type
- to checkpublic static boolean isJavaBuiltinDataType(Class<?> clazz)
clazz
- to checkpublic static EPType getCommonCoercionType(EPType[] 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 Class<?> getClassForName(String className, ClassForNameProvider classForNameProvider) throws ClassNotFoundException
className
- is the fully-qualified class name, java primitive types included.classForNameProvider
- lookup of class for class nameClassNotFoundException
- if the class cannot be foundpublic static Class<?> getClassForSimpleName(String className, ClassForNameProvider classForNameProvider)
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 namepublic static String getSimpleNameForClass(EPTypeClass clazz)
public static Class<?> getPrimitiveClassForName(String typeName)
typeName
- is a potential primitive Java type, or some other type namepublic static Object parse(Class<?> clazz, String text)
clazz
- is the class to parse the value totext
- is the text to parsepublic static boolean isImplementsInterface(EPType type, Class<?> interfaceClass)
type
- to check, including all its superclasses and their interfaces and extendsinterfaceClass
- is the interface class to look forpublic static boolean isImplementsInterface(Class<?> clazz, Class<?> interfaceClass)
clazz
- to check, including all its superclasses and their interfaces and extendsinterfaceClass
- is the interface class to look forpublic static boolean isSubclassOrImplementsInterface(EPType extendorOrImplementor, EPTypeClass extendedOrImplemented)
public static boolean isSubclassOrImplementsInterface(EPType extendorOrImplementor, Class<?> extendedOrImplemented)
public static boolean isSubclassOrImplementsInterface(Class<?> extendorOrImplementor, Class<?> extendedOrImplemented)
extendorOrImplementor
- is the class to inspect its extends and implements clausesextendedOrImplemented
- is the potential interface, or superclass, to checkpublic static <T> T instantiate(Class<T> implementedOrExtendedClass, String className, ClassForNameProvider classForNameProvider) throws ClassInstantiationException
T
- typeimplementedOrExtendedClass
- 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 Object instantiate(Class<?> implementedOrExtendedClass, 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(Class<?> clazz, Set<Class> result)
clazz
- to reflect uponresult
- set of classes to populatepublic static boolean isSimpleNameFullyQualfied(String simpleClassName, 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(EPType type)
type
- type to checkpublic static boolean isFragmentableType(Class<?> propertyType)
propertyType
- type to checkpublic static Class<?> getGenericFieldType(Field field, boolean isAllowNull)
field
- field or null if methodisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static Class<?> getGenericFieldTypeMap(Field field, boolean isAllowNull)
field
- field or null if methodisAllowNull
- whether null is allowed as a return value or expected Object.classpublic static int getArrayDimensions(Class<?> clazz)
public static Class<?> getArrayComponentTypeInnermost(Class<?> clazz)
public static void writeInstance(StringWriter writer, Object instance, boolean fullyQualified)
public static void writeInstance(StringWriter writer, String title, Object instance)
public static String getMessageInvocationTarget(String optionalStatementName, String methodName, Class[] methodParameters, String classOrPropertyName, Object[] args, Throwable targetException)
public static boolean isDatetimeClass(EPType inputType)
public static boolean isDatetimeClass(Class<?> inputType)
public static Map<String,Object> getClassObjectFromPropertyTypeNames(Properties properties, ClassForNameProvider classForNameProvider) throws ClassNotFoundException
ClassNotFoundException
public static Class<?> getClassInClasspath(String classname, ClassForNameProvider classForNameProvider)
public static List<Annotation> getAnnotations(Class<? extends Annotation> annotationClass, Annotation[] annotations)
public static boolean isAnnotationListed(Class<? extends Annotation> annotationClass, Annotation[] annotations)
public static Set<Field> findAnnotatedFields(Class<?> targetClass, Class<? extends Annotation> annotation)
public static Set<Method> findAnnotatedMethods(Class<?> targetClass, Class<? extends Annotation> annotation)
public static void setFieldForAnnotation(Object target, Class<? extends Annotation> annotation, Object value)
public static void getObjectValuePretty(Object value, StringWriter writer)
public static boolean isTypeVoid(EPType type)
public static boolean isTypeVoid(Class<?> clazz)
public static <T> void traverseAnnotations(List<Class> classes, Class<T> annotationClass, BiConsumer<Class,T> consumer)
public static EPTypeClass getArrayComponentType(EPTypeClass type)
public static EPTypeClass getArrayComponentTypeInnermost(EPTypeClass type)
public static EPTypeClass getSingleParameterTypeOrObject(EPTypeClass returnType)
public static EPTypeClass getSecondParameterTypeOrObject(EPTypeClass returnType)
public static EPTypeClass getTypeClassOrObjectType(EPType evaluationType)
public static EPTypeClass getArrayType(EPTypeClass type)
public static EPTypeClass getArrayType(EPTypeClass type, int numDimensions)
public static String getClassNameNormalized(EPTypeClass clazz)
Copyright © 2005–2021. All rights reserved.