How do I update an Eclipse template variable on th

2020-07-26 11:36发布

问题:

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?

回答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.