How can I override a service implementation in an IntelliJ plugin?

How can I override the default service implementation of, say, FrameTitleBuilder in my intellij plugin?

I am using IntelliJ 12.1.4, I have correctly configured the environment for creating plugins.

Now I tried to add this to my plugin.xml in a new plugin project:

 <extensions defaultExtensionNs="com.intellij"> <applicationService serviceInterface="com.intellij.openapi.wm.impl.FrameTitleBuilder" serviceImplementation="com.my.package.MyFrameTitleBuilder" overrides="com.intellij.openapi.wm.impl.FrameTitleBuilder" /> </extensions> 

However, it is not:

 org.picocontainer.defaults.DuplicateComponentKeyRegistrationException: Key com.intellij.openapi.wm.impl.FrameTitleBuilder duplicated 

Can anyone suggest some tips?

Thank you in advance!

+4
source share
2 answers

The "overrides" attribute is logical (in IntelliJ 13 anyway), set it to true and the old implementation will be deleted first.

 <extensions defaultExtensionNs="com.intellij"> <applicationService serviceInterface="com.intellij.openapi.wm.impl.FrameTitleBuilder" serviceImplementation="com.my.package.MyFrameTitleBuilder" overrides="true" /> </extensions> 
+3
source

Since I could not find a way in plugin.xml so that my plugin redefined the service implementation, I had to "replace" it manually through PicoContainer.

Take ApplicationManager.getApplication().getPicoContainer() and MutablePicoContainer it to MutablePicoContainer , and then you can unregister / reregister the component.

I would still like to know the correct format for this with plugin.xml , if possible.

0
source

Source: https://habr.com/ru/post/1501861/


All Articles