Last active
June 8, 2020 12:32
-
-
Save vijayrawatsan/d4e6a41223c3c9dc34790098f39f0b54 to your computer and use it in GitHub Desktop.
IntelliJ boolean fields better getter setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use the following templates for IntelliJ 2016.1.4 | |
Boolean isFoo; | |
public void getIsFoo() { | |
return foo; | |
} | |
public void setIsFoo(Boolean isFoo) { | |
this.isFoo = isFoo; | |
} | |
boolean isBar; | |
public void getIsBar() { | |
return foo; | |
} | |
public void setIsBar(Boolean isBar) { | |
this.isBar = isBar; | |
} | |
- Getter | |
#if($field.modifierStatic) | |
static ## | |
#end | |
$field.type ## | |
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))) | |
#if ($field.boolean && $StringUtil.startsWithIgnoreCase($field.name, 'is')) | |
#set($name = $StringUtil.join('Is' , $name)) | |
#end | |
get## | |
${name}() { | |
return $field.name; | |
} | |
- Setter | |
#if($field.boolean && $StringUtil.startsWithIgnoreCase($field.name, 'is')) | |
#set($paramName = $StringUtil.join('is', $StringUtil.capitalize($helper.getParamName($field, $project)))) | |
#else | |
#set($paramName = $helper.getParamName($field, $project)) | |
#end | |
#if($field.modifierStatic) | |
static ## | |
#end | |
#if($field.boolean && $StringUtil.startsWithIgnoreCase($field.name, 'is')) | |
#set($methodName = $StringUtil.join('setIs', $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))) | |
#else | |
#set($methodName = $StringUtil.join('set', $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))) | |
#end | |
void $methodName($field.type $paramName) { | |
#if ($field.name == $paramName) | |
#if (!$field.modifierStatic) | |
this.## | |
#else | |
$classname.## | |
#end | |
#end | |
$field.name = $paramName; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment