Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 922
Nosfert Avatar asked Mar 26 '26 22:03

Nosfert


1 Answers

Try this to catch all non private methods.

@Pointcut("execution(!private * *(..))")
like image 163
dogant Avatar answered Mar 28 '26 12:03

dogant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!