BaseTask
Abstract base class for code generation tasks.
This abstract class provides common functionality for code generation tasks, including input and output properties, file generation methods, and type conversion methods.
BaseTask provides the following features:
Input and output properties: BaseTask defines several input and output properties that can be used to configure the code generation process. These properties include the package name, module name, output directory, package details, and type.
File generation methods: BaseTask provides two methods for generating files:
fileSpec()
andgenerate()
. ThefileSpec()
method generates a file spec for the specified file name, and thegenerate()
method generates the code for the file spec.Type conversion methods: BaseTask provides a
type()
method that can be used to convert a package name and type name to a class name. This method is useful for generating code that references classes from other packages.
To use BaseTask, you should extend it and implement the doTask()
method. The doTask()
method is where you should perform the actual code generation work.
Example usage:
abstract class MyTask : BaseTask() {
override fun doTask() {
// Perform code generation work here
}
}
class MyTaskImpl : MyTask() {
override fun doTask() {
// Generate a file named "MyClass.kt"
fileSpec("MyClass") {
// Define the contents of the file here
}
// Generate a file named "MyInterface.kt"
fileSpec("MyInterface") {
// Define the contents of the file here
}
}
}
val myTask = MyTaskImpl()
myTask.execute()
This code will generate two files: `MyClass.kt` and `MyInterface.kt`.
The contents of the files will be defined by the `fileSpec()` blocks.