com.threerings.expr.util
Class ScopeUtil

java.lang.Object
  extended by com.threerings.expr.util.ScopeUtil

public class ScopeUtil
extends Object

Some general utility methods relating to scopes.


Field Summary
protected static HashMap<Class<?>,Field[]> _bound
          Cached bound fields.
protected static HashMap<Class<?>,HashMap<String,Member>> _scoped
          Cached scoped members.
 
Constructor Summary
ScopeUtil()
           
 
Method Summary
static Object call(Scope scope, String name, Object... args)
          Attempts to resolve, then call the specified function with the given arguments.
protected static Field[] createBound(Class<?> clazz)
          Creates the list of bound fields for the specified class.
protected static HashMap<String,Member> createScoped(Class<?> clazz)
          Creates the mapping from name to member for all scoped members of the specified class.
static
<T> T
get(Object object, String name, Class<T> clazz)
          Attempts to retrieve the value of the identified symbol using reflection.
protected static Field[] getBound(Class<?> clazz)
          Retrieves the list of the specified class's bound fields.
protected static HashMap<String,Member> getScoped(Class<?> clazz)
          Retrieves the mapping from name to member for all scoped members of the specified class.
static Boolean resolve(Scope scope, String name, Boolean defvalue)
          Attempts to resolve a boolean symbol.
static Color4f resolve(Scope scope, String name, Color4f defvalue)
          Attempts to resolve a color symbol.
static Function resolve(Scope scope, String name, Function defvalue)
          Attempts to resolve a function symbol.
static MutableBoolean resolve(Scope scope, String name, MutableBoolean defvalue)
          Attempts to resolve a mutable boolean symbol.
static MutableFloat resolve(Scope scope, String name, MutableFloat defvalue)
          Attempts to resolve a mutable float symbol.
static MutableInteger resolve(Scope scope, String name, MutableInteger defvalue)
          Attempts to resolve a mutable integer symbol.
static MutableLong resolve(Scope scope, String name, MutableLong defvalue)
          Attempts to resolve a mutable long symbol.
static Quaternion resolve(Scope scope, String name, Quaternion defvalue)
          Attempts to resolve a quaternion symbol.
static String resolve(Scope scope, String name, String defvalue)
          Attempts to resolve a string symbol.
static
<T> T
resolve(Scope scope, String name, T defvalue, Class<T> clazz)
          Attempts to resolve the identified symbol in the given scope.
static Transform3D resolve(Scope scope, String name, Transform3D defvalue)
          Attempts to resolve a transform symbol.
static Variable resolve(Scope scope, String name, Variable defvalue)
          Attempts to resolve a variable symbol.
static Vector3f resolve(Scope scope, String name, Vector3f defvalue)
          Attempts to resolve a vector symbol.
protected static String stripUnderscore(String name)
          Strips the leading underscore from the specified name, if present.
static void updateBound(Object object, Scope scope)
          Updates the Bound fields of the specified object using the provided scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_bound

protected static HashMap<Class<?>,Field[]> _bound
Cached bound fields.


_scoped

protected static HashMap<Class<?>,HashMap<String,Member>> _scoped
Cached scoped members.

Constructor Detail

ScopeUtil

public ScopeUtil()
Method Detail

updateBound

public static void updateBound(Object object,
                               Scope scope)
Updates the Bound fields of the specified object using the provided scope.


call

public static Object call(Scope scope,
                          String name,
                          Object... args)
Attempts to resolve, then call the specified function with the given arguments.


resolve

public static Quaternion resolve(Scope scope,
                                 String name,
                                 Quaternion defvalue)
Attempts to resolve a quaternion symbol.


resolve

public static Transform3D resolve(Scope scope,
                                  String name,
                                  Transform3D defvalue)
Attempts to resolve a transform symbol.


resolve

public static Vector3f resolve(Scope scope,
                               String name,
                               Vector3f defvalue)
Attempts to resolve a vector symbol.


resolve

public static Color4f resolve(Scope scope,
                              String name,
                              Color4f defvalue)
Attempts to resolve a color symbol.


resolve

public static String resolve(Scope scope,
                             String name,
                             String defvalue)
Attempts to resolve a string symbol.


resolve

public static Function resolve(Scope scope,
                               String name,
                               Function defvalue)
Attempts to resolve a function symbol.


resolve

public static Variable resolve(Scope scope,
                               String name,
                               Variable defvalue)
Attempts to resolve a variable symbol.


resolve

public static MutableBoolean resolve(Scope scope,
                                     String name,
                                     MutableBoolean defvalue)
Attempts to resolve a mutable boolean symbol.


resolve

public static MutableFloat resolve(Scope scope,
                                   String name,
                                   MutableFloat defvalue)
Attempts to resolve a mutable float symbol.


resolve

public static MutableInteger resolve(Scope scope,
                                     String name,
                                     MutableInteger defvalue)
Attempts to resolve a mutable integer symbol.


resolve

public static MutableLong resolve(Scope scope,
                                  String name,
                                  MutableLong defvalue)
Attempts to resolve a mutable long symbol.


resolve

public static Boolean resolve(Scope scope,
                              String name,
                              Boolean defvalue)
Attempts to resolve a boolean symbol.


resolve

public static <T> T resolve(Scope scope,
                            String name,
                            T defvalue,
                            Class<T> clazz)
Attempts to resolve the identified symbol in the given scope. If not found there, searches the parent of that scope, and so on.

Returns:
the mapping for the symbol, or defvalue if not found anywhere in the chain.

get

public static <T> T get(Object object,
                        String name,
                        Class<T> clazz)
Attempts to retrieve the value of the identified symbol using reflection.

Parameters:
object - the object upon which to reflect.
Returns:
the symbol value, or null if not found.

getBound

protected static Field[] getBound(Class<?> clazz)
Retrieves the list of the specified class's bound fields.


createBound

protected static Field[] createBound(Class<?> clazz)
Creates the list of bound fields for the specified class.


getScoped

protected static HashMap<String,Member> getScoped(Class<?> clazz)
Retrieves the mapping from name to member for all scoped members of the specified class.


createScoped

protected static HashMap<String,Member> createScoped(Class<?> clazz)
Creates the mapping from name to member for all scoped members of the specified class.


stripUnderscore

protected static String stripUnderscore(String name)
Strips the leading underscore from the specified name, if present.