ComplexityVisitor extends BaseTreeVisitor { public static int complexity(Tree pyTree) { ComplexityVisitor visitor = pyTree.is(Tree.Kind.FUNCDEF) ? new FunctionComplexityVisitor() : new ComplexityVisitor(); pyTree.accept(visitor); return visitor.complexity; }  static int complexity(Tree pyTree); @Override void visitFunctionDef(FunctionDef pyFunctionDefTree); @Override void visitForStatement(ForStatement pyForStatementTree); @Override void visitWhileStatement(WhileStatement pyWhileStatementTree); @Override void visitIfStatement(IfStatement pyIfStatementTree); @Override void visitConditionalExpression(ConditionalExpression pyConditionalExpressionTree); @Override void visitBinaryExpression(BinaryExpression pyBinaryExpressionTree); @Override void visitComprehensionIf(ComprehensionIf tree); int getComplexity();  }
@Test public void pass_keyword() { assertThat(complexity("pass")).isEqualTo(0); }
@Test public void if_keyword() { assertThat(complexity("if x: pass")).isEqualTo(1); }
@Test public void and_keyword() { assertThat(complexity("x = a and b and c")).isEqualTo(2); }
@Test public void or_keyword() { assertThat(complexity("x = a or b or c")).isEqualTo(2); }
@Test public void funcdef() { assertThat(complexity("def f(): pass")).isEqualTo(1); }
@Test public void while_statement() { assertThat(complexity("while(x): pass")).isEqualTo(1); }
@Test public void for_statement() { assertThat(complexity("for i in list: pass")).isEqualTo(1); }