Created
March 12, 2013 23:04
-
-
Save mikebrock/5147923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Retention(RetentionPolicy.RUNTIME) | |
| public @interface LogCall { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @CodeDecorator | |
| public class LogCallDecorator extends IOCDecoratorExtension<LogCall> { | |
| public LogCallDecorator(Class<LogCall> decoratesWith) { | |
| super(decoratesWith); | |
| } | |
| @Override | |
| public List<? extends Statement> generateDecorator(InjectableInstance<LogCall> ctx) { | |
| ctx.getInjector().addInvokeBefore(ctx.getMethod(), | |
| Stmt.invokeStatic(TestDataCollector.class, "beforeInvoke", Refs.get("a0"), Refs.get("a1"))); | |
| ctx.getInjector().addInvokeAfter(ctx.getMethod(), | |
| Stmt.invokeStatic(TestDataCollector.class, "afterInvoke", Refs.get("a0"), Refs.get("a1"))); | |
| return Collections.emptyList(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Singleton | |
| public class MyDecoratedBean { | |
| private final Map<String, Integer> testMap = new HashMap<String, Integer>(); | |
| @LogCall | |
| public void someMethod(final String text, final Integer blah) { | |
| testMap.put(text, blah); | |
| } | |
| public Map<String, Integer> getTestMap() { | |
| return testMap; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestDataCollector { | |
| private static final Map<String, Integer> beforeInvoke = new HashMap<String, Integer>(); | |
| private static final Map<String, Integer> afterInvoke = new HashMap<String, Integer>(); | |
| public static void beforeInvoke(String a, Integer b) { | |
| beforeInvoke.put(a, b); | |
| } | |
| public static void afterInvoke(String a, Integer b) { | |
| afterInvoke.put(a, b); | |
| } | |
| public static Map<String, Integer> getBeforeInvoke() { | |
| return beforeInvoke; | |
| } | |
| public static Map<String, Integer> getAfterInvoke() { | |
| return afterInvoke; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment