Created
November 21, 2024 06:53
-
-
Save krzema12/0bc0f5c8fc15324a06fcec4429aac6a7 to your computer and use it in GitHub Desktop.
Using KotlinPoet to generate a class (top-level function)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun generateActionClass( | |
| metadata: Metadata, | |
| coords: ActionCoords, | |
| inputTypings: Map<String, Typing>, | |
| className: String, | |
| untypedClass: Boolean, | |
| replaceWith: CodeBlock?, | |
| ): TypeSpec = | |
| TypeSpec | |
| .classBuilder(className) | |
| .addModifiers(KModifier.DATA) | |
| .addKdocIfNotEmpty(actionKdoc(metadata, coords, untypedClass)) | |
| .replaceWith(replaceWith) | |
| .addClassConstructorAnnotation() | |
| .inheritsFromRegularAction(coords, metadata, className) | |
| .primaryConstructor(metadata.primaryConstructor(inputTypings, coords, className, untypedClass)) | |
| .properties(metadata, coords, inputTypings, className, untypedClass) | |
| .addInitializerBlockIfNecessary(metadata, inputTypings, untypedClass) | |
| .addFunction(metadata.secondaryConstructor(inputTypings, coords, className, untypedClass)) | |
| .addFunction(metadata.buildToYamlArgumentsFunction(inputTypings, untypedClass)) | |
| .addCustomTypes(inputTypings, coords, className) | |
| .addOutputClassIfNecessary(metadata) | |
| .addBuildOutputObjectFunctionIfNecessary(metadata) | |
| .build() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment