简体   繁体   中英

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:

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:

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, ...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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