Search code examples
intellij-plugin

IntelliJ plugin template doesn't know about PsiJavaFile


I have an IntelliJ plugin, which was created from the github-template, that cannot resolve the class com.intellij.psi.PsiJavaFile.

Has anyone else run into this and figured out what needs to be configured?

I'm new to IntelliJ plugin development. I followed the instructions detailed at https://plugins.jetbrains.com/docs/intellij/github-template.html to create a plugin.

I imported the generated plugin into IntelliJ and everything seems OK. No compile warnings, etc..., but when I try to use the class com.intellij.psi.PsiJavaFile, IntelliJ says it cannot resolve the class.

I imagine I'm missing a configuration somewhere that tells IntelliJ which libraries to import, but I'm not finding it in the documentation.


Solution

  • You're probably missing the dependency on the Java intellij plugin, which is not enabled by default as you won't need it for every custom plugin.

    Add com.intellij.java to the platformPlugins section of the gradle.properties file:

    # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
    # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
    platformPlugins = com.intellij.java
    

    To address that the IDE cannot resolve PsiJavaClass specifically, I don't think it exists. Are you looking for PsiJavaFile or PsiClass?