com.threerings.util
Class ReflectionUtil

java.lang.Object
  extended by com.threerings.util.ReflectionUtil

public class ReflectionUtil
extends Object

Some general reflection utility methods.


Field Summary
protected static HashMap<Class<?>,Constructor> _ctors
          Maps classes to their default constructors.
protected static HashMap<Class<?>,Class<?>> _oclasses
          Maps classes to their outer classes, or to Void if they are not inner classes.
protected static HashMap<Class<?>,Field> _outers
          Maps inner classes to their outer class reference fields.
 
Constructor Summary
ReflectionUtil()
           
 
Method Summary
static Object getOuter(Object object)
          Returns a reference to an inner object's outer class reference, or null if the object represents an instance of a static class.
static Class<?> getOuterClass(Class<?> clazz)
          Returns the outer class for the given inner class (or null if not an inner class).
protected static Field getOuterField(Class<?> clazz)
          Returns a reference to the outer class reference field.
static boolean isInner(Class<?> clazz)
          Determines whether the specified class is a non-static inner class.
static Object newInstance(Class<?> clazz)
          Creates a new instance of the specified class.
static Object newInstance(Class<?> clazz, Object outer)
          Creates a new instance of the specified (possibly inner) class.
static Object newInstance(String classname)
          Creates a new instance of the named class.
static Object newInstance(String classname, Object outer)
          Creates a new instance of the named inner class.
static void setOuter(Object object, Object outer)
          Sets an inner object's outer class reference if it has one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_outers

protected static HashMap<Class<?>,Field> _outers
Maps inner classes to their outer class reference fields.


_oclasses

protected static HashMap<Class<?>,Class<?>> _oclasses
Maps classes to their outer classes, or to Void if they are not inner classes.


_ctors

protected static HashMap<Class<?>,Constructor> _ctors
Maps classes to their default constructors.

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

newInstance

public static Object newInstance(String classname)
Creates a new instance of the named class.

Parameters:
classname - the name of the class to instantiate.

newInstance

public static Object newInstance(String classname,
                                 Object outer)
Creates a new instance of the named inner class.

Parameters:
classname - the name of the class to instantiate.
outer - an instance of the enclosing class.

newInstance

public static Object newInstance(Class<?> clazz)
Creates a new instance of the specified class.

Parameters:
clazz - the class to instantiate.

newInstance

public static Object newInstance(Class<?> clazz,
                                 Object outer)
Creates a new instance of the specified (possibly inner) class.

Parameters:
clazz - the class to instantiate.
outer - for inner classes, a reference to the enclosing instance (otherwise null).
Returns:
the newly created object, or null if there was some error (in which case a message will be logged).

setOuter

public static void setOuter(Object object,
                            Object outer)
Sets an inner object's outer class reference if it has one.


getOuter

public static Object getOuter(Object object)
Returns a reference to an inner object's outer class reference, or null if the object represents an instance of a static class.


isInner

public static boolean isInner(Class<?> clazz)
Determines whether the specified class is a non-static inner class.


getOuterClass

public static Class<?> getOuterClass(Class<?> clazz)
Returns the outer class for the given inner class (or null if not an inner class).


getOuterField

protected static Field getOuterField(Class<?> clazz)
Returns a reference to the outer class reference field.