Search code examples
javaannotationsaopaspectjpointcut

Aspectj default constructor pointcut


Im working with some AspectJ code and i want to catch all the executions for none private pointcuts.

@Pointcut("execution(public * *(..))")//Public
public void publicMethod(){};
@Pointcut("execution(protected * *(..))"//Protected
public void protectedMethod(){}

@Pointcut("@annotation(mypackage.name.annotationName")
public void annotationPointcut(){}

@Around("annotationPointcut() && (protectedMethod() || publicMethod())")
public Object test(){ System.out.println("Should not print private"); }

I read about using ! (not) but could not get it to work. Something like

@Pointcut("!execution(private * *(..))"

But without getting it to work.

I could not find a modifier name for default class modifier in the aspectJ, have I missed it or do i need to try and solve it by using ! not sign in some sort of way?

Regards a new dev that are learning aspectJ


Solution

  • Try this to catch all non private methods.

    @Pointcut("execution(!private * *(..))")