在IntelliJ实时模板中自动生成随机长度

时间:2014-07-29 02:13:41

标签: intellij-idea auto-generate live-templates

如何在IntelliJ中的实时模板中自动生成任意数字(长整数)?

示例:

public static final long uid = $randomLong$;

其中randomLong替换为随机长值。我尝试在实时模板定义中添加以下内容作为变量的表达式,但在模板输出时不会生成任何内容。

new Random().nextLong()

我想要实现的内容与IDEA代码检查器为序列化版本UID字段生成的内容非常相似,但具有实时模板。

1 个答案:

答案 0 :(得分:5)

请尝试添加groovyScript("new Random().nextLong()")作为变量表达式。