Package ru.yojo.codegen.writer
Class JavaFileWriter
java.lang.Object
ru.yojo.codegen.writer.JavaFileWriter
Encapsulates file system operations for writing generated Java source files.
Handles:
- Directory creation
- Writing files with UTF-8 encoding
- Dry-run mode for testing (returns content without writing)
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a file writer that actually writes to disk.JavaFileWriter(boolean dryRun) Creates a file writer with optional dry-run mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateDirectories(String path) Creates directories for the given path.booleanisDryRun()Checks if dry-run mode is enabled.writeJavaFile(String outputDirectory, String packageName, String className, String content) Writes the given Java source content to a file in the specified directory.
-
Constructor Details
-
JavaFileWriter
public JavaFileWriter()Creates a file writer that actually writes to disk. -
JavaFileWriter
public JavaFileWriter(boolean dryRun) Creates a file writer with optional dry-run mode.- Parameters:
dryRun- iftrue, write operations return the content without writing to disk
-
-
Method Details
-
writeJavaFile
public String writeJavaFile(String outputDirectory, String packageName, String className, String content) throws IOException Writes the given Java source content to a file in the specified directory.The file name is derived from the class name (appended with ".java"). Directories are created if they don't exist.
- Parameters:
outputDirectory- the base directory for outputpackageName- the package name (used to create subdirectories)className- the class name (becomes file name)content- the Java source code to write- Returns:
- the path to the written file (or would-be path in dry-run mode)
- Throws:
IOException- if directory creation or file writing fails
-
createDirectories
Creates directories for the given path.- Parameters:
path- the directory path to create- Throws:
IOException- if creation fails
-
isDryRun
public boolean isDryRun()Checks if dry-run mode is enabled.- Returns:
trueif in dry-run mode
-