'Twas blind but...
Where in Eclipse do I do I add a Template Variable?
I was thinking of adding a few template variables, aka those
things that have ${...} that result in dynamic substitution when
Java code is generated. I was thinking of starting out with baby steps
and something fixed like ${author} or maybe ${copyright} so that
I can use them in code generation.
Window | Java | Code Generation
Several places in the docs discuss:
"You can insert your own template variables, which then evaluate to the name of
the variable itself. You must, however, make sure that the name does not
conflict with the pre-defined template variable names in the specific context."
-- Java Development Users Guide On-line Help: Writing your own templates
http://127.0.0.1:1574/help/index.jsp?tab=links&contextId=org.eclipse.jdt.ui.edit
_template_dialog_context&topic=%2Forg.eclipse.jdt.doc.user%2Fconcepts%2Fctemplat
es.htm
I thought
Window | Java | Editor | Templates
might eventually lead me to something, but New | insert variable just gives me
the current list.
Where is it?
Is this a PDE Function?
-Paul
Hello Paul,
<snip>
>those things that have ${...} that result in dynamic substitution when
>Java code is generated
<snip>
I don't think that this could be possible, because some of the predefined
Variables have some
action behind them, like searching for an array, so I think they are defined
somewhere in the Source Code.
> "You can insert your own template variables, which then evaluate to the name of
> the variable itself.
<snip>
I think you didn't get that right.
They wrote: "evaluate to the name of the variable itself" and that's exactly
what is meant.
1. Try defining a template in "preferences->java->editor->templates" with
name "TempTest"
2. write somewhere in this Template: ${MyTestVariable}
3. open a Java-Editor
4. Type in: "TempTest" and press Ctrl-Space.
In the Source-Code now ${MyTestVariable} is replaces with "MyTestVariable".
That's neither nice nor smothe, but it's exactly
what the help is saying.
Now you are asking: Why then define an Template Variable?
Because when the same Variable appears more than once and you overwrite the
Variable right after pressing Ctrl-Space,
all occurences are replaced at the same time.
For more infos, look into the Eclipse-Help:
Getting Started->Basic tutorial->Editing Java Elements->Using source code
templates
Alex