IntelliJ Platform Plugin SDK Help

Extension Points

By defining extension points in your plugin, you can allow other plugins to extend your plugin's functionality. There are two types of extension points:

  • Interface extension points allow other plugins to extend your plugins with code. When defining an interface extension point, specify an interface, and other plugins will provide classes implementing that interface. The providing plugin can then invoke methods on this interface. In most cases, the interface can be annotated with ApiStatus.@OverrideOnly (see Override-Only API).

  • Bean extension points allow other plugins to extend a plugin with data. Specify the fully qualified name of an extension class, and other plugins will provide data that will be turned into instances of that class.

Declaring Extension Points

You can declare extensions and extension points in the plugin configuration file plugin.xml, within the <extensions> and <extensionPoints> sections.

To declare extension points in your plugin, add an <extensionPoints> section to your plugin.xml. Then insert a child element <extensionPoint> that defines the extension point name and the name of a bean class or an interface that is allowed to extend the plugin functionality in the name, beanClass and interface attributes, respectively.

myPlugin/META-INF/plugin.xml

<idea-plugin> <id>my.plugin</id> <extensionPoints> <extensionPoint name="myExtensionPoint1" beanClass="com.example.MyBeanClass"/> <extensionPoint name="myExtensionPoint2" interface="com.example.MyInterface"/> </extensionPoints> </idea-plugin>

The name attribute assigns a unique name for this extension point. Its fully qualified name required in Using Extension Points is built by prefixing the plugin <id> as "namespace" followed by . separator: my.plugin.myExtensionPoint1 and my.plugin.myExtensionPoint2.

The beanClass attribute sets a bean class that specifies one or several properties annotated with the @Attribute annotation. Note that bean classes do not follow the JavaBean standard. Implement PluginAware to obtain information about the plugin providing the actual extension (see Error Handling).

Alternatively, the interface attribute sets an interface the plugin that contributes to the extension point must then implement.

The area attribute determines the scope in which the extension will be instantiated. As extensions should be stateless, it is not recommended to use non-default. Must be one of IDEA_APPLICATION for Application (default), IDEA_PROJECT for Project, or IDEA_MODULE for Module scope.

The plugin that contributes to the extension point will read those properties from the plugin.xml file.

If extension implementations are filtered according to dumb mode, the base class should be marked with PossiblyDumbAware to highlight this.

Base classes for extensions requiring a key:

Sample

To clarify this, consider the following sample MyBeanClass bean class used in the above plugin.xml file:

myPlugin/src/com/myplugin/MyBeanClass.java

public final class MyBeanClass extends AbstractExtensionPointBean { @Attribute("key") public String key; @Attribute("implementationClass") public String implementationClass; public String getKey() { return key; } public String getClass() { return implementationClass; } }

For above extension points usage in anotherPlugin would look like this (see also Declaring Extensions):

anotherPlugin/META-INF/plugin.xml

<idea-plugin> <id>another.plugin</id> <!-- Declare dependency on plugin defining extension point: --> <depends>my.plugin</depends> <!-- Use "my.plugin" namespace: --> <extensions defaultExtensionNs="my.plugin"> <myExtensionPoint1 key="someKey" implementationClass="another.some.implementation.class"/> <myExtensionPoint2 implementation="another.MyInterfaceImpl"/> </extension> </idea-plugin>

Using Extension Points

To refer to all registered extension instances at runtime, declare an ExtensionPointName with private visibility passing in the fully qualified name matching its declaration in plugin.xml. If needed, provide a public method to query registered extensions (Sample: TestSourcesFilter.isTestSources()).

myPlugin/src/com/myplugin/MyExtensionUsingService.java

@Service public final class MyExtensionUsingService { private static final ExtensionPointName<MyBeanClass> EP_NAME = ExtensionPointName.create("my.plugin.myExtensionPoint1"); public void useRegisteredExtensions() { for (MyBeanClass extension : EP_NAME.getExtensionList()) { String key = extension.getKey(); String clazz = extension.getClass(); // ... } } }

A gutter icon for the ExtensionPointName declaration allows navigating to the corresponding <extensionPoint> declaration in plugin.xml. Code insight is available for the extension point name String literal (2022.3).

Error Handling

When processing extension implementations or registrations, there might be errors, compatibility and configuration issues. Use PluginException to log and correctly attribute the causing plugin for builtin error reporting.

To report use of deprecated API, use PluginException.reportDeprecatedUsage() methods.

Examples:

Dynamic Extension Points

To support Dynamic Plugins (2020.1 and later), an extension point must adhere to specific usage rules:

  • extensions are enumerated on every use and extensions instances are not stored anywhere

  • alternatively, an ExtensionPointListener can perform necessary updates of data structures (register via ExtensionPointName.addExtensionPointListener())

Extension points matching these conditions can then be marked as dynamic by adding dynamic="true" in their declaration:

<extensionPoints> <extensionPoint name="myDynamicExtensionPoint" beanClass="com.example.MyBeanClass" dynamic="true"/> </extensionPoints>
Last modified: 09 April 2024