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);
}
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(";");
}
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(";");
}
Aggregations