搜索
首页Javajava教程idea live template高级知识, 进阶
idea live template高级知识, 进阶May 17, 2018 am 10:36 AM
ideajavascriptlivetemplate知识高级

为了解决用一个命令(宏)给方法,类,js方法添加注释,经过几天的研究.终于得到结果了.

实现的效果如下:

给Java中的method添加方法:

    /** *
     * @Method : addMenu
     * @Description :
     * @param menu :
     * @return : cn.yiyizuche.common.base.ResultMsg
     * @author : Rush.D.Xzj
     * @CreateDate : 2017-06-12 星期一 18:17:42
     *     */public ResultMsg addMenu(Menu menu){
        ResultMsg result = null;return result;
    }

给 Java class 添加注释:

/**
 *
 * @Project : 壹壹OA
 * @Package : cn.yiyizuche.common.ou.menu.controller
 * @Class : MenuController
 * @Description :
 * @author : Rush.D.Xzj
 * @CreateDate : 2017-06-12 星期一 18:15:32
 * @version : V1.0.0
 * @Copyright : 2017 yizukeji Inc. All rights reserved.
 * @Reviewed :
 * @UpateLog :    Name    Date    Reason/Contents
 *             ---------------------------------------
 *                 ***        ****    ****
 * */public class MenuController {
}

给js 的方法添加注释

/**
 *
 * @Method : standardShowBatchCheckBox
 * @Description :
 * @return :
 * @author : Rush.D.Xzj
 * @CreateDate : 2017-06-12 星期一 18:15:21
 * */function standardShowBatchCheckBox(jspElement, dataList, max, valueIdFunction, textFunction, selectedFunction) {
}

现在把答案公布如下

Abbreviation:

cmj

Template text(注1):

**
 *$context$ 
 */

Edit variables:

$context$的代码(主要代码)如下:

