Insert additional line fix template

If you selected the Insert additional line fix template, complete the following steps:
  1. In the Fix description field, type a description that will explain the fix to users before they apply the fix. For example, Insert an include statement for the myfile.h header file.
  2. If you used named patterns to match when detecting your rule, you might want to include text that was matched during detection in your fix description. For example, for a C/C++ rule that matches all header file names that use the $ character in their name and replaces the $ character with the underscore character, you might want to use the actual matched name in the fix description. By using the matched values from the rule, your fix description can be specific to the match. For example, if the rule matches file$name.h, the fix description is Replace file$name.h with file_name.h.
  3. To insert a named pattern that will be replaced with the matched text when the rule is matched, click Insert Matched Pattern to open the Named Patterns dialog box.
  4. From the list of named patterns, select the patterns that you want to insert into the Fix Description field, and then click Insert. The Preview section displays a preview of the selected named pattern in the Fix Description field.
    Note: The Fix description is displayed when users use the Quick Fix action.
  5. In the Insertion Text section, specify the lines that you want the rule to insert into the file when it matches the specified text. If you used named patterns to match when detecting your rule, you might want to include text that was matched during detection in your fix description. For example, you might have a C/C++ rule that matches all usage of numeric constants. If you want to insert a #define statement to define those constants when this rule is matched, you can use the named pattern that you created for detecting any arguments to insert those arguments into your fixed text.
    For example, if the rule detects constants that match $AnyNumber$ and the rule matches the constant 4, the fix might be to insert a line such as:
    #define NUMBER_$AnyNumber$ $AnyNumber$
    where the inserted text is:
    #define NUMBER_4 4
  6. To insert a named pattern that will be replaced with the matched text when the rule is matched, click Insert Matched Pattern to open the Named Patterns dialog box.
    Tip: You can use escape characters such as \n for new line and \t for tab.
  7. From the list of named patterns, select the patterns that you want to insert into the Fix Description field, and then click Insert. The Preview section displays a preview of the selected named pattern in the Fix Description field.
  8. In the Location section, do one of the following:
    • Click the Line above radio button to insert the specified lines above the matched error location in the file.
    • Click the Line below radio button to insert the specified lines below the matched error location.
      Note: If the error location spans multiple lines, the line below is considered to be the line following the last line that is part of the error location.
    • Click the First line radio button to insert the specified lines as the first line of the file.
    • Click the Last line radio button to insert the specified lines as the last line of the file.
    • Click the After line number radio button, and then type the line number after which you want to insert the specified lines into the file.
    Tip: When you use a fix that inserts text into the file, use a precondition on your rule to verify that the text you are inserting does not already exist in the file. If the text is already contained in the file, the rule will be flagged even after a fix is applied.