如何将参数传递到eclipse-plugin中的代码模板

2023-08-21Java开发问题
2

本文介绍了如何将参数传递到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 循环浏览它们,它将使这些自定义模板字段"的内容保持同步(因此您在 new 之后的部分被填写如果您在第一个字段中输入).

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 模板.

根据您提到的博客文章中的答案,目前只能使用编辑器模板,而不是代码模板.我建议提交一个针对 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中的代码模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13