Question about generating getter / setter

Answered

Intellij provides two default templates for generating setters: "IntelliJ Default" and "Builder". My team has decided to provide both standard setter and builder behavior in our DTO's. I tried to define a new template by just merging the two templates together and remove the "set" from the builder method, but IntelliJ gives me an error

Also when i try to generate standard getter and setter first and after that try to generate the setters using the builder template IntelliJ gives me the message "No property without setter".

Again, i just combined the two default templates. But each template starts with "#set($paramName..." and i deleted the second occurence after merging.

Is it possible to generate the three methods at once (maybe with another approach)?

Thanks in advance

Andreas

0
5 comments

Hello,

Can you please share the code sample you want to generate and the template that you are experimenting with. Thank you 

0

Here is the sample and setter template code. I tried to upload a sample solution via  your update service, but the upload failed for some reason.

public class MyLitteTestDto {

private Integer appId;
private Integer dbActive;
private Integer active;
private String appCode;
private String version;
private Boolean deleteAllowed;

}

#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;
}

public ##
#if($field.modifierStatic)
static void ##
#else
$classSignature ##
#end
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;
#if(!$field.modifierStatic)
return this;
#end
}

0

Hello,

Please also provide the code sample you expect to receive after the getters/setters generation? Thank you

0

Here it is (just the getter / setter for one property):

public Integer getAppId() {
return appId;
}

public void setAppId(Integer appId) {
this.appId = appId;
}

public MyLittleTestDto appId(Integer appId) {
this.appId = appId;
return this;
}
0

Hello,

Unfortunately you can't generate the two methods at once using the template of setter or getter. 

0

Please sign in to leave a comment.