循环 Eclipse 代码模板中的字段

发布于 2024-08-28 02:05:28 字数 44 浏览 5 评论 0原文

您可以在代码模板中执行循环吗,例如我想打印类中的所有字段。有这样的模板吗?

Can you do loops in code templates, e.g I want to print all the fields in a class. Is there a template for that?

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

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

发布评论

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

评论(3

与他有关 2024-09-04 02:05:28

假设您正在谈论 Java >编辑>模板参考(可能已过时)是这里

这个问题 useful-eclipse -java-code-templates 包含一些示例。

要使用 toString() 样式生成器迭代类成员,您可能会发现这很有用:
toString() 生成器:格式模板

Assuming you're talking about Java > Editor > Templates a reference (maybe outdated) is here

This SO question useful-eclipse-java-code-templates containes some examples.

To iterate over class members using a toString() style generator you may find this useful:
toString() Generator: Format Templates

后来的我们 2024-09-04 02:05:28

Eclipse 可以生成 toString(),其中包括所有字段及其字符串值的打印(如果您需要的话)。

Eclipse can generate toString(), which includes a print out of all fields and their string values, if that's what you are after.

挽心 2024-09-04 02:05:28

由于我没有找到我要找的东西,所以我将其放入我的插件中。它支持变化。
如果您有名为 Companyclass ,其中包含 companyNamecompanyType 等字段,它将生成如下所示的打印语句如果您选择 logger.debug 变体:

if (logger.isDebugEnabled()) {
    logger.debug("Company Name " + company.getCompanyName());
    logger.debug("Company Type " + company.getCompanyType());
}

template-variation

Since I didn't find what I was looking for, I put it in my plugin. It supports variations.
If you have class called Company with fields companyName, companyType, etc. it will generate print statements as shown below if you select logger.debug variation :

if (logger.isDebugEnabled()) {
    logger.debug("Company Name " + company.getCompanyName());
    logger.debug("Company Type " + company.getCompanyType());
}

template-variation

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