Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Multiple types in pointcut

I have a aspect to inject a value for a field:

    pointcut contextAccessed(Action action ):
        get( private com.example.api.IContext *.ctx ) && this(action) ;

    before(Action action ): contextAccessed(action) {
...

This is working fine so  far, and doing what I am expecting. However,
I need to inject IContext in more that one class. For example, I need
to define the pointcut to handle multiple classes. Currently, it's
processing "Action" class, but I want to add "Expression" class. I can
duplicate the code (copy/paste).

For example I am looking for something like (this wont work):

    pointcut contextAccessed(Action action   || Expression<?> expression):
        get( private com.example.api.IContext *.ctx ) && this(action) ;

    before(Action action   || Expression<?> expression ):
contextAccessed(action,expression) {
....

Is there a way to handle this case?
I am new to AspectJ, so an example would be highly appreciated.

Thank you in advance


Back to the top