Search in sources :

Example 1 with JavaProjectOptions

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);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) JavaProjectOptions(org.autorefactor.refactoring.JavaProjectOptions) ASTParser(org.eclipse.jdt.core.dom.ASTParser) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 JavaProjectOptions (org.autorefactor.refactoring.JavaProjectOptions)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ASTParser (org.eclipse.jdt.core.dom.ASTParser)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 Test (org.junit.Test)1