View Javadoc
1 package net.sourceforge.pmd.rules; 2 3 import net.sourceforge.pmd.AbstractRule; 4 import net.sourceforge.pmd.RuleContext; 5 import net.sourceforge.pmd.ast.ASTCompilationUnit; 6 import net.sourceforge.pmd.ast.ASTIfStatement; 7 8 public class AvoidDeeplyNestedIfStmtsRule extends AbstractRule { 9 10 private int depth; 11 12 public Object visit(ASTCompilationUnit node, Object data) { 13 depth = 0; 14 return super.visit(node, data); 15 } 16 17 public Object visit(ASTIfStatement node, Object data) { 18 if (!node.hasElse()) { 19 depth++; 20 } 21 super.visit(node, data); 22 if (depth == getIntProperty("problemDepth")) { 23 RuleContext ctx = (RuleContext) data; 24 ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginLine())); 25 } 26 depth--; 27 return data; 28 } 29 30 }

This page was automatically generated by Maven