最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談idea live template高級(jí)知識(shí)_進(jìn)階(給方法,類,js方法添加注釋)

 更新時(shí)間:2017年06月13日 08:56:55   投稿:jingxian  
下面小編就為大家?guī)硪黄獪\談idea live template高級(jí)知識(shí)_進(jìn)階(給方法,類,js方法添加注釋)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

為了解決用一個(gè)命令(宏)給方法,類,js方法添加注釋,經(jīng)過幾天的研究.終于得到結(jié)果了。

實(shí)現(xiàn)的效果如下:

給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) {
}

現(xiàn)在把答案公布如下

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鍵(此鍵是默認(rèn)的,可以更改成其他的)

注1 和注2

也可以換成第二種方法(網(wǎng)上大部分的方法):

Template text

*
 *$context$ 
 */

跟注1比較第一行少了一個(gè)*,

因此注2就是變成了:

/*cmj

我感覺用我的方法比第二種方法好。

Edit Variable中代碼詳解

首先我分解了如下的 10幾個(gè)函數(shù)(是小函數(shù)):

// 輸出方法名
  groovyScript("def methodName = \"${_1}\"; def result = ' * @Method : ' + methodName + '\\n'; return result;", methodName())
  
  // 輸出描述
  groovyScript("def result = ' * @Description : ' + '\\n'; return result;")
  
  // 輸出參數(shù)列表的子函數(shù)
  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())
  
  // 輸出  作者的    子函數(shù) 這里可以改作者
  groovyScript("def author = 'Rush.D.Xzj'; def result = ' * @author : ' + author + '\\n'; return result;")
  
  // 輸出  返回值的  子函數(shù)
  groovyScript("def returnType = \"${_1}\"; def result = ' * @return : ' + returnType + '\\n'; return result;", methodReturnType())
  
  // 輸出  日期的   字函數(shù), 這個(gè)可以更改日期格式
  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幾個(gè)函數(shù)當(dāng)做參數(shù)供給主要代碼使用.

判斷是函數(shù),類,js函數(shù)主要是通過如下的2個(gè)內(nèi)置變量來實(shí)現(xiàn)的;

methodName()
jsMethodName()

當(dāng)methodName()不為空的時(shí)候, 生成 方法的 注釋

當(dāng)jsMethodName()不為空的時(shí)候, 生成 js方法的注釋

否則生成類的注釋

所以上述的代碼可以簡(jiǎn)單的做如下的歸類了:

獲取相關(guān)參數(shù):

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;
  }

這下就可以了.就把整個(gè)這么難看(groopscript搞的?)代碼整理的比較清晰了.

我還有如下的幾個(gè)疑惑/問題需要解決, 如果有朋友能給我答案那就好了.

問題1. 不知道可以通過什么方法獲取js方法中的參數(shù)列表

問題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;

會(huì)出現(xiàn)如下的錯(cuò)誤:

startup failed:
Script1.groovy: 1: expecting EOF, found 'result' @ line 1, column 1036.
  lt += outputClassOtherInfo; } result += 
                 ^
error

問題3:不知道怎么獲取Override方法對(duì)應(yīng)的接口方法(父類方法)

關(guān)于問題3: 實(shí)際上給這種方法加注釋是沒有意義的,具體可以參考: https://stackoverflow.com/questions/4310858/comments-on-overridden-method-in-java

但是如果非要加該怎么去判斷.

以上這篇淺談idea live template高級(jí)知識(shí)_進(jìn)階(給方法,類,js方法添加注釋)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot JPA實(shí)現(xiàn)增刪改查、分頁(yè)、排序、事務(wù)操作等功能示例

    SpringBoot JPA實(shí)現(xiàn)增刪改查、分頁(yè)、排序、事務(wù)操作等功能示例

    本篇文章主要介紹了SpringBoot JPA實(shí)現(xiàn)增刪改查、分頁(yè)、排序、事務(wù)操作等功能示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • Java多線程編程之Lock用法實(shí)例

    Java多線程編程之Lock用法實(shí)例

    這篇文章主要介紹了Java多線程編程之Lock用法實(shí)例,本文直接給出代碼實(shí)例,需要的朋友可以參考下
    2015-05-05
  • Elasticsearch外部詞庫(kù)文件更新及使用

    Elasticsearch外部詞庫(kù)文件更新及使用

    這篇文章主要為大家介紹了Elasticsearch外部詞庫(kù)文件更新及使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-11-11
  • Java批量操作文件系統(tǒng)的實(shí)現(xiàn)示例

    Java批量操作文件系統(tǒng)的實(shí)現(xiàn)示例

    文件上傳和下載是java web中常見的操作,本文主要介紹了Java批量操作文件系統(tǒng)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-03-03
  • 新手學(xué)習(xí)java反射基礎(chǔ)

    新手學(xué)習(xí)java反射基礎(chǔ)

    Java反射就是在運(yùn)行狀態(tài)中,對(duì)于任意一個(gè)類,都能夠知道這個(gè)類的所有屬性和方法;對(duì)于任意一個(gè)對(duì)象,都能夠調(diào)用它的任意方法和屬性;并且能改變它的屬性。下面我們來一起學(xué)習(xí)一下吧
    2019-06-06
  • java中url任意跳轉(zhuǎn)漏洞的解決

    java中url任意跳轉(zhuǎn)漏洞的解決

    URL任意跳轉(zhuǎn)漏洞是一種安全漏洞,它發(fā)生在應(yīng)用程序沒有正確地驗(yàn)證目標(biāo)URL,允許攻擊者將用戶重定向到惡意網(wǎng)站,本文就來介紹一下漏洞的解決修復(fù)方案,感興趣的可以了解一下
    2024-06-06
  • 這么設(shè)置IDEA中的Maven,再也不用擔(dān)心依賴下載失敗了

    這么設(shè)置IDEA中的Maven,再也不用擔(dān)心依賴下載失敗了

    今天給大家?guī)硪粋€(gè)IDEA中Maven設(shè)置的小技巧.這個(gè)技巧可以說非常有用,學(xué)會(huì)設(shè)置之后,再也不用擔(dān)心maven依賴下載變慢的問題,需要的朋友可以參考下
    2021-05-05
  • SpringBoot下載文件的實(shí)現(xiàn)及速度對(duì)比

    SpringBoot下載文件的實(shí)現(xiàn)及速度對(duì)比

    這篇文章主要介紹了SpringBoot下載文件的實(shí)現(xiàn)及速度對(duì)比,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • 告訴你springboot各個(gè)文件夾的作用

    告訴你springboot各個(gè)文件夾的作用

    這篇文章主要介紹了springboot各個(gè)文件夾是干嘛的,本文通過截圖實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • 詳談鎖和監(jiān)視器之間的區(qū)別_Java并發(fā)

    詳談鎖和監(jiān)視器之間的區(qū)別_Java并發(fā)

    下面小編就為大家?guī)硪黄斦勬i和監(jiān)視器之間的區(qū)別_Java并發(fā)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06

最新評(píng)論

陇西县| 万宁市| 红桥区| 大连市| 深水埗区| 西丰县| 平安县| 体育| 建瓯市| 河西区| 丹东市| 彰武县| 长岭县| 定南县| 图们市| 漳州市| 防城港市| 衡阳市| 商河县| 尼玛县| 博湖县| 宾阳县| 获嘉县| 长汀县| 遵化市| 赫章县| 息烽县| 瑞昌市| 伊宁市| 夏邑县| 霍林郭勒市| 寿阳县| 安岳县| 石台县| 永寿县| 万州区| 监利县| 隆德县| 宁陵县| 承德市| 郧西县|