Generating a plug-in project for a user-written custom rule

To generate a plug-in project for a user-written custom rule, use the COBOL Rule Template page of the New Plug-in Project wizard.

Generating the project

Procedure

  1. Open the Plugin Development perspective.
  2. On the main menu of the workbench, click File > New > Project > Plug-in Development > Plug-in Project and click Next. The New Plug-in Project wizard opens.
  3. In the Project name field of the Plug-in Project page, enter a name for the new project and click Next.
  4. In the ID field of the Content page, enter an ID for the new project and click Next.
  5. On the Templates page, select Create a plug-in using one of the templates, then select Custom COBOL Code Review Rule, and click Next.
  6. On the COBOL Rule Template page, complete the following fields:
    Rule class
    Enter a fully qualified Java class name. The wizard assigns this name to the class that it creates to implement the new rule. The default value for this field is the Project ID followed by the character string CobolRule.
    Tip: The Project ID is the character string that you specified in the ID field on the Content page of the wizard.
    Rule label
    Enter a name for the new rule. This name is added to the list of available rules that are displayed in the analysis configuration editor. The default value for this field is "My custom COBOL rule".
    Note: This name is translatable. For information about internationalizing strings in a plug-in, see Internationalizing a rule label or category name.
    Category
    You can create a rule category for the new rule, or you can add the new rule to an existing built-in or custom rule category.
    • To place the new rule into a new rule category, click Create a new category and enter a category ID and category name for the new category.
    • To add the rule to an existing category, click Select an existing category, then expand the list and select the category to which you want to add the new rule.
    Category ID
    Enter a valid Eclipse ID for the category within which the user-written custom rule is displayed in the analysis configuration editor. The default value is the Project ID followed by the word custom.
    Tip: The Project ID is the character string that you specified in the ID field on the Content page of the wizard.
    Category name
    Enter a name for the category within which the user-written custom rule is displayed in the analysis configuration editor. The default value is Custom.
    Note: This name is translatable. For information about internationalizing strings in a plug-in, see Internationalizing a rule label or category name.
  7. Expand the Program tree and select the COBOL language element or elements that the implementation code for the new rule must check for violations. The default is no elements selected. For an example of the Java code that is generated for selected elements, see Generated files: Implementation code.
  8. Click Finish. The wizard creates a plug-in project for the new user-written custom rule, adds the project to the Package Explorer view, and opens the manifest file in the plug-in manifest editor.
  9. If you did not already open the Plug-in Development perspective, open it when prompted.
  10. Close the plug-in manifest editor.

Results

The COBOL Rule Template wizard adds rule and category extensions to the plugin.xml file that is generated for the custom rule plug-in project. For more information about these extensions, see Generated files: Rule and category extensions.

The wizard also generates a Java class for implementing a user-written custom rule. For more information about this class, see Generated files: Implementation code.

Internationalizing a rule label or category name

About this task

If you must make your plug-in translatable into different languages, you can internationalize the translatable strings. The method for internationalizing a string such as a rule label or a category name is described in Internationalize plug-in manifest. The following procedure describes the main steps.

Procedure

  1. In the rule extension that is created in the plugin.xml, use a %variable instead of a character string. For example, for the rule label, you can substitute the variable %myRuleLabel:
    <analysisRule
          category="category_id"
          class="rule_class"
          id="rule_class"
          label="%myRuleLabel"
          severity="1">
    </analysisRule>
  2. Define the variable in the plugin.properties file. For example:%myRuleLabel="My Rule Label".
  3. Build the project in the usual way.

Feedback