### Question:
StatementsVisitor extends TreeVisitor<TreeContext> { public int statements(Tree tree) { statements = 0; scan(new TreeContext(), tree); return statements; } StatementsVisitor(); int statements(Tree tree);  }### Answer:
@Test public void should_count_top_level_without_natives_and_blocks() throws Exception { String content = "" + "package abc;" + "import xyz;" + "native[] { };" + "foo;" + "class A{};" + "if (a) {};" + "fun foo() {};" + "{};"; assertThat(statements(content)).isEqualTo(2); }
@Test public void should_count_statements_inside_blocks() throws Exception { String content = "fun foo() {" + "native[] { };" + "foo;" + "if (a) { foo; bar; };" + "class A{};" + "fun bar(){};" + "};" + "{ 2; 3; };"; assertThat(statements(content)).isEqualTo(7); }