Search code examples
javaintellij-idea

Is there a way to write a custom postfix template for java declaring a new instance in IntelliJ IDEA


I want to be able to create the following snippet

Instance instance = new Instance();

using a custom postfix template.

I tried

$EXPR$ $expr$ = new $EXPR$(); 

But it transforms Instance.instance into Instance = new Instance(); missing instance. Only the first letter of the instance identifier should be lowercase, e.g. CustomTemplate should be transformed into CustomTemplate customTemplate = new CustomTemplate();.

Is there a function like lower($EXPR$) to use? I found Custom Postfix Templates plugin but I don't know if it helps me.


Solution

  • I was able to do it using Custom Postfix Templates:

    .instance : new Instance
        CLASS     →  $expr$ $var:suggestVariableName()$ = new $expr$();