Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Studio Getters & Setters Template.
public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
#if ($StringUtil.startsWithIgnoreCase($name, 'is'))
#set($name = $StringUtil.decapitalize($name))
#else
is##
#end
#else
get##
#end
#if ($name.length() > 1 && ($StringUtil.startsWith($name, 'm') || $StringUtil.startsWith($name, 's')))
#set($name = $name.substring(1))
#end
${name}() {
return $field.name;
}
#set($paramName = $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
static ##
#end
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($name.length() > 1 && ($StringUtil.startsWith($name, 'm') || $StringUtil.startsWith($name, 's')))
#set($name = $name.substring(1))
#if ($paramName.length() > 1 && ($StringUtil.startsWith($paramName, 'm') || $StringUtil.startsWith($paramName, 's')))
#set($paramName = $StringUtil.decapitalize($paramName.substring(1)))
#end
#end
void set${name}($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
}
#set($paramName = $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
static void ##
#else
$classname ##
#end
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($name.length() > 1 && ($StringUtil.startsWith($name, 'm') || $StringUtil.startsWith($name, 's')))
#set($name = $name.substring(1))
#if ($paramName.length() > 1 && ($StringUtil.startsWith($paramName, 'm') || $StringUtil.startsWith($paramName, 's')))
#set($paramName = $StringUtil.decapitalize($paramName.substring(1)))
#end
#end
set${name}($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
#if(!$field.modifierStatic)
return this;
#end
}
@lingdage

This comment has been minimized.

Copy link

@lingdage lingdage commented Nov 1, 2016

你好 你知道在这个模板里怎么拿到这个field的注释吗 ? 我想生成类似于这种效果:
/**

  • 特殊说明
    */
    private String test;

自动生成类似于这种:

/**
*@return test : 特殊说明
*/
public void getTest(){
return this.test;
}

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