2

我正在使用 JavaCC 5.0 版。与 Eclipse 伽利略。

但是当我在我的 jj 文件中设置选项“static=true”时,生成的 TokenManager 文件有许多警告,例如“应以静态方式访问 SimpleCharStream 类型的静态方法 readChar()”。此外,我的 jj 文件中的所有导入都已复制到 TokenManager,在那里它们被标记为未使用。有没有办法防止这种情况发生?

看来这个问题在 JavaCC v4.1 中已经修复了,那我为什么还要面对这个问题呢?

4

2 回答 2

1

JavaCC does not delete existing generated classes when you switch it to static. That behaviour is in case you've made changes to the classes, or provided your own versions.

Delete all generated classes, set 'static=true', and start again. Everything should work.

If you're automating builds (like with Ant), it would be good idea to always delete and regenerate JavaCC generated classes, just to make sure that what you're testing is reproducible.

As to Eclipse... You can tell it to run your Ant script when you've made changes to the JavaCC input files.

于 2011-02-18T14:03:06.133 回答
0

这些警告是由正确但不推荐的代码引起的。由于手动修复生成的代码不是一个好主意,我的建议是在 Eclipse 中禁用这些警告(Java > Compiler > Error/Warnings)。

我建议您使用项目特定设置来禁用这些警告(这样它就不会在您的所有项目中禁用),您还可以将所有生成的代码放在一个项目中并使您的代码依赖于该项目,这样您就可以保留那些您的代码的警告。

于 2011-02-15T21:39:16.063 回答