Menu

Cannot run custom rule class in eclipse

2017-11-27
2017-12-18
  • Suman alungh

    Suman alungh - 2017-11-27

    I am trying to run the sample PMD custom rule as described in http://pmd.sourceforge.net/pmd-5.3.2/customizing/howtowritearule.html#Write_a_rule_class and I am unable to compile/run it in eclipse. I am not sure what is missing. I added the external PMD jar files on my project to get rid of import issues but I just can't run it. Can anyone please help or give me a sample rule that runs on eclipse. I am a beginner and I want a sample that works. I basically needs to compile the .java rule file sothat I get a .class file that I can eventually convert to jar to use that rule in Jenkins with Gradle.

    import net.sourceforge.pmd.lang.ast.;
    import net.sourceforge.pmd.lang.java.ast.
    ;
    import net.sourceforge.pmd.lang.java.rule.*;

    public class WhileLoopsMustUseBracesRule extends AbstractJavaRule {
    public Object visit(ASTWhileStatement node, Object data) {
    Node firstStmt = node.jjtGetChild(1);
    if (!hasBlockAsFirstChild(firstStmt)) {
    addViolation(data, node);
    }
    return super.visit(node,data);
    }
    private boolean hasBlockAsFirstChild(Node node) {
    return (node.jjtGetNumChildren() != 0 && (node.jjtGetChild(0) instanceof ASTBlock));
    }
    }

     
  • Mamoon Rasheed

    Mamoon Rasheed - 2017-12-18

    @Suman I am also facing difficulty in building pmd-apex in order to develop new rule. I am getting error for pmd-apex-jorje is missing for pmd-apex module. Please let me know incase you find any solution to the same.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.