Search in sources :

Example 1 with UsesDirectiveTree

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

the class UsesDirectiveTreeImplTest method moduleDirective.

private UsesDirectiveTree moduleDirective(String exportsDirective) {
    CompilationUnitTree compilationUnitTree = createTree("module org.foo {\n  " + exportsDirective + "\n}");
    SemanticModel.createFor(compilationUnitTree, new SquidClassLoader(Collections.emptyList()));
    return (UsesDirectiveTree) compilationUnitTree.moduleDeclaration().moduleDirectives().get(0);
}
Also used : CompilationUnitTree(org.sonar.plugins.java.api.tree.CompilationUnitTree) UsesDirectiveTree(org.sonar.plugins.java.api.tree.UsesDirectiveTree) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader)

Example 2 with UsesDirectiveTree

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

the class UsesDirectiveTreeImplTest method simple_uses.

@Test
public void simple_uses() {
    UsesDirectiveTree exports = moduleDirective("uses foo.MyInterface;");
    assertThat(exports.kind()).isEqualTo(Tree.Kind.USES_DIRECTIVE);
    assertThat(exports.directiveKeyword().text()).isEqualTo("uses");
    TypeTree typeName = exports.typeName();
    assertThat(typeName.is(Tree.Kind.MEMBER_SELECT)).isTrue();
    assertThat(((MemberSelectExpressionTree) typeName).identifier().name()).isEqualTo("MyInterface");
    assertThat(exports.semicolonToken().text()).isEqualTo(";");
}
Also used : TypeTree(org.sonar.plugins.java.api.tree.TypeTree) UsesDirectiveTree(org.sonar.plugins.java.api.tree.UsesDirectiveTree) Test(org.junit.Test)

Aggregations

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