Eclipse 的 Checkstyle 插件
Eclipse 有 checkstyle 插件,它可以指出不好的编码实践。是否有某种工具或某种方式可以自动修复其中一些问题?
例如,假设清理未使用的导入。该工具是否可以自动访问整个项目并删除未使用的导入?
Eclipse has checkstyle plugin which points out the coding practices which are not good. Is there some tool or someway in which some of those issues can be automatically fixed?
For example, let's say cleanup unused imports. If the tool can automatically visit the whole project and remove the unused imports?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 3.3 版开始,Eclipse 就有了一个清理向导,可以帮助完成部分工作。但在我看来,这个问题是以错误的方式提出的:
因此,您应该执行以下操作:
Window >首选项>爪哇>代码风格>清理
,从现有的配置文件中创建一个新的配置文件,并将其调整为您想要在 Checkstyle 中使用的规则。代码组织>;在您的配置文件中格式化源代码
,同时调整 Java 的代码格式化程序。转到窗口>首选项>爪哇>代码风格> Formatter
,在这里也创建一个新的配置文件,并根据您的检查样式规则对其进行调整。经验法则应该是,在编写任何代码并使用格式化程序对其进行格式化后,不应存在只能通过插入或删除空格、空格、换行符和括号来纠正的检查样式警告。Eclipse has since the version 3.3 a cleanup wizard that could help doing part of the job. But in my opinion, the question is asked in the wrong way:
So you should do the following:
Window > Preferences > Java > Code Style > Clean Up
, create there a new profile from an existing one, and tweak it to the rules you want to use in Checkstyle.Code Organizing > Format Source Code
in your profile, tweak the code formatter for Java as well. Go toWindow > Preferences > Java > Code Style > Formatter
, create here as well a new profile as well, and tweak it according to your checkstyle rules. The rule of thumb should be that after writing any code and formatting it with the formatter, no checkstyle warning should exist that could be corrected by only inserting or removing spaces, blanks, newlines, and parantheses.我在 http://www.ibm.com/developerworks/ 找到了一个链接Library/os-eclipse-clean/ 回答了这个问题。
I found a link at http://www.ibm.com/developerworks/library/os-eclipse-clean/ which answers this question.