@Override public void leaveNode(AstNode astNode) { if (astNode.is(PythonGrammar.FUNCDEF, PythonGrammar.CLASSDEF)) { nestingLevelStack.pop(); } else if (astNode.is(PythonGrammar.SUITE)) { if (isSuiteIncrementsNestingLevel(astNode)) { nestingLevelStack.peek().decrement(); } } else if (astNode.is(PythonGrammar.TEST) && astNode.hasDirectChildren(PythonKeyword.IF)) { // conditional expression nestingLevelStack.peek().decrement(); } }
@Override public void leaveNode(AstNode astNode) { if (astNode.is(PythonGrammar.FUNCDEF, PythonGrammar.CLASSDEF)) { nestingLevelStack.pop(); } else if (astNode.is(PythonGrammar.SUITE)) { if (isSuiteIncrementsNestingLevel(astNode)) { nestingLevelStack.peek().decrement(); } } else if (astNode.is(PythonGrammar.TEST) && astNode.hasDirectChildren(PythonKeyword.IF)) { // conditional expression nestingLevelStack.peek().decrement(); } }
@Override public void visitNode(AstNode astNode) { if (astNode.is(PythonGrammar.FUNCDEF, PythonGrammar.CLASSDEF)) { nestingLevelStack.push(new NestingLevel(nestingLevelStack.peek(), astNode)); } else if (astNode.is(PythonGrammar.SUITE)) { if (isSuiteIncrementsNestingLevel(astNode)) { nestingLevelStack.peek().increment(); } } else if (astNode.is(PythonGrammar.IF_STMT, PythonGrammar.WHILE_STMT, PythonGrammar.FOR_STMT, PythonGrammar.EXCEPT_CLAUSE)) { incrementWithNesting(astNode.getFirstChild()); } else if (astNode.is(PythonKeyword.ELIF) || (astNode.is(PythonKeyword.ELSE) && astNode.getNextSibling().is(PythonPunctuator.COLON))) { incrementWithoutNesting(astNode); } else if (astNode.is(PythonGrammar.AND_TEST, PythonGrammar.OR_TEST)) { incrementWithoutNesting(astNode.getFirstChild(PythonKeyword.AND, PythonKeyword.OR)); } else if (astNode.is(PythonGrammar.TEST) && astNode.hasDirectChildren(PythonKeyword.IF)) { // conditional expression incrementWithNesting(astNode.getFirstChild(PythonKeyword.IF)); nestingLevelStack.peek().increment(); } }
@Override public void visitNode(AstNode astNode) { if (astNode.is(PythonGrammar.FUNCDEF, PythonGrammar.CLASSDEF)) { nestingLevelStack.push(new NestingLevel(nestingLevelStack.peek(), astNode)); } else if (astNode.is(PythonGrammar.SUITE)) { if (isSuiteIncrementsNestingLevel(astNode)) { nestingLevelStack.peek().increment(); } } else if (astNode.is(PythonGrammar.IF_STMT, PythonGrammar.WHILE_STMT, PythonGrammar.FOR_STMT, PythonGrammar.EXCEPT_CLAUSE)) { incrementWithNesting(astNode.getFirstChild()); } else if (astNode.is(PythonKeyword.ELIF) || (astNode.is(PythonKeyword.ELSE) && astNode.getNextSibling().is(PythonPunctuator.COLON))) { incrementWithoutNesting(astNode); } else if (astNode.is(PythonGrammar.AND_TEST, PythonGrammar.OR_TEST)) { incrementWithoutNesting(astNode.getFirstChild(PythonKeyword.AND, PythonKeyword.OR)); } else if (astNode.is(PythonGrammar.TEST) && astNode.hasDirectChildren(PythonKeyword.IF)) { // conditional expression incrementWithNesting(astNode.getFirstChild(PythonKeyword.IF)); nestingLevelStack.peek().increment(); } }