use of org.sonar.plugins.java.api.tree.CompilationUnitTree 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.CompilationUnitTree in project sonar-java by SonarSource.
the class ModuleDeclarationTreeImplTest method test_BaseTreeVisitor.
@Test
public void test_BaseTreeVisitor() {
CompilationUnitTree cut = createTree("import org.foo.Bar;", "", "@Bar", "open module com.greetings {", "}");
ModuleDeclarationVisitor moduleDeclarationVisitor = new ModuleDeclarationVisitor();
cut.accept(moduleDeclarationVisitor);
assertThat(moduleDeclarationVisitor.visited).isTrue();
assertThat(moduleDeclarationVisitor.annotations).hasSize(1);
AnnotationTree annotation = moduleDeclarationVisitor.annotations.iterator().next();
assertThat(((IdentifierTree) annotation.annotationType()).name()).isEqualTo("Bar");
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ModuleDeclarationTreeImplTest method createTree.
private CompilationUnitTree createTree(String... lines) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(Arrays.stream(lines).collect(Collectors.joining("\n")));
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return compilationUnitTree;
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ProvidesDirectiveTreeImplTest method createTree.
private CompilationUnitTree createTree(String... lines) {
CompilationUnitTree compilationUnitTree = (CompilationUnitTree) p.parse(Arrays.stream(lines).collect(Collectors.joining("\n")));
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return compilationUnitTree;
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ProvidesDirectiveTreeImplTest method test_BaseTreeVisitor.
@Test
public void test_BaseTreeVisitor() {
CompilationUnitTree cut = createTree("import org.foo.Bar;", "", "@Bar", "open module com.greetings {", " exports org.bar to com.module1, module2;", " provides org.MyInterface with com.MyInterface, MyInterface2;", "}");
ProvidesDirectiveVisitor moduleDeclarationVisitor = new ProvidesDirectiveVisitor();
cut.accept(moduleDeclarationVisitor);
assertThat(moduleDeclarationVisitor.visited).isTrue();
assertThat(moduleDeclarationVisitor.directives).hasSize(1);
assertThat(moduleDeclarationVisitor.identifiers).containsExactly("Bar", "Bar", "com", "greetings", "MyInterface", "MyInterface", "MyInterface2");
}
Aggregations