Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans Code Templates Formatting syntax

I'd like to know what's the syntax or the language used to format the code templates in netbeans ide. I mean, in the default templates I can see things like;

while (${EXP default="exp"})
{ 
   ${selection line}${cursor} 
}

And:

// <editor-fold defaultstate="collapsed" desc="${comment}">
${selection}${cursor}// </editor-fold>

And I experimented and did this:

int ${IDX newVarName default="loop"};

for (${IDX} = 0; ${IDX} < ${SIZE int default="size"}; ${IDX}++)
{
   ${cursor}
}

And it works but I don't really know where the "${IDX}" or the "${SIZE int default="size"}" or the "${selection}${cursor}" comes from and what other statements can I use to format my templates.

Is this some scripting or programming language?

Where can I find this information?

like image 971
m4l490n Avatar asked Nov 10 '12 19:11

m4l490n


People also ask

How can I get beautify code in NetBeans?

To format all the code in NetBeans, press Alt + Shift + F. If you want to indent lines, select the lines and press Alt + Shift + right arrow key, and to unindent, press Alt + Shift + left arrow key.

How do I change indentation in NetBeans?

Choose Tools | Options. Click Editor in the left panel and select the Indentation tab. Adjust the properties for the indentation engine to your taste. Reformat each file to the new rules by opening the file and pressing CtrlShift-F (with no text selected).

How change generated code in NetBeans?

You can't by directly editing the code. Netbeans uses a seperate file for code generation (. form, XML). This is a one-way process, Netbeans is not capable of parsing source code for editing in it's visual editor...

How many code templates does NetBeans provide?

Click Next and then click Finish. You now have two code templates. The first will be shown when "snf" is typed, followed by the expansion key, while the second requires "pe" to be typed, prior to the expansion key being pressed.


2 Answers

I think Netbeans uses the template engine Freemarker for this. So all variables (= ${...}) are filled in by Netbeans at the time you use the template.

Unfortunately I don't have a full list of all default variables / methods you can use, but here are two of them listed:

${cursor}:

defines a position where the caret will be located after the editing of the code template values finishes.

${selection}:

defines a position for pasting the content of the editor selection. This is used by so-called 'selection templates' that appear as hints whenever the user selects some text in the editor.

See here: http://wiki.netbeans.org/Java_EditorUsersGuide#How_to_use_Code_Templates

${IDX} looks like a custom variable you use.

See also:
- Code Assistance in the NetBeans IDE Java Editor: A Reference Guide (Code Template)
- Code Templates in NetBeans IDE for PHP

like image 116
ollo Avatar answered Oct 07 '22 13:10

ollo


How_to_use_Code_Templates pretty much covers everything there is. Looking at CodeTemplateParameter.java shows there is another hint called "completionInvoke" which requests showing of the code completion popup for the currently focused text component, but that is all.

like image 23
Slacker_CA Avatar answered Oct 07 '22 12:10

Slacker_CA