How do I update an Eclipse template variable on the fly?
Asked Answered
U

1

2

I've added the following new Eclipse template via extension point. It simply adds a template for a sample testTag tag.

<!-- Add code template -->
<extension point="org.eclipse.ui.editors.templates">
   <template autoinsert="true"
             contextTypeId="html_tag"
             description="[Description] Template populated by Snippet values ***"
             id="org.eclipse.jst.jsf.ui.newHtmltag"
             name="testTag">
       <pattern>
            <![CDATA[
                <testTag style="background: ${color}"></testTag> 
            ]]>
       </pattern>
   </template>
  <resolver
     contextTypeId="html_tag"
     type="src" 
     class="TestTagTemplateVariableResolver">
  </resolver>
</extension>

What I'd cannot figure out is how to change the value of the $(color) variable at runtime. More specifically, when the user presses Ctrl + Space (or the equivalent for content-assist) and types in "testTag" and presses Enter -- instead of the "color" placeholder text, I'd like it replaced by some other text value I have in another class. How do I do this?

Utgardloki answered 2/2, 2009 at 23:13 Comment(1)
I'm a little confused - you have provided an implementation of TestTagTemplateVariableResolver, which extends TemplateVariableResolver and implements resolve(), but it still doesn't work? Could you post more code or more details?Beane
T
1

This email chain from 2004 says it might not be possible:

the Java editor chooses not to respect resolvers contributed to its two context types ('java' and 'javadoc'), but only recognizes the built-in resolvers.

The html editor you are working with may have a similar restriction.

Typography answered 2/2, 2009 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.