Postfix Completion 的介绍
IDEA除了 Live Templates 模板之外还有一个比较好用的代码模板叫Postfix Completion环绕模板
效果
配置路径: Editor > General > Postfix Completion
下图选中的 ‘ifIsEmpty’ 是我自定义配置的点击编辑如后
Key
: 定义的简称,通过该简称生成指定代码
Applicable expression types
: 适用的表达式类型(上图的表达式在使用Collection接口的实现类中可用)
apply to the topmost expression
: 应用于最上面的表达式(具体的代码模板)
1. 生成Collection空判断
采用
org.springframework.util.CollectionUtils
工具类
key: ifIsEmpty
Applicable expression types:
- java.util.Collection
apply to the topmost expression
if (CollectionUtils.isEmpty($EXPR$)) {
$END$
}
2. 生成CharSequence空判断
采用
org.springframework.util.StringUtils
工具类
key: ifHashText
Applicable expression types:
- java.util.CharSequence
apply to the topmost expression
if (StringUtils.hasText($EXPR$)) {
$END$
}