Custom Setter template with one statement makes one line<---works. But with two statements it goes full block(?)
Answered
IntelliJ IDEA 2018.1 EAP (Community Edition)
Build #IC-181.3741.2, built on February 13, 2018
JRE: 1.8.0_152-release-1136-b11 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Ok, this is confusing.
Here is my setter template that works to produce a setting on one line:
#set($paramName = $helper.getParamName($field, $project))
#if($field.modifierStatic)
static ##
#end
void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {##
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName; }
It produces (properly) this:
public void setMsDelay(int msDelay) { this.msDelay = msDelay; }
But I would like a cascading style setter, so I modified the above setter template to this:
#set($paramName = $helper.getParamName($field, $project))
#if($field.modifierStatic)
static ##
#end
$classname set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {##
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName; return this; }
(I know that it will fail with statics. But one issue at a time). It produces this:
public Central setMsDelay(int msDelay)
{
this.msDelay = msDelay;
return this;
}
How do I defeat this?
Thanks!
PS: Here are my code-style settings that (maybe?) are pertinent:
Please sign in to leave a comment.
It should work with Multiple expressions in one line option enabled. Feel free to report a bug at https://youtrack.jetbrains.com/issues/IDEA.
Serge, before I do that though, I would like to run this by you (and others).
I discovered a wrinkle in this.
In the working template, if I start entering something lengthy at the beginning of line 5 (the "set" line) such as $classname (which is longer than "void"), then there is a forced line break/wrap and suddenly the template simply stops working and produces blank. Line 5 becomes a line 5 and 6 and the setter croaks silently.
If I then go back and carefully edit line 5 back to a single line, it works again.
Questions: Does the template editor obey my line-wrap and line-break rules I set for the regular editor? Is this expected behavior?
If it helps, here are my settings (.jar): https://drive.google.com/open?id=1AUnt3iWO_VGQH489SFF1Z9Yt601p-qfR