上一篇文章(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 + " : \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;
在 java文件/js文件中输入:
/*
后 按 tab键(tab键是默认的,可以更改成其他的)
这样就可以了.
剩下的问题:
无法区分java中的 构造函数和普通函数还有类函数
无法识别出 throws
无法识别出 @Override
无法识别出 js method 的参数