Groovy is great for developers because of its simple scripting feel, but in order to compile to java bytecode, it adds lots of bloat at compile time to make the magic work. When mixing it with AspectJ's post-compile binary weaving, it will cause lots of unwanted methods to be caught by your AspectJ Advice. I wrote a pointcut to help eliminate this problem:
It's not beautiful, but it works! Now, if I wanted to have advice to log "ENTER" for every method defined in another pointcut but exclude the groovy methods, I could do something like this:
@Pointcut("!(execution(* getProperty(..)) || execution(* getMetaClass(..)) || execution(* *\$*(..)) || execution(* doCall(..)) || execution(* invokeMethod(..)))") public void notGroovyBloat(){}
It's not beautiful, but it works! Now, if I wanted to have advice to log "ENTER" for every method defined in another pointcut but exclude the groovy methods, I could do something like this:
@Before("(methods())&& notGroovyBloat()") public void logEntry(final JoinPoint joinPoint){ logMessage(joinPoint.getSignature().getName() + ":ENTER"); }
0 Comments On This Entry
Trackbacks for this entry [ Trackback URL ]
← March 2021 →
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
My Blog Links
Recent Entries
-
-
-
Excluding Groovy Methods in AspectJ Advice
on Aug 29 2013 12:13 PM
-
-
Recent Comments
Search My Blog
2 user(s) viewing
2 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)