use of org.autorefactor.refactoring.JavaProjectOptions in project AutoRefactor by JnRouvignac.
the class CFGBuilderTest method testCFGBuilder.
@Test
public void testCFGBuilder() throws Exception {
final String sampleName = testName + ".java";
final File javaFile = new File("src/test/java/org/autorefactor/cfg", sampleName);
assertTrue(testName + ": sample in java file " + javaFile + " should exist", javaFile.exists());
final File dotFile = new File("src/test/resources/org/autorefactor/cfg", testName + ".dot");
assertTrue(testName + ": sample out dot file " + dotFile + " should exist", dotFile.exists());
final String dotSource = readAll(dotFile).trim();
final String javaSource = readAll(javaFile);
final IPackageFragment packageFragment = JavaCoreHelper.getPackageFragment("org.autorefactor.cfg");
final ICompilationUnit cu = packageFragment.createCompilationUnit(sampleName, javaSource, true, null);
cu.getBuffer().setContents(javaSource);
cu.save(null, true);
final JavaProjectOptions options = newJavaProjectOptions(Release.javaSE("1.8"), 4);
final ASTParser parser = ASTParser.newParser(AST.JLS8);
autoRefactorHandlerResetParser(cu, parser, options);
final CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
final CFGBuilder builder = new CFGBuilder(javaSource, options);
final List<CFGBasicBlock> blocks = builder.buildCFG(astRoot);
final CFGBasicBlock block = blocks.get(methodDeclarationNb);
final String actual = new CFGDotPrinter().toDot(block).trim();
final File dotFileOut = new File("src/test/resources/org/autorefactor/cfg", testName + "_out.dot");
writeAll(dotFileOut, actual);
assertEquals(testName + ": wrong output;", dotSource, actual);
}
Aggregations