zoukankan      html  css  js  c++  java
  • 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 + " : 
    ";
    }
    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;
    

    设置应用

    内容转载自:http://www.cnblogs.com/xzjxylophone/p/7060035.html

  • 相关阅读:
    正则表达式
    iOS获取设备型号、设备类型等信息
    Dubbo-Zookeeper安装
    CentOS-常用安装
    多线程-线程通信
    JVM-高效并发
    静态代理与JDK动态代理
    JVM-类加载机制
    RPC原理及实现
    JVM-自动内存管理机制
  • 原文地址:https://www.cnblogs.com/townsend/p/8488283.html
Copyright © 2011-2022 走看看