Problem when using PSI to parse Java
Answered
I'm trying to use the PSI tree structure for parse Java files and manipulate them for security purposes, following the documentation that i found here https://plugins.jetbrains.com/docs/intellij/psi.html
The problem is most of the suggested methods to retrieve Psi from Files seems not working for me, only two with unwanted result:
1
// Recognize correctly the type but with no children
var localDef = PsiManager.getInstance(project).findViewProvider(LightVirtualFile(fileName, file.readText(Charset.defaultCharset())))
var local = PsiJavaFileImpl(localDef)
return local
2
// Recognize wrongly the type as ANY with no children
var localDef2 = CoreLocalFileSystem().findFileByIoFile(file)!!
val local2 = PsiManager.getInstance(project).findFile(localDef2)!!
return local2
Any idea / suggestion about?
P.S. Thanks to everyone who will try to reply, even with this small part of code, unfortunately i can't share more
Please sign in to leave a comment.
Hello,
Please try method used in this thread: https://intellij-support.jetbrains.com/hc/en-us/community/posts/4403910273042-Parse-Java-source-code-file-into-PSI-file-and-do-some-operations-on-the-PSI-elements
Also you may create new thread in Plugin Development forum.
Thank you for reply,
I've already seen this thread but i think isn't very useful:
I'll give a try reading all the project documentation, but i think however that Psi documentation needs to be more clear on his usage