• 2 replies
  • Latest Post - ‏2013-06-19T17:24:37Z by syik
14 Posts

Pinned topic RDz Add new Custom Code Review Rule - Java Source Sample?

‏2013-06-13T19:40:25Z | code rdz review rule


  I am trying to add a new custom rule to RDz code review. I have watched the Youtube video by Cindy Krauss  regarding of the process needed for new custom rule. I understand the example in the video and did tried the same and work. Since I am not a java programmer (still learning) and  have limited knowledge on Java. I have been struggling on the java coding part to put my new rule. I am trying to add a rule so that the paragraph name should start with a sequence number such as 0100-XXXXX.  In the Cobol rule Template, I choose Paragraph.   But I have problem when I get to the point of changing the java source on the visit method. By looking at the javadoc, it seems getSentences is the only feature for paragraph. And the getSentences return is a list. And I don't know how to do it. I was thinking may be I can get the paragraph name and then check if the first few character is a number, something like that.  Just wondering if anyone has try to create similar rule?  Also, is there any resource that we can look at the java source for all code review rules that come with RDz? I think it will definitely help to have a better understanding of the java code if it is available.

Thanks  Sidney

  • jgellin
    16 Posts

    Re: RDz Add new Custom Code Review Rule - Java Source Sample?


    Hi Sidney - 

    Since Java is an object-oriented language, each class inherits the public features of it's parent classes. Let's take another look at the Paragraph Javadoc:

    Notice the list of superinterfaces at the top of of the page. In addition to Sentences, all the features of these interfaces are supported as well. You can click the links to the javadoc for these classes, but it's easier to just scroll down a bit, where you'll find the methods inherited from these superinterfaces. The most important for your purposes is the method getName(), inherited from the superinterface NamedElement. The getName() method will return the paragraph name, and you were on the right track as far as algorithm. Here is an example performRule() method for testing whether all of the characters before the first '-' in a paragraph name are numeric.

    public List<ASTNode> performRule(ASTNode baseNode) {
      final List<ASTNode> nodes = new ArrayList<ASTNode>();
      COBOLVisitorAdapter adapter = new COBOLVisitorAdapter();
      adapter.accept(baseNode, new AbstractCOBOLVisitor() {
        public void unimplementedVisitor(String s) {
        public boolean visit(Paragraph n) {
          // test to make sure paragraph name has a numeric prefix (e.g. 0100-XXXXX)
          // get paragraph name
          String paragraphName = n.getName();
          // get prefix (all characters before '-')
          if (paragraphName.indexOf('-') > 0) {
            String prefix = paragraphName.substring(0, paragraphName.indexOf('-'));
            // make sure all characters in prefix are numeric digits
            for (int i = 0; i < prefix.length(); i++) {
              char c = prefix.charAt(i);
              if (!Character.isDigit(c)) {
                // not a digit; does not comply with rule
          } else {
            // paragraph has no prefix; does not comply with rule
          return true;
      return nodes;
    Complete source for a sample project containing the above method attached.

    I hope this helps.



    Updated on 2013-06-17T19:27:29Z at 2013-06-17T19:27:29Z by jgellin
  • syik
    14 Posts

    Re: RDz Add new Custom Code Review Rule - Java Source Sample?


    Hi Jon,

     Thank you so much for your detail explanation and provide the solution for my puzzle. Now, I have a better understanding of the java stuff.  Really appreciate that !!!  Can't wait to try this out.

    Thanks again