本文主要介绍使用IDEA编辑器的活动模板,结合groovy脚本,天生注释模板。现在天生的注释主要适用于java和js文件
推荐此方式,可以根据需要界说groovy脚本,天生不同格式的注释
找到 Edtor >> Live Temolates , 发起创建一个模板组 java_often(非必须,创建一个好管理)
- 再次点击+号,创建一个 Live Temolate
缩写Abbreviation处填写星号 *
模板文本填写 **$context$ */ , 留意星号顶头填写,前面没有空格,变量context可自界说
Name处填写 context ,留意对应上一步的变量
Expression处不可选择
Default value填写 - groovyScript("D:\\idea\\javadoc.groovy", currentPackage(), className(), methodName(), jsMethodName(), methodParameters(), methodReturnType(), date("yyyy-MM-dd"), time("HH:mm:ss"))
复制代码 由于需要的groovy脚本过长,所以创建了一个文件,这个文件发起跟idea安装目次放一起,文件内容放到了文章结尾

设置触发键 Enter 。
选择适用文件 java,

在Java类名输入 /* ,点击回车,即可生产注释,


groovy脚本文件- def packageName = _1;
- def className = _2;
- def methodName = _3;
- def jsMethodName = _4;
- def methodParameters = _5;
- def methodReturnType = _6;
- def date = _7;
- def time = _8;
- def confirmedDateTimeString = "2022-03-01 12:20:40";
- // 可以修改成自己的相关信息
- def author = "mutouyang";
- def projectName = "demoProject";
- def version = "V1.0.0";
- def copyright = "2017 mutouyang Inc. All rights reserved.";
- if(packageName){
- String[] str = packageName.split("\\.")
- if(str.length >2){
- projectName=str[1];
- }
- }
- def outputParams = "";
- for(param in methodParameters) {
- outputParams += " * @param " + param + " : \n";
- }
- def outputReturnType = "";
- if (methodReturnType != null & methodReturnType != "void") {
- outputReturnType = " * @return : " + methodReturnType + "\n";
- }
- def outputMethodName = " * method : " + methodName + "</br>\n";
- def outputDesc = " * description : </br>\n";
- if(!outputReturnType){
- //outputDesc = " * description : 构造方法 </br>\n";
- }
- def outputAuthor = " * @author : " + author + "</br>\n";
- def outputDateTime = " * @CreateDate : " + date + " " + time + "</br>\n";
- def outputProjectName = " * @Project : " + projectName +"</br>\n";
- def outputPackageName = " * @Package : " + packageName + "</br>\n";
- def outputClass = " * @ClassName : " + className + "</br>\n";
- def outputVersion = " * @version : " + version + "</br>\n";
- def outputClassOtherInfo = " * @Copyright : " + copyright + "</br>\n";
- outputClassOtherInfo += " * @Reviewed : " + "\n";
- outputClassOtherInfo += " * @UpateLog : Name Date Reason/Contents\n";
- outputClassOtherInfo += " * ---------------------------------------\n";
- outputClassOtherInfo += " * **** **** **** \n";
- def outputJsMethodName = " * method : " + jsMethodName + "</br>\n";
- def outputJsParams = " * @param </br>\n";
- def outputJsReturnType = " * @return : </br>\n";
- def result = "";
- result += "\n";
- if (methodName) {
- result += outputMethodName;
- result += outputDesc;
- result += outputParams;
- result += outputReturnType;
- result += outputAuthor;
- result += outputDateTime;
- } else if (jsMethodName) {
- result += outputJsMethodName;
- result += outputDesc;
- result += outputJsParams;
- result += outputJsReturnType;
- result += outputAuthor;
- result += outputDateTime;
- } else {
- result += outputProjectName;
- // result += outputPackageName;
- result += outputClass;
- result += outputDesc;
- result += outputAuthor;
- result += outputDateTime;
- result += outputVersion;
- // result += outputClassOtherInfo;
- }
- //result += " *";
- return result;
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |