如何在Netbeans代码模板中获取当前的类名? [英] How to get current class name in Netbeans code template?
本文介绍了如何在Netbeans代码模板中获取当前的类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为Netbeans中的记录器编写代码模板:
I want to write code template for logger in Netbeans:
org.slf4j.LoggerFactory.getLogger(XXXXXX.class).warn("${cursor}");
I can't find syntax to insert current class name into template (see XXXXXX placeholder above) in reference.
推荐答案
我创建了以下代码模板:
I have created the following code template:
private static final ${LOGGER_TYPE type="org.slf4j.Logger" default="Logger" editable=false} LOGGER = ${LOGGER_FACTORY type="org.slf4j.LoggerFactory" default="LoggerFactory" editable=false}.getLogger(${CLASS editable="false" currClassName}.class);
,并且我已将其与缩写log
关联.
and I have associated it to the abbreviation log
.
所以在光标处:
...
public class MyClass {
|
...
我键入log
+ TAB ,然后NetBeans展开文本:
I type log
+ TAB and NetBeans expands the text:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
public class MyClass {
private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
...
我也有:
-
logd
+ TAB -
logw
+ TAB -
logi
+ TAB -
loge
+ TAB
logd
+ TABlogw
+ TABlogi
+ TABloge
+ TAB
编码为:
${LOGGER_CONST default="LOGGER" editable=false}.debug("${logMessage}");
${LOGGER_CONST default="LOGGER" editable=false}.warn("${logMessage}");
${LOGGER_CONST default="LOGGER" editable=false}.info("${logMessage}");
${LOGGER_CONST default="LOGGER" editable=false}.error("${logMessage}", ex);
会生成:
LOGGER.debug("logMessage");
LOGGER.warn("logMessage");
LOGGER.info("logMessage");
LOGGER.error("logMessage", ex);
这篇关于如何在Netbeans代码模板中获取当前的类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文