groovyScript("def methodName = \"${_1}\"; 
def jsMethodName = \"${_2}\"; 
def outputMethodName = \"${_3}\"; 
def outputDesc = \"${_4}\"; 
def outputParams = \"${_5}\"; 
def outputAuthor = \"${_6}\"; 
def outputReturnType = \"${_7}\"; 
def outputDateTime = \"${_8}\"; 
def outputPackage = \"${_9}\"; 
def outputClass = \"${_10}\"; 
def outputClassOtherInfo = \"${_11}\"; 
def outputProject = \"${_12}\"; 
def outputVersion = \"${_13}\"; 
def outputJsMethodName = \"${_14}\"; 
def outputJsReturnType = \"${_15}\"; 
def result = ''; 
if (methodName != 'null') { 
result += '\\n'; 
result += outputMethodName; 
result += outputDesc; 
result += outputParams; 
result += outputReturnType; 
result += outputAuthor; 
result += outputDateTime; 
result += ' *'; return result;
} else if (jsMethodName != 'null') { 
result += '\\n'; 
result += outputJsMethodName; 
result += outputDesc; 
result += outputJsReturnType; 
result += outputAuthor; 
result += outputDateTime; result += ' *'; return result;
} else { 
result += '\\n'; 
result += outputProject; 
result += outputPackage; 
result += outputClass; 
result += outputDesc; 
result += outputAuthor; 
result += outputDateTime; 
result += outputVersion; 
result += outputClassOtherInfo; 
result += ' *'; return result;
} ", methodName(), jsMethodName(), groovyScript("def methodName = \"${_1}\"; 
def result = ' * @Method : ' + methodName + '\\n'; 
return result;", methodName()), groovyScript("def result = ' * @Description : ' + '\\n'; 
return result;"), groovyScript("if(\"${_1}\".length() == 2) 
{
return '';
} else {
def result=''; 
def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();
for(i = 0; i < params.size(); i++) 
{
result+=' * @param ' + params[i] + ' : ' + '\\n'
}; 
return result;}", methodParameters()), groovyScript("def author = 'Rush.D.Xzj'; 
def result = ' * @author : ' + author + '\\n'; 
return result;"), groovyScript("def returnType = \"${_1}\"; 
def result = ' * @return : ' + returnType + '\\n'; 
return result;", methodReturnType()), groovyScript("def date = \"${_1}\"; 
def time = \"${_2}\"; 
def result = ' * @CreateDate : ' + date + ' ' + time + '\\n'; 
return result;", date("yyyy-MM-dd E"), time("HH:mm:ss")), groovyScript("def currentPackage = \"${_1}\"; 
def result = ' * @Package : ' + currentPackage + '\\n'; 
return result;", currentPackage()), groovyScript("def className = \"${_1}\"; 
def result = ' * @Class : ' + className + '\\n'; 
return result;", className()), groovyScript("def result = ' * @Copyright : 2017 yizukeji Inc. All rights reserved.' + '\\n'; 
result += ' * @Reviewed : ' + '\\n'; result += ' * @UpateLog :    Name    Date    Reason/Contents' + '\\n'; 
result += ' *             ---------------------------------------' + '\\n'; 
result += ' *                 ***        ****    **** ' + '\\n'; 
return result;"), groovyScript("def result = ' * @Project : 壹壹OA' + '\\n'; 
return result;"), groovyScript("def result = ' * @version : V1.0.0' + '\\n'; 
return result;"), groovyScript("def jsMethodName = \"${_1}\"; 
def result = ' * @Method : ' + jsMethodName + '\\n'; 
return result;", jsMethodName()), groovyScript("def result = ' * @return : ' + '\\n'; return result;"))

使用如下:

在xx.java或者 xx.js中输出(注2):

/cmj

后 按 tab键(此键是默认的,可以更改成其他的)

注1 和注2

也可以换成第二种方法(网上大部分的方法):

Template text

*
 *$context$ 
 */

跟注1比较第一行少了一个*,

因此注2就是变成了:

/*cmj

我感觉用我的方法比第二种方法好.

Edit Variable中代码详解

首先我分解了如下的 10几个函数(是小函数):

    // 输出方法名groovyScript("def methodName = \"${_1}\"; def result = ' * @Method : ' + methodName + '\\n'; 
    return result;", methodName())    // 输出描述
    groovyScript("def result = ' * @Description : ' + '\\n'; 
    return result;")    // 输出参数列表的子函数
    groovyScript("if(\"${_1}\".length() == 2) {return '';
    } else {
    def result=''; 
    def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList(); 
    for(i = 0; i < params.size(); i++) {result+=' * @param ' + params[i] + ' : ' + '\\n'}; 
    return result;}", methodParameters())    // 输出    作者的        子函数  这里可以改作者
    groovyScript("def author = 'Rush.D.Xzj'; 
    def result = ' * @author : ' + author + '\\n'; 
    return result;")    // 输出    返回值的   子函数
    groovyScript("def returnType = \"${_1}\"; 
    def result = ' * @return : ' + returnType + '\\n'; 
    return result;", methodReturnType())    // 输出    日期的     字函数, 这个可以更改日期格式
    groovyScript("def date = \"${_1}\"; def time = \"${_2}\"; 
    def result = ' * @CreateDate : ' + date + ' ' + time + '\\n'; 
    return result;", date("yyyy-MM-dd E"), time("HH:mm:ss"))    // 输出Project
    groovyScript("def result = ' * @Project : 壹壹OA' + '\\n'; 
    return result;")    // 输出package
    groovyScript("def currentPackage = \"${_1}\"; 
    def result = ' * @Package : ' + currentPackage + '\\n'; 
    return result;", currentPackage())    // 输出class
    groovyScript("def className = \"${_1}\"; 
    def result = ' * @Class : ' + className + '\\n'; 
    return result;", className())    // 输出copyright/reviewd/updatelog
    groovyScript("def result = ' * @Copyright : 2017 yizukeji Inc. All rights reserved.' + '\\n'; 
    result += ' * @Reviewed : ' + '\\n'; 
    result += ' * @UpateLog :    Name    Date    Reason/Contents' + '\\n'; 
    result += ' *             ---------------------------------------' + '\\n'; 
    result += ' *                 ***        ****    **** ' + '\\n'; 
    return result;")    // 输出version
    groovyScript("def result = ' * @version : V1.0.0' + '\\n'; return result;")    // 输出jsMethodName
    groovyScript("def jsMethodName = \"${_1}\"; def result = ' * @Method : ' + jsMethodName + '\\n'; 
    return result;", jsMethodName())    // 输出 js 的return
    groovyScript("def result = ' * @return : ' + '\\n'; return result;")

然后在主要代码中,需要把上述的10几个函数当做参数供给主要代码使用.

判断是函数,类,js函数主要是通过如下的2个内置变量来实现的:

methodName()
jsMethodName()

当methodName()不为空的时候, 生成 方法的 注释

当jsMethodName()不为空的时候, 生成 js方法的注释

否则生成类的注释

所以上述的代码可以简单的做如下的归类了:

获取相关参数:

    def methodName = \"${_1}\"; 
    def jsMethodName = \"${_2}\"; 
    def outputMethodName = \"${_3}\"; 
    def outputDesc = \"${_4}\"; 
    def outputParams = \"${_5}\"; 
    def outputAuthor = \"${_6}\"; 
    def outputReturnType = \"${_7}\"; 
    def outputDateTime = \"${_8}\"; 
    def outputPackage = \"${_9}\"; 
    def outputClass = \"${_10}\"; 
    def outputClassOtherInfo = \"${_11}\"; 
    def outputProject = \"${_12}\"; 
    def outputVersion = \"${_13}\"; 
    def outputJsMethodName = \"${_14}\"; 
    def outputJsReturnType = \"${_15}\"; 
    def result = '';

判断是哪一种类型的注释(代码片段2):

   if (methodName != 'null') {
        result += '\\n';
        result += outputMethodName;
        result += outputDesc;
        result += outputParams;
        result += outputReturnType;
        result += outputAuthor;
        result += outputDateTime;
        result += ' *';return result;
    } else if (jsMethodName != 'null') {
        result += '\\n';
        result += outputJsMethodName;
        result += outputDesc;
        result += outputJsReturnType;
        result += outputAuthor;
        result += outputDateTime;
        result += ' *';return result;
    } else {
        result += '\\n';
        result += outputProject;
        result += outputPackage;
        result += outputClass;
        result += outputDesc;
        result += outputAuthor;
        result += outputDateTime;
        result += outputVersion;
        result += outputClassOtherInfo;
        result += ' *';return result;
    }

这下就可以了.就把整个这么难看(groopscript搞的?)代码整理的比较清晰了.

我还有如下的几个疑惑/问题需要解决, 如果有朋友能给我答案那就好了.

问题1. 不知道可以通过什么方法获取js方法中的参数列表

问题2. 代码片段2中如果我改成了:

    result += '\\n';if (methodName != 'null') {
        result += outputMethodName;
        result += outputDesc;
        result += outputParams;
        result += outputReturnType;
        result += outputAuthor;
        result += outputDateTime;
    } else if (jsMethodName != 'null') {
        result += '\\n';
        result += outputJsMethodName;
        result += outputDesc;
        result += outputJsReturnType;
        result += outputAuthor;
        result += outputDateTime;
    } else {
        result += '\\n';
        result += outputProject;
        result += outputPackage;
        result += outputClass;
        result += outputDesc;
        result += outputAuthor;
        result += outputDateTime;
        result += outputVersion;
        result += outputClassOtherInfo;
    }
    result += ' *';return result;

会出现如下的错误:

startup failed:
Script1.groovy: 1: expecting EOF, found 'result' @ line 1, column 1036.
   lt += outputClassOtherInfo; } result += 
                                 ^

1 error

问题3: 不知道怎么获取Override方法对应的接口方法(父类方法)

关于问题3: 实际上给这种方法加注释是没有意义的,具体可以参考:

但是如果非要加该怎么去判断.

最后可以把 缩写(abbreviation)  改成:   *

这样以后只需要输入:

/*

然后按一下 tab 键就出现结果了

哈哈!!!


以上是idea live template高级知识, 进阶的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
es6数组怎么去掉重复并且重新排序es6数组怎么去掉重复并且重新排序May 05, 2022 pm 07:08 PM

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

JavaScript的Symbol类型、隐藏属性及全局注册表详解JavaScript的Symbol类型、隐藏属性及全局注册表详解Jun 02, 2022 am 11:50 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

原来利用纯CSS也能实现文字轮播与图片轮播!原来利用纯CSS也能实现文字轮播与图片轮播!Jun 10, 2022 pm 01:00 PM

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

JavaScript对象的构造函数和new操作符(实例详解)JavaScript对象的构造函数和new操作符(实例详解)May 10, 2022 pm 06:16 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

javascript怎么移除元素点击事件javascript怎么移除元素点击事件Apr 11, 2022 pm 04:51 PM

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

JavaScript面向对象详细解析之属性描述符JavaScript面向对象详细解析之属性描述符May 27, 2022 pm 05:29 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

foreach是es6里的吗foreach是es6里的吗May 05, 2022 pm 05:59 PM

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

整理总结JavaScript常见的BOM操作整理总结JavaScript常见的BOM操作Jun 01, 2022 am 11:43 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具