Search in sources :

Example 1 with StaticInitializerTree

use of org.sonar.plugins.java.api.tree.StaticInitializerTree in project sonar-java by SonarSource.

the class JavaTreeModelTest method class_init_declaration.

@Test
public void class_init_declaration() {
    BlockTree tree = (BlockTree) firstTypeMember("class T { { ; ; } }");
    assertThat(tree.is(Tree.Kind.INITIALIZER)).isTrue();
    assertThat(tree.body()).hasSize(2);
    assertThat(tree.openBraceToken().text()).isEqualTo("{");
    assertThat(tree.closeBraceToken().text()).isEqualTo("}");
    assertThatChildrenIteratorHasSize(tree, 4);
    tree = (BlockTree) firstTypeMember("class T { static { ; ; } }");
    assertThat(tree.is(Tree.Kind.STATIC_INITIALIZER)).isTrue();
    StaticInitializerTree staticInitializerTree = (StaticInitializerTree) tree;
    assertThat(staticInitializerTree.body()).hasSize(2);
    assertThat(staticInitializerTree.staticKeyword().text()).isEqualTo("static");
    assertThat(staticInitializerTree.openBraceToken().text()).isEqualTo("{");
    assertThat(staticInitializerTree.closeBraceToken().text()).isEqualTo("}");
    assertThatChildrenIteratorHasSize(tree, 5);
}
Also used : StaticInitializerTree(org.sonar.plugins.java.api.tree.StaticInitializerTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree) Test(org.junit.Test)

Example 2 with StaticInitializerTree

use of org.sonar.plugins.java.api.tree.StaticInitializerTree in project sonar-java by SonarSource.

the class LeftCurlyBraceBaseTreeVisitor method visitBlock.

@Override
public void visitBlock(BlockTree tree) {
    if (tree.is(Tree.Kind.STATIC_INITIALIZER)) {
        StaticInitializerTree staticInitializerTree = (StaticInitializerTree) tree;
        checkTokens(staticInitializerTree.staticKeyword(), staticInitializerTree.openBraceToken());
    }
    super.visitBlock(tree);
}
Also used : StaticInitializerTree(org.sonar.plugins.java.api.tree.StaticInitializerTree)

Aggregations

StaticInitializerTree (org.sonar.plugins.java.api.tree.StaticInitializerTree)2 Test (org.junit.Test)1 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)1