idea live template高級知識, 進階
为了解决用一个命令(宏)给方法,类,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中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

百度高級搜尋怎麼用百度搜尋引擎是目前中國最常用的搜尋引擎之一,它提供了豐富的搜尋功能,其中之一就是進階搜尋。進階搜尋可以幫助使用者更精確地搜尋到所需的信息,提高搜尋效率。那麼,百度高級搜尋要怎麼使用呢?第一步,打開百度搜尋引擎首頁。首先,我們需要開啟一個百度的官方網站,也就是www.baidu.com。這是百度搜索的入口。第二步,點選進階搜尋按鈕。在百度搜尋框的右側,有

IDEA(IntelliJIDEA)是一款強大的整合開發環境,可協助開發人員快速且有效率地開發各種Java應用程式。在Java專案開發中,使用Maven作為專案管理工具能夠幫助我們更好地管理依賴函式庫、建置專案等。本文將詳細介紹如何在IDEA中建立一個Maven專案的基本步驟,同時提供具體的程式碼範例。步驟一:開啟IDEA並建立新專案開啟IntelliJIDEA

JavaScript教學:如何取得HTTP狀態碼,需要具體程式碼範例前言:在Web開發中,經常會涉及到與伺服器進行資料互動的場景。在與伺服器進行通訊時,我們經常需要取得傳回的HTTP狀態碼來判斷操作是否成功,並根據不同的狀態碼來進行對應的處理。本篇文章將教你如何使用JavaScript來取得HTTP狀態碼,並提供一些實用的程式碼範例。使用XMLHttpRequest

設定步驟:1、開啟IntelliJ IDEA並進入專案;2、點選頂部選單中「Run」;3、選擇左上角的加號並選擇「Tomcat Server」 > 「Local」;4、在「Server」選項中,點擊“Configure” 並選擇Tomcat的安裝目錄;5、在“Deployment” 選項中,點擊加號添加你的項目;6、在“Before launch” 中操作保存即可

本文將引導您修正0x87dd0019Xbox登入錯誤,錯誤會在您嘗試連線到XboxLive或登入XboxOne時出現連線逾時問題。 Xbox上的錯誤碼0x87e00019是什麼?在Xbox主機上安裝或更新遊戲時,如果你遇到錯誤代碼0x87e00019,這表示你的Xbox硬碟可能已經儲存空間不足或接近滿。為了解決這個問題,你需要釋放一些儲存空間。同時,也應該檢查XboxLive服務的狀態,因為這個錯誤可能是由於Xbox伺服器問題導致的。如何修復0x87dd0019Xbox登入錯誤使用這些建

JavaScript中的HTTP狀態碼取得方法簡介:在進行前端開發中,我們常常需要處理與後端介面的交互,而HTTP狀態碼就是其中非常重要的一部分。了解並取得HTTP狀態碼有助於我們更好地處理介面傳回的資料。本文將介紹使用JavaScript取得HTTP狀態碼的方法,並提供具體程式碼範例。一、什麼是HTTP狀態碼HTTP狀態碼是指當瀏覽器向伺服器發起請求時,服務

配置方法:1、開啟IntelliJ IDEA,在工具列中下拉選單選擇「Edit Configurations」;2、進入新的窗口,點選「+」號,進入下拉式選單,然後選擇「Tomcat Server」中的「Local」; 3.在新的介面中,選擇Tomcat的安裝目錄,選好目錄後,點選「OK」;4、設定啟動Tomcat的瀏覽器即可。

idea建立一個maven專案的步驟:1、開啟IntelliJ IDEA,點擊“Create New Project”;2、在左側的清單中選擇“Maven”,然後在右側選擇安裝的JDK版本,如果沒有安裝JDK,IDEA會提示安裝;3、在「GroupId」欄位中輸入項目的組織唯一識別符,通常是公司或組織的反向域名,在「ArtifactId」欄位中輸入項目的名稱等等。
