11

The Eclipse Checkstyle plugin offers two ways to auto-correct issues:

  1. Right-click on an individual source file and select "Apply Checkstyle Corrections".

  2. Right-click on problem marker and select "Quick Fix".

If I select multiple markers of the same type and attempt to quick fix all of them, Eclipse states:

The selected problems do not have a common applicable quick fix.

Is there a way for me to execute multiple Checkstyle corrections of the same type in a more efficient manner?

(See related question: How can I easily fix Checkstyle errors?)


To give an example, consider the following code:

/**
 * 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.");
  }
}

When checked against Sun's checkstyle configuration, three errors are picked up:

Checkstyle errors

If I select the two errors relating to missing braces and try and quick-fix the pair of them, it will not work.

Community
  • 1
  • 1
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254

2 Answers2

4

Just a guess here, but I think the answer is to file a bug/feature request with the cs-eclipse plug-in team. The message Eclipse is giving you seems to indicate it's a special case that would need to be handled by the developer.

If you do submit a ticket, let us know. I'd like to watch it. I think it would be a useful feature.

Snekse
  • 15,474
  • 10
  • 62
  • 77
  • Well, I would make the argument that my answer was the solution, your answer was just the execution of the solution. No matter. Glad it's getting resolved. – Snekse Oct 23 '12 at 14:34
  • Agreed, but if you are going to put the green tick next to this answer, you may want to edit it with an update either pointing to your answer or just integrating it in. – Snekse Oct 23 '12 at 14:50
0

Since version 5.6.1, this capability is now available in eclipse-cs. I've just tested this with 5.7.0 (the latest version) and confirmed it works.

For reference, the original bug report is here. The feature doesn't appear in the release notes for that version, but that's due to omission (see comments in bug report).

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254