Search in sources :

Example 1 with ExportsDirectiveTree

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

the class ExportsDirectiveTreeImplTest method exportsDirective.

private ExportsDirectiveTree exportsDirective(String exportsDirective) {
    CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n  " + exportsDirective + "\n}");
    SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
    return (ExportsDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) ExportsDirectiveTree(org.sonar.plugins.java.api.tree.ExportsDirectiveTree) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

Example 2 with ExportsDirectiveTree

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

the class ExportsDirectiveTreeImplTest method simple_exports.

@Test
public void simple_exports() {
    ExportsDirectiveTree exports = exportsDirective("exports foo;");
    assertThat(exports.kind()).isEqualTo(Tree.Kind.EXPORTS_DIRECTIVE);
    assertThat(exports.directiveKeyword().text()).isEqualTo("exports");
    assertThat(((IdentifierTree) exports.packageName()).name()).isEqualTo("foo");
    assertThat(exports.toKeyword()).isNull();
    assertThat(exports.moduleNames()).isEmpty();
    assertThat(exports.semicolonToken().text()).isEqualTo(";");
}
Also used : IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) ExportsDirectiveTree(org.sonar.plugins.java.api.tree.ExportsDirectiveTree) Test(org.junit.Test)

Example 3 with ExportsDirectiveTree

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

the class ExportsDirectiveTreeImplTest method exports_with_modules.

@Test
public void exports_with_modules() {
    ExportsDirectiveTree exports = exportsDirective("exports org.foo to com.module1, module2;");
    assertThat(exports.kind()).isEqualTo(Tree.Kind.EXPORTS_DIRECTIVE);
    assertThat(exports.directiveKeyword().text()).isEqualTo("exports");
    ExpressionTree packageName = exports.packageName();
    assertThat(packageName.is(Tree.Kind.MEMBER_SELECT)).isTrue();
    MemberSelectExpressionTree mset = (MemberSelectExpressionTree) packageName;
    assertThat(((IdentifierTree) mset.expression()).name()).isEqualTo("org");
    assertThat(mset.identifier().name()).isEqualTo("foo");
    assertThat(exports.toKeyword().text()).isEqualTo("to");
    ListTree<ModuleNameTree> moduleNames = exports.moduleNames();
    assertThat(moduleNames).hasSize(2);
    assertThat(moduleNames.get(0).stream().map(IdentifierTree::name)).containsExactly("com", "module1");
    assertThat(moduleNames.separators()).hasSize(1);
    assertThat(moduleNames.separators().iterator().next().text()).isEqualTo(",");
    assertThat(moduleNames.get(1).stream().map(IdentifierTree::name)).containsExactly("module2");
    assertThat(exports.semicolonToken().text()).isEqualTo(";");
}
Also used : MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) MemberSelectExpressionTree(org.sonar.plugins.java.api.tree.MemberSelectExpressionTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) ExportsDirectiveTree(org.sonar.plugins.java.api.tree.ExportsDirectiveTree) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree) Test(org.junit.Test)

Aggregations

ExportsDirectiveTree (org.sonar.plugins.java.api.tree.ExportsDirectiveTree)3 Test (org.junit.Test)2 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)2 SquidClassLoader (org.sonar.java.bytecode.loader.SquidClassLoader)1 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)1 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)1 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)1 ModuleNameTree (org.sonar.plugins.java.api.tree.ModuleNameTree)1