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