开发者

IntelliJ Live Template: modified setters template

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) -

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,开发者_JAVA百科 $property$);
}

I have a semi-working version that generate the implementation with variables defined like this: $property$ --> completeSmart() $PROPERTY$ --> completeSmart()

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 !

Any suggestion ?


Something like this

private $TYPE$ $NAME$;
public $THIS$ set$BNAME$($TYPE$ $NAME$) {
    this.$NAME$ = $NAME$;
    return this;
}

where

Type = complete()
NAME = suggestVariableName()
BNAME = capitalize(NAME)
THIS = className()

The only Problem ist that className will not work in nested classes as it will return "Outer$Inner" but it should work good enough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