Class OutputFile
java.lang.Object
org.javacc.utils.OutputFile
- All Implemented Interfaces:
Closeable, AutoCloseable
This class handles the creation and maintenance of the boiler-plate classes,
such as Token.java, JavaCharStream.java etc.
It is responsible for:
- Writing the JavaCC header lines to the file.
- Writing the checksum line.
- Using the checksum to determine if an existing file has been changed by the user (and so should be left alone).
- Checking any existing file's version (if the file can not be overwritten).
- Checking any existing file's creation options (if the file can not be overwritten).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classTheOutputFile.TrapClosePrintWriterimplements aPrintWriter, avoiding to close the relatedOutputStreamwith anOutputFile.TrapClosePrintWriter.close(). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stringprivate DigestOutputStreamprivate final Fileprivate final booleanprivate final Stringprivate OutputFile.TrapClosePrintWriter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Close the OutputFile, writing any necessary trailer information (such as a checksum).final PrintWriterReturn a PrintWriter object that may be used to write to this file.final booleanReturntrueif the file needs to be written.
-
Field Details
-
file
-
options
-
toolName
-
compatibleVersion
-
needToWrite
private final boolean needToWrite -
writer
-
digestStream
-
-
Constructor Details
-
OutputFile
OutputFile(File file, String toolName, String compatibleVersion, List<String> options, Context context) throws IOException Create a new OutputFile.- Parameters:
file- the file to write to.toolName- the name of the generating tool.compatibleVersion- the minimum compatible JavaCC version.options- if the file already exists, and cannot be overwritten, this is a list of options (such s STATIC=false) to check for changes.- Throws:
IOException
-
-
Method Details
-
isNeedToWrite
public final boolean isNeedToWrite()Returntrueif the file needs to be written. -
getPrintWriter
Return a PrintWriter object that may be used to write to this file. Any necessary header information is written by this method.- Throws:
IOException
-
close
Close the OutputFile, writing any necessary trailer information (such as a checksum).- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-