Customizable Method Bodies in NetBeans IDE 7.3

Posted by Geertjan on Oracle Blogs See other posts from Oracle Blogs or by Geertjan
Published on Thu, 6 Dec 2012 18:37:56 +0000 Indexed on 2012/12/06 23:14 UTC
Read the original article Hit count: 145

Filed under:
In NetBeans IDE 7.3, bodies of newly created methods can now be customized in Tools/Templates/Java/Code Snippets, see below:

The content of the first of the two above, "Generated Method Body", is like this:

<#--
A built-in Freemarker template (see http://freemarker.sourceforge.net) used for
filling the body of methods generated by the IDE. When editing the template,
the following predefined variables, that will be then expanded into
the corresponding values, could be used together with Java expressions and
comments:
${method_return_type}       a return type of a created method
${default_return_value}     a value returned by the method by default
${method_name}              name of the created method
${class_name}               qualified name of the enclosing class
${simple_class_name}        simple name of the enclosing class
-->
throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

The second one, "Overriden Methody Body", is as follows:

<#--
A built-in Freemarker template (see http://freemarker.sourceforge.net) used for
filling the body of overridden methods generated by the IDE. When editing
the template, the following predefined variables, that will be then expanded
into the corresponding values, could be used together with Java expressions and
comments:
${super_method_call}        a super method call
${method_return_type}       a return type of a created method
${default_return_value}     a value returned by the method by default
${method_name}              name of the created method
${class_name}               qualified name of the enclosing class
${simple_class_name}        simple name of the enclosing class
-->
<#if method_return_type?? && method_return_type != "void">
return ${super_method_call}; //To change body of generated methods, choose Tools | Templates.
<#else>
${super_method_call}; //To change body of generated methods, choose Tools | Templates.
</#if>

© Oracle Blogs or respective owner

Related posts about /NetBeans IDE