public class SReflect extends Object
Constructor and Description |
---|
SReflect() |
Modifier and Type | Method and Description |
---|---|
static Class |
classForName(String name,
ClassLoader classloader)
Extension for Class.forName(), because primitive
types are not supported.
|
static Class |
classForName0(String name,
boolean initialize,
ClassLoader classloader)
Extension for Class.forName(), because primitive
types are not supported.
|
static Class |
classForName0(String name,
ClassLoader classloader)
Extension for Class.forName(), because primitive
types are not supported.
|
static Object |
convertWrappedValue(Object value,
Class clazz)
Convert a value to the correct wrapped type.
|
static Class |
findClass(String clname,
String[] imports,
ClassLoader classloader)
Find a class.
|
static Class |
findClass0(String clname,
String[] imports,
ClassLoader classloader)
Find a class.
|
static Object |
getArray(Object collection)
Get an array for an arbitrary collection object.
|
static Field |
getCachedField(Class clazz,
String name)
Get a cached field.
|
static String |
getClassName(Class clazz)
Beautifies names of arrays (eg 'String[]' instead of '[LString;').
|
static Object |
getDeclared(Object o,
String fieldname)
Get the declared object, doesnt cumulate through superclasses.
|
static Object |
getDefaultValue(Class clazz)
Get default value for basic types.
|
static Field |
getField(Class clazz,
String name)
Get a field of the class,
or any of it's superclasses.
|
static String |
getInnerClassName(Class clazz)
Get inner class name.
|
static Iterator |
getIterator(Object collection)
Get an iterator for an arbitrary collection object.
|
static Method |
getMethod(Class clazz,
String name,
Class[] types)
Get a method of the class.
|
static Method[] |
getMethods(Class clazz,
String name)
Get public method(s) of the class by name.
|
static String |
getPackageName(Class clazz)
Get the package of a class.
|
static Class[] |
getSuperInterfaces(Class[] interfaces)
Get the super interfaces.
|
static String |
getUnqualifiedClassName(Class clazz)
Get unqualified class name.
|
static String |
getUnqualifiedTypeName(String name)
Get unqualified type name.
|
static Class |
getWrappedType(Class clazz)
Get the wrapped type.
|
static boolean |
instanceOf(Object o,
Class c)
Is an object instanceof a class or its superclasses.
|
static boolean |
isBasicType(Class clazz)
Is basic type.
|
static boolean |
isIterable(Object obj)
Test if object is some kind of collection.
|
static boolean |
isIterableClass(Class clazz)
Test if class is some kind of collection.
|
static boolean |
isSupertype(Class clazz1,
Class clazz2)
Check if a class is a supertype of, or the same as another class.
|
static int[] |
matchArgumentTypes(Class[] argtypes,
Class[][] paramtypes)
Match the given argument types to a set
of parameter type arrays.
|
public static Class getWrappedType(Class clazz)
clazz
- The basic class.public static boolean isBasicType(Class clazz)
public static Class classForName0(String name, ClassLoader classloader)
name
- The class name.public static Class classForName0(String name, boolean initialize, ClassLoader classloader)
name
- The class name.public static Class classForName(String name, ClassLoader classloader) throws ClassNotFoundException
name
- The class name.ClassNotFoundException
public static String getClassName(Class clazz)
public static String getUnqualifiedClassName(Class clazz)
public static String getUnqualifiedTypeName(String name)
public static String getInnerClassName(Class clazz)
public static String getPackageName(Class clazz)
public static Field getField(Class clazz, String name)
Class.getField(String)
,
this will also return nonpublic fields
(except when running in netscape :-( ).clazz
- The class to search.name
- The name of the field to search for.public static Field getCachedField(Class clazz, String name) throws NoSuchFieldException
clazz
- The clazz.name
- The name.NoSuchFieldException
public static Object getDeclared(Object o, String fieldname)
o
- The object.fieldname
- The name of the array.public static Method getMethod(Class clazz, String name, Class[] types)
Class.getMethod(String, Class[])
,
this uses the methodcache.clazz
- The class to search.name
- The name of the method to search for.types
- The parameter types.public static Method[] getMethods(Class clazz, String name)
clazz
- The class to search.name
- The name of the method to search for.public static Class findClass(String clname, String[] imports, ClassLoader classloader) throws ClassNotFoundException
clname
- The class name.imports
- The comma separated list of imported packages.ClassNotFoundException
- when the class is not found in the imports.public static Class findClass0(String clname, String[] imports, ClassLoader classloader)
clname
- The class name.imports
- The comma separated list of imported packages.public static int[] matchArgumentTypes(Class[] argtypes, Class[][] paramtypes)
argtypes
- The array of argument types.paramtypes
- The array of parameter type arrays.public static boolean isSupertype(Class clazz1, Class clazz2)
clazz1
- The assumed supertype.clazz2
- The assumed subtype.public static Object convertWrappedValue(Object value, Class clazz)
value
- The value.clazz
- The target clazz.isSupertype(Class, Class)
public static Iterator getIterator(Object collection)
collection
- The collection object.IllegalArgumentException
- when argument is not
one of (Iterator, Enumeration, Collection, Map, Array).public static boolean isIterable(Object obj)
obj
- The object.public static boolean isIterableClass(Class clazz)
class
- The class.public static Object getArray(Object collection)
collection
- The collection object.IllegalArgumentException
- when argument is not
one of (Iterator, Enumeration, Collection, Map, Array).public static boolean instanceOf(Object o, Class c)
o
- The object.c
- The class.public static Class[] getSuperInterfaces(Class[] interfaces)
interfaces
- The interfacesCopyright © 2012. All Rights Reserved.