如何在Eclipse中为Java文件添加自定义警告? [英] How can I add a custom warning to Java files in Eclipse?

查看:666
本文介绍了如何在Eclipse中为Java文件添加自定义警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Eclipse中为 .java 文件添加一个自定义警告消息(即在问题选项卡的警告部分添加一个条目)。

I'd like to add a custom warning message (i.e. add an entry to the Warnings section of the Problems tab) for .java files in Eclipse.

虽然我发现了关于创建插件和使用标记的信息(这里和其他地方),但我还没有发现任何涉及扩展问题查找过程的内容。我发现的大部分文章在 时不会讨论来创建标记,只有 ,而那些假定我有兴趣将它们附加到自定义构建步骤或自定义编辑器,这两个都不适合我正在尝试做的。

While I've found information (here and elsewhere) on creating plugins and using markers, I haven't yet found anything which talks about extending the "problem-finding" process. Most of the articles I've found don't discuss when to create markers, only how, and those that do assume that I'm interested in attaching them to a custom build step or custom editor, neither of which seems appropriate for what I'm trying to do.

如何创建一个警告,通过Window> Preferences > Java>编译器>错误/警告?

How can I create a warning which functions like those available via Window > Preferences > Java > Compiler > Errors/Warnings?

推荐答案

我认为构建器可能适合您要做的事情。新插件向导中有一个模板可以创建构建器所需的所有内容(例如业务逻辑)。由于构建器在每次修改文件时运行,您可以清除旧的警告(为您生成的代码),并添加新警告(为此生成的代码)(如果适用)。这也适用于首次创建文件时。

I think that a builder might be appropriate for what you want to do. There's a template in the new plugin wizard that creates everything you need for a builder (ex. business logic). Since the builder runs every time the file is modified, you can clear the old warning (code generated for you) and add a new warning (code generated for you) if applicable. This also applies when the file is first created.

您甚至可以查看代码并找到硬编码的字符串,如果需要,可以使用警告标记它们。

You could even look through the code and find hard-coded strings and flag them with warnings if you want.

对于今天代码中的翻译键的注释,那些在那里指导NLS工具(你可能已经知道了)。这个想法是先写代码,然后再回去翻译。如果稍后对代码进行更改,这些工具可以再次运行,只能对由delta增加的新字符串执行。

As for the comments marking translation keys in the code today, those are there to guide NLS tools (you probably already knew that). The idea was to write the code first and then go back later and translate. If a change is made to the code later, the tools can run again and only act on new strings added by the delta.

这篇关于如何在Eclipse中为Java文件添加自定义警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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