Search code examples
javajava-bytecode-asm

visitParameter of MethodVisitor is never called


I need to get the method parameter names using asm 5.2. My sources are java 1.8. Looking at the javadoc of MethodVisitor#visitParameter it seems that this is exactly what I need:

Visits a parameter of this method.

But this method is never called. I thought it might be related to missing debugging information, so I compiled the classes with -g:source,lines,vars, but this didn't help either.

I resorted to using visitLocalVariable, but for the purpose of the utility that I'm writing I don't care about the method's code, so I was looking at providing the ClassReader.SKIP_CODE to the ClassReader's accept method.

I'm I missing something? Is there a way to get the parameter names w/o visiting the code.


Solution

  • You need to compile your class with the -parameters option to make javac include the parameter names. This is why the method is never invoked, without the option your parameter names are not included.

    Alternatively, you can check the visitLocalVariable method for the parameter names. For non-abstract methods with debug symbols included, the parameter names will be included here.