public class SReflect
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.util.Map |
basictypes
Mapping from basic class name -> basic type(class).
|
protected static java.util.Map<Tuple2<java.lang.String,java.lang.Integer>,java.lang.Class<?>> |
classcache
Class lookup cache (classloader(weak)->Map([name, import]->class)).
|
protected static java.util.Set |
convertabletypes
String convertable types.
|
protected static java.lang.Object[] |
EMPTY_ARRAY |
protected static java.util.Map |
fieldcache
Field lookup cache (class->(name->field[])).
|
static boolean |
HAS_GUI
This is set to true if the VM has a working GUI environment available.
|
protected static java.util.Map |
innerclassnamecache
Inner class name lookup cache.
|
protected static java.lang.Boolean |
isAndroid
Cached flag for android check.
|
protected static java.util.Map |
methodcache
Method lookup cache (class->(name->method[])).
|
protected static java.util.Map |
wrappedtypes
Mapping from basic class -> object type(class).
|
Constructor and Description |
---|
SReflect() |
Modifier and Type | Method and Description |
---|---|
static ISubscriptionIntermediateFuture<java.lang.String> |
asyncScanDir(java.net.URL[] urls,
java.io.File file,
IFilter filter,
java.util.List<java.lang.String> donedirs)
Scan directories.
|
static ISubscriptionIntermediateFuture<java.lang.Class<?>> |
asyncScanForClasses(java.lang.ClassLoader classloader,
IFilter<java.lang.Object> filefilter,
IFilter<java.lang.Class<?>> classfilter,
int max,
boolean includebootpath)
Scan for classes that fulfill certain criteria as specified by the file and classfilters.
|
static ISubscriptionIntermediateFuture<java.lang.Class<?>> |
asyncScanForClasses(java.net.URL[] urls,
java.lang.ClassLoader classloader,
IFilter<java.lang.Object> filefilter,
IFilter<java.lang.Class<?>> classfilter,
int max)
Scan for classes that fulfill certain criteria as specified by the file and classfilters.
|
static ISubscriptionIntermediateFuture<java.lang.String> |
asyncScanForFiles(java.net.URL[] urls,
IFilter<java.lang.Object> filter)
Scan for files in a given list of urls.
|
static java.lang.String |
chooseAvailableResource(java.lang.ClassLoader cl,
java.lang.String... choices)
Select the first available resource from a choice of potential resources.
|
static java.lang.String |
chooseAvailableResource(java.lang.String... choices)
Select the first available resource from a choice of potential resources.
|
static java.lang.Class<?> |
classForName(java.lang.String name,
java.lang.ClassLoader classloader)
Extension for Class.forName(), because primitive
types are not supported.
|
static java.lang.Class<?> |
classForName0(java.lang.String name,
boolean initialize,
java.lang.ClassLoader classloader)
Extension for Class.forName(), because primitive
types are not supported.
|
static java.lang.Class<?> |
classForName0(java.lang.String name,
java.lang.ClassLoader classloader)
Extension for Class.forName(), because primitive
types are not supported.
|
static java.lang.Object |
convertWrappedValue(java.lang.Object value,
java.lang.Class clazz)
Convert a value to the correct wrapped type.
|
static java.lang.String |
cutPackageFromClassName(java.lang.String name)
Cut package off from classname.
|
static java.lang.Object[] |
fillArguments(java.lang.Object[] args,
java.lang.Class<?>[] paramtypes)
Map arguments to parameters using varargs, if necessary.
|
static <T> java.lang.Class<T> |
findClass(java.lang.String clname,
java.lang.String[] imports,
java.lang.ClassLoader classloader)
Find a class.
|
static <T> java.lang.Class<T> |
findClass0(java.lang.String clname,
java.lang.String[] imports,
java.lang.ClassLoader classloader)
Find a class.
|
static java.lang.reflect.Field[] |
getAllFields(java.lang.Class clazz)
Get all fields of a class including public, protected
and private fields of the class and its superclasses.
|
static java.lang.reflect.Method[] |
getAllMethods(java.lang.Class clazz)
Get all methods of a class including public, protected
and private methods of the class and its superclasses.
|
static java.lang.Object |
getArray(java.lang.Object collection)
Get an array for an arbitrary collection object.
|
static java.lang.reflect.Field |
getCachedField(java.lang.Class clazz,
java.lang.String name)
Get a cached field.
|
static java.lang.Class<?> |
getClass(java.lang.reflect.Type type)
Get the class for a type.
|
static java.lang.String |
getClassName(java.lang.Class<?> clazz)
Beautifies names of arrays (eg 'String[]' instead of '[LString;').
|
static java.lang.Object |
getDeclared(java.lang.Object o,
java.lang.String fieldname)
Get the declared object, doesnt cumulate through superclasses.
|
static java.lang.Object |
getDefaultValue(java.lang.Class clazz)
Get default value for basic types.
|
static java.lang.reflect.Field |
getField(java.lang.Class clazz,
java.lang.String name)
Get a field of the class,
or any of it's superclasses.
|
static java.lang.String |
getGenericClassName(java.lang.reflect.Type t,
java.lang.Class<?> c)
Returns generic type name.
|
static java.lang.String |
getInnerClassName(java.lang.Class clazz)
Get inner class name.
|
static java.lang.reflect.Type |
getInnerGenericType(java.lang.reflect.Type type)
Unwrap a generic type.
|
static <T> java.lang.Iterable<T> |
getIterable(java.lang.Object collection)
Get an iterator for an arbitrary collection object.
|
static <T> java.util.Iterator<T> |
getIterator(java.lang.Object collection)
Get an iterator for an arbitrary collection object.
|
static java.lang.reflect.Method |
getMethod(java.lang.Class clazz,
java.lang.String name,
java.lang.Class[] types)
Get a method of the class.
|
static java.lang.String |
getMethodName()
Get the current method name from the caller.
|
static java.lang.reflect.Method[] |
getMethods(java.lang.Class clazz,
java.lang.String name)
Get public method(s) of the class by name.
|
static java.lang.String |
getMethodSignature(java.lang.reflect.Method method)
Get the generic signature of a method.
|
static java.lang.String |
getPackageName(java.lang.Class clazz)
Get the package of a class.
|
static java.lang.Class[] |
getSuperInterfaces(java.lang.Class[] interfaces)
Get the super interfaces.
|
static java.lang.String |
getUnqualifiedClassName(java.lang.Class clazz)
Get unqualified class name.
|
static java.lang.String |
getUnqualifiedTypeName(java.lang.String name)
Get unqualified type name.
|
static java.lang.Class<?> |
getWrappedType(java.lang.Class<?> clazz)
Get the wrapped type.
|
static boolean |
instanceOf(java.lang.Object o,
java.lang.Class c)
Is an object instanceof a class or its superclasses.
|
static boolean |
isAndroid()
Test if running on android.
|
static boolean |
isBasicType(java.lang.Class clazz)
Is basic type.
|
static boolean |
isIterable(java.lang.Object obj)
Test if object is some kind of collection.
|
static boolean |
isIterableClass(java.lang.Class clazz)
Test if class is some kind of collection.
|
static boolean |
isStringConvertableType(java.lang.Class clazz)
Test if the class is automatically convertable
from/to a string.
|
static boolean |
isSupertype(java.lang.Class<?> clazz1,
java.lang.Class<?> clazz2)
Check if a class is a supertype of, or the same as another class.
|
static void |
main(java.lang.String[] args) |
static java.lang.String |
makeNiceArrayNotation(java.lang.String name)
Process a type name and replace array notation with nice one.
|
static int[] |
matchArgumentTypes(java.lang.Class[] argtypes,
java.lang.Class[][] paramtypes)
Match the given argument types to a set
of parameter type arrays.
|
static void |
scanDir(java.net.URL[] urls,
java.io.File file,
IFilter filter,
java.util.List<java.lang.String> results,
java.util.List<java.lang.String> donedirs)
Scan directories.
|
static java.lang.Class<?>[] |
scanForClasses(java.lang.ClassLoader classloader,
IFilter filefilter,
IFilter classfilter,
boolean includebootpath)
Scan for classes that fulfill certain criteria as specified by the file and classfilters.
|
static java.lang.Class<?>[] |
scanForClasses(java.net.URL[] urls,
java.lang.ClassLoader classloader,
IFilter filefilter,
IFilter classfilter)
Scan for classes that fulfill certain criteria as specified by the file and classfilters.
|
static java.lang.String[] |
scanForFiles(java.net.URL[] urls,
IFilter filter)
Scan for files in a given list of urls.
|
static java.lang.Class<?> |
unwrapGenericType(java.lang.reflect.Type type)
Unwrap a generic type.
|
static java.lang.Object |
wrapValue(boolean val) |
static java.lang.Object |
wrapValue(byte val) |
static java.lang.Object |
wrapValue(char val) |
static java.lang.Object |
wrapValue(double val) |
static java.lang.Object |
wrapValue(float val) |
static java.lang.Object |
wrapValue(int val) |
static java.lang.Object |
wrapValue(long val) |
static java.lang.Object |
wrapValue(java.lang.Object val) |
static java.lang.Object |
wrapValue(short val) |
protected static final java.util.Map<Tuple2<java.lang.String,java.lang.Integer>,java.lang.Class<?>> classcache
protected static final java.util.Map innerclassnamecache
protected static final java.util.Map methodcache
protected static final java.util.Map fieldcache
protected static final java.util.Map basictypes
protected static final java.util.Map wrappedtypes
protected static final java.util.Set convertabletypes
public static final boolean HAS_GUI
protected static final java.lang.Object[] EMPTY_ARRAY
protected static volatile java.lang.Boolean isAndroid
public static java.lang.Class<?> getWrappedType(java.lang.Class<?> clazz)
clazz
- The basic class.public static java.lang.Class<?> unwrapGenericType(java.lang.reflect.Type type)
type
- The generic type.public static java.lang.reflect.Type getInnerGenericType(java.lang.reflect.Type type)
type
- The generic type.public static java.lang.Class<?> getClass(java.lang.reflect.Type type)
public static boolean isStringConvertableType(java.lang.Class clazz)
clazz
- The class.public static boolean isBasicType(java.lang.Class clazz)
public static java.lang.Object wrapValue(boolean val)
public static java.lang.Object wrapValue(int val)
public static java.lang.Object wrapValue(long val)
public static java.lang.Object wrapValue(byte val)
public static java.lang.Object wrapValue(char val)
public static java.lang.Object wrapValue(float val)
public static java.lang.Object wrapValue(double val)
public static java.lang.Object wrapValue(short val)
public static java.lang.Object wrapValue(java.lang.Object val)
public static java.lang.Class<?> classForName0(java.lang.String name, java.lang.ClassLoader classloader)
name
- The class name.public static java.lang.Class<?> classForName0(java.lang.String name, boolean initialize, java.lang.ClassLoader classloader)
name
- The class name.public static java.lang.Class<?> classForName(java.lang.String name, java.lang.ClassLoader classloader) throws java.lang.ClassNotFoundException
name
- The class name.java.lang.ClassNotFoundException
public static java.lang.String getClassName(java.lang.Class<?> clazz)
public static java.lang.String getGenericClassName(java.lang.reflect.Type t, java.lang.Class<?> c)
t
- The type.c
- The class, used when type is variable declaration.public static java.lang.String getUnqualifiedClassName(java.lang.Class clazz)
public static java.lang.String getUnqualifiedTypeName(java.lang.String name)
public static java.lang.String makeNiceArrayNotation(java.lang.String name)
public static java.lang.String cutPackageFromClassName(java.lang.String name)
public static void main(java.lang.String[] args)
public static java.lang.String getInnerClassName(java.lang.Class clazz)
public static java.lang.String getPackageName(java.lang.Class clazz)
public static java.lang.String chooseAvailableResource(java.lang.String... choices)
public static java.lang.String chooseAvailableResource(java.lang.ClassLoader cl, java.lang.String... choices)
public static java.lang.String getMethodSignature(java.lang.reflect.Method method)
method
- The method.public static java.lang.reflect.Field getField(java.lang.Class clazz, java.lang.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 java.lang.reflect.Field getCachedField(java.lang.Class clazz, java.lang.String name) throws java.lang.NoSuchFieldException
clazz
- The clazz.name
- The name.java.lang.NoSuchFieldException
public static java.lang.Object getDeclared(java.lang.Object o, java.lang.String fieldname)
o
- The object.fieldname
- The name of the array.public static java.lang.reflect.Method getMethod(java.lang.Class clazz, java.lang.String name, java.lang.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 java.lang.reflect.Method[] getMethods(java.lang.Class clazz, java.lang.String name)
clazz
- The class to search.name
- The name of the method to search for.public static java.lang.reflect.Method[] getAllMethods(java.lang.Class clazz)
public static java.lang.reflect.Field[] getAllFields(java.lang.Class clazz)
public static <T> java.lang.Class<T> findClass(java.lang.String clname, java.lang.String[] imports, java.lang.ClassLoader classloader) throws java.lang.ClassNotFoundException
clname
- The class name.imports
- The comma separated list of imported packages.java.lang.ClassNotFoundException
- when the class is not found in the imports.public static <T> java.lang.Class<T> findClass0(java.lang.String clname, java.lang.String[] imports, java.lang.ClassLoader classloader)
clname
- The class name.imports
- The comma separated list of imported packages.public static int[] matchArgumentTypes(java.lang.Class[] argtypes, java.lang.Class[][] paramtypes)
argtypes
- The array of argument types.paramtypes
- The array of parameter type arrays.public static java.lang.Object[] fillArguments(java.lang.Object[] args, java.lang.Class<?>[] paramtypes)
public static boolean isSupertype(java.lang.Class<?> clazz1, java.lang.Class<?> clazz2)
clazz1
- The assumed supertype.clazz2
- The assumed subtype.public static java.lang.Object convertWrappedValue(java.lang.Object value, java.lang.Class clazz)
value
- The value.clazz
- The target clazz.isSupertype(Class, Class)
public static <T> java.lang.Iterable<T> getIterable(java.lang.Object collection)
collection
- The collection object.java.lang.IllegalArgumentException
- when argument is not
one of (Iterator, Enumeration, Collection, Map, Array).public static <T> java.util.Iterator<T> getIterator(java.lang.Object collection)
collection
- The collection object.java.lang.IllegalArgumentException
- when argument is not
one of (Iterator, Enumeration, Collection, Map, Array).public static boolean isIterable(java.lang.Object obj)
obj
- The object.public static boolean isIterableClass(java.lang.Class clazz)
clazz
- The class.public static java.lang.Object getArray(java.lang.Object collection)
collection
- The collection object.java.lang.IllegalArgumentException
- when argument is not
one of (Iterator, Enumeration, Collection, Map, Array).public static boolean instanceOf(java.lang.Object o, java.lang.Class c)
o
- The object.c
- The class.public static java.lang.Class[] getSuperInterfaces(java.lang.Class[] interfaces)
interfaces
- The interfacespublic static java.lang.Object getDefaultValue(java.lang.Class clazz)
public static java.lang.String getMethodName()
public static java.lang.Class<?>[] scanForClasses(java.lang.ClassLoader classloader, IFilter filefilter, IFilter classfilter, boolean includebootpath)
public static java.lang.Class<?>[] scanForClasses(java.net.URL[] urls, java.lang.ClassLoader classloader, IFilter filefilter, IFilter classfilter)
public static java.lang.String[] scanForFiles(java.net.URL[] urls, IFilter filter)
public static void scanDir(java.net.URL[] urls, java.io.File file, IFilter filter, java.util.List<java.lang.String> results, java.util.List<java.lang.String> donedirs)
public static ISubscriptionIntermediateFuture<java.lang.Class<?>> asyncScanForClasses(java.lang.ClassLoader classloader, IFilter<java.lang.Object> filefilter, IFilter<java.lang.Class<?>> classfilter, int max, boolean includebootpath)
public static ISubscriptionIntermediateFuture<java.lang.Class<?>> asyncScanForClasses(java.net.URL[] urls, java.lang.ClassLoader classloader, IFilter<java.lang.Object> filefilter, IFilter<java.lang.Class<?>> classfilter, int max)
public static ISubscriptionIntermediateFuture<java.lang.String> asyncScanForFiles(java.net.URL[] urls, IFilter<java.lang.Object> filter)
public static ISubscriptionIntermediateFuture<java.lang.String> asyncScanDir(java.net.URL[] urls, java.io.File file, IFilter filter, java.util.List<java.lang.String> donedirs)
public static boolean isAndroid()