Idea Live template advanced knowledge, advance (add comment to method, class, JS method)

Source: Internet
Author: User

In order to solve with a command (macro) to the method, class, JS method to add comments, after a few days of research. finally got the result.

The effect of the implementation is as follows:

To add methods to the method in Java:

    /**      *     * @Method: AddMenu     * @Description:     @param  menu:     @return  : cn.yiyizuche.common.base.ResultMsg     @author  : Rush.d.xzj     * @CreateDate : 2017-06-12 Mon 18:17:42     *     **  /Public resultmsg addMenu (Menu menu) {         null;         return result;    }

Add comments to Java class:

/**@author@version  : V1.0.0 * @Copyright: Yizukeji Inc. All rights reserved. * @Reviewed: * @UpateLog:    Name    Date    reason/contents *             ---------------------------------------* * * * * * public class                 Menucontroller {}      

Add a comment to the JS method

/**@return@author*/function Standardshowbatchcheckbox (Jspelement, DataList, Max, valueidfunction, Textfunction, selectedfunction) {}

Now publish the answers as follows

Abbreviation:

Cmj

Template text (note 1):

* *$context $  */

Edit variables:

The code for $context $ (the main code) is as follows:

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; res Ult + = Outputreturntype; result + = Outputauthor; result + = Outputdatetime; Result + = ' * '; return result;} else if (jsmethodname! = ' null ') {result + = ' \\n '; result + = Outputjsmethodname; result + = Outputdesc; result + = Outputjs ReturnType; 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}\". Replac Eall (' [\\\\[|\\\\]|\\\\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 ResU lt; ", 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: 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: one 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; "))

Use the following:

Output in Xx.java or xx.js (Note 2):

/cmj

Press the TAB key (this key is the default and can be changed to another)

Note 1 and note 2

You can also switch to the second method (most of the way online):

Template text

* *$context $  */

Call 1 to compare the first line with one less *,

So note 2 is turned into:

/* CMJ

I feel that my method is better than the second method.

Edit Variable code in detail


First I break down the following 10 functions (which are small functions):

    //Output Method NameGroovyscript ("def methodName = \" ${_1}\ "; def result = ' * @Method: ' + methodName + ' \\n '; return result;", MethodName ())//Output DescriptionGroovyscript ("def result = ' * @Description: ' + ' \\n '; return result; ")        //Sub-function of output parameter listGroovyscript ("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 ())//the child function of the output author can be changed by author hereGroovyscript ("def author = ' Rush.d.xzj '; def result = ' * @author: ' + author + ' \\n '; return result; ")        //sub-function for output return valueGroovyscript ("def returntype = \" ${_1}\ "; def result = ' * @return: ' + returntype + ' \\n '; return result;", Methodreturntype ())//The output date of the word function, this can change the date formatGroovyscript ("def date = \" ${_1}\ "; def time = \" ${_2}\ "; def result = ' * @CreateDate: ' + date + ' + time + ' \\n '; re turn result; ", Date (" Yyyy-mm-dd E "), Time (" HH:mm:ss "))    //Output ProjectGroovyscript ("def result = ' * @Project: one OA ' + ' \\n '; return result; ")        //Output PackageGroovyscript ("def currentpackage = \" ${_1}\ "; def result = ' * @Package: ' + currentpackage + ' \\n '; return result;", Currentpackage ())//Output ClassGroovyscript ("def className = \" ${_1}\ "; def result = ' * @Class: ' + className + ' \\n '; return result;", ClassName ())//Output Copyright/reviewd/updatelogGroovyscript ("def result = ' * @Copyright: Yizukeji Inc. All rights reserved. ' + ' \\n '; Result + = ' * @Reviewed: ' + ' \\n '; Result + = ' * @UpateLog: Name Date reason/contents ' + ' \\n '; Result + = ' *---------------------------------------' + ' \\n '; Result + = ' * * * * * * * * * * * * * * * * \\n '; return result; ")        //Output VersionGroovyscript ("def result = ' * @version: V1.0.0 ' + ' \\n '; return result; ")    //Output JsmethodnameGroovyscript ("def jsmethodname = \" ${_1}\ "; def result = ' * @Method: ' + jsmethodname + ' \\n '; return result;", Jsmethodname ())//Output JS returnGroovyscript ("def result = ' * @return: ' + ' \\n '; return result; ")

Then in the main code, the above 10 functions need to be used as parameters to supply the main code.

Judgment is the function, class, JS function is mainly through the following 2 built-in variables to achieve:

MethodName () Jsmethodname ()

Generates a comment for a method when MethodName () is not empty

Generates a comment for the JS method when Jsmethodname () is not empty

Otherwise generate a comment for the class

So the above code can be simply categorized as follows:

Get related parameters:

    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 = ';

Determine which type of comment (Code snippet 2):

   if(MethodName! = ' null ') {result+ = ' \\n '; Result+=Outputmethodname; Result+=Outputdesc; Result+=Outputparams; Result+=Outputreturntype; Result+=Outputauthor; Result+=Outputdatetime; Result+ = ' * '; returnresult; } Else if(Jsmethodname! = ' null ') {result+ = ' \\n '; Result+=Outputjsmethodname; Result+=Outputdesc; Result+=Outputjsreturntype; Result+=Outputauthor; Result+=Outputdatetime; Result+ = ' * '; returnresult; } Else{result+ = ' \\n '; Result+=Outputproject; Result+=Outputpackage; Result+=Outputclass; Result+=Outputdesc; Result+=Outputauthor; Result+=Outputdatetime; Result+=outputversion; Result+=Outputclassotherinfo; Result+ = ' * '; returnresult; }

That's it. It's all so ugly (groopscript?) The code collation is quite clear.

I also have a few doubts/questions to solve, if a friend can give me the answer that would be good.

Question 1. Do not know how to get a list of parameters in the JS method

Question 2. In code Snippet 2, if I change to:

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+ = ' * '; returnResult

The following error will appear:

1:expecting EOF, found ' result ' @ Line 1, column 1036.    + = Outputclassotherinfo; } result + =                                  ^1 error

Issue 3: Do not know how to get the override method corresponding to the interface method (parent class method)

About Question 3: it is meaningless to annotate this method in practice, for reference: Https://stackoverflow.com/questions/4310858/comments-on-overridden-method-in-java

But if you have to add how to judge.

Resources:

Http://blog.sina.com.cn/s/blog_4c4195e70102wh7e.html

Https://stackoverflow.com/questions/4310858/comments-on-overridden-method-in-java

Idea Live template advanced knowledge, advance (add comment to method, class, JS method)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.