mmichaelis
6/8/2018 - 6:53 AM

IntelliJ Idea Live Template: Setter (Builder, requireNonNull)

#macro( fieldaccess $expr )
  #if($field.collection)
    com.google.common.collect.ImmutableList.copyOf($expr) ##
  #elseif($field.map)
    com.google.common.collect.ImmutableMap.copyOf($expr) ##
  #else
    $expr ##
  #end
#end
#set($paramName = $helper.getParamName($field, $project))
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
#if ($field.boolean && $field.primitive)
  $field.name = $paramName;
#else
  $field.name = #fieldaccess( "java.util.Objects.requireNonNull($paramName, ""$paramName must not be null."")" );
#end
#if(!$field.modifierStatic)
return this;
#end
}