IDEA使用 live template添加groovy脚本给方法,类,js方法添加注释(转载)
Posted 唐 森
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA使用 live template添加groovy脚本给方法,类,js方法添加注释(转载)相关的知识,希望对你有一定的参考价值。
IDEA添加Live Template:
File->Setting->Editor->Live Templates
Abbreviation:
*
Template text:
** *$context$ */
设置context内容:
Edit variables ->Default value
groovyScript("C:\\\\IDEACommentLiveTemplate.groovy", currentPackage(), className(), methodName(), jsMethodName(), methodParameters(), methodReturnType(), date("yyyy-MM-dd"), time("HH:mm:ss"))
IDEACommentLiveTemplate.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; // 固定的时间,默认的是false def confirmedDateTime = false; def confirmedDateTimeString = "2017-06-15 12:20:40"; // 可以修改成自己的相关信息 def author = "yz"; def projectName = ""; def version = "V1.0.0"; def copyright = "yz All rights reserved."; def outputParams = ""; for(param in methodParameters) { outputParams += " * @param " + param + " : \\n"; } def outputReturnType = ""; if (methodReturnType != "void") { outputReturnType = " * @return : " + methodReturnType + "\\n"; } def outputMethodName = " * @Method : " + methodName + "\\n"; def outputDesc = " * @Description : \\n"; def outputAuthor = " * @author : " + author + "\\n"; def outputDateTime = " * @CreateDate : " + date + " " + time + "\\n"; if (confirmedDateTime) { outputDateTime = " * @CreateDate : " + confirmedDateTimeString + "\\n"; } def outputProjectName = " * @Project : " + projectName + "\\n"; def outputPackageName = " * @Package : " + packageName + "\\n"; def outputClass = " * @Class : " + className + "\\n"; def outputVersion = " * @version : " + version + "\\n"; def outputClassOtherInfo = " * @Copyright : " + copyright + "\\n"; outputClassOtherInfo += " * @Reviewed : " + "\\n"; outputClassOtherInfo += " * @UpateLog : Name Date Reason/Contents\\n"; outputClassOtherInfo += " * ---------------------------------------\\n"; outputClassOtherInfo += " * **** **** **** \\n"; def outputJsMethodName = " * @Method : " + jsMethodName + "\\n"; def outputJsParams = " * @param \\n"; def outputJsReturnType = " * @return : \\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;
设置应用
内容转载自:http://www.cnblogs.com/xzjxylophone/p/7060035.html
以上是关于IDEA使用 live template添加groovy脚本给方法,类,js方法添加注释(转载)的主要内容,如果未能解决你的问题,请参考以下文章
详细:idea2021自定义注解模板live Templates
详细:idea2021自定义注解模板live Templates