|
1 | 1 | package com.github.mustachejava.codegen; |
2 | 2 |
|
3 | | -import com.github.mustachejava.MustacheException; |
4 | 3 | import com.github.mustachejava.codegen.guards.*; |
5 | | -import com.github.mustachejava.reflect.*; |
| 4 | +import com.github.mustachejava.reflect.Guard; |
| 5 | +import com.github.mustachejava.reflect.MissingWrapper; |
| 6 | +import com.github.mustachejava.reflect.ReflectionObjectHandler; |
6 | 7 | import com.github.mustachejava.reflect.guards.*; |
7 | | -import com.github.mustachejava.util.GuardException; |
8 | 8 | import com.github.mustachejava.util.Wrapper; |
9 | 9 |
|
10 | 10 | import java.lang.reflect.AccessibleObject; |
@@ -48,33 +48,12 @@ protected WrappedGuard createWrappedGuard(int i, List<Wrapper> wrappers, List<Gu |
48 | 48 |
|
49 | 49 | @Override |
50 | 50 | protected MissingWrapper createMissingWrapper(List<Guard> guards) { |
51 | | - final Guard compiledGuards = compile(guards); |
52 | | - return new MissingWrapper(guards.toArray(new Guard[guards.size()])) { |
53 | | - @Override |
54 | | - protected void guardCall(Object[] scopes) throws GuardException { |
55 | | - if (!compiledGuards.apply(scopes)) { |
56 | | - throw guardException; |
57 | | - } |
58 | | - } |
59 | | - }; |
| 51 | + return new CompiledMissingWrapper(guards); |
60 | 52 | } |
61 | 53 |
|
62 | 54 | @Override |
63 | 55 | protected Wrapper createWrapper(int scopeIndex, Wrapper[] wrappers, List<? extends Guard> guards, AccessibleObject member, Object[] arguments) { |
64 | | - final Guard compiledGuards = compile(guards); |
65 | | - return new ReflectionWrapper(scopeIndex, wrappers, guards.toArray(new Guard[guards.size()]), member, arguments, this) { |
66 | | - @Override |
67 | | - protected void guardCall(Object[] scopes) throws GuardException { |
68 | | - if (!compiledGuards.apply(scopes)) { |
69 | | - throw guardException; |
70 | | - } |
71 | | - } |
72 | | - }; |
| 56 | + return new CompiledReflectionWrapper(this, scopeIndex, wrappers, guards, member, arguments); |
73 | 57 | } |
74 | 58 |
|
75 | | - private Guard compile(List<? extends Guard> guard) { |
76 | | - Guard[] compiled = GuardCompiler.compile(guard.toArray(new Guard[guard.size()])); |
77 | | - if (compiled.length != 1) throw new MustacheException("Failed to compile all guards: " + guard); |
78 | | - return compiled[0]; |
79 | | - } |
80 | 59 | } |
0 commit comments