IDEA自定义liveTemplates(方法模板、类模板)
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(方法模板、类模板)的更多相关文章
- C++程序设计方法4:类模板
类模板 在定义类时也可以将一些类型抽象出来,用模板参数来替换,从而使类更具有通用性.这种类被称为模板类,例如: template <typename T> class A { T data ...
- C++ - 模板类模板成员函数(member function template)隐式处理(implicit)变化
模板类模板成员函数(member function template)隐式处理(implicit)变化 本文地址: http://blog.csdn.net/caroline_wendy/articl ...
- C++函数模板&类模板
函数模板 模板概念及语法 主要目的,简化代码,减少重复代码.基本语法格式: template<class T> 或者 template<typename T> //末尾不加分 ...
- C++ 函数模板&类模板详解
在 C++ 中,模板分为函数模板和类模板两种.函数模板是用于生成函数的,类模板则是用于生成类的. 函数模板&模板函数 类模板&模板类 必须区分概念 函数模板是模板,模板函数时 ...
- C++ 函数模板/类模板
#include <iostream> #include <vector> using namespace std; template < class T > // ...
- 函数模板&类模板
#include <iostream> #if 0//函数模板 template<typename T> T max(T a, T b, T c)//函数模板 { if (a ...
- 类模板、Stack的类模板实现(自定义链栈方式,自定义数组方式)
一.类模板 类模板:将类定义中的数据类型参数化 类模板实际上是函数模板的推广,可以用相同的类模板来组建任意类型的对象集合 (一).类模板的定义 template <类型形参表> clas ...
- C++类模板和模板类
C++ 中有一个重要特性,那就是模板类型.类似于Objective-C中的泛型.C++通过类模板来实现泛型支持. 1 基础的类模板 类模板,可以定义相同的操作,拥有不同数据类型的成员属性. 通常使用t ...
- 【C++】C++中的类模板
基础的类模板 模板类的继承 内部声明定义普通模板函数和友元模板函数 内部声明友元模板函数+外部定义友元模板函数 声明和定义分别在不同的文件(模板函数.模板友元) C++中有一个重要特性,那就是模板类型 ...
随机推荐
- Java学习笔记-基础语法Ⅶ-集合
集合 集合类特点:提供一种存储空间可变的存储模型,存储的数据容量可以随时发生改变 这里需要回顾一下,因为数组和字符串一旦创建,就不可改变,需要区分一下 import java.util.ArrayLi ...
- 力扣算法:125-验证回文串,131-分割回文串---js
LC 125-验证回文串 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 注:回文串是正着读和反着读都一样的字符串. ...
- Spring Boot 动态修改 log level
引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- Docker学习重点(7)~DockerFile
一.DockerFile DockerFile是用来构建docker镜像的文件,可以理解为命令参数脚本! 1.构建步骤: 编写一个dockerfile文件 docker build 构建成为一个镜像 ...
- Linux系统执行命令方法
现在我们无论是工作中还是学习中很多情况下用到Linux系统,当我们需要在C#代码中调用类似与cmd窗口执行命令时候,就需要用到此方法 public static Process CommitComma ...
- MySQL之事务隔离级别和MVCC
事务隔离级别 事务并发可能出现的问题 脏写 事务之间对增删改互相影响 脏读 事务之间读取其他未提交事务的数据 不可重复读 一个事务在多次执行一个select读到的数据前后不相同.因为被别的未提交事务修 ...
- Hive参数与性能企业级调优
Hive作为大数据平台举足轻重的框架,以其稳定性和简单易用性也成为当前构建企业级数据仓库时使用最多的框架之一. 但是如果我们只局限于会使用Hive,而不考虑性能问题,就难搭建出一个完美的数仓,所以Hi ...
- python发QQ邮件
python发qq邮件相对比较简单,网上教程一大把:固定套路,后面封装看自己怎么方便可以怎样进行封装:原版代码如下: """ # -*- coding : utf-8 - ...
- 【故障公告】取代 memcached 的 redis 出现问题造成网站故障
6月19日开始,我们将博客站点的缓存服务器从 memcached 换成了 redis,稳定运行了3天,今天上午访问高峰突然出现问题,在 11:00-12:30 期间影响了网站的正常访问,由此给您带来麻 ...
- Node.js精进(6)——文件
文件系统是一种用于向用户提供底层数据访问的机制,同时也是一套实现了数据的存储.分级组织.访问和获取等操作的抽象数据类型. Node.js 中的fs模块就是对文件系统的封装,整合了一套标准 POSIX ...