Subscribe to The Way I See It        RSS Feed
-----

Excluding Groovy Methods in AspectJ Advice

Icon Leave Comment
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:

   @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 ]

There are no Trackbacks for this entry

November 2017

S M T W T F S
   1234
567891011
1213141516 17 18
19202122232425
2627282930  

Recent Entries

Recent Comments

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)