您的位置:首页 > 其它

InterlliJ 定制Getter and Setter分享

2016-07-07 22:36 260 查看
Getter@Lovell:

/**
* Getter method for property <tt>$field.name</tt>.
*
* @return property value of $field.name
*/

public ##
#if($field.modifierStatic)
static ##
#end
$field.type ##
#if ($StringUtil.startsWith($helper.getPropertyName($field, $project),"_"))
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($StringUtil.substringAfter($helper.getPropertyName($field, $project),"_"))))
#elseif ($StringUtil.startsWith($helper.getPropertyName($field, $project),"m") && $StringUtil.isCapitalized($StringUtil.substringAfter($helper.getPropertyName($field, $project),"m")))
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($StringUtil.substringAfter($helper.getPropertyName($field, $project),"m"))))
#else
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#end#if ($field.boolean && $field.primitive)
#if ($StringUtil.startsWithIgnoreCase($name, 'is'))
#set($name = $StringUtil.decapitalize($name))
#else
is##
#end
#else
get##
#end
${name}() {
return $field.name;
}


Setter@Lovell

#if ($StringUtil.startsWith($helper.getPropertyName($field, $project),"_"))
#set($paramName = $StringUtil.substringAfter($helper.getParamName($field, $project),"_"))
#elseif ($StringUtil.startsWith($helper.getPropertyName($field, $project),"m") && $StringUtil.isCapitalized($StringUtil.substringAfter($helper.getPropertyName($field, $project),"m")))
#set($paramName = $StringUtil.substringAfter($helper.getParamName($field, $project),"m"))
#else
#set($paramName = $helper.getParamName($field, $project))
#end
/**
* Setter method for property <tt>$field.name</tt>.
*
* @param $paramName  value to be assigned to property $field.name
*/
#if($field.modifierStatic)
static ##
#end
void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($paramName))($field.type $paramName) {
#if ($field.name == $paramName)
#if (!$field.modifierStatic)
this.##
#else
$classname.##
#end
#end
$field.name = $paramName;
}


StringUtil的源码在http://grepcode.com/file/repository.grepcode.com/java/ext/com.jetbrains/intellij-idea/12.0/com/intellij/openapi/util/text/StringUtil.java这个链接

参考:http://blog.csdn.net/aerfahaidao/article/details/50733128
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: