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:
- Open the Plug-in Development perspective.
- 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.
- In the Java editor,
add Java code to each of the
generated
visit()methods to do the code analysis.Avisit()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, avisit()method is generated for theAllocateStatementinterface.Note: Thevisit()methods belong to the interfaceIPLIVisitor, in the packagecom.ibm.rsar.analysis.codereview.pli.custom.model.util, in the Custom Rules API for PL/I Code Review. Do not implementIPLIVisitordirectly; instead, subclassAbstractPLIVisitor. The method signature of thevisit()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 avisit()method whenever it encounters an instance of the correspondingPLINode. - In each
visit()method, add Java code for the following functions:- Use the
PLINode nthat is passed as input to thevisit()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 aProcedureStatementobject, 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 individualvisit()methods. - Set the return code and the return information. Return
trueto continue visiting child nodes of the current node orfalseto 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.
- Use the
- When you are finished, close the Java editor.