Skip to content

Instantly share code, notes, and snippets.

@pablisco
Created April 19, 2017 09:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablisco/2c08f94e629d9df42bda374df9a16d37 to your computer and use it in GitHub Desktop.
Save pablisco/2c08f94e629d9df42bda374df9a16d37 to your computer and use it in GitHub Desktop.
#set($paramName = $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
static void ##
#else
$classname ##
#end
with$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
}
@pablisco
Copy link
Author

This is an InteliJ template to create "withXX" methods for setters. This is helpful for builders
The resulting method will be something like:

public Builder withProperty(String property) {
  this.property = property;
  return this;
}

@pablisco
Copy link
Author

How to add it

  1. Select to add a getter on the new menu (cmd+n or ctr+n):
    image

  2. Select the button with the 3 dots to add a new template:
    image

  3. Add it as a new template:
    image

  4. Profit

@voghDev
Copy link

voghDev commented Apr 20, 2017

Hi Pablo :-)

where do you copy Wither.template file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment