Netbeans Code Templates Formatting syntax
Asked Answered
C

2

8

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?

Connieconniption answered 10/11, 2012 at 19:2 Comment(0)
I
9

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

Inna answered 11/11, 2012 at 17:47 Comment(0)
F
3

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.

Fourthclass answered 16/12, 2012 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.