Skip to content

INFO

See Plugin Extensions for using extension points in your plugin.

By defining extension points in your plugin, you can allow other plugins to extend your plugin's functionality. An extension point is declared by annotating an interface or abstract class with @ExtensionAPI. Other plugins then provide implementations of that interface, annotated with @ExtensionImpl, which the platform discovers automatically at runtime.

Declaring Extension Points

Extension points are defined by annotating an interface or abstract class with @ExtensionAPI(ComponentScope.xxx).

The ComponentScope determines the extension's lifecycle:

  • ComponentScope.APPLICATION - the extension is a global singleton, instantiated once for the entire application.
  • ComponentScope.PROJECT - the extension is instantiated once per open project.
  • ComponentScope.MODULE - the extension is instantiated once per module.

myPlugin/src/com/myplugin/MyExtensionPoint.java

java
@ExtensionAPI(ComponentScope.APPLICATION)
public interface MyExtensionPoint {
    String getKey();
    void process();
}

No XML declaration is needed. The @ExtensionAPI annotation is sufficient to register the extension point with the platform.

Sample

A plugin that wants to implement the above extension point simply creates a class implementing the interface and annotates it with @ExtensionImpl:

anotherPlugin/src/another/MyExtensionImpl.java

java
@ExtensionImpl
public class MyExtensionImpl implements MyExtensionPoint {
    @Override
    public String getKey() { return "myKey"; }

    @Override
    public void process() { /* implementation */ }
}

The platform discovers the @ExtensionImpl-annotated class automatically. No XML configuration or plugin dependency declarations beyond the standard module dependency are required.

Using Extension Points

To access all registered extension instances at runtime, use Application.get().getExtensionPoint() or ExtensionPointName.create():

myPlugin/src/com/myplugin/MyExtensionUsingService.java

java
public class MyExtensionUsingService {

    public void useExtensions() {
      // Option 1: via Application
      List<MyExtensionPoint> extensions =
        Application.get().getExtensionPoint(MyExtensionPoint.class).getExtensionList();

      // Option 2: via ExtensionPointName
      ExtensionPointName<MyExtensionPoint> EP_NAME =
        ExtensionPointName.create(MyExtensionPoint.class);
      List<MyExtensionPoint> extensionList = EP_NAME.getExtensionList();

      for (MyExtensionPoint extension : extensionList) {
        String key = extension.getKey();
        extension.process();
        // ...
      }
    }
}