如何动态更新Eclipse模板变量?

时间:2022-09-11 19:52:29

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

我通过扩展点添加了以下新的Eclipse模板。它只是为示例testTag标记添加了一个模板。

<!-- 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?

我无法弄清楚的是如何在运行时更改$(color)变量的值。更具体地说,当用户按下Ctrl + Space(或内容辅助的等价物)并键入“testTag”并按Enter键 - 而不是“颜色”占位符文本时,我希望它被其他一些文本值替换我在另一堂课。我该怎么做呢?

1 个解决方案

#1


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

2004年的这个电子邮件链说它可能不可能:

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

Java编辑器选择不尊重对其两种上下文类型('java'和'javadoc')有贡献的解析器,但只识别内置的解析器。

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

您正在使用的html编辑器可能有类似的限制。

#1


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

2004年的这个电子邮件链说它可能不可能:

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

Java编辑器选择不尊重对其两种上下文类型('java'和'javadoc')有贡献的解析器,但只识别内置的解析器。

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

您正在使用的html编辑器可能有类似的限制。