Intellij 现场模板

在 IntellijLive templates中有没有使用默认令牌值的方法?例如,我有以下活动模板,它声明了一个私有变量,我想创建几乎每个类:

private static final Logger logger = Logger.getLogger($CLASS$.class)

每次使用这个活动模板时,似乎没有必要键入 $CLASS$,因为它可以从作用域或文件名中的类派生出来。我想知道是否可以在活动模板中使用环境定义的令牌作为默认值?

20348 次浏览

Check some other templates that already use the current class name:

enter image description here

log4j:

private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger($CLASS_NAME$.class);

slf4j:

private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);

Make sure that you set the applicable context to Java and that shorten FQ names and skip if defined are enabled.

log4j 2:

private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger($CLASS_NAME$.class);