Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Getting the method arguments of a Pointcut using args

Hi there I have the following code sample 

public class MyAspect {

    @Pointcut("cflowbelow(execution(@CallerAnnotation * *(..)) && @annotation(callerAnnotation))")
    protected void executeBelowAnnotation(final CallerAnnotation callerAnnotation) {

    @Pointcut(value = "execution(public void callee(String, Integer))")
    protected void executeCallee() {

    @Around("executeCallee() && executeBelowAnnotation(callerAnnotation)")
    public Object finalAdvice(final ProceedingJoinPoint joinPointfinal CallerAnnotation callerAnnotation)
            throws Throwable {
        return joinPoint.proceed();

public class SampleClazz() {

    public void caller(Foo foo, Bar bar){

    private void callee(String s, Integer i){
      // Do Something

and I would like to know is there any possibility to use the args such as args(..) in order to get the method arguments of the caller method in the following example?

I know that I can in my first pointcut define 
@Pointcut("cflowbelow(call(@CallerAnnotation * *(..)) && @annotation(callerAnnotation) && args(foo, bar))")
    protected void executeBelowAnnotation(final CallerAnnotation callerAnnotation, Foo foo, Bar bar) {

So that I also pass on those method params to the finalAdvice method, however I would like to do this without explicitly defining the arguments in my pointcut so that it doesn’t depend on the signature of the annotated method. 

One way that I have done before has been using another annotation to annotate the params and then having @annotation in my pointcut but I would like to see whether I can skip having yet another annotation for this. 

Also another way might be the use of executionAdvice and then defining two advices and combining them together for the two pointcuts. That way I guess I can use the getMethodArgs() from ProceedingJoinPoint.

So is there any way to use the args() to achieve this? 


Back to the top