Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: How to specify anonymous inner class directly?



takao,

Trying to target a specific anonymous inner class is problematic. Using a
name is inappropriate (by definition) because it is generated by the
compiler. If another anonymous inner class is added higher up the source
code the name of the class you are interested in will change e.g. $1 to $2.
There are 3 possible approaches that I can think of:

1. Target the class by type e.g. "execution(Runnable+.new(..));" .This may
unfortunately pick up all Runnable implementations.
2. Use cflow e.g. "execution(Runnable+.new(..)) && cflow(test());". This
needs a runtime check but is more reliable/robust than using a name.
3. Use a call joinpoint e.g. "call(Runnable+.new(..)) && within(Test);"
4. Refactor the code to create a named inner class.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



Back to the top