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

查看:35
本文介绍了如何在 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 > Compiler > Errors/Warnings 提供的功能的警告?

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 工具的(你可能已经知道了).这个想法是先写代码,然后再回去翻译.如果稍后对代码进行更改,工具可以再次运行,并且只对增量添加的新字符串起作用.

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天全站免登陆