Idea live template high-level knowledge, advanced (add comments to methods, classes, and js methods), ideatemplate
In order to solve the problem of adding comments to methods, classes, and js methods using a command (macro), after several days of research, the results are finally obtained.
The implementation result is as follows:
Add methods to methods in Java:
/***** @ Method: addMenu * @ Description: * @ param menu: * @ return: cn. yiyizuche. common. base. resultMsg * @ author: Rush. d. xzj * @ CreateDate: Monday 18:17:42 **/public ResultMsg addMenu (Menu menu) {ResultMsg result = null; return result ;}
Add a comment to the Java class:
/***** @ Project: OA * @ Package: cn. yiyizuche. common. ou. menu. controller * @ Class: MenuController * @ Description: * @ author: Rush. d. xzj * @ CreateDate: 18:15:32 * @ version: V1.0.0 * @ Copyright: 2017 yizukeji Inc. all rights reserved. * @ Reviewed: * @ UpateLog: Name Date Reason/Contents * --------------------------------------- ************/public class MenuController {}
Add comments to js Methods
/***** @ Method: standardShowBatchCheckBox * @ Description: * @ return: * @ author: Rush. d. xzj * @ CreateDate: Monday 18:15:21 **/function standardShowBatchCheckBox (jspElement, dataList, max, valueIdFunction, textFunction, selectedFunction ){}
The answer is as follows:
Abbreviation:
cmj
Template text (Note 1 ):
** *$context$ */
Edit variables:
$ Context $ code (Main Code) is as follows:
Policyscript ("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 outpu TVersion = \ "$ {_ 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 (), policyscript ("def methodName = \" $ {_ 1} \ "; def result = '* @ Method: '+ methodName +' \ n'; return result; ", methodName (), policyscript (" def result = '* @ Description:' + '\ n '; return result; "), policyscript (" 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 (), policyscript ("def author = 'rush. d. xzj '; def result =' * @ author: '+ author +' \ n'; return result ;"), policyscript ("def returnType = \" $ {_ 1} \ "; def result = '* @ return:' + returnType + '\ n'; return result ;", methodReturnType (), policyscript ("def date = \" $ {_ 1} \ "; def time = \" $ {_ 2 }\"; def result = '* @ CreateDate:' + date + ''+ time + '\ n'; return result;", date ("yyyy-MM-dd E "), time ("HH: mm: ss"), policyscript ("def currentPackage = \" $ {_ 1} \ "; def result = '* @ Package: '+ currentPackage +' \ n'; return result; ", currentPackage (), policyscript (" def className = \ "$ {_ 1 }\"; def result = '* @ Class:' + className + '\ n'; return result; ", className (), policyscript (" 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 ;"), policyscript ("def result = '* @ Project: OA' + '\ n'; return result;"), policyscript ("def result =' * @ version: v1.0.0 '+' \ n'; return result; "), policyscript (" def jsMethodName = \ "$ {_ 1} \"; def result = '* @ Method: '+ jsMethodName +' \ n'; return result; ", jsMethodName (), policyscript (" def result = '* @ return:' + '\ n '; return result ;"))
Use:
Output in xx. java or xx. js (note 2 ):
/cmj
Press the tab key (this key is default and can be changed to another one)
Note 1 and Note 2
You can also use the second method (most of the methods on the Internet ):
Template text
* *$context$ */
Compared with Note 1, the first line is missing *,
Therefore, Note 2 is changed:
/*cmj
I feel better using my method than the second one.
Code details in Edit Variable
First, I break down the following 10 functions (small functions ):
// Output Method name policyscript ("def methodName = \" $ {_ 1} \ "; def result = '* @ Method:' + methodName + '\ n '; return result; ", methodName () // output Description yyscript (" def result = '* @ Description:' + '\ n'; return result ;") // The subfunction of the output parameter list policyscript ("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 () // output the author's sub-function. Here we can change the author's policyscript ("def author = 'rush. d. xzj '; def result =' * @ author: '+ author +' \ n'; return result ;") // subfunction policyscript ("def returnType = \" $ {_ 1} \ "; def result = '* @ return: '+ returnType +' \ n'; return result; ", methodReturnType () // name function of the output date, you can change the date format of policyscript ("def date = \" $ {_ 1} \ "; def time = \" $ {_ 2 }\"; def result = '* @ CreateDate:' + date + ''+ time + '\ n'; return result;", date ("yyyy-MM-dd E "), time ("HH: mm: ss") // output Project groovyScript ("def result = '* @ Project: OA' + '\ n'; return result; ") // output package policyscript (" def currentPackage = \ "$ {_ 1} \"; def result = '* @ Package:' + currentPackage + '\ n '; return result; ", currentPackage () // output class policyscript (" def className = \ "$ {_ 1} \"; def result = '* @ Class: '+ className +' \ n'; return result; ", className () // output copyright/reviewd/updatelog policyscript (" 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 ;") // output version policyscript ("def result = '* @ version: V1.0.0' + '\ n'; return result ;") // output jsMethodName policyscript ("def jsMethodName = \" $ {_ 1} \ "; def result = '* @ Method:' + jsMethodName + '\ n '; return result; ", jsMethodName () // output js return policyscript (" def result = '* @ return:' + '\ n'; return result ;")
Then, in the main code, the above 10 functions need to be used as parameters for the main code.
Judgment is a function and Class. js functions are implemented mainly through the following two built-in variables:
methodName()jsMethodName()
When methodName () is not empty, generate method comments
When jsMethodName () is not empty, the js method annotation is generated.
Otherwise, generate class comments.
Therefore, the above Code can be simply classified as follows:
Obtain 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 segment 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; }
This is enough. It's so ugly (groopscript ?) The code is clear.
I still have the following questions/problems to solve. If a friend can give me the answer, that would be fine.
Question 1. Do not know how to obtain the parameter list in the js method
Question 2. if I change it:
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;
The following error occurs:
startup failed:Script1.groovy: 1: expecting EOF, found 'result' @ line 1, column 1036. lt += outputClassOtherInfo; } result += ^1 error
Question 3: I don't know how to obtain the interface method corresponding to the Override method (parent method)
On the Problem 3: in fact to add a comment for this method is meaningless, specific can refer to: https://stackoverflow.com/questions/4310858/comments-on-overridden-method-in-java
However, if you have to add it, how can you determine it.
References:
Http://blog.sina.com.cn/s/blog_4c4195e70102wh7e.html
Https://stackoverflow.com/questions/4310858/comments-on-overridden-method-in-java