Inject Java code within a xml file

Hi everyone,

I know IDEA support language injection out of the box. But how can I extend that support into a plugin? As an example In my xml file I have following tag

     System.out.println("hello World");

I want to inject java language for that tag with a prefix and a suffix, so that when I type System.out. IDEA would show me autocompletion and other java specific functionalities. Thanks in advance.

Comment actions Permalink

See com.intellij.lang.injection.MultiHostInjector for programmatic or EP "injectionConfig" from IntelliLang plugin for config-file based injection.

Comment actions Permalink

HI Yaan,

After creating a class implementing MultiHostInjector, from where should I call it? I mean do I have to add an extension point to the plugin.xml?

Comment actions Permalink

Yes, you will need to register it in your plugin.xml like

<extensions defaultExtensionNs="com.intellij">
    <multiHostInjector implementation="com.intellij.struts2.freemarker.FreeMarkerCssInlineStyleInjector"/>

Btw there should be automatic "Unused" highlighting for extension points not mapped with automatic quickfix ;-)

Comment actions Permalink

Wonderful. Thanks Yann. You've been most helpful :)


Please sign in to leave a comment.