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?



0
4 comments

com.intellij.psi.util.ClassUtil#getAsmMethodSignature | getVMParametersMethodSignature and methods below should be useful

1
Avatar
Permanently deleted user

Thanks, this works.

0

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.

0
Avatar
Permanently deleted user

You can convert KtFunction to PsiMethod using ktFunction.toLightMethods() and then use the same functions that are applicable for Java:

import com.intellij.psi.util.ClassUtil
import org.jetbrains.kotlin.asJava.toLightMethods

fun computeAsmSignature(ktFunction: KtFunction): String? {
val psiMethod = ktFunction.toLightMethods().singleOrNull() ?: return null
return ClassUtil.getAsmMethodSignature(psiMethod)
}
1

Please sign in to leave a comment.