How to retrieve the signature of a PsiMethod in the original JVM format?
Answered
So ASM gives me
(Ljava/lang/String;)V
as the signature of a method but I couldn't find any way to retrieve this signature from a PsiMethod in this format. The only thing which I can do is to retrieve the parameters with
getParameters()
and then get the canonical text of every parameter:
p.getType().getCanonicalText()
but this shows boolean instead of Z(this is the signature of boolean in the JVM).
So is there any way to retrieve the JVM signature or do I have to write my own function to do this?
Please sign in to leave a comment.
com.intellij.psi.util.ClassUtil#getAsmMethodSignature | getVMParametersMethodSignature and methods below should be useful
Thanks, this works.
It works for me, too.
BTW,
How to retrieve the signature of a KtFunction in the original JVM format?
I try to do this conversion for both Java and Kotlin in my plugin.
I had seen the post:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009307639-Retrieving-Java-method-signature-from-Kotlin-PSI
but got no correct answer.
You can convert KtFunction to PsiMethod using ktFunction.toLightMethods() and then use the same functions that are applicable for Java: