use of org.sonar.plugins.java.api.tree.ProvidesDirectiveTree in project sonar-java by SonarSource.
the class ProvidesDirectiveTreeImplTest method providesDirective.
private ProvidesDirectiveTree providesDirective(String exportsDirective) {
CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n " + exportsDirective + "\n}");
SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
return (ProvidesDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
use of org.sonar.plugins.java.api.tree.ProvidesDirectiveTree in project sonar-java by SonarSource.
the class ProvidesDirectiveTreeImplTest method provides_with_modules.
@Test
public void provides_with_modules() {
ProvidesDirectiveTree exports = providesDirective("provides org.MyInterface with com.MyInterface, MyInterface2;");
assertThat(exports.kind()).isEqualTo(Tree.Kind.PROVIDES_DIRECTIVE);
assertThat(exports.directiveKeyword().text()).isEqualTo("provides");
TypeTree typeName = exports.typeName();
assertThat(typeName.is(Tree.Kind.MEMBER_SELECT)).isTrue();
MemberSelectExpressionTree mset = (MemberSelectExpressionTree) typeName;
assertThat(((IdentifierTree) mset.expression()).name()).isEqualTo("org");
assertThat(mset.identifier().name()).isEqualTo("MyInterface");
assertThat(exports.withKeyword().text()).isEqualTo("with");
ListTree<TypeTree> typeNames = exports.typeNames();
assertThat(typeNames).hasSize(2);
assertThat(((MemberSelectExpressionTree) typeNames.get(0)).identifier().name()).isEqualTo("MyInterface");
assertThat(typeNames.separators()).hasSize(1);
assertThat(typeNames.separators().iterator().next().text()).isEqualTo(",");
assertThat(((IdentifierTree) typeNames.get(1)).name()).isEqualTo("MyInterface2");
assertThat(exports.semicolonToken().text()).isEqualTo(";");
}
Aggregations