search
HomeJavajavaTutorialAdvanced knowledge of idea live template, advanced

Advanced knowledge of idea live template, advanced

May 17, 2018 am 10:36 AM
ideajavascriptlivetemplateKnowledgeadvanced

为了解决用一个命令(宏)给方法,类,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 <p></p><p>使用如下:</p><p>在xx.java或者 xx.js中输出(注2):</p><p class="cnblogs_code"></p><pre class="brush:php;toolbar:false">/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 <p>然后在主要代码中,需要把上述的10几个函数当做参数供给主要代码使用.</p><p>判断是函数,类,js函数主要是通过如下的2个内置变量来实现的:</p><p class="cnblogs_code"></p><pre class="brush:php;toolbar:false">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 键就出现结果了

哈哈!!!


The above is the detailed content of Advanced knowledge of idea live template, advanced. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Java Platform Independence: Compatibility with different OSJava Platform Independence: Compatibility with different OSMay 13, 2025 am 12:11 AM

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunondifferentoperatingsystemswithoutmodification.TheJVMcompilesJavacodeintoplatform-independentbytecode,whichittheninterpretsandexecutesonthespecificOS,abstractingawayOS

What features make java still powerfulWhat features make java still powerfulMay 13, 2025 am 12:05 AM

Javaispowerfulduetoitsplatformindependence,object-orientednature,richstandardlibrary,performancecapabilities,andstrongsecurityfeatures.1)PlatformindependenceallowsapplicationstorunonanydevicesupportingJava.2)Object-orientedprogrammingpromotesmodulara

Top Java Features: A Comprehensive Guide for DevelopersTop Java Features: A Comprehensive Guide for DevelopersMay 13, 2025 am 12:04 AM

The top Java functions include: 1) object-oriented programming, supporting polymorphism, improving code flexibility and maintainability; 2) exception handling mechanism, improving code robustness through try-catch-finally blocks; 3) garbage collection, simplifying memory management; 4) generics, enhancing type safety; 5) ambda expressions and functional programming to make the code more concise and expressive; 6) rich standard libraries, providing optimized data structures and algorithms.

Is Java Truly Platform Independent? How 'Write Once, Run Anywhere' WorksIs Java Truly Platform Independent? How 'Write Once, Run Anywhere' WorksMay 13, 2025 am 12:03 AM

JavaisnotentirelyplatformindependentduetoJVMvariationsandnativecodeintegration,butitlargelyupholdsitsWORApromise.1)JavacompilestobytecoderunbytheJVM,allowingcross-platformexecution.2)However,eachplatformrequiresaspecificJVM,anddifferencesinJVMimpleme

Demystifying the JVM: Your Key to Understanding Java ExecutionDemystifying the JVM: Your Key to Understanding Java ExecutionMay 13, 2025 am 12:02 AM

TheJavaVirtualMachine(JVM)isanabstractcomputingmachinecrucialforJavaexecutionasitrunsJavabytecode,enablingthe"writeonce,runanywhere"capability.TheJVM'skeycomponentsinclude:1)ClassLoader,whichloads,links,andinitializesclasses;2)RuntimeDataAr

Is java still a good language based on new features?Is java still a good language based on new features?May 12, 2025 am 12:12 AM

Javaremainsagoodlanguageduetoitscontinuousevolutionandrobustecosystem.1)Lambdaexpressionsenhancecodereadabilityandenablefunctionalprogramming.2)Streamsallowforefficientdataprocessing,particularlywithlargedatasets.3)ThemodularsystemintroducedinJava9im

What Makes Java Great? Key Features and BenefitsWhat Makes Java Great? Key Features and BenefitsMay 12, 2025 am 12:11 AM

Javaisgreatduetoitsplatformindependence,robustOOPsupport,extensivelibraries,andstrongcommunity.1)PlatformindependenceviaJVMallowscodetorunonvariousplatforms.2)OOPfeatureslikeencapsulation,inheritance,andpolymorphismenablemodularandscalablecode.3)Rich

Top 5 Java Features: Examples and ExplanationsTop 5 Java Features: Examples and ExplanationsMay 12, 2025 am 12:09 AM

The five major features of Java are polymorphism, Lambda expressions, StreamsAPI, generics and exception handling. 1. Polymorphism allows objects of different classes to be used as objects of common base classes. 2. Lambda expressions make the code more concise, especially suitable for handling collections and streams. 3.StreamsAPI efficiently processes large data sets and supports declarative operations. 4. Generics provide type safety and reusability, and type errors are caught during compilation. 5. Exception handling helps handle errors elegantly and write reliable software.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!