use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method typeOf.
private JavaType typeOf(String input) {
SemanticModel semanticModel = mock(SemanticModel.class);
when(semanticModel.getEnv(any(Tree.class))).thenReturn(env);
TypeAndReferenceSolver visitor = new TypeAndReferenceSolver(semanticModel, symbols, new Resolve(symbols, bytecodeCompleter, parametrizedTypeCache), parametrizedTypeCache);
String p = "class Test { void wrapperMethod() { " + input + "; } }";
CompilationUnitTree tree = parse(p);
tree.accept(visitor);
TestedNodeExtractor testedNodeExtractor = new TestedNodeExtractor(false);
testedNodeExtractor.visitCompilationUnit(tree);
return visitor.getType(((ExpressionStatementTree) testedNodeExtractor.testedNode).expression());
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ComplexityVisitorTest method lambda_complexity.
@Test
public void lambda_complexity() throws Exception {
CompilationUnitTree cut = (CompilationUnitTree) p.parse("class A { Function f = s -> {if(s.isEmpty()) return s; return new MyClass(){ void foo(){if(a) return;} };};}");
ExpressionTree lambda = ((VariableTree) ((ClassTree) cut.types().get(0)).members().get(0)).initializer();
List<Tree> nodes = new ComplexityVisitor().getNodes(lambda);
assertThat(nodes).hasSize(2);
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ComplexityVisitorTest method method_complexity.
@Test
public void method_complexity() throws Exception {
CompilationUnitTree cut = (CompilationUnitTree) p.parse("class A {" + " Object foo(){" + " if(a) { " + " return new MyClass(){ " + " void foo(){" + " if(a) {return;} " + " } " + " };" + " } " + "}}");
MethodTree methodTree = (MethodTree) ((ClassTree) cut.types().get(0)).members().get(0);
List<Tree> nodes = new ComplexityVisitor().getNodes(methodTree);
assertThat(nodes).hasSize(2);
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ExportsDirectiveTreeImplTest method test_BaseTreeVisitor.
@Test
public void test_BaseTreeVisitor() {
CompilationUnitTree cut = createTree("@org.foo.Bar", "open module com.greetings {", " exports foo;", " requires org.gul;", " exports org.bar to com.module1, module2;", "}");
ExportsDirectiveVisitor moduleDeclarationVisitor = new ExportsDirectiveVisitor();
cut.accept(moduleDeclarationVisitor);
assertThat(moduleDeclarationVisitor.visited).isTrue();
assertThat(moduleDeclarationVisitor.directives).hasSize(2);
assertThat(moduleDeclarationVisitor.identifiers).containsExactly("com", "greetings", "foo", "com", "module1", "module2");
}
use of org.sonar.plugins.java.api.tree.CompilationUnitTree in project sonar-java by SonarSource.
the class ModuleDeclarationTreeImplTest method no_module.
@Test
public void no_module() {
CompilationUnitTree cut = createTree("package org.foo;");
assertThat(cut.moduleDeclaration()).isNull();
}
Aggregations