Search in sources :

Example 1 with ModuleNameTree

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

Example 2 with ModuleNameTree

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(";");
}
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) OpensDirectiveTree(org.sonar.plugins.java.api.tree.OpensDirectiveTree) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree) Test(org.junit.Test)

Example 3 with ModuleNameTree

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

Example 4 with ModuleNameTree

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("}");
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) ModuleDeclarationTree(org.sonar.plugins.java.api.tree.ModuleDeclarationTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree) Test(org.junit.Test)

Example 5 with ModuleNameTree

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);
}
Also used : ModuleNameListTreeImpl(org.sonar.java.model.declaration.ModuleNameListTreeImpl) TypeArgumentListTreeImpl(org.sonar.java.model.expression.TypeArgumentListTreeImpl) OpensDirectiveTreeImpl(org.sonar.java.model.declaration.OpensDirectiveTreeImpl) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree)

Aggregations

ModuleNameTree (org.sonar.plugins.java.api.tree.ModuleNameTree)6 Test (org.junit.Test)4 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)4 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)2 ModuleNameListTreeImpl (org.sonar.java.model.declaration.ModuleNameListTreeImpl)2 TypeArgumentListTreeImpl (org.sonar.java.model.expression.TypeArgumentListTreeImpl)2 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)2 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)2 ExportsDirectiveTreeImpl (org.sonar.java.model.declaration.ExportsDirectiveTreeImpl)1 OpensDirectiveTreeImpl (org.sonar.java.model.declaration.OpensDirectiveTreeImpl)1 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)1 ExportsDirectiveTree (org.sonar.plugins.java.api.tree.ExportsDirectiveTree)1 ModuleDeclarationTree (org.sonar.plugins.java.api.tree.ModuleDeclarationTree)1 OpensDirectiveTree (org.sonar.plugins.java.api.tree.OpensDirectiveTree)1 RequiresDirectiveTree (org.sonar.plugins.java.api.tree.RequiresDirectiveTree)1