For my work with aspectJ and invokedynamic I need to weave in an advice into a method when a pointcut matches the called method. First I have exchanged the bootstrapmethod of the invokedynamic-instruction in the script with my own one. Now in my bootstrap method I want to return a CallSite that first invokes the called method and after that an advice that I have defined.
The problem is that the I have to return a CallSite build out of ONE MethodHandle with the same typesignature used in the original bootstrapmethod. I thought about combining two methodhandles (original + advice) into a new one and using that for the returning CallSite. But I can't find the right methods for doing it. MethodHandles.foldArguments seems to be promising, but it didn't work for me. Another idea was to build a MethodHandle from a wrappermethod that invokes the original methodhandle and the advice, but the problem is the right type signature.
Has anyone ideas or suggentions for me? How can I patch a MethodHandle with an advice?
Thank you.