如何为相同类型的Checkstyle问题应用多个快速修复?

Dun*_*nes 11 java eclipse refactoring checkstyle

Eclipse Checkstyle插件提供了两种自动更正问题的方法:

  1. 右键单击单个源文件,然后选择"应用Checkstyle更正".

  2. 右键单击问题标记,然后选择"快速修复".

如果我选择多个相同类型的标记并尝试快速修复所有标记,则Eclipse指出:

所选问题没有常见的适用快速修复方法.

有没有办法让我以更有效的方式执行相同类型的多个Checkstyle修正?

(参见相关问题:如何轻松修复Checkstyle错误?)


举个例子,考虑以下代码:

/**
 * Example to demonstrate check-style quick fix.
 */
public final class CheckStyle {

  /**
   * Example constructor with no if braces.
   *
   * @param arg an argument
   */
  public CheckStyle(final String arg) {
    if (arg == null)
      throw new RuntimeException("Arg is null.");

    if (arg.isEmpty())
      throw new RuntimeException("Arg is empty.");
  }
}
Run Code Online (Sandbox Code Playgroud)

根据Sun的checkstyle配置检查时,会收到三个错误:

Checkstyle错误

如果我选择与缺少大括号相关的两个错误并尝试快速修复它们,那么它将无法工作.

Dun*_*nes 0

从版本 5.6.1 开始,此功能现已在 eclipse-cs 中可用。我刚刚用 5.7.0(最新版本)对此进行了测试并确认它有效。

作为参考,原始错误报告位于此处。该功能未出现在该版本的发行说明中,但这是由于遗漏造成的(请参阅错误报告中的评论)。