Generated files: Implementation code

The New Plug-in Project wizard generates a Java™ package and class for implementing COBOL or PL/I user-written rules.

You must add your own Java code to this class to do the analysis that is required by your custom rule.

Implementation code for COBOL

Figure 1 shows an example of the generated code for a COBOL rule class. The example assumes that the following elements were selected on the COBOL Rule Template page:
  • IdentificationDivision
  • DataDivision
  • ProcedureDivision
The name of the rule class, com.example.CobolRule, is taken from the example value column of Table 1 in the topic Generated files: Rule and category extensions.
Notice the following elements in 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 COBOL 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;
  }
}

Implementation code for PL/I

Figure 2 shows an example of the generated code for a PL/I rule class. The example assumes that the following elements were selected on the PL/I Rule Template page:
  • SelectGroup
  • DefineStructureStatement
  • EntryStatement
The name of the rule class, com.example.PLIRule, is taken from the example value column of Table 1 in the topic Generated files: Rule and category extensions.
Notice the following elements in 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, PLI.
  • A visit() method is generated for each of the three elements that are selected on the PL/I Rule Template wizard page.
Figure 2. Class for implementing a PL/I 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.pli.application.model.pli.*;
import com.ibm.rsar.analysis.codereview.pl1.custom.rules.AbstractCustomPliAnalysisRule;
import com.ibm.rsar.analysis.codereview.pl1.custom.model.util.*;

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

  @Override
  public List<PLINode> performRule(PLINode baseNode) {
    final List<PLINode> nodes = new ArrayList<PLINode>();
    Pl1VisitorAdapter adapter = new Pl1VisitorAdapter();

  adapter.accept(baseNode, new AbstractPl1Visitor() {

      @Override
      public boolean visit(DefineStructureStatement node) {
        // TODO examine node for rule violations and add violating nodes to node list
        return true;
        }

      @Override
      public boolean visit(EntryStatement node) {
        // TODO examine node for rule violations and add violating nodes to node list
        return true;
      }

      @Override
      public boolean visit(SelectGroup node) {
        // TODO examine node for rule violations and add violating nodes to node list
        return true;
      }
    });

    return nodes;
  }
}

Feedback