Applying quick fixes to rule results

A quick fix is an automated solution for an exception that is identified in the rule results.

Use a quick fix to save time fixing problems. The quick fix icon Quick fix icon for rule results identifies whether a quick fix is available for a rule result.

To get additional information about a quick fix, including solutions and examples, press F1 or click the Help icon.

Even if a quick fix is available, you must open the source file and verify that the quick fix will fix the exception that is identified in the rule results.

To apply a quick fix to a rule result, right-click the rule result that has a quick fix and, on the pop-up menu, click a quick fix and follow instructions provided by the rule author.

Quick fixes migration

Starting from the December release of 2018, the Core and UI code is separated out. That is, a plugin that contains the core function must not have any dependencies on the UI plugins, such as org.eclipse.ui.

This separation affects the code review rules and their quick fixes. A typical code review rule in analysis phase is going through source files and trying to find violations, which is an example of the core functionality. A quick fix, if it is applied, is then to modify the source file, refresh the text editor, and refresh any other UI elements if the file is opened in the Eclipse UI.

To support the separation between Core and UI, the schemas for analysisRule and analysisRuleQuickFix extension points are changed. Now the code review rules that the quick fix is applied to are to be defined inside analysisRuleQuickFix elements.
Note: There is a many-to-many relationship between rules and quick fixes, which means that a rule violation could have multiple ways to fix and the same fix can be applied to multiple rule violations, although the more typical scenario is one quick fix for one rule.
To make a code review rule set complaint with Static Analysis, you need to refactor the plugin.xml file. For example, a rule that contains one or more quick fixes might have the following definition in the plugin.xml file previously:
<analysisRule
         category="codereview.java.category.examle"
         class="com.ibm.rsar.analysis.codereview.java.rules.example.ExampleRule"
         id="codereview.java.rules.ExampleRule"
         severity="0">
      <quickfix id="com.ibm.java.rules.example.quickfix.ExampleQuickFix1"/>
      <quickfix id="com.ibm.java.rules.example.quickfix.ExampleQuickFix2"/>
</analysisRule>

<analysisRuleQuickFix
        class="com.ibm.java.rules.example.quickfix.ExampleQuickFix1"
        id="com.ibm.java.rules.example.quickfix.ExampleQuickFix1"/>
<analysisRuleQuickFix
        class="com.ibm.java.rules.example.quickfix.ExampleQuickFix2"
        id="com.ibm.java.rules.example.quickfix.ExampleQuickFix2"/>
You can refactor the example plugin.xml as following:
<analysisRule
         category="codereview.java.category.examle"
         class="com.ibm.rsar.analysis.codereview.java.rules.example.ExampleRule"
         id="codereview.java.rules.ExampleRule"
         severity="0">
</analysisRule>

<analysisRuleQuickFix
        class="com.ibm.java.rules.example.quickfix.ExampleQuickFix1"
        id="com.ibm.java.rules.example.quickfix.ExampleQuickFix1">
	codereview.java.rules.ExampleRule/>
</analysisRuleQuickFix>
<analysisRuleQuickFix
        class="com.ibm.java.rules.example.quickfix.ExampleQuickFix2"
        id="com.ibm.java.rules.example.quickfix.ExampleQuickFix2">
       <rule id="codereview.java.rules.ExampleRule"/>
</analysisRuleQuickFix>
The refactoring that is described above is enough to make a rule set compliant with Static Analysis. However, to benefit from Core/UI separation, that is, to run analysis in environments without GUI, you can consider separating rules and quick fixes. Complete the following steps to separate rules and quick fixes.
  1. Create a plugin for quick fixes and move the quickfix classes into the plugin that you create.
  2. Move <analysisRuleQuickFix> elements into the plugin.xml file of the new plugin.