public static JavaCompilation compileSource(String source) { //Compiler Options CompilerOptions options = getDefaultCompilerOptions(); //CommentRecorder Parser parser = createCommentRecorderParser(options); //Create Compilation Unit from Source ICompilationUnit cu = createCompilationunit(source, ""); //Compilation Result CompilationResult compilationResult = createDefaultCompilationResult(cu, options); return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner); }
/** * Returns the generated {@link JavaCompilation} from the file identified by the given filename. This method assumes * that the filename is relative to <code>{@value #TEST_DATA_BASE_DIR}</code>. * * @param filename * of the file to compile * @return the compilation of the file */ public static JavaCompilation compileFile(String filename) { CompilerOptions options = getDefaultCompilerOptions(); Parser parser = createCommentRecorderParser(options); ICompilationUnit cu = createCompilationunit(getContentOfFile(filename), filename); CompilationResult compilationResult = createDefaultCompilationResult(cu, options); return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner); }