Search in sources :

Example 1 with TypeParameterListTreeImpl

use of org.sonar.java.ast.parser.TypeParameterListTreeImpl in project sonar-java by SonarSource.

the class JavaTreeModelTest method type_parameters_and_bounds.

@Test
public void type_parameters_and_bounds() {
    TypeParameterListTreeImpl tree = (TypeParameterListTreeImpl) firstType("class Foo<T, U extends Object & Number> {}").typeParameters();
    assertThat(tree.openBracketToken().text()).isEqualTo("<");
    assertThat(tree.closeBracketToken().text()).isEqualTo(">");
    assertThat(tree).hasSize(2);
    assertThat(tree.separators()).hasSize(1);
    assertThatChildrenIteratorHasSize(tree, 5);
    TypeParameterTree param = tree.get(0);
    assertThat(param.identifier().name()).isEqualTo("T");
    assertThat(param.bounds()).isEmpty();
    assertThat(param.bounds().separators()).isEmpty();
    assertThatChildrenIteratorHasSize(param, 1);
    param = tree.get(1);
    assertThat(param.identifier().name()).isEqualTo("U");
    assertThat(param.bounds()).hasSize(2);
    assertThat(param.bounds().separators()).hasSize(1);
    assertThat(((IdentifierTree) param.bounds().get(0)).name()).isEqualTo("Object");
    assertThat(((IdentifierTree) param.bounds().get(1)).name()).isEqualTo("Number");
    assertThatChildrenIteratorHasSize(param, 3);
}
Also used : TypeParameterTree(org.sonar.plugins.java.api.tree.TypeParameterTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) TypeParameterListTreeImpl(org.sonar.java.ast.parser.TypeParameterListTreeImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 TypeParameterListTreeImpl (org.sonar.java.ast.parser.TypeParameterListTreeImpl)1 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)1 TypeParameterTree (org.sonar.plugins.java.api.tree.TypeParameterTree)1