use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class CFGTest method build_partial_cfg.
private void build_partial_cfg(String breakOrContinue) {
String methodCode = "void meth(){ try {fun(); } catch ( Exception e) {e.printStackTrace(); " + breakOrContinue + "; } }";
CompilationUnitTree cut = (CompilationUnitTree) parser.parse("class A {" + methodCode + "}");
SemanticModel.createFor(cut, new SquidClassLoader(Collections.emptyList()));
MethodTree methodTree = (MethodTree) ((ClassTree) cut.types().get(0)).members().get(0);
List<StatementTree> body = methodTree.block().body();
CFG cfg = CFG.buildCFG(body, true);
cfg.setMethodSymbol(methodTree.symbol());
assertThat(cfg.blocks()).hasSize(5);
assertThat(cfg.methodSymbol()).isSameAs(methodTree.symbol());
try {
CFG.buildCFG(body, false);
fail("IllegalStateException should have been thrown");
} catch (IllegalStateException iae) {
assertThat(iae).hasMessage("'" + breakOrContinue + "' statement not in loop or switch statement");
}
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class TypeAndReferenceSolverTest method treeOf.
private CompilationUnitTree treeOf(String input) {
CompilationUnitTree tree = parse(input);
SemanticModel.createFor(tree, new SquidClassLoader(Collections.emptyList()));
return tree;
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class ModuleDeclarationTreeImplTest 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.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class ProvidesDirectiveTreeImplTest 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.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class UsesDirectiveTreeImplTest 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;
}
Aggregations