IDEA File Template 中类名转换为常量的蛇形命名

167 阅读1分钟

背景

如题,这几天遇到文件模板中希望只输入一个类名,然后自动对应到其蛇形命名的状态。由于对 Velocity 不熟悉,还真是左找右找。

解决方案

终于在JetBrains官网找到了:How to use Live Templates functions in File Templates?

#set( $regex = "([a-z])([A-Z]+)")
#set( $replacement = "$1_$2")
#set( $toSnake = $NAME.replaceAll($regex, $replacement).toUpperCase())
#set( $toLower = $NAME.toLowerCase())

拓展阅读