Search in sources :

Example 1 with ProvidesDirectiveTree

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);
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) ProvidesDirectiveTree(org.sonar.plugins.java.api.tree.ProvidesDirectiveTree) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

Example 2 with ProvidesDirectiveTree

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

Aggregations

ProvidesDirectiveTree (org.sonar.plugins.java.api.tree.ProvidesDirectiveTree)2 Test (org.junit.Test)1 SquidClassLoader (org.sonar.java.bytecode.loader.SquidClassLoader)1 CompilationUnitTree (org.sonar.plugins.java.api.tree.CompilationUnitTree)1 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)1 MemberSelectExpressionTree (org.sonar.plugins.java.api.tree.MemberSelectExpressionTree)1 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)1