public void writeClassDefinition(ClassDefinition classDef) { if (!this.continueGenerating) return; // could be null in the case of a core type if (classDef == null) return; File sourceRootDirectory = this.sourceRootDirectory; if (sourceRootDirectory == null) sourceRootDirectory = this.project.absoluteModelSourceDirectory(); String writeDirectory = buildDirectory(classDef.getPackageName(), sourceRootDirectory); File javaFile = new File(writeDirectory, classDef.getName() + ".java"); CodeGenerator codeGenerator = new CodeGenerator(); try { FileOutputStream stream = new FileOutputStream(javaFile); codeGenerator.setOutput(new OutputStreamWriter(stream, "utf-8")); } catch (IOException ioe) { fireContinuableExceptionEvent(ioe); return; } classDef.write(codeGenerator); this.anyFileWritten = true; try { codeGenerator.getOutput().flush(); codeGenerator.getOutput().close(); } catch (IOException ioe) { fireContinuableExceptionEvent(ioe); return; } }
private File doesFileExist(ClassDefinition classDef) { if (!this.continueGenerating) return null; // could be null in the case of a core type if (classDef == null) return null; File sourceRootDirectory = this.sourceRootDirectory; if (sourceRootDirectory == null) sourceRootDirectory = this.project.absoluteModelSourceDirectory(); String writeDirectory = buildDirectory(classDef.getPackageName(), sourceRootDirectory); File javaFile = new File(writeDirectory, classDef.getName() + ".java"); if (javaFile.exists()) return javaFile; return null; }