Package es.bsc.dataclay.util.reflection
Class Reflector
- java.lang.Object
- 
- es.bsc.dataclay.util.reflection.Reflector
 
- 
 public final class Reflector extends Object This class contains useful functions when Java Reflection is necessary.
- 
- 
Field SummaryFields Modifier and Type Field Description static ClassLoaderBOOTSTRAP_CLASSLOADERBootstrap class loader.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static intcountOccurrences(String str, String findStr)Count the occurrences of some string into anotherstatic StringgetCanonicalTypeNameFromSignature(String signature)Get the name of the type corresponding to the provided signature and also get the [] array representation.static Class<?>getClassFromSignatureAndArray(String signature, ClassLoader classLoader)Get the class corresponding to the provided signature.static StringgetDescriptorFromTypeName(String typeName)Get the descriptor from of the type with name providedstatic ObjectgetField(Object instance, String fieldName)This function gets the value of the field with name specified in the object instance provided.static StringgetImmutableTypeNameFromPrimitiveTypeName(String typeName)This function returns the primitive type name from immutable type name.static StringgetInternalNameFromTypeName(String typeName)Get internal name from type namestatic StringgetPackageName(String fullName)Get package name from full class namestatic StringgetPrimitiveTypeNameFromImmutableTypeName(String typeName)This function returns the primitive type name from immutable type name.static StringgetSignatureFromConstructor(Constructor<?> constructor)Get the signature from constructor providedstatic StringgetSignatureFromInternalName(String internalName)Get the signature from of the fully qualified type name (internal name) providedstatic StringgetSignatureFromMethod(Method method)Get the signature from method providedstatic StringgetSignatureFromTypeName(String typeName)Get the signature from of the type with name providedstatic ObjectgetStaticField(Class<?> staticClass, String fieldName)This function gets the value of the static field with name specified in the object instance provided.static List<String>getSubtypes(String signature)Get sub typesstatic StringgetTypeNameFromInternalName(String internalName)Get type name from internal namestatic StringgetTypeNameFromSignatureOrDescriptor(String signature)Get the name of the type corresponding to the provided signature.static booleanisArrayTypeName(String typeName)Indicates if type name is an array type.static booleanisImmutableSignature(String signature)This function verifies if there is a immutable type with the signature providedstatic booleanisImmutableTypeName(String typeName)This function verifies if there is a lang type with the name provided.static booleanisJavaPrimitiveOrArraySignature(String signature)Check if the signature provided belongs to a Java type or to a Primitive type.static booleanisJavaPrimitiveOrArrayTypeName(String typeName)This function verifies if type name is java, array or primitive.static booleanisJavaTypeName(String className)This function verifies if there is a Java type with the name providedstatic booleanisPrimitiveSignature(String signature)This function verifies if there is a primitive type with the signature providedstatic booleanisPrimitiveTypeName(String typeName)Check if a name/signature is a Primitive type (quite close to Java primitives, but agnostic).static booleanisStub(String className, ClassLoader theclassLoader)Check if class with name provided is an stub.static booleanisStubField(String fieldName)Check if the field provided is DataClay fieldstatic voidnullifyAllFields(Object object)Nullify all fields of the object in order to free space.static voidsetField(Object instance, String fieldName, Object fieldValue)Sets the value of the field of instance provided with field name specified
 
- 
- 
- 
Field Detail- 
BOOTSTRAP_CLASSLOADERpublic static final ClassLoader BOOTSTRAP_CLASSLOADER Bootstrap class loader.
 
- 
 - 
Method Detail- 
getFieldpublic static Object getField(Object instance, String fieldName) throws NoSuchFieldException, IllegalAccessException This function gets the value of the field with name specified in the object instance provided. The field must exists in the class of the instance and must be accessible.- Parameters:
- instance- Instance from which to get the field value
- fieldName- Name of the field
- Returns:
- The value of the field with name specified in the instance provided
- Throws:
- NoSuchFieldException- If field not exists
- IllegalAccessException- If field is not accessible
 
 - 
