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

October 2017

S M T W T F S
1234567
891011121314
1516171819 20 21
22232425262728
293031    

Recent Entries

Recent Comments

Search My Blog

0 user(s) viewing

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