MCPcopy
hub / github.com/antlr/antlr4 / getOutputFileWriter

Method getOutputFileWriter

tool/src/org/antlr/v4/Tool.java:764–785  ·  view source on GitHub ↗

This method is used by all code generators to create new output files. If the outputDir set by -o is not present it will be created. The final filename is sensitive to the output directory and the directory where the grammar file was found. If -o is /tmp and the original grammar file was foo/t.

(Grammar g, String fileName)

Source from the content-addressed store, hash-verified

762 * If outputDirectory==null then write a String.
763 */
764 public Writer getOutputFileWriter(Grammar g, String fileName) throws IOException {
765 if (outputDirectory == null) {
766 return new StringWriter();
767 }
768 // output directory is a function of where the grammar file lives
769 // for subdir/T.g4, you get subdir here. Well, depends on -o etc...
770 File outputDir = getOutputDirectory(g.fileName);
771 File outputFile = new File(outputDir, fileName);
772
773 if (!outputDir.exists()) {
774 outputDir.mkdirs();
775 }
776 FileOutputStream fos = new FileOutputStream(outputFile);
777 OutputStreamWriter osw;
778 if ( grammarEncoding!=null ) {
779 osw = new OutputStreamWriter(fos, grammarEncoding);
780 }
781 else {
782 osw = new OutputStreamWriter(fos);
783 }
784 return new BufferedWriter(osw);
785 }
786
787 public File getImportedGrammarFile(Grammar g, String fileName) {
788 File importedFile = new File(inputDirectory, fileName);

Callers 3

writeDOTFileMethod · 0.95
writeMethod · 0.45

Calls 1

getOutputDirectoryMethod · 0.95

Tested by

no test coverage detected