Search in sources :

Example 1 with ModuleDeclarationTree

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

the class TreeFactory method newCompilationUnit.

// End of literals
// Compilation unit
public CompilationUnitTreeImpl newCompilationUnit(JavaTree spacing, Optional<PackageDeclarationTree> packageDeclaration, Optional<List<ImportClauseTree>> importDeclarations, Optional<ModuleDeclarationTree> moduleDeclaration, Optional<List<Tree>> typeDeclarations, InternalSyntaxToken eof) {
    ImmutableList.Builder<ImportClauseTree> imports = ImmutableList.builder();
    if (importDeclarations.isPresent()) {
        for (ImportClauseTree child : importDeclarations.get()) {
            imports.add(child);
        }
    }
    ImmutableList.Builder<Tree> types = ImmutableList.builder();
    if (typeDeclarations.isPresent()) {
        for (Tree child : typeDeclarations.get()) {
            types.add(child);
        }
    }
    return new CompilationUnitTreeImpl(packageDeclaration.orNull(), imports.build(), types.build(), moduleDeclaration.orNull(), eof);
}
Also used : CompilationUnitTreeImpl(org.sonar.java.model.JavaTree.CompilationUnitTreeImpl) ImportClauseTree(org.sonar.plugins.java.api.tree.ImportClauseTree) ImmutableList(com.google.common.collect.ImmutableList) ImportClauseTree(org.sonar.plugins.java.api.tree.ImportClauseTree) ModuleNameTree(org.sonar.plugins.java.api.tree.ModuleNameTree) ParameterizedTypeTree(org.sonar.plugins.java.api.tree.ParameterizedTypeTree) ExpressionTree(org.sonar.plugins.java.api.tree.ExpressionTree) VariableTree(org.sonar.plugins.java.api.tree.VariableTree) ArrayDimensionTree(org.sonar.plugins.java.api.tree.ArrayDimensionTree) Tree(org.sonar.plugins.java.api.tree.Tree) ListTree(org.sonar.plugins.java.api.tree.ListTree) TypeTree(org.sonar.plugins.java.api.tree.TypeTree) JavaTree(org.sonar.java.model.JavaTree) StatementTree(org.sonar.plugins.java.api.tree.StatementTree) ModifierTree(org.sonar.plugins.java.api.tree.ModifierTree) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) PackageDeclarationTree(org.sonar.plugins.java.api.tree.PackageDeclarationTree) AnnotationTree(org.sonar.plugins.java.api.tree.AnnotationTree) TypeParameterTree(org.sonar.plugins.java.api.tree.TypeParameterTree) ModuleDirectiveTree(org.sonar.plugins.java.api.tree.ModuleDirectiveTree) ModuleDeclarationTree(org.sonar.plugins.java.api.tree.ModuleDeclarationTree)

Example 2 with ModuleDeclarationTree

use of org.sonar.plugins.java.api.tree.ModuleDeclarationTree 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)

Aggregations

IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)2 ModuleDeclarationTree (org.sonar.plugins.java.api.tree.ModuleDeclarationTree)2 ModuleNameTree (org.sonar.plugins.java.api.tree.ModuleNameTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 Test (org.junit.Test)1 JavaTree (org.sonar.java.model.JavaTree)1 CompilationUnitTreeImpl (org.sonar.java.model.JavaTree.CompilationUnitTreeImpl)1 AnnotationTree (org.sonar.plugins.java.api.tree.AnnotationTree)1 ArrayDimensionTree (org.sonar.plugins.java.api.tree.ArrayDimensionTree)1 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)1 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)1 ImportClauseTree (org.sonar.plugins.java.api.tree.ImportClauseTree)1 ListTree (org.sonar.plugins.java.api.tree.ListTree)1 ModifierTree (org.sonar.plugins.java.api.tree.ModifierTree)1 ModuleDirectiveTree (org.sonar.plugins.java.api.tree.ModuleDirectiveTree)1 PackageDeclarationTree (org.sonar.plugins.java.api.tree.PackageDeclarationTree)1 ParameterizedTypeTree (org.sonar.plugins.java.api.tree.ParameterizedTypeTree)1 StatementTree (org.sonar.plugins.java.api.tree.StatementTree)1 Tree (org.sonar.plugins.java.api.tree.Tree)1 TypeParameterTree (org.sonar.plugins.java.api.tree.TypeParameterTree)1