Use the Custom Rules API for COBOL Code
Review and the COBOL Application Model API (CAM) to analyze the
COBOL language elements that you selected for your user-written custom
rule.
About this task
The Custom Rules API for COBOL Code Review
and the COBOL Application Model API are complementary. Some knowledge
of both is required to implement a user-written custom rule:
- Custom Rules API for COBOL Code Review
This API
provides the base class for user-written rules and includes useful
classes for manipulating the objects in the COBOL Application Model
(CAM).
To read the documentation for this API, see Custom Rules API for COBOL Code Review.
- COBOL Application Model (CAM) API
This API provides interfaces
for accessing the elements of a COBOL source code program while the
program is being analyzed by the COBOL Code Review component.
To
read the documentation for this API, see COBOL Application Model API.Note: For
an overview of this API, select the topic "Package com.ibm.etools.cobol.application.model.cobol" and
scroll to the end of the topic to read the "Description" section.
Procedure
To implement the code analysis for a custom rule:
- Open the Plug-in Development perspective.
- In the Package Explorer, right-click
the Java™ source file that was
generated for your custom rule, then click . The location of the Java file
in the Package Explorer is . For example: .
- In the Java editor,
add Java code as needed to each
of the generated visit() methods to do the required
code analysis. A visit() method is generated for each
nonabstract subinterface of the Cobol Application Model interface
corresponding to the COBOL language element that you selected. For example, suppose that you selected the ACCEPT element
in the Program tree on the third page of the creation wizard:
- The CAM interface corresponding to ACCEPT is the AcceptStmt interface.
- The Javadoc information
for the AcceptStmt interface shows, under the heading All
Known Subinterfaces, that AcceptStmt has
two subinterfaces: AcceptDataTranferStmt and AcceptSystemInfoTransferStmt.
- Two visit() methods are generated, one for
each of the two subinterfaces.
Note: - The visit() methods belong to the interface ICOBOLVisitor,
in the package com.ibm.rsar.analysis.codereview.cobol.custom.model.util,
in the Custom Rules API for COBOL Code Review. Do not implement ICOBOLVistor directly;
instead, subclass AbstractCOBOLVisitor. The following
examples show the generated visit() methods:
- boolean visit(com.ibm.etools.cobol.application.model.cobol.AcceptDataTransferStmt
n)
- boolean visit(com.ibm.etools.cobol.application.model.cobol.AcceptSystemInfoTransferStmt
n)
- The node that is passed as input to a visit() method
is a subinterface of the interface ASTNode in the
package com.ibm.etools.cobol.application.model.cobol in
the COBOL Application Model (CAM) API.
When a COBOL source file is analyzed,
the code analyzer starts a visit() method whenever
it encounters an instance of the corresponding ASTNode.
- In each visit() method, add Java code for the following functions:
- When you are finished, close the Java editor.