Generated files: Implementation code

The COBOL Rule Template wizard generates a Java™ class for implementing a user-written custom rule.

You must add your own Java code to this class to perform the checking required by your custom rule.

Figure 1 shows an example of the generated code for a custom rule class. This example makes the following assumptions:
  • The rule class is com.example.CobolRule (see Table 1).
  • The following elements were selected on the COBOL Rule Template wizard page:
    • IdentificationDivision
    • DataDivision
    • ProcedureDivision
Notice the following aspects of the generated code:
  • The package name is set to the package-name portion of the rule class, com.example.
  • The class name is set to the class-name portion of the rule class, CobolRule.
  • A visit() method is generated for each of the three elements that are selected on the COBOL Rule Template wizard page.
Figure 1. Class for implementing a custom rule
// The package name is set to the package-name portion of analysisRule.ruleclass 
package com.example;

import java.util.ArrayList;
import java.util.List;

import com.ibm.etools.cobol.application.model.cobol.*;
import com.ibm.rsar.analysis.codereview.cobol.custom.rules.AbstractCustomCobolAnalysisRule;
import com.ibm.rsar.analysis.codereview.cobol.custom.model.util.*;

// The class name is set to the class-name portion of analysisRule.ruleclass 
public class CobolRule extends
    AbstractCustomCobolAnalysisRule {

  @Override
  public List<ASTNode> performRule(ASTNode baseNode) {
    final List<ASTNode> tokens = new ArrayList<ASTNode>();
    COBOLVisitorAdapter adapter = new COBOLVisitorAdapter();

    adapter.accept(baseNode, new AbstractCOBOLVisitor() {
      @Override
      public void unimplementedVisitor(String s) {
      }

      @Override
      public boolean visit(IdentificationDivision node) {
        //TODO analyze node for violations of rule and add violating nodes to tokens
        return true;
      }

      @Override
      public boolean visit(DataDivision node) {
        //TODO analyze node for violations of rule and add violating nodes to tokens
        return true;
      }

      @Override
      public boolean visit(ProcedureDivision node) {
        //TODO analyze node for violations of rule and add violating nodes to tokens
        return true;
      }
    });

    return tokens;
  }
}

Feedback