|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.arakhne.vmutil.ReflectionUtil
public class ReflectionUtil
This utility class provides a way to extend the reflection API and the Class class with autoboxing-compliant functions.
| Constructor Summary | |
|---|---|
ReflectionUtil()
|
|
| Method Summary | ||
|---|---|---|
static Class<?> |
forName(String name)
Replies the type that corresponds to the specified class. |
|
static Class<?> |
forName(String name,
boolean typeInitialization,
ClassLoader loader)
Replies the type that corresponds to the specified class. |
|
static Class<?> |
forName(String name,
ClassLoader loader)
Replies the type that corresponds to the specified class. |
|
static
|
getAllDirectInterfaces(Class<? extends T> lowestType,
Class<T> highestType)
Determines the interfaces implemented by the classes from the lowest type to the highestType which are extended the given interfaceType. |
|
static
|
getAllDirectInterfaces(Class<? extends T> lowestType,
Class<T> highestType,
Class<I> interfaceType)
Determines the interfaces implemented by the classes from the lowest type to the highestType which are extended the given interfaceType. |
|
static Class<?> |
getCommonType(Class<?> type1,
Class<?> type2)
Replies the top-most type which is common to both given types. |
|
static Class<?> |
getCommonType(Object instance1,
Object instance2)
Replies the top-most type which is common to both given objects. |
|
static Collection<Class<?>> |
getPackageClasses(Package pkg)
Replies the list of the classes in the given package. |
|
static Collection<Class<?>> |
getPackageClasses(String packageName)
Replies the list of the classes in the given package. |
|
static
|
getSubClasses(Class<T> className)
Replies the list of all the subclasses of the given class in the current classpath. |
|
static
|
getSubClasses(Class<T> className,
boolean allowAbstract,
boolean allowInterface,
boolean allowEnum,
Collection<Class<? extends T>> result)
Replies the list of all the subclasses of the given class in the current classpath. |
|
static
|
getSuperClasses(Class<T> className)
Replies the list of all the superclasses of the given class. |
|
static boolean |
isAssignableFrom(Class<?> assignementTarget,
Class<?> assignementSource)
Determines if the assignmentTarget object is either the same as,
or is a superclass or superinterface of, the class or interface
represented by the specified
assignementSource parameter. |
|
static boolean |
isInstance(Class<?> type,
Object obj)
Determines if the specified Object is assignment-compatible
with the object represented by the Class. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ReflectionUtil()
| Method Detail |
|---|
public static boolean isInstance(Class<?> type,
Object obj)
Object is assignment-compatible
with the object represented by the Class. This method extends
Class.isInstance(Object) with autoboxing support.
type - is the class against which the object must be testobj - is the object to check
true if obj is an instance of the typeClass.isInstance(Object)
public static boolean isAssignableFrom(Class<?> assignementTarget,
Class<?> assignementSource)
assignmentTarget object is either the same as,
or is a superclass or superinterface of, the class or interface
represented by the specified
assignementSource parameter. This method extends
Class.isAssignableFrom(Class) with autoboxing support.
assignementTarget - is the class that is tested to be a super class.assignementSource - is the class that is tested to be a sub class.
true if an object of the assignementSource type
could be assigned to a variable of assignementTarget type,
otherwise false.
public static Class<?> forName(String name)
throws ClassNotFoundException
Class.forName(String) with autoboxing support.
name - is the name of the class to load.
ClassNotFoundException - if name names an
unknown class or primitive
public static Class<?> forName(String name,
ClassLoader loader)
throws ClassNotFoundException
Class.forName(String) with autoboxing support.
name - is the name of the class to load.loader - is the class loader to use.
ClassNotFoundException - if name names an
unknown class or primitive
public static Class<?> forName(String name,
boolean typeInitialization,
ClassLoader loader)
throws ClassNotFoundException
Class.forName(String) with autoboxing support.
name - is the name of the class to load.typeInitialization - must be true to initialize the type, false otherwise.loader - is the class loader to use.
ClassNotFoundException - if name names an
unknown class or primitivepublic static Collection<Class<?>> getPackageClasses(Package pkg)
pkg - is the package to explore.
public static Collection<Class<?>> getPackageClasses(String packageName)
packageName - is the name of the package to explore.
public static <T> Collection<Class<? extends T>> getSubClasses(Class<T> className)
T - is the type of the superclass.className - is the name of the class to explore.
public static <T> void getSubClasses(Class<T> className,
boolean allowAbstract,
boolean allowInterface,
boolean allowEnum,
Collection<Class<? extends T>> result)
T - is the type of the superclass.className - is the name of the class to explore.allowAbstract - is true to allow abstract classes to be put in the replied listallowInterface - is true to allow interfaces to be put in the replied list.allowEnum - is true to allow enumeration to be put in the replied list.result - is the list of subclasses which will be filled by this function.
public static <T,I> Set<Class<? extends I>> getAllDirectInterfaces(Class<? extends T> lowestType,
Class<T> highestType,
Class<I> interfaceType)
Insteed of Class.getInterfaces(), this function is exploring
the super classes. This function does not explore super-interfaces
of implemented interfaces.
interface IA {}
interface IB extends IA {}
interface IC {}
interface ID extends IB, IC {}
class CA implements IC {}
class CB extends CA {}
class CC extends CB implements IB {}
This function replies for:
getAllDirectInterfaces(IA,null,null)={}getAllDirectInterfaces(IB,null,null)={IA}getAllDirectInterfaces(IC,null,null)={}getAllDirectInterfaces(ID,null,null)={IB,IC}getAllDirectInterfaces(CA,null,null)={IC}getAllDirectInterfaces(CB,null,null)={IC}getAllDirectInterfaces(CC,null,null)={IB,IC}
T - is the highest type to explore in type hierarchy.I - indicates the type of the replied interfaces.lowestType - is the lowest type to explore in type hierarchy.highestType - is the highest type to explore in type hierarchy.interfaceType - indicates the type of the replied interfaces.
public static <T> Set<Class<?>> getAllDirectInterfaces(Class<? extends T> lowestType,
Class<T> highestType)
Insteed of Class.getInterfaces(), this function is exploring
the super classes. This function does not explore super-interfaces
of implemented interfaces.
interface IA {}
interface IB extends IA {}
interface IC {}
interface ID extends IB, IC {}
class CA implements IC {}
class CB extends CA {}
class CC extends CB implements IB {}
This function replies for:
getAllDirectInterfaces(IA,null,null)={}getAllDirectInterfaces(IB,null,null)={IA}getAllDirectInterfaces(IC,null,null)={}getAllDirectInterfaces(ID,null,null)={IB,IC}getAllDirectInterfaces(CA,null,null)={IC}getAllDirectInterfaces(CB,null,null)={IC}getAllDirectInterfaces(CC,null,null)={IB,IC}
T - is the highest type to explore in type hierarchy.lowestType - is the lowest type to explore in type hierarchy.highestType - is the highest type to explore in type hierarchy.
public static <T> Collection<Class<? super T>> getSuperClasses(Class<T> className)
This function does not replies Object.class.
T - is the type of the lowest class.className - is the type of the lowest class.
public static Class<?> getCommonType(Class<?> type1,
Class<?> type2)
type1 - type2 -
public static Class<?> getCommonType(Object instance1,
Object instance2)
instance1 - instance2 -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||