|
|
|
[
Permlink
| « Hide
]
Niels Ull Harremoës - 31 Aug 05 16:32
The currently generated equals code trigger the "Redundant 'if' statement" inspection. We'd like to modify it.
Josh Bloch, in his "Effective Java Reloaded"
II also would like to control the format that is used when IDEA generates getter/setter pairs for me. For example, if I'm generating getter/setter pairs for two members (foo and bar), I'd like it to look like this:
public void setFoo(Foo foo) { this.foo = foo; } public void setBar(Bar bar) { this.bar = bar; } So basically, one method == one line, and no space between the getter/setter pair, but a line between each pair. Right now, it generates each getter/setter over three lines and with white space between each method. If there was a generic mechanism to edit the output of these methods (and the templates could be tied to a project file so that it's used for all developers in a project), that'd rock. I would like it to be possible to generate "setters and getters" using methods which do not start with "set" and "get". For example like this:
public Foo foo() { return foo; } public void changeFooTo(Foo foo) { this.foo = foo; } It would be best to be able to have many setter/getter templates in use at the same time, so that you could choose at code generation time whether you need to create a setter which uses the traditional "setFoo" style (required by many frameworks) or a fluent "changeFooTo" style (makes the code more readable). Also this kind of "setter" for immutable objects could be handy:
public MyClass withFoo(Foo foo) { MyClass copy = this.clone(); copy.foo = foo; return copy; } or public MyClass withFoo(Foo foo) { MyClass copy = new MyClass(this); copy.foo = foo; return copy; } In other words, the template system should be flexible enough to allow creating just about any kind of setters and getters. I have another use case: Lazy initialized getters. A previous employer used to use them as a convention in Swing guis to initialize each component before returning them. It actually went a long way towards cleaning up Swing code which very easily becomes messy. At the time, I tried using code templates for this, but I was never able to get them to work:
public $FIELDTYPE get$FIELDNAME() { |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||