PSIReference can't resolve in LightJavaCodeInsightFixtureTestCase
Answered
Hi guys,
I met a problem when writing psi test case about myFixture.addFileToProject.
Detailed as follows :
I have push my test project to github
Please sign in to leave a comment.
Hi,
Your project seems to be incomplete so it is hard to understand what's the issue. I agree with Yann that it is probably a misconfiguration of the project or test project. I suggest digging deeper into this topic by looking at other plugins or other forum questions, e.g.:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/4530503696402-Inferred-type-is-null-even-if-it-shows-in-the-IDE-in-tests
If everything is configurated correctly and the problem still happens, I suggest inspecting the PSI of the file you test and making sure that resolvable references are exactly in the elements you try to resolve. Open the PSI Viewer:
https://plugins.jetbrains.com/docs/intellij/explore-api.html#31-use-internal-mode-and-psiviewer
and make sure that PsiMethodCallExpression element contains references in the References tab. It may happen that reference is actually in the element's parent or child and you just use the wrong element to resolve it.
Hi Karol
I have open the PSI Viewer ,Invoker1.java ’s and Invoker2.java‘s PSI are normal in the Intelij IDEA.
This problem may only occur in `myFixture.AddFileToProject` PsiFile returns, if I add multiple files, their references don't seem to be related.
In particular, `import static` or invoke static methods
check out my debug console output https://github.com/liaohang122/psitest/blob/main/debug.png
What does it mean that PSI is normal? Are there references in the PsiMethodCallExpression elements? Could you please share a screenshot of the PSI Viewer showing references?
Hi Karol, thks for your reply
I solved the problem. the method addFileToProject first parameter is a String,it must contains package path. and then resolve is ok.
I'm not sure what the first parameter means, but it work now
this.myFixture.addFileToProject("com/Hello.java",HelloContent);this.myFixture.addFileToProject("com/HelloWorld.java",HelloWorldContent);
PsiFile invoker1PsiFile = this.myFixture.addFileToProject("com/Invoker1.java",Invoker1Content);
PsiFile invoker2PsiFile = this.myFixture.addFileToProject("com/Invoker2.java",Invoker2Content);