java Intellij 实时模板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6097646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:19:20  来源:igfitidea点击:

Intellij Live Template

javaintellij-idealive-templates

提问by Leonid

Is there any way to use a default token value in Intellij Live templates? For example I have the following live template which declares a private variable that I would like to create nearly for every class:

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

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

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

It seems unnecessary to type $CLASS$every time when this live template is used, because it can be derived from the class in scope or filename. I was wondering if it is possible to use environment defined tokens in live templates as defaults?

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

回答by CrazyCoder

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

检查其他一些已经使用当前类名的模板:

enter image description here

在此处输入图片说明

回答by Nowaker

log4j:

日志4j:

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

slf4j:

slf4j:

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

Make sure that you set the applicable contextto Java and that shorten FQ namesand skip if definedare enabled.

确保将适用的上下文设置为 Java 并缩短 FQ 名称并启用已定义的跳过

回答by bruno.do.amaral

log4j 2:

log4j 2:

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