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

烂漫一生 提交于 2019-12-06 10:31:34

问题


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.



来源:https://stackoverflow.com/questions/505389/how-do-i-update-an-eclipse-template-variable-on-the-fly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!