Convert aspect to native AspectJ notation

142 views Asked by At

I have this aspect:

public privileged aspect Teste {
private ISupermarket supermarket;

@AfterReturning(pointcut = "execution(* ca1.business.SupermarketFactory.createSupermarket(..))", returning = "result")
    public void afterCreateSupermarket(JoinPoint joinPoint, Object result) {
        supermarket = (ISupermarket) result;
    }
}

The thing is that I want to code it in native AspectJ notation.

I searched but the closest I got was to this:

void after() returning(result) : pointcut(* ca1.business.SupermarketFactory.createSupermarket(..)) {
    supermarket = (ISupermarket) result;
}

But this gives me some errors because it is not well coded.

Can anyone help me with this?

2

There are 2 answers

1
undisp On BEST ANSWER

I managed to find the answer:

pointcut afterCreateSupermarket():
    call(ISupermarket ca1.business.SupermarketFactory.createSupermarket(..));

after() returning(Object result): afterCreateSupermarket() {
    supermarket = (ISupermarket) result;
}
0
kriegaex On

If you want to get rid of the cast and the named pointcut, you can also do this:

after() returning(ISupermarket result) : call(ISupermarket ca1.business.SupermarketFactory.createSupermarket(..)) {
    supermarket = result;
}