IDEA自定义liveTemplates(方法模板、类模板)

前言,搞这个模板有何意义? 降低大家写方法注释的成本,统一风格。有时候不是开发同学不爱写注释,而是没有合适的载体和空间。

IDEA模板设置入口

模板设置入口: Preferences | Editor | Live Templates

一、方法注释快速生成设置

第一步

点击号,增加模板,并设置快捷键为'ff',作用域为Java文件

模板内容

/**
* $description$
$params$
* @return {@link $retrun$}
* @author $author$
* @date $date$
*
*/

第二步 配置变量

点击EDIT VARIABLES有弹框

对几个$$的变量进行配置,如\(description\)

其中params特别注意,要配置groovy脚本,才能自动识别方法参数,如下

groovyScript("def result = ''; def params = \"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();  for (i = 0; i < params.size(); i++) {      if (i == 0) {         if (1 == params.size()) {             result += ' * @param ' + params.getAt(i) + ' description '         } else {             result += ' * @param ' + params.getAt(i) + ' description \\n\\b'         }     } else {         result += '    * @param ' + params.getAt(i) + ((i < params.size() - 1) ? ' description \\n\\b' : ' description ')     } }; return result ", methodParameters())

第三步 使用

随意点击某个方法

例如

    public String main(String[] args, String aaa) {
在此处键入ff后,按tab键,即可生成模板注释,将模板注释复制到方法上,格式化即可
return "";
}

结果

    /**
* main
*
* @param args description
* @param aaa description
* @return {@link String}
* @author starkhu
* @date 2021/6/23
*/
public String main(String[] args, String aaa) { return "";
}

其他常用模板

todo的模板,带有生成todo的责任人和时间

// TODO: (所属人:$author$ $date$ $time$) description

常用函数

currentPackage()

Returns the name of the current package (with the class where you expanded the template).

date([format])

Returns the current system date.

By default, without a parameter, it returns the date in the current system format. To use a different format, provide a parameter according to the SimpleDateFormat specification. For example, the date("Y-MM-d, E, H:m") returns the date formatted as 2020-02-27, Thu, 16:11.

fileName()

Returns the name of the current file with its extension.

fileNameWithoutExtension()

Returns the name of the current file without its extension.

filePath()

Returns the absolute path to the current file.

fileRelativePath()

Returns the current file path relative to the current project. To check what the relative path is for a given file, right-click it and select Copy Reference, or press ⌥ ⇧ ⌘ C.

groovyScript(, [arg, ...])

Executes the Groovy script passed as a string.

The first argument is a string with either the text of the script or the path to the file that contains the script. The function passes other optional arguments to the script as values for _1, _2, _3, ..., _n variables. Also, you can access the current editor from inside the script using the _editor variable.

methodName()

Returns the name of the method in which the template expands.

methodParameterTypes()

Returns the list of parameter types of the method in which the template expands.

methodParameters()

Returns the list of parameter names of the method in which the template expands.

methodReturnType()

Returns the type of the value returned by the current method in which the template expands.

qualifiedClassName()

Returns the fully qualified name of the current class in which the template expands.

user()

Returns the name of the current user.

团队中,导出/导入自定义liveTemplate

导出Export live template configuration

点击 File | Manage IDE Settings | Export Settings from the menu.

导入Import live template configuration

点击 File | Manage IDE Settings | Import Settings from the menu.

