How can i add custom expression functions for Live templates in Intellij

Aman picture Aman · Aug 28, 2012 · Viewed 8.2k times · Source

How can add new custom functions for Live Templates in Idea Intellij.

For example i need a custom function which can convert a live template variable from Camel Case to Spaced. i.e in Live Template on variable has to be inserted at multiple places with & without space.

Eg. "MyVar" and "My Var". So i want to insert an expression to convert 'MyVar' to 'My Var'.

No expression available by default can be used for this.

Thanks.

Answer

CrazyCoder picture CrazyCoder · Aug 28, 2012

There is OpenAPI for providing Live Template functions. One can create IntelliJ IDEA plug-in that will add more functions.

See the Macro abstract class. Plug-in should define extension point, like this one:

<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CapitalizeMacro"/>

Search IntelliJ IDEA Community code base for sample implementations.