@@ -26,35 +26,43 @@ public Object get(List<Object> scopes) {
2626 };
2727 }
2828
29+ public Object get (String name , Object scope ) {
30+ // Special case Maps
31+ if (scope instanceof Map ) {
32+ Map map = (Map ) scope ;
33+ if (map .containsKey (name )) {
34+ return map .get (name );
35+ } else if (!areMethodsAccessible (map )) {
36+ return NOT_FOUND ;
37+ }
38+ }
39+ // Check to see if there is a method or field that matches
40+ try {
41+ AccessibleObject ao = lookup (scope .getClass (), name );
42+ if (ao instanceof Method ) {
43+ return ((Method ) ao ).invoke (scope );
44+ } else if (ao instanceof Field ) {
45+ return ((Field ) ao ).get (scope );
46+ }
47+ } catch (InvocationTargetException ie ) {
48+ throw new MustacheException ("Failed to get " + name + " from " + scope .getClass (), ie );
49+ } catch (IllegalAccessException iae ) {
50+ throw new MustacheException ("Set accessible failed to get " + name + " from " + scope .getClass (), iae );
51+ }
52+ return NOT_FOUND ;
53+ }
54+
2955 @ Override
30- public Wrapper find (final String name , final List <Object > scopes ) {
56+ public Wrapper find (String name , List <Object > scopes ) {
3157 return scopes1 -> {
3258 for (int i = scopes1 .size () - 1 ; i >= 0 ; i --) {
3359 Object scope = scopes1 .get (i );
3460 if (scope != null ) {
3561 int index = name .indexOf ("." );
3662 if (index == -1 ) {
37- // Special case Maps
38- if (scope instanceof Map ) {
39- Map map = (Map ) scope ;
40- if (map .containsKey (name )) {
41- return map .get (name );
42- } else if (!areMethodsAccessible (map )) {
43- continue ; //don't check methods, move to next scope
44- }
45- }
46- // Check to see if there is a method or field that matches
47- try {
48- AccessibleObject ao = lookup (scope .getClass (), name );
49- if (ao instanceof Method ) {
50- return ((Method ) ao ).invoke (scope );
51- } else if (ao instanceof Field ) {
52- return ((Field ) ao ).get (scope );
53- }
54- } catch (InvocationTargetException ie ) {
55- throw new MustacheException ("Failed to get " + name + " from " + scope .getClass (), ie );
56- } catch (IllegalAccessException iae ) {
57- throw new MustacheException ("Set accessible failed to get " + name + " from " + scope .getClass (), iae );
63+ Object result = get (name , scope );
64+ if (result != NOT_FOUND ) {
65+ return result ;
5866 }
5967 } else {
6068 // Dig into the dot-notation through recursion
@@ -109,6 +117,7 @@ public boolean equals(Object obj) {
109117
110118 // Used to cache misses
111119 private static AccessibleObject NONE ;
120+
112121 static {
113122 try {
114123 NONE = SimpleObjectHandler .class .getDeclaredField ("NONE" );
0 commit comments