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 <T> Class<T> |
findClass(String clname,
String[] imports,
ClassLoader classloader)
Find a class.
|
static <T> Class<T> |
findClass0(String clname,
String[] imports,
ClassLoader classloader)
Find a class.
|
static Method[] |
getAllMethods(Class clazz)
Get all methods of a class including public, protected
and private methods of the class and its superclasses.
|
static int |
getAndroidVersion()
Get Android API version.
|
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 Class<?> |
getClass(Type type)
Get the class for a type.
|
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 Type |
getInnerGenericType(Type type)
Unwrap a generic type.
|
static <T> Iterator<T> |
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 String |
getMethodName()
Get the current method name from the caller.
|
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 |
hasXmlSupport()
Checks wether the Platform has the necessary classes to provide XML
encoding and decoding support.
|
static boolean |
instanceOf(Object o,
Class c)
Is an object instanceof a class or its superclasses.
|
static boolean |
isAndroid()
Test if running on android.
|
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 |
isStringConvertableType(Class clazz)
Test if the class is automatically convertable
from/to a string.
|
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.
|
static void |
scanDir(URL[] urls,
File file,
IFilter filter,
List<String> results,
List<String> donedirs) |
static Class<?>[] |
scanForClasses(URL[] urls,
ClassLoader classloader,
IFilter filefilter,
IFilter classfilter) |
static String[] |
scanForFiles(URL[] urls,
IFilter filter) |
static Class<?> |
unwrapGenericType(Type type)
Unwrap a generic type.
|
static Object |
wrapValue(boolean val) |
static Object |
wrapValue(byte val) |
static Object |
wrapValue(char val) |
static Object |
wrapValue(float val) |
static Object |
wrapValue(int val) |
static Object |
wrapValue(long val) |
static Object |
wrapValue(Object val) |
static Object |
wrapValue(short val) |
public static Class getWrappedType(Class clazz)
clazz
- The basic class.public static Class<?> unwrapGenericType(Type type)
type
- The generic type.public static Type getInnerGenericType(Type type)
type
- The generic type.public static boolean isStringConvertableType(Class clazz)
clazz
- The class.public static boolean isBasicType(Class clazz)
public static Object wrapValue(boolean val)
public static Object wrapValue(int val)
public static Object wrapValue(long val)
public static Object wrapValue(byte val)
public static Object wrapValue(char val)
public static Object wrapValue(float val)
public static Object wrapValue(short val)
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 Method[] getAllMethods(Class clazz)
public static <T> Class<T> 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 <T> Class<T> 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 <T> Iterator<T> 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)
clazz
- 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 interfacespublic static Object getDefaultValue(Class clazz)
public static String getMethodName()
public static Class<?>[] scanForClasses(URL[] urls, ClassLoader classloader, IFilter filefilter, IFilter classfilter)
public static void scanDir(URL[] urls, File file, IFilter filter, List<String> results, List<String> donedirs)
public static boolean isAndroid()
public static int getAndroidVersion()
public static boolean hasXmlSupport()
Copyright © 2012. All Rights Reserved.