private static void write(ContextFactory factory, SourceFile file) {
   try {
     RuntimeModel model = factory.create(file.getInputPath()).getModel();
     String source = generator.generate(file, model);
     Files.createDirectories(file.getOutputPath().getParent());
     Files.write(
         file.getOutputPath(),
         source.getBytes(Charset.forName("UTF-8")),
         StandardOpenOption.CREATE,
         StandardOpenOption.TRUNCATE_EXISTING);
   } catch (Throwable t) {
     throw new CodeGeneratorException(t);
   }
 }
 public String generate(Path path) {
   ContextFactory factory = ContextFactoryScanner.get(path);
   SourceFile sourceFile = new SourceFile(path);
   return generate(sourceFile, factory.create(path).getModel());
 }