IntelliJ Live模板:修改后的setters模板 [英] IntelliJ Live Template: modified setters template
问题描述
有没有人知道如何在intellij中设置一个实时模板来做专门的setter
- 我正在使用v5,但我很乐意接受最近发布的知识) -
Is anyone know how to set up a live template in intellij for doing specialized setters - i'm using v5, but I accept with pleasure knowledge for a more recent release) -
我首先需要的是firePropertyChange setter:
My first need is a firePropertyChange setter:
public final static String $PROPERTY$ = "$property$"
public void set$Property$($TYPE$ $property$) {
Object oldValue = this.$property$;
this.$property$ = $property$;
firePropertyChange($PROPERTY$, oldValue, $property$);
}
我有一个半工作版本,使用这样定义的变量生成实现:
$ property $ - > completeSmart()
$ PROPERTY $ - > completeSmart()
I have a semi-working version that generate the implementation with variables defined like this: $property$ --> completeSmart() $PROPERTY$ --> completeSmart()
我的第二个需求是生成器样式设置器调用常规setter然后在set之后返回:
My second need is a builder style setter that call the regular setter and then return this after the set:
public $THIS_TYPE$ with$Property$($TYPE$ $property$) {
set$Property$($property$);
return this;
}
对于这个我没什么好看的:我还是要打字很多!
For this one I have nothing really good: I still have to type a lot !
有什么建议吗?
推荐答案
像这样的东西
private $TYPE$ $NAME$;
public $THIS$ set$BNAME$($TYPE$ $NAME$) {
this.$NAME$ = $NAME$;
return this;
}
其中
Type = complete()
NAME = suggestVariableName()
BNAME = capitalize(NAME)
THIS = className()
唯一的问题是className在嵌套类中不起作用,因为它将返回Outer $ Inner但它应该足够好。
The only Problem ist that className will not work in nested classes as it will return "Outer$Inner" but it should work good enough.
这篇关于IntelliJ Live模板:修改后的setters模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!