Joeblackdev
Joeblackdev

Reputation: 7327

Aspect oriented question - Pointcut

i'm wondering what the following means in a pointcut

after(FigureElement fe, int x, int y) returning:
        call(void FigureElement.setXY(int, int))
        && target(fe)
        && args(x, y) {
    System.out.println(fe + " moved to (" + x + ", " + y + ")");
}

what does target and args mean here? i've no idea.

Many thanks

Upvotes: 0

Views: 119

Answers (1)

NOtherDev
NOtherDev

Reputation: 9672

Let's look to the AspectJ guide.

target(Type or Id) every join point when the target executing object is an instance of Type or Id's type

args(Type or Id, ...) every join point when the arguments are instances of Types or the types of the Ids

In your example, for pointcut to match, the method must be called on FigureElement instances and have two int arguments. Names given as target and args parameters means that those parameters are accessible inside your advice body.

So, your pointcut matches all calls to FigureElement.setXY method with two int arguments and gives you access to the matched instance as fe and method arguments as x and y.

Upvotes: 4

Related Questions