Bug 206480 - Enable "Code Templates" syntax in templates of "Template Manager"
Enable "Code Templates" syntax in templates of "Template Manager"
Status: NEW
Product: platform
Classification: Unclassified
Component: Templates
7.1
PC All
: P3 with 3 votes (vote)
: TBD
Assigned To: Martin Entlicher
issues@platform
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-16 17:19 UTC by artisan
Modified: 2011-12-19 09:26 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo