Get the detailed information of the method called in a KtFile
Answered
Hi, everyone, I'm trying to use psi to explore the deeper information about method calls in kotlin files.
How can I use psi to obtain the detailed information of the method called in a KtFile, such as the member variables and member methods (signature) of the class it belongs to, and continue to recursively obtain the associated method information, such as recursively to the Kotlin.Any as much as possible?
Currently I use
bindingContext[BindingContext.Class, ktClass]
[BindingContext.FUNCTION, ktFunc]
to get the description information of a class or a method,
ktNameFunction.collectDescendantsOfType<KtCallExpression> {true}.map {it.getResolvedCall(bindingContext)}
Gets the signature of the directly called method, but cannot get deeper information. In particular, the method called may come from a java file or a class in the jar.
Thank you in advance.
Please sign in to leave a comment.
Could you please give code and explain use-case in more details? You can use PSI Viewer to inspect tree structure of Kotlin source file and find their PSI classes https://plugins.jetbrains.com/plugin/227-psiviewer
Hello,Yann.
I need to analyze Kotlin and java code in an environment that does not rely on IDE. I want to get the details of a method called from another code file. I have solved it by converting it to PsiClass or directly searching for the PsiFile.
But I can't get the compile error message of converting a java file with some errors to PsiJavaFile.
When I use TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration() to analyze KtFile, I can add dependencies and get kotlin compilation error message.
Is there a corresponding method for PsiJavaFile?
You need to "emulate" full Project setup with SDK, libraries, etc. to make it work for Java.