如何在Intellij IDEA的实时模板中使用变量值?

时间:2012-12-27 10:39:52

标签: intellij-idea live-templates

我想为setter创建实时模板。

我已经创建了这个模板 enter image description here

如何使用 par 变量的值生成 var 变量的值?基本上,我想在这里避免冗余,只将变量名称放一次,其他一个将由某些算法自动生成。

更新

我想澄清一点我想要实现的目标。

假设我想创建名为 setTime 的setter,其参数 time

public void setTime(long time)
{
    // ...
}

我不想两次输入“time” - 大写和非大写。我想只键入参数名称,因此将自动生成方法名称。

更新(答案)

原来,变量订单很重要。这是我想要的最终结果

enter image description here

1 个答案:

答案 0 :(得分:13)

您可以使用soutv作为示例,注意它如何定义变量的副本:

copy

还可以通过插件或Groovy代码为实时模板定义自定义表达式: How can i add custom expression functions for Live templates in Intellij