8

I was wondering whether intellij has a feature that would allow it to scan through files and perform things such as organising imports, safely deleting unused functions and fields etc. This feature was very helpful in .NET in Resharper plugin. Thanks for any pointers.

4

4 回答 4

12

使用Analyze| 启用相应选项的检查代码以查找未使用的代码,在结果中,您可以将修复应用于所有事件,同时删除所有未使用的方法和字段。

使用Code| 重新格式化代码优化其余部分的导入。Reformat Code 具有优化导入的选项,您可以在整个项目上运行它,以便在一个步骤中全局执行这两项操作。

还可以动态优化导入(在设置中启用)并在提交版本控制时重新格式化/优化导入。代码检查也可以在提交之前执行,以通知您可能存在的问题。

于 2012-08-08T11:56:43.160 回答
6

There is a plugin for IDEA - FindBugs-IDEA. It scans for cases you listed and a lot more.

于 2012-08-08T11:39:49.677 回答
1

You can try it out using the trial.

As to the imports, yes, you can Organize Imports ctrl-alt-o, and you can choose to do so on the current file or on every file in the project.

Not sure if you can delete all unused methods in a project, but you do get warnings regarding methods/variables that aren't used and can be safely deleted (and IntelliJ does offer the option to safely delete).

Also, in the Preferences, you can setup a ton of things that you choose to be considered as warnings, depending on your coding style, conventions, etc.

于 2012-08-08T11:40:04.457 回答
0

我建议使用这 10 个你可能没有使用的 IDEA 检查:

http://hamletdarcy.blogspot.com/2008/04/10-best-idea-inspections-youre-not.html

从我自己来说,我喜欢在Intellij IDEA的帮助下与NullPointerException作斗争。

以下检查对我有很大帮助:

  1. 恒定条件和例外 在此处输入图像描述
  2. @NotNull/@Nullable 问题 在此处输入图像描述
于 2016-10-19T18:57:30.150 回答