mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-29 17:57:53 +08:00
114 lines
5.6 KiB
Markdown
114 lines
5.6 KiB
Markdown
---
|
|
layout: editable
|
|
title: Plugin Extensions and Extension Points
|
|
---
|
|
|
|
Intellij IDEA provides the concept of _extensions_ and _extension points_ that allows a plugin to interact with other plugins or with the IDEA core.
|
|
|
|
## Extension Points
|
|
|
|
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.
|
|
|
|
## Extensions
|
|
|
|
If you want your plugin to extend the functionality of other plugins or the IDEA core, in the plugin, you must declare one or several _extensions_.
|
|
|
|
## How to Declare Extensions and Extension Points?
|
|
|
|
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:
|
|
|
|
```xml
|
|
<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](https://github.com/JetBrains/intellij-community/blob/master/xml/dom-openapi/src/com/intellij/util/xml/Attribute.java)
|
|
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:
|
|
|
|
```java
|
|
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 the sample plugin.xml file below).
|
|
|
|
*To declare an extension*
|
|
|
|
1. For the \<extensions\> element, set the *xmlns* (deprecated) or *defaultExtensionNs* attribute to one of the following values:
|
|
|
|
* _com.intellij_, if your plugin extends the IDEA core functionality.
|
|
|
|
* _ID of a plugin_, if your plugin extends a functionality of another plugin.
|
|
|
|
2. 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.
|
|
|
|
3. 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 the *implementation* 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](https://github.com/JetBrains/intellij-community/blob/master/xml/dom-openapi/src/com/intellij/util/xml/Attribute.java)
|
|
annotations in the specified bean class.
|
|
|
|
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 IDEA core and one extension to access the _MyExtensionPoint1_ extension point in a test plugin:
|
|
|
|
```xml
|
|
<!-- Declare extensions to access extension points in the IDEA core. These extension points
|
|
have been declared using the "interface" attribute.
|
|
-->
|
|
<extensions defaultExtensionNs="com.intellij">
|
|
<appStarter implementation="MyTestPackage.MyTestExtension1"></appStarter>
|
|
<applicationConfigurable implementation="MyTestPackage.MyTestExtension2"></applicationConfigurable>
|
|
</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>
|
|
```
|
|
|
|
## How to Get the Extension Points List?
|
|
|
|
To get a list of extension points available in the *IntelliJ IDEA* core, consult the _\<extensionPoints\>_ section of the following XML configuration files:
|
|
|
|
* [LangExtensionPoints.xml](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-resources/src/META-INF/LangExtensionPoints.xml)
|
|
|
|
* [PlatformExtensionPoints.xml](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml)
|
|
|
|
* [VcsExtensionPoints.xml](https://github.com/JetBrains/intellij-community/blob/master/platform/platform-resources/src/META-INF/VcsExtensionPoints.xml)
|
|
|
|
## Additional Information and Samples
|
|
|
|
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](TODO)
|
|
and
|
|
[Creation of Tool Windows](TODO). |