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?
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.
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).
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...
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With