Search in sources :

Example 1 with EnumConstantTree

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);
}
Also used : ImportClauseTree(org.sonar.plugins.java.api.tree.ImportClauseTree) BlockTree(org.sonar.plugins.java.api.tree.BlockTree) CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) SynchronizedStatementTree(org.sonar.plugins.java.api.tree.SynchronizedStatementTree) StaticInitializerTree(org.sonar.plugins.java.api.tree.StaticInitializerTree) TryStatementTree(org.sonar.plugins.java.api.tree.TryStatementTree) IfStatementTree(org.sonar.plugins.java.api.tree.IfStatementTree) CaseLabelTree(org.sonar.plugins.java.api.tree.CaseLabelTree) UnionTypeTree(org.sonar.plugins.java.api.tree.UnionTypeTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) ArrayTypeTree(org.sonar.plugins.java.api.tree.ArrayTypeTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) NewArrayTree(org.sonar.plugins.java.api.tree.NewArrayTree) ContinueStatementTree(org.sonar.plugins.java.api.tree.ContinueStatementTree) ExpressionStatementTree(org.sonar.plugins.java.api.tree.ExpressionStatementTree) ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) StatementTree(org.sonar.plugins.java.api.tree.StatementTree) TypeCastTree(org.sonar.plugins.java.api.tree.TypeCastTree) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) AssignmentExpressionTree(org.sonar.plugins.java.api.tree.AssignmentExpressionTree) ClassTree(org.sonar.plugins.java.api.tree.ClassTree) UnaryExpressionTree(org.sonar.plugins.java.api.tree.UnaryExpressionTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) PackageDeclarationTree(org.sonar.plugins.java.api.tree.PackageDeclarationTree) WildcardTree(org.sonar.plugins.java.api.tree.WildcardTree) LabeledStatementTree(org.sonar.plugins.java.api.tree.LabeledStatementTree) BreakStatementTree(org.sonar.plugins.java.api.tree.BreakStatementTree) ThrowStatementTree(org.sonar.plugins.java.api.tree.ThrowStatementTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) ForStatementTree(org.sonar.plugins.java.api.tree.ForStatementTree) ParenthesizedTree(org.sonar.plugins.java.api.tree.ParenthesizedTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) SwitchStatementTree(org.sonar.plugins.java.api.tree.SwitchStatementTree) ArrayDimensionTree(org.sonar.plugins.java.api.tree.ArrayDimensionTree) AssertStatementTree(org.sonar.plugins.java.api.tree.AssertStatementTree) EnumConstantTree(org.sonar.plugins.java.api.tree.EnumConstantTree) MethodReferenceTree(org.sonar.plugins.java.api.tree.MethodReferenceTree) AnnotationTree(org.sonar.plugins.java.api.tree.AnnotationTree) BinaryExpressionTree(org.sonar.plugins.java.api.tree.BinaryExpressionTree) ReturnStatementTree(org.sonar.plugins.java.api.tree.ReturnStatementTree) LiteralTree(org.sonar.plugins.java.api.tree.LiteralTree) ConditionalExpressionTree(org.sonar.plugins.java.api.tree.ConditionalExpressionTree) ImportTree(org.sonar.plugins.java.api.tree.ImportTree) PrimitiveTypeTree(org.sonar.plugins.java.api.tree.PrimitiveTypeTree) ModifierKeywordTree(org.sonar.plugins.java.api.tree.ModifierKeywordTree) TypeParameterTree(org.sonar.plugins.java.api.tree.TypeParameterTree) CaseGroupTree(org.sonar.plugins.java.api.tree.CaseGroupTree) Tree(org.sonar.plugins.java.api.tree.Tree) ArrayAccessExpressionTree(org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree) WhileStatementTree(org.sonar.plugins.java.api.tree.WhileStatementTree) EmptyStatementTree(org.sonar.plugins.java.api.tree.EmptyStatementTree) MethodInvocationTree(org.sonar.plugins.java.api.tree.MethodInvocationTree) DoWhileStatementTree(org.sonar.plugins.java.api.tree.DoWhileStatementTree) LambdaExpressionTree(org.sonar.plugins.java.api.tree.LambdaExpressionTree) InstanceOfTree(org.sonar.plugins.java.api.tree.InstanceOfTree) CatchTree(org.sonar.plugins.java.api.tree.CatchTree) MethodTree(org.sonar.plugins.java.api.tree.MethodTree) NewClassTree(org.sonar.plugins.java.api.tree.NewClassTree) EnumConstantTree(org.sonar.plugins.java.api.tree.EnumConstantTree) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 AnnotationTree (org.sonar.plugins.java.api.tree.AnnotationTree)1 ArrayAccessExpressionTree (org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree)1 ArrayDimensionTree (org.sonar.plugins.java.api.tree.ArrayDimensionTree)1 ArrayTypeTree (org.sonar.plugins.java.api.tree.ArrayTypeTree)1 AssertStatementTree (org.sonar.plugins.java.api.tree.AssertStatementTree)1 AssignmentExpressionTree (org.sonar.plugins.java.api.tree.AssignmentExpressionTree)1 BinaryExpressionTree (org.sonar.plugins.java.api.tree.BinaryExpressionTree)1 BlockTree (org.sonar.plugins.java.api.tree.BlockTree)1 BreakStatementTree (org.sonar.plugins.java.api.tree.BreakStatementTree)1 CaseGroupTree (org.sonar.plugins.java.api.tree.CaseGroupTree)1 CaseLabelTree (org.sonar.plugins.java.api.tree.CaseLabelTree)1 CatchTree (org.sonar.plugins.java.api.tree.CatchTree)1 ClassTree (org.sonar.plugins.java.api.tree.ClassTree)1 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)1 ConditionalExpressionTree (org.sonar.plugins.java.api.tree.ConditionalExpressionTree)1 ContinueStatementTree (org.sonar.plugins.java.api.tree.ContinueStatementTree)1 DoWhileStatementTree (org.sonar.plugins.java.api.tree.DoWhileStatementTree)1 EmptyStatementTree (org.sonar.plugins.java.api.tree.EmptyStatementTree)1 EnumConstantTree (org.sonar.plugins.java.api.tree.EnumConstantTree)1