在哪里可以找到所有可能的 Java 编译时错误的列表?

发布于 2024-11-29 16:59:35 字数 762 浏览 1 评论 0原文

因此,我尝试编写一个 Java 程序来尝试编译另一个 Java 项目,并使用编译器(在本例中为 Javac)中出现的任何潜在错误,该程序将尝试修复损坏的代码。这是我正在尝试做的事情的一个极其简化的视图,但我真正的问题是我找不到 Javac 可能出现的任何具体错误列表。我不想把这变成一场巨大的语言战争,但 C#(当然)有一个我正在寻找的确切示例

http://msdn.microsoft.com/en-us/library/ms228296%28v=vs.80%29.aspx

我已经找到http://mindprod.com/jgloss/compileerrormessages.html,但如某处所述在本网站的其他地方,此列表包括来自 Jikes 和其他编译器的错误。

如果有人有任何信息,我一定会很感激。

编辑: 如果还有其他人想知道这个问题,我最终会打开位于 jdk(version_here)/lib 中的tools.jar 文件。如果您想实际阅读这些消息,请从那里转到 sun/tools/javac/javac.properties。您需要解压该文件夹/文件。希望这隐藏在文档中的某个地方,因为我讨厌将解决方案作为本手册。感谢所有发布答案的人,我将仔细研究所有内容以获得更好的方法。

So I'm trying to write a Java program that attempts to compile another Java project, and using any potential errors that come out of the compiler(in this case Javac) the program would attempt to repair the broken code. This is an extremely simplified view of what I'm trying to do, but my real problem is that I can't find any concrete list of errors that may come out of Javac. I don't want to turn this into a giant language war, but C#(of course) has an exact example of what I'm looking for

http://msdn.microsoft.com/en-us/library/ms228296%28v=vs.80%29.aspx

I have already found http://mindprod.com/jgloss/compileerrormessages.html, but as stated somewhere else on this site, this list includes errors from Jikes and other compilers.

If anyone has any info, I would certainly appreciate it.

Edit:
If anyone else has ever wondered about this I eventually tore open the tools.jar file located in jdk(version_here)/lib. From there your going to sun/tools/javac/javac.properties if you want to actually read the messages. You will need to extract this folder/file. Hopefully this is hidden somewhere in documentation because I hate for solutions to be this manual. Thank you everyone who posted answers, I'm going to look through everything to get a better approach to this.

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

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

发布评论

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

评论(2

清风夜微凉 2024-12-06 16:59:36

好吧,我认为你不会找到任何关于这一点的明确信息。但是编译器消息可能是国际化的,在这种情况下它们必须被翻译,这意味着通常应该只有少数文件包含所有错误消息。

所以我认为这个应该很有用。似乎您应该仔细查看 javac 源中的 compiler.properties 文件 - 显然并不完美,但可惜我认为您不会得到任何更好的东西。

至少这应该让你得到他们抛出的每个错误,然后你可以通过谷歌搜索或者更好地通过源代码 grep 找到它实际抛出的位置,以找出确切的原因。

PS:该文件是 jdk7 源代码的一部分,所以这里是一个小例子 - 完整的文件约为 1.5kloc

# 0: symbol, 1: string, 2: string
compiler.err.cant.inherit.diff.arg=\
    {0} cannot be inherited with different arguments: <{1}> and <{2}>

compiler.err.catch.without.try=\
    ''catch'' without ''try''

# 0: symbol kind, 1: symbol
compiler.err.clash.with.pkg.of.same.name=\
    {0} {1} clashes with package of same name

Well I don't think you'll find anything definite about this. But compiler messages may be internationalized in which case they must be translated, which means that generally there should be only a handful files containing all the error messages.

So this should be useful I think. Seems like you should have a closer look at the compiler.properties file in the javac source - not perfect obviously but alas I don't think you'll get anything better.

At least this should get you every error they throw and you can then either google it or better grep through the source to find the locations where it is actually thrown to find out the exact reasons.

PS: The file is part of the jdk7 sources, so here's a small example - the complete file is ~1.5kloc

# 0: symbol, 1: string, 2: string
compiler.err.cant.inherit.diff.arg=\
    {0} cannot be inherited with different arguments: <{1}> and <{2}>

compiler.err.catch.without.try=\
    ''catch'' without ''try''

# 0: symbol kind, 1: symbol
compiler.err.clash.with.pkg.of.same.name=\
    {0} {1} clashes with package of same name
我的黑色迷你裙 2024-12-06 16:59:36

Eclipse JDT 编译器 有点做你想做的事。

The Eclipse JDT compiler kind of does what you are trying to do.

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