use of org.sonar.plugins.java.api.tree.EnumConstantTree in project sonar-java by SonarSource.
the class JavaTreeModelTest method enum_constant.
@Test
public void enum_constant() {
List<Tree> declarations = firstType("enum T { C1, C2(2) { }; }").members();
assertThat(declarations).hasSize(2);
EnumConstantTree tree = (EnumConstantTree) declarations.get(0);
assertThat(tree.is(Tree.Kind.ENUM_CONSTANT)).isTrue();
assertThat(tree.simpleName().name()).isEqualTo("C1");
assertThat(tree.separatorToken().text()).isEqualTo(",");
assertThatChildrenIteratorHasSize(tree, 3);
NewClassTree newClassTree = tree.initializer();
assertThat(newClassTree.arguments()).isEmpty();
assertThat(newClassTree.classBody()).isNull();
assertThat(newClassTree.newKeyword()).isNull();
assertThatChildrenIteratorHasSize(newClassTree, 2);
tree = (EnumConstantTree) declarations.get(1);
assertThat(tree.is(Tree.Kind.ENUM_CONSTANT)).isTrue();
assertThat(tree.simpleName().name()).isEqualTo("C2");
assertThat(tree.separatorToken().text()).isEqualTo(";");
assertThatChildrenIteratorHasSize(tree, 3);
newClassTree = tree.initializer();
assertThat(newClassTree.arguments().openParenToken()).isNotNull();
assertThat(newClassTree.arguments()).hasSize(1);
assertThat(newClassTree.arguments().closeParenToken()).isNotNull();
assertThat(newClassTree.classBody()).isNotNull();
assertThat(newClassTree.classBody().openBraceToken().text()).isEqualTo("{");
assertThat(newClassTree.newKeyword()).isNull();
assertThatChildrenIteratorHasSize(newClassTree, 3);
}
Aggregations