use of org.sonar.plugins.java.api.tree.ModuleNameTree 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(";");
}
use of org.sonar.plugins.java.api.tree.ModuleNameTree in project sonar-java by SonarSource.
the class OpensDirectiveTreeImplTest method opens_with_modules.
@Test
public void opens_with_modules() {
OpensDirectiveTree exports = moduleDirective("opens org.foo to com.module1, module2;");
assertThat(exports.kind()).isEqualTo(Tree.Kind.OPENS_DIRECTIVE);
assertThat(exports.directiveKeyword().text()).isEqualTo("opens");
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(";");
}
use of org.sonar.plugins.java.api.tree.ModuleNameTree 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(";");
}
use of org.sonar.plugins.java.api.tree.ModuleNameTree in project sonar-java by SonarSource.
the class ModuleDeclarationTreeImplTest method with_module.
@Test
public void with_module() {
CompilationUnitTree cut = createTree("module org.foo { }");
ModuleDeclarationTree moduleDeclaration = cut.moduleDeclaration();
assertThat(moduleDeclaration).isNotNull();
assertThat(moduleDeclaration.is(Tree.Kind.MODULE)).isTrue();
assertThat(moduleDeclaration.openKeyword()).isNull();
assertThat(moduleDeclaration.moduleKeyword().text()).isEqualTo("module");
assertThat(moduleDeclaration.moduleDirectives()).isEmpty();
ModuleNameTree moduleName = moduleDeclaration.moduleName();
assertThat(moduleName).hasSize(2);
assertThat(moduleName.stream().map(IdentifierTree::name)).containsExactly("org", "foo");
assertThat(moduleDeclaration.openBraceToken().text()).isEqualTo("{");
assertThat(moduleDeclaration.closeBraceToken().text()).isEqualTo("}");
}
use of org.sonar.plugins.java.api.tree.ModuleNameTree in project sonar-java by SonarSource.
the class TreeFactory method newOpensModuleDirective.
public ModuleDirectiveTree newOpensModuleDirective(InternalSyntaxToken opensKeyword, ExpressionTree packageName, Optional<Tuple<InternalSyntaxToken, ListTreeImpl<ModuleNameTree>>> moduleNames, InternalSyntaxToken semicolonToken) {
InternalSyntaxToken toKeyword = null;
ListTreeImpl<ModuleNameTree> otherModuleNames = ModuleNameListTreeImpl.emptyList();
if (moduleNames.isPresent()) {
Tuple<InternalSyntaxToken, ListTreeImpl<ModuleNameTree>> toModuleNames = moduleNames.get();
toKeyword = toModuleNames.first();
otherModuleNames = toModuleNames.second();
}
return new OpensDirectiveTreeImpl(opensKeyword, packageName, toKeyword, otherModuleNames, semicolonToken);
}
Aggregations