private void visitIfStatementNode(AstNode node) { if (checkedIfStatements.contains(node)) { return; } List<AstNode> branchNodes = Lists.newArrayList(); AstNode ifNode = node; while (ifNode != null) { checkedIfStatements.add(ifNode); branchNodes.add(ifNode.getFirstChild(ifBranchNodeType())); AstSelect elseIfNodes = ifNode .select() .children(PHPGrammar.ELSEIF_LIST) .children(PHPGrammar.ELSEIF_CLAUSE) .children(ifBranchNodeType()); for (AstNode condition : elseIfNodes) { branchNodes.add(condition); } AstSelect elseNodes = ifNode.select().children(PHPGrammar.ELSE_CLAUSE); for (AstNode elseNode : elseNodes.children(ifBranchNodeType())) { branchNodes.add(elseNode); } AstSelect elseIfs = elseNodes.children(PHPGrammar.STATEMENT).children(PHPGrammar.IF_STATEMENT); ifNode = elseIfs.isEmpty() ? null : elseIfs.get(0); } checkBranches(branchNodes, "branch"); }
@Override public void visitNode(AstNode suiteNode) { if (suiteNode.getParent().is(PythonGrammar.FUNCDEF, PythonGrammar.CLASSDEF) || isInExcept(suiteNode)) { return; } AstSelect suite = suiteNode.select(); AstSelect stmtLists = suite.children(PythonGrammar.STMT_LIST); if (stmtLists.isEmpty()) { AstSelect statementSelect = suite.children(PythonGrammar.STATEMENT); if (statementSelect.children(PythonGrammar.COMPOUND_STMT).isNotEmpty()) { return; } stmtLists = statementSelect.children(PythonGrammar.STMT_LIST); } AstSelect nonPassSimpleStatements = stmtLists.children(PythonGrammar.SIMPLE_STMT).children().filter(NOT_PASS_PREDICATE); if (nonPassSimpleStatements.isEmpty() && !containsComment(suiteNode)) { getContext().createLineViolation(this, MESSAGE, stmtLists.get(0)); } }