android class 文件头注释模板

系统环境:macOS High Sierra 10.13.6
android studio version:3.4.1

```
/**
 * 描 述:
 * 作 者:xxx
 * 时 间: ${DATE} ${HOUR}:${MINUTE}
 * 邮 箱:xxxxxxx@163.com
 * 版 本:1.0
 */
```
写注释的主要目的增加可读性和规范个人代码,个人粗线总结了一下。
先上我自己的模板。
下面是注释下的一些通用方式和说明:


这是一个内置模板,它包含一个代码片段,可以在parse指令的帮助下包含到文件模板(Templates tab)中。模板可编辑。除了静态文本、代码和注释之外,您还可以使用预定义的变量,这些变量将像宏一样展开为相应的值。
This is a built-in template. It contains a code fragment that can be included into file templates (Templates tab) with the help of the #parse directive. The template is editable. Along with static text, code and comments, you can also use predefined variables that will then be expanded like macros into the corresponding values. 

预定义变量将采用以下值:
Predefined variables will take the following values:
```
${PACKAGE_NAME} name of the package in which the new file is created
${PACKAGE_NAME} 创建新文件在其中的包的名称。

${USER} current user system login name
${USER} 当前用户系统登录名。

${DATE} current system date
${DATE} 当前系统日期

${TIME} current system time
${TIME} 当前系统时间

${YEAR} current year
${YEAR} 当前年份

${MONTH} current month
${MONTH} 当前月份

${MONTH_NAME_SHORT} first 3 letters of the current month name. Example: Jan, Feb, etc.
${MONTH_NAME_SHORT} 当前月份名称的前3个字母。示例:1月、2月等。(英文下简称)

${MONTH_NAME_FULL} full name of the current month. Example: January, February, etc.
${MONTH_NAME_FULL} 当前月份的全名。示例:一月、二月等。(英文下全程)

${DAY} current day of the month
${DAY} 当月的当前日期

${DAY_NAME_SHORT} first 3 letters of the current day name. Example: Mon, Tue, etc.
${DAY_NAME_SHORT} 当前日期名称的前3个字母。例如:周一、周二等。(英文下简称)

${DAY_NAME_FULL} full name of the current day. Example: Monday, Tuesday, etc.
${DAY_NAME_FULL} 当前日期的全名。例如:星期一、星期二等。(英文下全称)

${HOUR} current hour
${HOUR} 当前小时

${MINUTE} current minute
${MINUTE} 当前分钟

${PROJECT_NAME} the name of the current project
${PROJECT_NAME} 当前项目的名称
```

2019年 12 月 18 日更新
添加文件头注释模板的方法
打开 Android studio,选择菜单栏Android studio 的Preferences,进入Editor 栏,选择File and Code Templates,  可选择本工程设置和默认设置,下面选择 inCludes,可本地创建,如 创建Android Java file header(默认是 File Header),在右边的输入框内,输入自己的注释模板保存即可。最后就是引用此模板了,在inCludes左边有另外一个选项,叫Files,列表中的 Class就是引用的地方
```
#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

#if (${IMPORT_BLOCK} != "")${IMPORT_BLOCK}
#end
#parse("File Header.java")
#if (${VISIBILITY} == "PUBLIC")public #end #if (${ABSTRACT} == "TRUE")abstract #end #if (${FINAL} == "TRUE")final #end class ${NAME} #if (${SUPERCLASS} != "")extends ${SUPERCLASS} #end #if (${INTERFACES} != "")implements ${INTERFACES} #end {
}
```
#parse("File Header.java")里 File Header.java就是引用,修改成我们定义的即可。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值