There is built-in way in Byte Buddy to do redefine method m
in this way. Byte Buddy is however voluntarily exposing the ASM API on top of which Byte Buddy is implemented. ASM offers quite extensive documentation which would show you how to do this. I can however tell you that it will be quite a lot of code. Note that you require to compile any method with debug symbols enabled, otherwise these internal variables are not available at run time.
Are you however sure you want to do this? Without knowing your exact use case, it feels like it is a bad idea. By implementing this solution, you make the names of local variables a part of your application instead of letting them be an implementation detail.
I would therefore suggest you to rather instrument the doSomething
method. Would this suffice yourn what is easily done in Byte Buddy using an interceptor like the following:
class Interceptor {
void intercept(@Origin Method method, @AllArguments Object[] args) {
int index = 0;
for(Parameter p : method.getParameters()) {
context.add(p.getName(), args[index++]);
}
}
}
This interceptor could then be used as follows:
MethodDelegation.to(new Interceptor()).andThen(SuperMethodCall.INSTANCE);