javareflectionaspectjaspectaspects

Convert aspect to native AspectJ notation


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?


Solution

  • I managed to find the answer:

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