IDEA自定义liveTemplates(方法模板、类模板)的更多相关文章

  1. C++程序设计方法4:类模板

    类模板 在定义类时也可以将一些类型抽象出来,用模板参数来替换,从而使类更具有通用性.这种类被称为模板类,例如: template <typename T> class A { T data ...

  2. C++ - 模板类模板成员函数(member function template)隐式处理(implicit)变化

    模板类模板成员函数(member function template)隐式处理(implicit)变化 本文地址: http://blog.csdn.net/caroline_wendy/articl ...

  3. C++函数模板&类模板

    函数模板 模板概念及语法 主要目的,简化代码,减少重复代码.基本语法格式:  template<class T> 或者 template<typename T> //末尾不加分 ...

  4. C++ 函数模板&类模板详解

    在 C++ 中,模板分为函数模板和类模板两种.函数模板是用于生成函数的,类模板则是用于生成类的. 函数模板&模板函数     类模板&模板类  必须区分概念 函数模板是模板,模板函数时 ...

  5. C++ 函数模板/类模板

    #include <iostream> #include <vector> using namespace std; template < class T > // ...

  6. 函数模板&类模板

    #include <iostream> #if 0//函数模板 template<typename T> T max(T a, T b, T c)//函数模板 { if (a ...

  7. 类模板、Stack的类模板实现(自定义链栈方式,自定义数组方式)

    一.类模板 类模板:将类定义中的数据类型参数化 类模板实际上是函数模板的推广,可以用相同的类模板来组建任意类型的对象集合 (一).类模板的定义 template  <类型形参表> clas ...

  8. C++类模板和模板类

    C++ 中有一个重要特性,那就是模板类型.类似于Objective-C中的泛型.C++通过类模板来实现泛型支持. 1 基础的类模板 类模板,可以定义相同的操作,拥有不同数据类型的成员属性. 通常使用t ...

  9. 【C++】C++中的类模板

    基础的类模板 模板类的继承 内部声明定义普通模板函数和友元模板函数 内部声明友元模板函数+外部定义友元模板函数 声明和定义分别在不同的文件(模板函数.模板友元) C++中有一个重要特性,那就是模板类型 ...

随机推荐

  1. Python 什么是flask框架?快速入门

    一:Python flask框架 前言 1.Python 面向对象的高级编程语言,以其语法简单.免费开源.免编译扩展性高,同时也可以嵌入到C/C++程序和丰富的第三方库,Python运用到大数据分析. ...

  2. linux篇-linux修改网卡名(亲测有效)

    1查看网卡ip addr 2cd /etc/sysconfig/network-scripts Ls查看 3mv ifcfg-eno16777736 ifcfg-eth0重命名,然后编辑 最后一行加入 ...

  3. 深度学习可视化工具--tensorboard的使用

    tensorboard的使用 官方文档 # writer.add_scalar() # 添加标量 """ Args: tag (string): Data identif ...

  4. vue大型电商项目尚品汇(前台篇)day05

    紧急更新第二弹,然后就剩下最后一弹,也就是整个前台的项目 一.购物车 1.加入购物车(新知识点) 加入到购物车是需要接口操作的,因为我们需要将用户的加入到购物车的保存到服务器数据库,你的账号后面才会在 ...

  5. python常用标准库(os系统模块、shutil文件操作模块)

    常用的标准库 系统模块 import os 系统模块用于对系统进行操作. 常用方法 os模块的常用方法有数十种之多,本文中只选出最常用的几种,其余的还有权限操作.文件的删除创建等详细资料可以参考官方文 ...

  6. CSP J/S 初赛总结

    CSP J/S 初赛总结 2021/9/19 19:29 用官方答案估计 J 涂卡的时候唯一的一支 2B 铅笔坏了,只能用笔芯一个个涂 选择 \(-6\ pts\) 判断 \(-3\ pts\) 回答 ...

  7. vscode远程调试c++

    0.背景 最近在学习linux webserver开发,需要在linux下调试自己的C/C++代码,但是linux下不像在windows下,直接Visio Studio或者其它集成开发环境那么方便,现 ...

  8. 【python基础】第08回 流程控制 for循环

    本章内容概要 1.循环结构之 for 循环 本章内容详解 1.循环结构之for循环 1.1 语法结构 for 变量名 in 可迭代对象: #字符串 列表 字典 元组 for 循环的循环体代码 针对变量 ...

  9. mysql密码忘记了重置方法

    #先把mysql停止 service mysqld stop #安全模式进入mysql,并且跳过授权表 mysqld_safe --skip-grant-tables & #如果上面这个命令报 ...

  10. Java TIF、JPG、PNG等图片转换

    代码如下: public static void main(String[] args) { try { BufferedImage bufferegImage = ImageIO.read(new ...