IntelliJ Plugin Development Notes
  • Plugin Development Notes for JetBrains IDEs
  • Project Setup
    • Target a Specific IDE
  • OpenAPI
    • Actions
      • DumbAwareAction
    • Options
      • SettingsEditor
  • UI
    • Navigation
    • Tool Window
    • Icons
    • Project Wizard
    • Internationalization
    • Status Bar
    • Layout Managers
    • Text
    • Dialogs
    • Services Tool Window
  • Common Patterns
    • PSI Facade
    • Smart Mode and Dumb Mode
    • Lazy
  • Official Documentation
    • IntelliJ Platform SDK DevGuide
    • IntelliJ SDK Platform Documentation (GitHub)
    • Design Guidelines
    • Getting Started With IntelliJ
    • Creating IntelliJ Platform SDK Code Samples
  • Example Code
    • IntelliJ IDEA - Community Edition (Upsource)
    • IntelliJ IDEA Community Edition (GitHub)
    • Code Samples from SDK Docs
    • Open Source IntelliJ Plugins
    • Gradle Plugin Examples
    • IntelliJ Platform Plugin Template
  • Community
    • JetBrains Platform Slack
    • JetBrains Community Discord
    • Open API Community Support
  • Misc Links
    • FileDocumentManager Examples
  • Tools
    • Indices viewer
    • PsiViewer
    • UI Inspector
    • IntelliJ Platform Explorer
    • Plugin Validator
  • Tutorials
    • Publishing and Distributing a development build
    • Add New Module Type to the New Project Wizard
    • Auto-detect Executable File
  • Questions
    • Where are persistant state and settings files
Powered by GitBook
On this page
  • Creating
  • Common Methods
  • Examples
  • Reference

Was this helpful?

  1. Common Patterns

PSI Facade

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;
    }
}

Common Methods

Method
Notes

getInstance()

get the service instance

getProject()

get the project the user is working on

Examples

Reference

PreviousServices Tool WindowNextSmart Mode and Dumb Mode

Last updated 1 year ago

Was this helpful?

/

JavaPsiFacade
JavaPsiFacadeImpl
https://plugins.jetbrains.com/docs/intellij/psi.html
https://plugins.jetbrains.com/docs/intellij/plugin-services.html#0