Package org.apache.wayang.core.util
Class ReflectionUtils
java.lang.Object
org.apache.wayang.core.util.ReflectionUtils
Utilities for reflection code.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TTries to evaluate the given statement, thereby supporting the following statement types:new <class name>()<class name>.<constant><class name>.<static method>()static <T> TexecuteStaticArglessMethod(String className, String methodName) Executes a parameterless static method.static <T> Class<T>generalize(Class<? extends T> baseClass) Casts the givenClassto a more general one.static StringgetDeclaringJar(Class<?> cls) Identifies and returns the JAR file declaring the givenClassif no such file could be determined.static StringgetDeclaringJar(Object object) Identifies and returns the JAR file declaring theClassof the givenobjectornullif no such file could be determined.static <T> TgetProperty(Object obj, String property) Retrieve a property from an object.static URLgetResourceURL(String resourceName) Provides a resource asURL.getTypeParameters(Class<?> subclass, Class<?> superclass) Retrieve theTypes of type parameters from an extended/implemented superclass/interface.static TypegetWrapperClass(Type type, int index) static <T> TinstantiateDefault(Class<? extends T> cls) Creates a new instance of the givenClassvia the default constructor.static <T> TinstantiateDefault(String className) Creates a new instance of aClassvia the default constructor.static <T> TTries to instantiate an arbitrary instance of the givenClass.static <T> TinstantiateSomehow(Class<T> cls, Tuple<Class<?>, Supplier<?>>... defaultParameters) Tries to instantiate an arbitrary instance of the givenClass.static InputStreamloadResource(String resourceName) Provides a resource as anInputStream.static <T> TretrieveStaticVariable(String className, String variableName) Retrieves a static variable.static <T> Class<T>Casts the givenClassto a more specific one.static doubleConvert the givenObjectto adouble.
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils()
-
-
Method Details
-
getDeclaringJar
Identifies and returns the JAR file declaring theClassof the givenobjectornullif no such file could be determined. -
getDeclaringJar
Identifies and returns the JAR file declaring the givenClassif no such file could be determined. -
loadResource
Provides a resource as anInputStream.- Parameters:
resourceName- the name or path of the resource- Returns:
- an
InputStreamwith the contents of the resource ornullif the resource could not be found
-
getResourceURL
Provides a resource asURL.- Parameters:
resourceName- the name or path of the resource- Returns:
- a
URLdescribing the path to the resource ornullif the resource could not be found
-
specify
Casts the givenClassto a more specific one.- Type Parameters:
T- the specific type parameter for thebaseClass- Parameters:
baseClass- that should be casted- Returns:
- the
baseClass, casted
-
generalize
Casts the givenClassto a more general one.- Type Parameters:
T- the specific type parameter for thebaseClass- Parameters:
baseClass- that should be casted- Returns:
- the
baseClass, casted
-
evaluate
Tries to evaluate the given statement, thereby supporting the following statement types:new <class name>()<class name>.<constant><class name>.<static method>()
- Type Parameters:
T- the return type- Parameters:
statement- the statement- Returns:
- the result of the evaluated statement
- Throws:
IllegalArgumentException
-
executeStaticArglessMethod
Executes a parameterless static method.- Type Parameters:
T-- Parameters:
className- the name of theClassthat comprises the methodmethodName- the name of the method- Returns:
- the return value of the executed method
-
retrieveStaticVariable
Retrieves a static variable.- Type Parameters:
T-- Parameters:
className- the name of theClassthat comprises the methodvariableName- the name of the method- Returns:
- the return value of the executed method
-
instantiateDefault
Creates a new instance of aClassvia the default constructor.- Parameters:
className- name of theClassto be instantiated- Returns:
- the instance
-
instantiateDefault
Creates a new instance of the givenClassvia the default constructor.- Parameters:
cls- theClassto be instantiated- Returns:
- the instance
-
instantiateSomehow
public static <T> T instantiateSomehow(Class<T> cls, Tuple<Class<?>, Supplier<?>>... defaultParameters) Tries to instantiate an arbitrary instance of the givenClass.- Parameters:
cls- that should be instantiateddefaultParameters- designate specific default parameter values for parameterClasses- Returns:
- the instance
-
instantiateSomehow
public static <T> T instantiateSomehow(Class<T> cls, List<Tuple<Class<?>, Supplier<?>>> defaultParameters) Tries to instantiate an arbitrary instance of the givenClass.- Parameters:
cls- that should be instantiateddefaultParameters- designate specific default parameter values for parameterClasses- Returns:
- the instance
-
getTypeParameters
Retrieve theTypes of type parameters from an extended/implemented superclass/interface. -
getProperty
Retrieve a property from an object.- Type Parameters:
T- the return type- Parameters:
obj- from which the property should be retrievedproperty- the property- Returns:
- the property
-
toDouble
Convert the givenObjectto adouble.- Parameters:
o- theObject- Returns:
- the
double
-
getWrapperClass
-