-- Templates & Default Class Name --

Lo there.

I was trying to write a template so that I could append a literal

to the end of the class name. However, every time I create a

new class from the template the class name is as specified in

the wizard and it acts like I didn't even set up the appending

literal.

Here's a snippet of what I put in the template:

public class __NAME__Form extends ActionForm {

Imagine I'd called my class 'Grinning' in the template wizard....

I was expecting to get:

public class GrinningForm extends ActionForm {

Alas, Netbeans ends up giving me:

public class Grinning extends ActionForm {

Is it possible to achieve what I want?

Cheers.

(e)

[747 byte] By [Evans,Andy] at [2007-11-25 16:47:27]
# 1

Andy Evans wrote:

> I was trying to write a template so that I could append a literal

> to the end of the class name. However, every time I create a

> new class from the template the class name is as specified in

> the wizard and it acts like I didn't even set up the appending

> literal.

>

> public class __NAME__Form extends ActionForm {

>

> Imagine I'd called my class 'Grinning' in the template wizard....

> I was expecting to get:

>

> public class GrinningForm extends ActionForm {

>

> Alas, Netbeans ends up giving me:

>

> public class Grinning extends ActionForm {

Actually it first substitutes to GrinningForm, then the Java parser

notices that the outer class name does not match the file name, and

automatically corrects it for you. It is illegal to have

public class GrinningForm

as the outermost class in a file named Grinning.java.

Maybe you need to rethink what you want to do. If you really want to

make GrinningForm.java when the user types "Grinning" in the Name field,

I think this is possible using a .group file:

%< Templates/Classes/SomethingHere.group

Templates/Classes/__SomethingElseHere__Form.java

%< Templates/Classes/__SomethingElseHere__Form.java

package Templates.Classes;

// note: package, class name, & constructor names automatic!

public class __SomethingElseHere__Form extends ActionForm {

public __SomethingElseHere__Form() {}

// etc.

// to get access to e.g. GrinningForm use: __NAME__

// for e.g. Grinning use: __NAME$Form$$UnknownPrefix__

}

%<

where Templates/Classes/SomethingHere.group is marked Template = True

but Templates/Classes/__SomethingElseHere__Form.java is not. Select File

| New | Templates | Classes | SomethingHere, type "Grinning" as the

name, and you should get GrinningForm.java:

package whatever.you.selected;

public class GrinningForm extends ActionForm {

public GrinningForm() {}

// etc.

}

It is possible to set this all up using the Options window, or you can

directly edit $userdir/system/ subdirectories.

-Jesse

--

Jesse Glick <mailto:jesse.glick@sun.com> x22801

NetBeans, Open APIs <http://www.netbeans.org/>

Glick,Jesse at 2007-7-2 23:27:25 > top of Java-index,Archived Forums,Sun ONE Studio 4...