Coding analysis methods with the PL/I APIs

Use the PL/I APIs to analyze the PL/I language elements that you select for your user-written rules.

About this task

For more information about the PL/I APIs and the generated implementation code, see the related links at the end of the topic.

Procedure

To implement the code analysis for a user-written rule:

  1. Open the Plug-in Development perspective.
  2. In the Package Explorer, right-click the Java™ source file that was generated for your user-written rule, then click Open With > Java Editor. The location of the Java file in the Package Explorer is project_name > src > package_name > class_name.java. For example: MyPluginProject > src > com.example > PL1Rule.java.
  3. In the Java editor, add Java code to each of the generated visit() methods to do the code analysis. A visit() method is generated for each PL/I Application Model interface that corresponds to the PL/I language element that you selected. Some language elements have only one corresponding interface; other language elements have more. For example, suppose that you selected the AllocateStatement element in the PL/I language elements tree on the third page of the creation wizard. An AllocateStatement element has one corresponding interface, AllocateStatement. Therefore, a visit() method is generated for the AllocateStatement interface.
    Note: The visit() methods belong to the interface IPLIVisitor, in the package com.ibm.rsar.analysis.codereview.pli.custom.model.util, in the Custom Rules API for PL/I Code Review. Do not implement IPLIVisitor directly; instead, subclass AbstractPLIVisitor. The method signature of the visit() method for an AllocateStatement object is as follows:
    boolean visit(com.ibm.etools.pli.application.model.pli.AllocateStatement n)
    When a PL/I source file is analyzed, the code analyzer starts a visit() method whenever it encounters an instance of the corresponding PLINode.
  4. In each visit() method, add Java code for the following functions:
    • Use the PLINode n that is passed as input to the visit() method to get information about the instance of the PL/I language element that you are analyzing. For example, to get the parameters of a procedure statement, where n is a ProcedureStatement object, you can write:
      List<Reference> parameters = n.getParameters();
    • Do the code analysis for your user-written rule. If you have more than one visit() method for your rule, you probably also must write Java code to coordinate the results from the individual visit() methods.
    • Set the return code and the return information. Return true to continue visiting child nodes of the current node or false to skip visiting child nodes. If the PL/I language element that is being analyzed violates the rule, add the corresponding node to the tokens list.
  5. When you are finished, close the Java editor.

Feedback