Package com.github.mustachejava.reflect
Class ReflectionObjectHandler
- java.lang.Object
-
- com.github.mustachejava.reflect.BaseObjectHandler
-
- com.github.mustachejava.reflect.ReflectionObjectHandler
-
- All Implemented Interfaces:
ObjectHandler
public class ReflectionObjectHandler extends BaseObjectHandler
Lookup objects using reflection and execute them the same way. User: sam Date: 7/24/11 Time: 3:02 PM
-
-
Field Summary
Fields Modifier and Type Field Description private static Guard[]EMPTY_GUARDSprivate static Wrapper[]EMPTY_WRAPPERSprotected static java.lang.reflect.MethodMAP_METHOD
-
Constructor Summary
Constructors Constructor Description ReflectionObjectHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanareMethodsAccessible(java.util.Map<?,?> map)BindingcreateBinding(java.lang.String name, TemplateContext tc, Code code)Each call site has its own binding to allow for fine grained caching without a separate parallel hierarchy of objects.protected ClassGuardcreateClassGuard(int i, java.lang.Object scope)protected DepthGuardcreateDepthGuard(int length)protected DotGuardcreateDotGuard(int i, java.lang.Object scope, java.lang.String lookup)protected MapGuardcreateMapGuard(int scopeIndex, Wrapper[] wrappers, java.lang.String name, boolean contains)protected MissingWrappercreateMissingWrapper(java.lang.String name, java.util.List<Guard> guards)protected NullGuardcreateNullGuard()protected WrappedGuardcreateWrappedGuard(int i, java.util.List<Wrapper> wrappers, java.util.List<Guard> wrapperGuard)protected WrappercreateWrapper(int scopeIndex, Wrapper[] wrappers, java.util.List<? extends Guard> guard, java.lang.reflect.AccessibleObject member, java.lang.Object[] arguments)Wrapperfind(java.lang.String name, java.util.List<java.lang.Object> scopes)Find a value named "name" in the array of scopes in reverse order.protected WrapperfindWrapper(int scopeIndex, Wrapper[] wrappers, java.util.List<Guard> guards, java.lang.Object scope, java.lang.String name)Find a wrapper given the current context.static java.lang.Objectunwrap(ObjectHandler oh, int scopeIndex, Wrapper[] wrappers, java.util.List<java.lang.Object> scopes)-
Methods inherited from class com.github.mustachejava.reflect.BaseObjectHandler
checkClass, checkField, checkMethod, coerce, falsey, findMember, getField, getMethod, iterate, stringify
-
-
-
-
Method Detail
-
unwrap
public static java.lang.Object unwrap(ObjectHandler oh, int scopeIndex, Wrapper[] wrappers, java.util.List<java.lang.Object> scopes) throws GuardException
- Throws:
GuardException
-
find
public Wrapper find(java.lang.String name, java.util.List<java.lang.Object> scopes)
Description copied from interface:ObjectHandlerFind a value named "name" in the array of scopes in reverse order.- Parameters:
name- the variable namescopes- the ordered list of scopes- Returns:
- a wrapper that can be used to extract a value
-
findWrapper
protected Wrapper findWrapper(int scopeIndex, Wrapper[] wrappers, java.util.List<Guard> guards, java.lang.Object scope, java.lang.String name)
Find a wrapper given the current context. If not found, return null.- Parameters:
scopeIndex- the index into the scope arraywrappers- the current set of wrappers to get hereguards- the list of guards used to find thisscope- the current scopename- the name in the scope- Returns:
- null if not found, otherwise a wrapper for this scope and name
-
createMissingWrapper
protected MissingWrapper createMissingWrapper(java.lang.String name, java.util.List<Guard> guards)
-
createDotGuard
protected DotGuard createDotGuard(int i, java.lang.Object scope, java.lang.String lookup)
-
createWrappedGuard
protected WrappedGuard createWrappedGuard(int i, java.util.List<Wrapper> wrappers, java.util.List<Guard> wrapperGuard)
-
createNullGuard
protected NullGuard createNullGuard()
-
createDepthGuard
protected DepthGuard createDepthGuard(int length)
-
createClassGuard
protected ClassGuard createClassGuard(int i, java.lang.Object scope)
-
createMapGuard
protected MapGuard createMapGuard(int scopeIndex, Wrapper[] wrappers, java.lang.String name, boolean contains)
-
createWrapper
protected Wrapper createWrapper(int scopeIndex, Wrapper[] wrappers, java.util.List<? extends Guard> guard, java.lang.reflect.AccessibleObject member, java.lang.Object[] arguments)
-
createBinding
public Binding createBinding(java.lang.String name, TemplateContext tc, Code code)
Description copied from interface:ObjectHandlerEach call site has its own binding to allow for fine grained caching without a separate parallel hierarchy of objects.- Specified by:
createBindingin interfaceObjectHandler- Specified by:
createBindingin classBaseObjectHandler- Parameters:
name- the name that we boundtc- the textual context of the binding sitecode- the code that was bound- Returns:
- the binding
-
areMethodsAccessible
protected boolean areMethodsAccessible(java.util.Map<?,?> map)
-
-