Rational Developer for System z

Generated files: Implementation code

This topic describes the Java™ class that the COBOL Rule Template wizard generates 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 assumes the following: Notice that in the generated code:
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