Use the EGL APIs to analyze the EGL language elements that
you select for your user-written rules.
About this task
For more information about the EGL APIs and the generated
implementation code, see the related links at the end of the topic.
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 to each of the
generated visit() methods to do the code analysis. A visit() method is generated for each nonabstract
subinterface of the EGL Application Model interface corresponding
to the EGL language element that you selected. For
example, suppose that you selected the AddStatement element in the
Statements tree on the third page of the creation wizard:
- The EAM interface corresponding to AddStatement is the AddStatement interface.
- Two visit() methods are generated, one for each
of an AST visit and an IR visit for the interface.
Note: - The visit() methods belong to the interfaces IASTVisitor and IRVisitor,
in the Custom Rules API for EGL code review. Do not implement IASTVistor or IRVistor directly;
instead, subclass AbstractASTRuleVisitor or AbstractIRRuleVisitor.
The following examples show the generated visit() methods:
- boolean visit(com.ibm.etools.edt.core.ast.AddStatement
node)
- boolean visit(com.ibm.etools.edt.core.ir.api.AddStatement
clause)
- The node that is passed as input to a visit() method
is a subinterface of the interface Node in the package com.ibm.etools.edt.core.ast in
the EGL Application Model (EAM) API.
- The clause that is passed as input to a visit() method,
if RUN_AS_IR is set to true, is a subinterface of the interface Element in
the package com.ibm.etools.edt.core.ir.api in the
EGL Application Model (EAM) API.
When a EGL source file is analyzed,
the code analyzer starts a visit() method whenever
it encounters an instance of the corresponding Node or Element.
- In each visit() method, add Java code for the following functions:
- Use the Node node, or Element clause if
using RUN_AS_IR, that is passed as input to the visit() method
to get information about the instance of the EGL language element
that you are analyzing.
- Perform the code analysis for your custom 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 EGL language element that is being
analyzed violates the rule, add the corresponding node to the tokens
list.
- When you are finished, close the Java editor.