Search code examples
intellij-ideaauto-generatelive-templates

Auto generate random long in IntelliJ Live Template


How do I auto generate an arbitrary number (Long) for use in a Live Template in IntelliJ?

Example:

public static final long uid = $randomLong$;

where randomLong is replaced with a random long value. I have tried adding the following as an expression for the variable on the live template definition but nothing is generated when the template outputs.

new Random().nextLong()

What I am trying to achieve is very similar to what the IDEA code inspector generates for the Serialization version UID field but with a live template.


Solution

  • Please try adding groovyScript("new Random().nextLong()") as the variable expression instead.