Search in sources :

Example 1 with RequiresDirectiveTree

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

the class RequiresDirectiveTreeImplTest method transitive_as_name.

@Test
public void transitive_as_name() {
    RequiresDirectiveTree requires = requireDirective("requires transitive;");
    assertThat(requires.kind()).isEqualTo(Tree.Kind.REQUIRES_DIRECTIVE);
    assertThat(requires.directiveKeyword().text()).isEqualTo("requires");
    assertThat(requires.modifiers()).isEmpty();
    assertThat(requires.moduleName().stream().map(IdentifierTree::name)).containsExactly("transitive");
    assertThat(requires.semicolonToken().text()).isEqualTo(";");
}
Also used : RequiresDirectiveTree(org.sonar.plugins.java.api.tree.RequiresDirectiveTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) Test(org.junit.Test)

Example 2 with RequiresDirectiveTree

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

the class RequiresDirectiveTreeImplTest method transitive_as_name_with_static.

@Test
public void transitive_as_name_with_static() {
    RequiresDirectiveTree requires = requireDirective("requires static transitive;");
    assertThat(requires.kind()).isEqualTo(Tree.Kind.REQUIRES_DIRECTIVE);
    assertThat(requires.directiveKeyword().text()).isEqualTo("requires");
    assertThat(requires.modifiers()).hasSize(1);
    assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.STATIC)).isTrue();
    assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.TRANSITIVE)).isFalse();
    assertThat(requires.moduleName().stream().map(IdentifierTree::name)).containsExactly("transitive");
    assertThat(requires.semicolonToken().text()).isEqualTo(";");
}
Also used : RequiresDirectiveTree(org.sonar.plugins.java.api.tree.RequiresDirectiveTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) Test(org.junit.Test)

Example 3 with RequiresDirectiveTree

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

the class RequiresDirectiveTreeImplTest method requires.

@Test
public void requires() {
    RequiresDirectiveTree requires = requireDirective("requires static transitive foo.bar;");
    assertThat(requires.kind()).isEqualTo(Tree.Kind.REQUIRES_DIRECTIVE);
    assertThat(requires.directiveKeyword().text()).isEqualTo("requires");
    assertThat(requires.modifiers()).hasSize(2);
    assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.STATIC)).isTrue();
    assertThat(ModifiersUtils.hasModifier(requires.modifiers(), Modifier.TRANSITIVE)).isTrue();
    ModuleNameTree moduleName = requires.moduleName();
    assertThat(moduleName).hasSize(2);
    assertThat(moduleName.stream().map(IdentifierTree::name)).containsExactly("foo", "bar");
    assertThat(moduleName.separators()).hasSize(1);
    assertThat(requires.semicolonToken().text()).isEqualTo(";");
}
Also used : RequiresDirectiveTree(org.sonar.plugins.java.api.tree.RequiresDirectiveTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)3 RequiresDirectiveTree (org.sonar.plugins.java.api.tree.RequiresDirectiveTree)3 ModuleNameTree (org.sonar.plugins.java.api.tree.ModuleNameTree)1