您可以在Eclipse中定义自己的模板变量 [英] Can you define your own template variables in Eclipse

查看:359
本文介绍了您可以在Eclipse中定义自己的模板变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中有一些模板可以通过自动插入一些代码或注释来帮助您。您可以通过首选项> Java>编辑器>模板自己编辑这些模板。有一些所谓的模板变量可以用来使这些模板更加智能。

In Eclipse there are templates that help you by automatically inserting some code or comments. You can edit these templates yourself via Preferences > Java > Editor > Templates. There are so-called "template variables" that you can use to make these templates a little smarter.

例如,有$ {see_to_overridden}变量插入 @see my.package.name.SpuerclassName#methodName(int,my.other.package.SomeType,...)转换为javadoc注释。如果我可以定义自己的变量,那么真的很好,所以我可以获得超级类,SomeType等,而不必提供@see的东西,以便我可以链接到适当的方法。似乎没有模板变量,所以我想知道是否有任何方法来创建自己的模板变量。

For instance, there is the ${see_to_overridden} variable that inserts "@see my.package.name.SpuerclassName#methodName(int, my.other.package.SomeType, ...)" into a javadoc comment. It would be really great if I could define my own variables, so that I could obtain Superclassname, SomeType etc. without having the "@see" thing prepended to it so that I could for instance link to the appropriate method. There appear to exist no template variables for this, so I was wondering if there was any way to create your own template variables.

推荐答案

根据这个博客文章(< a href =http://web.archive.org/web/20100414054049/http://dev.eclipse.org/blogs/jdtui/2007/12/04/text-templates-2/ =noreferrer >替代链接),你可以。

According to this Blog post (alternative link) by the eclipse team, you can.

扩展org.eclipse.ui.editors.templates,添加一个org.eclipse.jface。 text.templates.TemplateVariableResolver并填写系统所需的值。如果您定义了自己的模板,他们应该是自我解释的。

Extend org.eclipse.ui.editors.templates, add a org.eclipse.jface.text.templates.TemplateVariableResolver and fill in the values required by the system. They should be self explanatory if you ever defined your own template.

然后实现解析器,用适当的字符串替换变量。

Then implement the resolver, replacing your variable with a appropriate string.

博客文章包含更多的细节和截图。

The Blog post holds more details and screenshots.

这篇关于您可以在Eclipse中定义自己的模板变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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