The name of the Java file to be generated (without the .java
extension).
The package name for the Java file (e.g., com.example.project
).
The manager responsible for handling file creation and output.
A function that generates
the body of the Java file. It receives an importManager
function to handle class imports and returns a CompositeGeneratorNode
representing the body content.
Optional
options: CreateFileOptionsOptional settings for file creation, such as encoding or overwrite behavior.
generateJavaFile(
'MyClass',
'com.example.project',
generatorManager,
(importClass) => expandToNode`
public class MyClass {
public ${imp('java.util.Properties')} getProperties() {
// ...
}
}
}`
);
The above example generates a Java class MyClass
in the package com.example.project
, with an imported java.util.Properties
.
The imp
function handles the import management, ensuring that java.util.Properties
is imported and conflicts are resolved.
Generates a Java source file with proper package declaration, imports, and body content.
This function simplifies the generation of Java files by handling common boilerplate code such as package declarations and import statements. It leverages a
JavaImportManager
to manage imports automatically based on the classes used in the body content.