Many plugins create an interface/class with the named with the suffix PsiFacade. Typically this class will be registered as a project service and is used to provide a simpler method of querying, and working with PSI Elements.
Creating
plugin.xml
<!-- Extension points defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<extensions defaultExtensionNs="com.intellij">
<projectService serviceInterface="com.example.psi.ExamplePsiFacade"
serviceImplementation="com.example.psi.ExamplePsiFacadeImpl"/>
</extensions>
ExamplePsiFacade.java
package com.example.psi;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
public abstract class ExamplePsiFacade {
@NotNull
public static ExamplePsiFacade getInstance(@NotNull Project project) {
return project.getService(ExamplePsiFacade.class);
}
@NotNull
public abstract Project getProject();
}
ExamplePsiFacade.java
package com.example.psi;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
public class ExamplePsiFacadeImpl extends ExamplePsiFacade {
private final Project myProject;
public ExamplePsiFacadeImpl(@NotNull Project project) {
this.myProject = project;
}
@Override
@NotNull
public Project getProject() {
return this.myProject;
}
}