getStaticFieldpublic static Object getStaticField(Class<?> staticClass, String fieldName) throws NoSuchFieldException, IllegalAccessException This function gets the value of the static field with name specified in the object instance provided. The field must exists in the class and must be static and accessible.- Parameters:
- staticClass- Class from which to get the field value
- fieldName- Name of the field
- Returns:
- The value of the static field with name specified in the instance provided
- Throws:
- NoSuchFieldException- If field not exists
- IllegalAccessException- If field is not accessible
 
 - 
setFieldpublic static void setField(Object instance, String fieldName, Object fieldValue) throws NoSuchFieldException, IllegalAccessException Sets the value of the field of instance provided with field name specified- Parameters:
- instance- Instance to modify
- fieldName- Name of the field to set
- fieldValue- Value to set
- Throws:
- NoSuchFieldException- If the field does not exist.
- IllegalAccessException- If the field is not accessible.
 
 - 
countOccurrencespublic static int countOccurrences(String str, String findStr) Count the occurrences of some string into another- Parameters:
- str- String to analyze
- findStr- String to count
- Returns:
- Number of occurrences of 'findStr' into 'str'.
 
 - 
getSubtypespublic static List<String> getSubtypes(String signature) Get sub types- Parameters:
- signature- Signature from which to get subtypes
- Returns:
- List of sub types found
 
 - 
isPrimitiveTypeNamepublic static boolean isPrimitiveTypeName(String typeName) Check if a name/signature is a Primitive type (quite close to Java primitives, but agnostic).- Parameters:
- typeName- type name to check.
- Returns:
- TRUE if the signature provided belongs to a Primitive type. FALSE otherwise.
 
 - 
isArrayTypeNamepublic static boolean isArrayTypeName(String typeName) Indicates if type name is an array type.- Parameters:
- typeName- Type name
- Returns:
- TRUE if type name is array type.
 
 - 
isJavaTypeNamepublic static boolean isJavaTypeName(String className) This function verifies if there is a Java type with the name provided- Parameters:
- className- name of the class
- Returns:
- TRUE if there is a java type with name provided. FALSE otherwise.
 
 - 
isJavaPrimitiveOrArrayTypeNamepublic static boolean isJavaPrimitiveOrArrayTypeName(String typeName) This function verifies if type name is java, array or primitive.- Parameters:
- typeName- Type name.
- Returns:
- TRUE if type name is java, array or primitive.
 
 - 
isImmutableTypeNamepublic static boolean isImmutableTypeName(String typeName) This function verifies if there is a lang type with the name provided.- Parameters:
- typeName- name of the type
- Returns:
- TRUE if there is a lang type with name provided. FALSE otherwise.
 
 - 
getPrimitiveTypeNameFromImmutableTypeNamepublic static String getPrimitiveTypeNameFromImmutableTypeName(String typeName) This function returns the primitive type name from immutable type name. WARNING: this function return "string" for immutable "java.lang.String". Used in ByteCode generation.- Parameters:
- typeName- name of the type
- Returns:
- the primitive type name from immutable type name or the same type name if not immutable.
 
 - 
getImmutableTypeNameFromPrimitiveTypeNamepublic static String getImmutableTypeNameFromPrimitiveTypeName(String typeName) This function returns the primitive type name from immutable type name. WARNING: this function return "string" for immutable "java.lang.String". Used in ByteCode generation.- Parameters:
- typeName- name of the type
- Returns:
- the primitive type name from immutable type name or the same type name if not immutable.
 
 - 
isJavaPrimitiveOrArraySignaturepublic static boolean isJavaPrimitiveOrArraySignature(String signature) Check if the signature provided belongs to a Java type or to a Primitive type.- Parameters:
- signature- Signature to check.
- Returns:
- TRUE if the signature provided belongs to a Java type or to a Primitive type. FALSE otherwise.
 
 - 
