This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 206480

Summary: Enable "Code Templates" syntax in templates of "Template Manager"
Product: platform Reporter: artisan <artisan>
Component: TemplatesAssignee: Martin Entlicher <mentlicher>
Status: NEW ---    
Severity: normal CC: artisan, bichoflyer, markiewb
Priority: P3    
Version: 7.1   
Hardware: PC   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description artisan 2011-12-16 17:19:41 UTC
=============
Clarification
=============
"Code Templates" syntax: These are the templates one can define in the editor settings: "Options > Editor > Code" Templates. For example:

while (${expr instanceof="boolean" default="true"}) {
  ${cursor}
}

Invoked by the template acronym + TAB. The above statement will be generated, the user can enter the ${...} expression and finally the cursor is set to the location of ${cursor}.

VS.

Templates of "Template Manager": The templates which can be defined in "Tools > Templates". For example the template "Java/Java Class" :

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>
/**
 *
 * @author ${user}
 */
public class ${name} {

}

With this template you right-click, select new "Java Class", a wizard appears to prompt for the class name, folder, etc... and finally the Java class file is generated according to the template.

===================
Enhancement request
===================

The request is about merging the two template systems together. For example I might have a well-established coding convention for certain types of classes. Which I'd rather not retype all over again. And that I can share with the other developers:

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>

import foo.MyParser;
import foo.Parser;
import foo.Bar;

/**
 * ${comments}
 * 
 * @author ${user}
 */
@MyParser( version = ${version} )
public class ${name} extends Parser<${expr instanceof="Bar"}> {

  public void init( final ${expr instanceof="Bar"} bar ) {
  }

  public ${expr instanceof="Bar"} parse() {
  }
}

In this specific case ${name} and ${user} will be resolved. But the undefined variables won't. And neither will NetBeans prompt for filling-in the unresolved variables.

What I'd like to see is that once the Java class has been generated, the remaining markup is resolved as though there were added with Code Templates.

So in this case the editor will prompt me to fill in ${comments}, ${version} and 
${expr instanceof="Bar"} which must resolve to a class/interface which extends/implements Bar. 

==========
Workaround
==========

Create a new Module project and build a wizard to prompt the user for the unresolved values.

=================================
Justification to do otherwise :-)
=================================
* A template-only solution means there's no coding whatsoever involved. With all its advantages.

* Making a Netbeans module requires the knowledge of the Netbeans platform API. The template-only approach has almost no prerequisite.

* Making and maintaining a wizard in a Netbeans Module is by no means as fast and flexible as a template-only approach. Each change would involve modifying the module project, testing, deploying, ... While templates are immediately updateable and usable.

* Templates are independent of Netbeans. While the modules are versioned. With all its implications when upgrading.

* Allows a coding convention and avoids typing boilerplate.

* The base technology is already there: Freemarker.
Comment 1 Martin Entlicher 2016-08-25 10:03:52 UTC
Please do not change the version field, it's the oldest NetBeans version for which the issue was filed.