How do I get the values ​​of the method parameters?

I have an aspect:

public aspect TestAspect {
    pointcut publicMethodExecuted(): execution(public !static * *(..));

    int around() : publicMethodExecuted() {
        //I need parameters values here
        //to write their to log

        int original_return_value = proceed();
        return original_return_value * 100;
    }
}

      

How to get the parameters with which the method was called? I need to write them to a log file.

I am most interested in native AspectJ

-way without using reflection.

+3


source to share


2 answers


Sorry If I misunderstood, but this should lead to parameters



Object[] args = thisJoinPoint.getArgs();

      

+6


source


You can access the junction point from thisJoinPoint

within your aspect.

You can access your options with thisJoinPoint.getArgs()

.

Alternatively, you can access the signature of your method call with thisJoinPointStaticPart

.



eg. you can access the method name with thisJoinPointStaticPart.getSignature().getName()

.

For more information, please use the JoinPoint and JoinPoint.StaticPart documentation .

+2


source







All Articles