Reference to Android Code Style Guidelines
Last active
August 21, 2017 05:55
-
-
Save ligboy/0eae9ecffc694595d40e to your computer and use it in GitHub Desktop.
Android Studio Getters & Setters Template.
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
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; | |
} |
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
#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; | |
} |
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
#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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好 你知道在这个模板里怎么拿到这个field的注释吗 ? 我想生成类似于这种效果:
/**
*/
private String test;
自动生成类似于这种:
/**
*@return test : 特殊说明
*/
public void getTest(){
return this.test;
}