如何将参数传递给eclipse-plugin中的代码模板 [英] How to pass parameter into code-template in eclipse-plugin

查看:133
本文介绍了如何将参数传递给eclipse-plugin中的代码模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个定义新代码模板的插件(喜欢这篇博文)。如何将参数传递给模板?像 $ {name:param}

I want to create a plugin which defines a new code template (like this blog post). How can I pass a parameter into the template? like ${name:param}?

推荐答案

许多事情可以传递给代码模板。例如 $ {word_selection} 包含当前的选择。

There aren't many things that you can pass into a code template. For example ${word_selection} contains the current selection.

但是,许多人缺少的是你可以定义你自己的变量:

But what many people are missing is that you can define your own variables:

private static final ${type} ${name} = new ${type} (${cursor});

$ {type} $ {name} 位于您单击插入变量...按钮时获得的列表。 Eclipse通知并允许您使用 Tab 循环浏览它们,并且将使这些自定义模板字段的内容保持同步(因此您在之后的部分新增如果您输入第一个字段,则会被填入。)

Neither ${type} nor ${name} are in the list which you get when you click the "Insert variable..." button. Eclipse notices and allows you to cycle through them with Tab and it will keep the content of these custom "template fields" in sync (so you the part after new gets filled in if you type in the first field).

对于其他有用的Eclipse模板,请参阅此答案。

See this answer for other useful Eclipse templates.

根据您提到的博客文章中的答案,这只能在编辑器模板的时候,而不是代码模板。我建议向JDT Text提交一个错误,以打开这个API。

According to the answers in the blog post which you mention, this is only possible at the moment with editor templates, not code templates. I suggest to file a bug against JDT Text to open the API for this.

这篇关于如何将参数传递给eclipse-plugin中的代码模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