JavaCC:警告太多
我使用的是 JavaCC 5.0 版。与日食伽利略。
但是当我在 jj 文件中设置选项“static=true”时,生成的 TokenManager 文件有许多警告,例如“SimpleCharStream 类型的静态方法 readChar() 应以静态方式访问”。此外,我的 jj 文件中的所有导入都已复制到 TokenManager,在那里它们被标记为未使用。有没有办法可以防止这种情况发生?
看来这个 问题已在 JavaCC v4.1 中修复,那么为什么我仍然面临这个问题?
I am using JavaCC version 5.0. with Eclipse Galileo.
But when I set option "static=true" in my jj file, the generated TokenManager file has many warnings like "The static method readChar() from the type SimpleCharStream should be accessed in a static way". Also, all the imports from my jj file have been copied over to the TokenManager, where they are flagged as unused. Is there an option to prevent this?
It seems this issue was fixed in JavaCC v4.1, then why do I still face this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您将 JavaCC 切换为静态时,它不会删除现有的生成类。该行为是在您对类进行更改或提供您自己的版本的情况下发生的。
删除所有生成的类,设置'static=true',然后重新开始。一切都应该有效。
如果您正在自动化构建(如使用 Ant),最好始终删除并重新生成 JavaCC 生成的类,以确保您正在测试的内容是可重现的。
至于 Eclipse...当您对 JavaCC 输入文件进行更改时,您可以告诉它运行您的 Ant 脚本。
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.
这些警告是由正确但不推荐的代码引起的。由于手动修复生成的代码不是一个好主意,因此我的建议是禁用 Eclipse 中的这些警告(Java > 编译器 > 错误/警告)。
我建议您使用项目特定设置来禁用这些警告(这样它就不会在您的所有项目中禁用),您还可以将所有生成的代码放在一个项目中,并使您的代码依赖于该项目,这样您就可以保留这些警告对您的代码的警告。
Those warnings are due to code that is correct but not recommended. Since it won't be a good idea to go fixing generated code by hand, my suggestion is to disable those warnings in Eclipse (Java > Compiler > Error/Warnings).
I recommend you to use project specific settings to disable those warnings (so it won't disable in all your projects), you can also put all the generated code in a project and make your code depend on this project, so you can keep those warnings for your code.