isPrimitiveSignaturepublic static boolean isPrimitiveSignature(String signature) This function verifies if there is a primitive type with the signature provided- Parameters:
- signature- signature of the type
- Returns:
- TRUE if there is a primitive type with signature provided. FALSE otherwise.
 
 - 
isImmutableSignaturepublic static boolean isImmutableSignature(String signature) This function verifies if there is a immutable type with the signature provided- Parameters:
- signature- signature of the type
- Returns:
- TRUE if there is a immutable type with signature provided. FALSE otherwise.
 
 - 
getDescriptorFromTypeNamepublic static String getDescriptorFromTypeName(String typeName) Get the descriptor from of the type with name provided- Parameters:
- typeName- Name of the type
- Returns:
- The descriptor of the type with name provided
 
 - 
getSignatureFromTypeNamepublic static String getSignatureFromTypeName(String typeName) Get the signature from of the type with name provided- Parameters:
- typeName- Name of the type
- Returns:
- The signature of the type with name provided
 
 - 
getSignatureFromInternalNamepublic static String getSignatureFromInternalName(String internalName) Get the signature from of the fully qualified type name (internal name) provided- Parameters:
- internalName- Internal Name of the type
- Returns:
- The signature from of the fully qualified type name (internal name) provided
 
 - 
getInternalNameFromTypeNamepublic static String getInternalNameFromTypeName(String typeName) Get internal name from type name- Parameters:
- typeName- Type name
- Returns:
- Internal name.
 
 - 
getTypeNameFromInternalNamepublic static String getTypeNameFromInternalName(String internalName) Get type name from internal name- Parameters:
- internalName- Internal name
- Returns:
- Type name
 
 - 
getTypeNameFromSignatureOrDescriptorpublic static String getTypeNameFromSignatureOrDescriptor(String signature) Get the name of the type corresponding to the provided signature.- Parameters:
- signature- Signature to analyze
- Returns:
- The name of the type corresponding to the provided signature.
 
 - 
getCanonicalTypeNameFromSignaturepublic static String getCanonicalTypeNameFromSignature(String signature) Get the name of the type corresponding to the provided signature and also get the [] array representation.- Parameters:
- signature- Signature to analyze
- Returns:
- The name of the type corresponding to the provided signature.
 
 - 
isStubFieldpublic static boolean isStubField(String fieldName) Check if the field provided is DataClay field- Parameters:
- fieldName- Name of the field
- Returns:
- TRUE if the class provided is some of the types in a stub. FALSE otherwise.
 
 - 
getSignatureFromMethodpublic static String getSignatureFromMethod(Method method) Get the signature from method provided- Parameters:
- method- Method
- Returns:
- The signature of method provided
 
 - 
getSignatureFromConstructorpublic static String getSignatureFromConstructor(Constructor<?> constructor) Get the signature from constructor provided- Parameters:
- constructor- Method
- Returns:
- The signature of constructor provided
 
 - 
getClassFromSignatureAndArraypublic static Class<?> getClassFromSignatureAndArray(String signature, ClassLoader classLoader) Get the class corresponding to the provided signature. If the signature belongs to an array get its component type.- Parameters:
- signature- Signature to check.
- classLoader- Class loader to use
- Returns:
- The class corresponding to the provided signature. If the signature belongs to an array get its component type.
 
 - 
isStubpublic static boolean isStub(String className, ClassLoader theclassLoader) Check if class with name provided is an stub.- Parameters:
- className- Name of the class to analyze.
- theclassLoader- Class loader being used
- Returns:
- TRUE if it is an stub for the class loader used for this class. FALSE otherwise.
 
 - 
nullifyAllFieldspublic static void nullifyAllFields(Object object) Nullify all fields of the object in order to free space.- Parameters:
- object- Object to nullify.
 
 
- 
 
-