title |
---|
Plugin Extensions and Extension Points |
The IntelliJ Platform provides the concept of extensions and extension points that allows a plugin to interact with other plugins or with the IDE itself.
If you want your plugin to allow other plugins to extend its functionality, in the plugin, you must declare one or several extension points. Each extension point defines a class or an interface that is allowed to access this point.
If you want your plugin to extend the functionality of other plugins or the IntelliJ Platform, you must declare one or several extensions.
You can declare extensions and extension points in the plugin configuration file plugin.xml
, within the <extensions>
and <extensionPoints>
sections, respectively.
To declare an extension point
In the <extensionPoints>
section, 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.
To clarify this procedure, consider the following sample section of the plugin.xml file:
<extensionPoints>
<extensionPoint name="MyExtensionPoint1" beanClass="MyPlugin.MyBeanClass1">
<extensionPoint name="MyExtensionPoint2" interface="MyPlugin.MyInterface">
</extensionPoints>
- The
interface
attribute sets an interface the plugin that contributes to the extension point must implement. - The
beanClass
attribute sets a bean class that specifies one or several properties annotated with the @Attribute annotation.
The plugin that contributes to the extension point will read those properties from the plugin.xml
file.
To clarify this, consider the following sample MyBeanClass1
bean class used in the above plugin.xml
file:
public class MyBeanClass1 extends AbstractExtensionPointBean {
@Attribute("key")
public String key;
@Attribute("implementationClass")
public String implementationClass;
public String getKey() {
return key;
}
public String getClass() {
return implementationClass;
}
}
Note that to declare an extension designed to access the MyExtensionPoint1
extension point, your plugin.xml
file must contain the <MyExtensionPoint1>
tag with the key
and implementationClass
attributes set to appropriate values (see sample below).
To declare an extension
- For the
<extensions>
element, set thexmlns
(deprecated) ordefaultExtensionNs
attribute to one of the following values:com.intellij
, if your plugin extends the IntelliJ Platform core functionality.{ID of a plugin}
, if your plugin extends a functionality of another plugin.
- Add a new child element to the
<extensions>
element. The child element name must match the name of the extension point you want the extension to access. - Depending on the type of the extension point, do one of the following:
- If the extension point was declared using the
interface
attribute, for newly added child element, set theimplementation
attribute to the name of the class that implements the specified interface. - If the extension point was declared using the
beanClass
attribute, for newly added child element, set all attributes annotated with the @Attribute annotations in the specified bean class.
- If the extension point was declared using the
To clarify this procedure, consider the following sample section of the plugin.xml
file that defines two extensions designed to access the appStarter
and applicationConfigurable
extension points in the IntelliJ Platform and one extension to access the MyExtensionPoint1
extension point in a test plugin:
<!-- Declare extensions to access extension points in the IntelliJ Platform.
These extension points have been declared using the "interface" attribute.
-->
<extensions defaultExtensionNs="com.intellij">
<appStarter implementation="MyTestPackage.MyTestExtension1" />
<applicationConfigurable implementation="MyTestPackage.MyTestExtension2" />
</extensions>
<!-- Declare extensions to access extension points in a custom plugin
The MyExtensionPoint1 extension point has been declared using *beanClass* attribute.
-->
<extensions defaultExtensionNs="MyPluginID">
<MyExtensionPoint1 key="keyValue" implementationClass="MyTestPackage.MyClassImpl"></MyExtensionPoint1>
</extensions>
To get a list of extension points available in the IntelliJ Platform core, consult the <extensionPoints>
section of the following XML configuration files:
LangExtensionPoints.xml
PlatformExtensionPoints.xml
VcsExtensionPoints.xml
For samples plugins and detailed instructions on how to create your plugin that contributes to the IDEA core, refer to Customizing the IDEA Settings Dialog and Creation of Tool Windows.