上一篇文章(http://www.cnblogs.com/xzjxylophone/p/6994488.html) 是在 groovyScript中直接添加的代码,这个看起来是简单,粗暴,麻烦和不美观.
这一片文章是用groovyScript 调用文件的方式,直接上代码:
添加一个 live template
设置 abbreviation为:
*
Template text:
**
*$context$
*/
edit variables 中设置context 为(mac系统):
groovyScript("/Users/ceshi/Documents/goodgoodstudy/groovy/test.groovy", currentPackage(), className(), methodName(), jsMethodName(), methodParameters(), methodReturnType(), date("yyyy-MM-dd"), time("HH:mm:ss"))
其中
/Users/ceshi/Documents/goodgoodstudy/groovy/test.groovy
是你脚本文件的路径.
如果是windows的:
需要添加是如下的:
C:\user\username\test.groovy
test.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 = "Rush.D.Xzj"; def projectName = "yibasic"; def version = "V1.0.0"; def copyright = "2017 yizukeji Inc. All rights reserved."; def outputParams = ""; for(param in methodParameters) { outputParams += " * @param " + param + " : "; } def outputReturnType = ""; if (methodReturnType != "void") { outputReturnType = " * @return : " + methodReturnType + " "; } def outputMethodName = " * @Method : " + methodName + " "; def outputDesc = " * @Description : "; def outputAuthor = " * @author : " + author + " "; def outputDateTime = " * @CreateDate : " + date + " " + time + " "; if (confirmedDateTime) { outputDateTime = " * @CreateDate : " + confirmedDateTimeString + " "; } def outputProjectName = " * @Project : " + projectName + " "; def outputPackageName = " * @Package : " + packageName + " "; def outputClass = " * @Class : " + className + " "; def outputVersion = " * @version : " + version + " "; def outputClassOtherInfo = " * @Copyright : " + copyright + " "; outputClassOtherInfo += " * @Reviewed : " + " "; outputClassOtherInfo += " * @UpateLog : Name Date Reason/Contents "; outputClassOtherInfo += " * --------------------------------------- "; outputClassOtherInfo += " * **** **** **** "; def outputJsMethodName = " * @Method : " + jsMethodName + " "; def outputJsParams = " * @param "; def outputJsReturnType = " * @return : "; def result = ""; result += " "; 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;
在 java文件/js文件中输入:
/*
后 按 tab键(tab键是默认的,可以更改成其他的)
这样就可以了.
剩下的问题:
无法区分java中的 构造函数和普通函数还有类函数
无法识别出 throws
无法识别出 @Override
无法识别出 js method 的参数