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

发布于 2024-07-13 00:46:29 字数 975 浏览 6 评论 0原文

我通过扩展点添加了以下新的 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>

我无法弄清楚如何在运行时更改 $(color) 变量的值。 更具体地说,当用户按 Ctrl + Space (或内容辅助的等效键)并输入“testTag”并按 Enter 键时——而不是“颜色”占位符文本,我希望将其替换为我在另一个类中拥有的其他文本值。 我该怎么做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风铃鹿 2024-07-20 00:46:29

2004 年的此电子邮件链 表示可能不是可能的:

Java 编辑器选择不尊重为其两种上下文类型(“java”和“javadoc”)贡献的解析器,而仅识别内置解析器。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文