简体   繁体   English

如何在NetBeans 7.1.1中为日志消息创建代码模板

[英]How can I create a code template in NetBeans 7.1.1 for a log message

How can I create a code template in NetBeans 7.1.1 for this: 如何在NetBeans 7.1.1中为此创建代码模板:

public static void someMethodName(String arg1, Integer arg2) {
    LOG.debug("someMethodName{}, {}", new Object[]{arg1, arg2});
...
}

Something like the following should work :) 像下面这样的东西应该工作:)

public static ${ret default="void"} ${mname default="someMethodName"}(${Type1 default="String"} ${var1 default="arg1"}, ${Type2 default="Integer"} ${var2 default="arg2"}) {
    LOG.debug("${mname}{}, {}", new Object[] {${var1}, ${var2}});
    ${cursor}
}

But you probably wanted to be able to specify the number of parameters. 但是您可能希望能够指定参数数量。 Unfortunately something like the following: 不幸的是,如下所示:

public static ${ret default="void"} ${mname default="someMethodName"}(${args default=""}) {
    LOG.debug("${mname}{}, {}", new Object[] {${args}});
    ${cursor}
}

would not work because it would include the type names also in the LOG line: 将不起作用,因为它还将在LOG行中包括类型名称:

public static void someMethodName(String arg1, int arg2) {
    LOG.debug("someMethodName{}, {}", new Object[]{String arg1, int arg2});

}

A workaround that comes to my mind is to use the first solution and provide different code templates for different number of method parameters (eg Psm1, Psm2, ...). 我想到的解决方法是使用第一种解决方案,并为不同数量的方法参数(例如Psm1,Psm2等)提供不同的代码模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM