use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class RequiresDirectiveTreeImplTest 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 MethodInvocationTreeImplTest method first_token.
@Test
public void first_token() {
CompilationUnitTree cut = createTree("class A {\n" + " void bar(){\n" + " foo();\n" + " }" + "}");
ClassTree classTree = (ClassTree) cut.types().get(0);
MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) ((MethodTree) (classTree.members().get(0))).block().body().get(0)).expression();
SyntaxToken firstToken = mit.firstToken();
assertThat(firstToken.text()).isEqualTo("foo");
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class MethodInvocationTreeImplTest method first_token_with_type_arguments.
@Test
public void first_token_with_type_arguments() {
CompilationUnitTree cut = createTree("class A {\n" + " void bar(){\n" + " new A().<String>foo();\n" + " }" + " <T> void foo() {}" + "}");
ClassTree classTree = (ClassTree) cut.types().get(0);
MethodInvocationTree mit = (MethodInvocationTree) ((ExpressionStatementTree) ((MethodTree) (classTree.members().get(0))).block().body().get(0)).expression();
SyntaxToken firstToken = mit.firstToken();
assertThat(firstToken.text()).isEqualTo("new");
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class GenericsTest method treeOf.
private static CompilationUnitTree treeOf(String... lines) {
StringBuilder builder = new StringBuilder();
for (String line : lines) {
builder.append(line).append(System.lineSeparator());
}
CompilationUnitTree cut = (CompilationUnitTree) JavaParser.createParser().parse(builder.toString());
SemanticModel.createFor(cut, new SquidClassLoader(Lists.newArrayList(new File("target/test-classes"), new File("target/classes"))));
return cut;
}
Aggregations