如何在Intellij IDEA的实时模板中使用变量值? [英] How to use variable value in live templates in Intellij IDEA?

查看:666
本文介绍了如何在Intellij IDEA的实时模板中使用变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为setter创建实时模板。

I want to create live template for setter.

我创建了这个模板

I've created this template

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

How can I use value of par variable to generate value of var variable? Basically, I want to avoid redundancy here and put name of variable only once and other one will be generated automatically by some algorithm.

更新

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

I want to clarify a little bit what I want to achieve.

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

Suppose I want to create setter with name setTime which has parameter time.

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

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

I don't want to type "time" twice - capitalized and non-capitalized. I want to type just parameter name so method name will be generated automatically.

更新(答案)

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

Turned out that variable order is important. This is final result of what I want

推荐答案

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

You can use the soutv as an example, notice how it defines a copy of a variable:

也可以通过插件或Groovy代码为实时模板定义自定义表达式:
如何在Intellij中为Live模板添加自定义表达式功能

It's also possible to define custom expression for live templates via plugins or Groovy code: How can i add custom expression functions for Live templates in Intellij.

这篇关于如何在Intellij IDEA的实时模板中使用变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