@goast/kotlin 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/assets.d.ts +17 -0
- package/dist/src/assets.js +17 -0
- package/dist/src/ast/common.d.ts +4 -0
- package/dist/src/ast/node.d.ts +11 -0
- package/dist/src/ast/node.js +11 -0
- package/dist/src/ast/nodes/annotation.d.ts +44 -0
- package/dist/src/ast/nodes/annotation.js +40 -0
- package/dist/src/ast/nodes/argument.d.ts +33 -0
- package/dist/src/ast/nodes/argument.js +33 -0
- package/dist/src/ast/nodes/call.d.ts +42 -0
- package/dist/src/ast/nodes/call.js +42 -0
- package/dist/src/ast/nodes/class.d.ts +96 -0
- package/dist/src/ast/nodes/class.js +90 -0
- package/dist/src/ast/nodes/collection-literal.d.ts +35 -0
- package/dist/src/ast/nodes/collection-literal.js +35 -0
- package/dist/src/ast/nodes/constructor.d.ts +65 -0
- package/dist/src/ast/nodes/constructor.js +62 -0
- package/dist/src/ast/nodes/doc-tag.d.ts +41 -0
- package/dist/src/ast/nodes/doc-tag.js +41 -0
- package/dist/src/ast/nodes/doc.d.ts +44 -0
- package/dist/src/ast/nodes/doc.js +44 -0
- package/dist/src/ast/nodes/enum-value.d.ts +50 -0
- package/dist/src/ast/nodes/enum-value.js +47 -0
- package/dist/src/ast/nodes/enum.d.ts +67 -0
- package/dist/src/ast/nodes/enum.js +64 -0
- package/dist/src/ast/nodes/function.d.ts +105 -0
- package/dist/src/ast/nodes/function.js +105 -0
- package/dist/src/ast/nodes/generic-parameter.d.ts +37 -0
- package/dist/src/ast/nodes/generic-parameter.js +37 -0
- package/dist/src/ast/nodes/init-block.d.ts +32 -0
- package/dist/src/ast/nodes/init-block.js +32 -0
- package/dist/src/ast/nodes/interface.d.ts +73 -0
- package/dist/src/ast/nodes/interface.js +68 -0
- package/dist/src/ast/nodes/lambda-type.d.ts +42 -0
- package/dist/src/ast/nodes/lambda-type.js +42 -0
- package/dist/src/ast/nodes/lambda.d.ts +41 -0
- package/dist/src/ast/nodes/lambda.js +41 -0
- package/dist/src/ast/nodes/object.d.ts +66 -0
- package/dist/src/ast/nodes/object.js +62 -0
- package/dist/src/ast/nodes/parameter.d.ts +68 -0
- package/dist/src/ast/nodes/parameter.js +68 -0
- package/dist/src/ast/nodes/property.d.ts +152 -0
- package/dist/src/ast/nodes/property.js +148 -0
- package/dist/src/ast/nodes/reference.d.ts +107 -0
- package/dist/src/ast/nodes/reference.js +75 -0
- package/dist/src/ast/nodes/string.d.ts +57 -0
- package/dist/src/ast/nodes/string.js +57 -0
- package/dist/src/ast/nodes/types.d.ts +9 -0
- package/dist/src/ast/references/jackson.d.ts +67 -0
- package/dist/src/ast/references/jackson.js +59 -0
- package/dist/src/ast/references/jakarta.d.ts +13 -0
- package/dist/src/ast/references/jakarta.js +13 -0
- package/dist/src/ast/references/java.d.ts +19 -0
- package/dist/src/ast/references/java.js +19 -0
- package/dist/src/ast/references/kotlin.d.ts +28 -0
- package/dist/src/ast/references/kotlin.js +28 -0
- package/dist/src/ast/references/kotlinx.d.ts +8 -0
- package/dist/src/ast/references/kotlinx.js +8 -0
- package/dist/src/ast/references/okhttp3.d.ts +8 -0
- package/dist/src/ast/references/okhttp3.js +8 -0
- package/dist/src/ast/references/reactor.d.ts +8 -0
- package/dist/src/ast/references/reactor.js +8 -0
- package/dist/src/ast/references/spring-reactive.d.ts +18 -0
- package/dist/src/ast/references/spring-reactive.js +18 -0
- package/dist/src/ast/references/spring.d.ts +27 -0
- package/dist/src/ast/references/spring.js +27 -0
- package/dist/src/ast/references/swagger.d.ts +13 -0
- package/dist/src/ast/references/swagger.js +13 -0
- package/dist/src/ast/utils/get-kotlin-builder-options.d.ts +10 -0
- package/dist/src/ast/utils/get-kotlin-builder-options.js +10 -0
- package/dist/src/ast/utils/to-kt-node.d.ts +40 -0
- package/dist/src/ast/utils/write-kt-annotations.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-annotations.js +13 -0
- package/dist/src/ast/utils/write-kt-arguments.d.ts +15 -0
- package/dist/src/ast/utils/write-kt-arguments.js +15 -0
- package/dist/src/ast/utils/write-kt-enum-values.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-enum-values.js +13 -0
- package/dist/src/ast/utils/write-kt-generic-parameters.d.ts +10 -0
- package/dist/src/ast/utils/write-kt-generic-parameters.js +10 -0
- package/dist/src/ast/utils/write-kt-members.d.ts +16 -0
- package/dist/src/ast/utils/write-kt-members.js +16 -0
- package/dist/src/ast/utils/write-kt-node.d.ts +29 -0
- package/dist/src/ast/utils/write-kt-node.js +24 -0
- package/dist/src/ast/utils/write-kt-parameters.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-parameters.js +13 -0
- package/dist/src/common-results.d.ts +9 -0
- package/dist/src/config.d.ts +72 -0
- package/dist/src/config.js +5 -0
- package/dist/src/file-builder.d.ts +91 -0
- package/dist/src/file-builder.js +81 -0
- package/dist/src/generators/file-generator.d.ts +12 -0
- package/dist/src/generators/file-generator.js +7 -0
- package/dist/src/generators/models/args.d.ts +233 -0
- package/dist/src/generators/models/model-generator.d.ts +25 -0
- package/dist/src/generators/models/model-generator.js +14 -0
- package/dist/src/generators/models/models-generator.d.ts +15 -0
- package/dist/src/generators/models/models-generator.js +15 -0
- package/dist/src/generators/models/models.d.ts +93 -2
- package/dist/src/generators/models/models.js +5 -0
- package/dist/src/generators/services/okhttp3-clients/args.d.ts +138 -0
- package/dist/src/generators/services/okhttp3-clients/models.d.ts +83 -0
- package/dist/src/generators/services/okhttp3-clients/models.js +5 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +33 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +20 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts +21 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +21 -0
- package/dist/src/generators/services/okhttp3-clients/refs.d.ts +25 -0
- package/dist/src/generators/services/okhttp3-clients/refs.js +7 -0
- package/dist/src/generators/services/spring-controllers/args.d.ts +169 -0
- package/dist/src/generators/services/spring-controllers/models.d.ts +120 -0
- package/dist/src/generators/services/spring-controllers/models.js +4 -0
- package/dist/src/generators/services/spring-controllers/refs.d.ts +9 -0
- package/dist/src/generators/services/spring-controllers/refs.js +9 -0
- package/dist/src/generators/services/spring-controllers/spring-controller-generator.d.ts +29 -0
- package/dist/src/generators/services/spring-controllers/spring-controller-generator.js +19 -0
- package/dist/src/generators/services/spring-controllers/spring-controllers-generator.d.ts +22 -0
- package/dist/src/generators/services/spring-controllers/spring-controllers-generator.js +22 -0
- package/dist/src/generators/services/spring-reactive-web-clients/args.d.ts +224 -0
- package/dist/src/generators/services/spring-reactive-web-clients/models.d.ts +86 -0
- package/dist/src/generators/services/spring-reactive-web-clients/models.js +4 -0
- package/dist/src/generators/services/spring-reactive-web-clients/refs.d.ts +7 -0
- package/dist/src/generators/services/spring-reactive-web-clients/refs.js +7 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +36 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +25 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.d.ts +20 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.js +20 -0
- package/dist/src/import-collection.d.ts +64 -0
- package/dist/src/import-collection.js +46 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/src/utils.d.ts +52 -0
- package/dist/src/utils.js +52 -0
- package/package.json +2 -2
package/dist/src/assets.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the text content of a file from the `assets` directory that ships with this package. The directory is resolved
|
|
3
|
+
* relative to this module. Rejects if the file cannot be read.
|
|
4
|
+
* @param relativePath The path of the asset file, relative to the assets directory.
|
|
5
|
+
* @returns A promise that resolves with the text content of the asset file.
|
|
6
|
+
* @see AssetManager.getAssetFileContent
|
|
7
|
+
*/
|
|
1
8
|
export declare const getAssetFileContent: (relativePath: string) => Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Copies a file from the `assets` directory that ships with this package into a directory, keeping its base name. An
|
|
11
|
+
* existing file at the target path is overwritten.
|
|
12
|
+
* @param relativePath The path of the asset file, relative to the assets directory.
|
|
13
|
+
* @param destDir The directory to copy the file into.
|
|
14
|
+
* @param logName The name to show in the log message. Nothing is logged if omitted, and the relative path is logged if
|
|
15
|
+
* empty.
|
|
16
|
+
* @returns A promise that resolves when the file has been copied.
|
|
17
|
+
* @see AssetManager.copyAssetFile
|
|
18
|
+
*/
|
|
2
19
|
export declare const copyAssetFile: (relativePath: string, destDir: string, logName?: string) => Promise<void>;
|
package/dist/src/assets.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { AssetManager } from '@goast/core';
|
|
2
2
|
import { URL } from 'node:url';
|
|
3
3
|
const manager = new AssetManager(new URL('../assets/', import.meta.url));
|
|
4
|
+
/**
|
|
5
|
+
* Gets the text content of a file from the `assets` directory that ships with this package. The directory is resolved
|
|
6
|
+
* relative to this module. Rejects if the file cannot be read.
|
|
7
|
+
* @param relativePath The path of the asset file, relative to the assets directory.
|
|
8
|
+
* @returns A promise that resolves with the text content of the asset file.
|
|
9
|
+
* @see AssetManager.getAssetFileContent
|
|
10
|
+
*/
|
|
4
11
|
export const getAssetFileContent = manager.getAssetFileContent.bind(manager);
|
|
12
|
+
/**
|
|
13
|
+
* Copies a file from the `assets` directory that ships with this package into a directory, keeping its base name. An
|
|
14
|
+
* existing file at the target path is overwritten.
|
|
15
|
+
* @param relativePath The path of the asset file, relative to the assets directory.
|
|
16
|
+
* @param destDir The directory to copy the file into.
|
|
17
|
+
* @param logName The name to show in the log message. Nothing is logged if omitted, and the relative path is logged if
|
|
18
|
+
* empty.
|
|
19
|
+
* @returns A promise that resolves when the file has been copied.
|
|
20
|
+
* @see AssetManager.copyAssetFile
|
|
21
|
+
*/
|
|
5
22
|
export const copyAssetFile = manager.copyAssetFile.bind(manager);
|
package/dist/src/ast/common.d.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The visibility modifier written before a declaration, such as `private` in `private interface Foo`.
|
|
3
|
+
* A declaration with no visibility modifier is written without a keyword, so Kotlin's default of `public` applies.
|
|
4
|
+
*/
|
|
1
5
|
export type KtAccessModifier = 'public' | 'protected' | 'internal' | 'private';
|
package/dist/src/ast/node.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { AstNode, type AstNodeOptions, type SourceBuilder } from '@goast/core';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all Kotlin AST nodes. It adds no behavior of its own. Nodes are written with `write`, and their
|
|
4
|
+
* injection points, such as `before` and `beforeName`, come from `AstNode` in `@goast/core`.
|
|
5
|
+
*
|
|
6
|
+
* @template TBuilder The type of the builder that the node is written to.
|
|
7
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
8
|
+
*/
|
|
2
9
|
export declare abstract class KtNode<TBuilder extends SourceBuilder, TInjects extends string = never> extends AstNode<TBuilder, TInjects> {
|
|
10
|
+
/**
|
|
11
|
+
* Initializes a new instance of the KtNode class.
|
|
12
|
+
* @param options The options of the node. They are passed on to the constructor of `AstNode`.
|
|
13
|
+
*/
|
|
3
14
|
constructor(options: AstNodeOptions<typeof AstNode<TBuilder, TInjects>>);
|
|
4
15
|
}
|
package/dist/src/ast/node.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { AstNode } from '@goast/core';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all Kotlin AST nodes. It adds no behavior of its own. Nodes are written with `write`, and their
|
|
4
|
+
* injection points, such as `before` and `beforeName`, come from `AstNode` in `@goast/core`.
|
|
5
|
+
*
|
|
6
|
+
* @template TBuilder The type of the builder that the node is written to.
|
|
7
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
8
|
+
*/
|
|
2
9
|
export class KtNode extends AstNode {
|
|
10
|
+
/**
|
|
11
|
+
* Initializes a new instance of the KtNode class.
|
|
12
|
+
* @param options The options of the node. They are passed on to the constructor of `AstNode`.
|
|
13
|
+
*/
|
|
3
14
|
constructor(options) {
|
|
4
15
|
super(options);
|
|
5
16
|
}
|
|
@@ -9,15 +9,59 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
9
9
|
arguments?: Nullable<Nullable<KtArgument<TBuilder> | KtValue<TBuilder>>[]>;
|
|
10
10
|
target?: Nullable<KtAnnotationTarget>;
|
|
11
11
|
}>;
|
|
12
|
+
/**
|
|
13
|
+
* The use-site target of an annotation, written as a prefix before the colon, such as `field` for `@field:Inject`.
|
|
14
|
+
* Without a target, the annotation applies to the element that it is written on.
|
|
15
|
+
*/
|
|
12
16
|
export type KtAnnotationTarget = 'file' | 'property' | 'field' | 'get' | 'set' | 'receiver' | 'param' | 'setparam' | 'delegate';
|
|
17
|
+
/**
|
|
18
|
+
* Represents a Kotlin annotation, such as `@Inject` or `@field:JsonProperty("user_id")`.
|
|
19
|
+
*
|
|
20
|
+
* Written in this order: the `@` sign, the use-site target followed by a colon, the annotation class, then the
|
|
21
|
+
* arguments in parentheses.
|
|
22
|
+
*
|
|
23
|
+
* @template TBuilder The type of the source builder the annotation is written to.
|
|
24
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
25
|
+
* @see ktAnnotation
|
|
26
|
+
*/
|
|
13
27
|
export declare class KtAnnotation<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
28
|
+
/**
|
|
29
|
+
* The annotation class, written right after the `@` sign and the optional target, such as `Inject` or
|
|
30
|
+
* `kotlin.Deprecated`.
|
|
31
|
+
*/
|
|
14
32
|
class: KtType<TBuilder>;
|
|
33
|
+
/**
|
|
34
|
+
* The arguments written in parentheses after the annotation class, such as `("user_id")`. Nothing is written when the
|
|
35
|
+
* list is empty, so the annotation stays a marker annotation without parentheses.
|
|
36
|
+
*/
|
|
15
37
|
arguments: (KtArgument<TBuilder> | KtValue<TBuilder>)[];
|
|
38
|
+
/**
|
|
39
|
+
* The use-site target written between the `@` sign and the annotation class, followed by a colon, such as `field` for
|
|
40
|
+
* `@field:Inject`. `null` omits the target.
|
|
41
|
+
*/
|
|
16
42
|
target: KtAnnotationTarget | null;
|
|
43
|
+
/**
|
|
44
|
+
* Initializes a new instance of the KtAnnotation class.
|
|
45
|
+
* @param options The options to use for this instance.
|
|
46
|
+
*/
|
|
17
47
|
constructor(options: Options<TBuilder, TInjects>);
|
|
18
48
|
protected onWrite(builder: TBuilder): void;
|
|
19
49
|
}
|
|
20
50
|
declare const createAnnotation: <TBuilder extends SourceBuilder>($class: Options<TBuilder>['class'], $arguments?: Options<TBuilder>['arguments'], options?: Prettify<Omit<Options<TBuilder>, 'class' | 'arguments'>>) => KtAnnotation<TBuilder>;
|
|
51
|
+
/**
|
|
52
|
+
* Factory for creating annotation nodes. The `write` function writes one or more annotations to a builder,
|
|
53
|
+
* each followed by a line break when `multiline` is set and by a space otherwise.
|
|
54
|
+
*
|
|
55
|
+
* @param $class The annotation class. See `KtAnnotation.class`.
|
|
56
|
+
* @param $arguments The arguments of the annotation. See `KtAnnotation.arguments`.
|
|
57
|
+
* @param options The settings of the annotation. See `KtAnnotation` for the available properties.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* ktAnnotation('JsonProperty', ['"user_id"'], { target: 'field' });
|
|
61
|
+
* // Emits:
|
|
62
|
+
* // @field:JsonProperty("user_id")
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
21
65
|
export declare const ktAnnotation: typeof createAnnotation & {
|
|
22
66
|
write: typeof writeKtAnnotations;
|
|
23
67
|
};
|
|
@@ -3,10 +3,36 @@ import { KtNode } from '../node.js';
|
|
|
3
3
|
import { writeKtAnnotations } from '../utils/write-kt-annotations.js';
|
|
4
4
|
import { writeKtNode } from '../utils/write-kt-node.js';
|
|
5
5
|
import { ktArgument } from './argument.js';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a Kotlin annotation, such as `@Inject` or `@field:JsonProperty("user_id")`.
|
|
8
|
+
*
|
|
9
|
+
* Written in this order: the `@` sign, the use-site target followed by a colon, the annotation class, then the
|
|
10
|
+
* arguments in parentheses.
|
|
11
|
+
*
|
|
12
|
+
* @template TBuilder The type of the source builder the annotation is written to.
|
|
13
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
14
|
+
* @see ktAnnotation
|
|
15
|
+
*/
|
|
6
16
|
export class KtAnnotation extends KtNode {
|
|
17
|
+
/**
|
|
18
|
+
* The annotation class, written right after the `@` sign and the optional target, such as `Inject` or
|
|
19
|
+
* `kotlin.Deprecated`.
|
|
20
|
+
*/
|
|
7
21
|
class;
|
|
22
|
+
/**
|
|
23
|
+
* The arguments written in parentheses after the annotation class, such as `("user_id")`. Nothing is written when the
|
|
24
|
+
* list is empty, so the annotation stays a marker annotation without parentheses.
|
|
25
|
+
*/
|
|
8
26
|
arguments;
|
|
27
|
+
/**
|
|
28
|
+
* The use-site target written between the `@` sign and the annotation class, followed by a colon, such as `field` for
|
|
29
|
+
* `@field:Inject`. `null` omits the target.
|
|
30
|
+
*/
|
|
9
31
|
target;
|
|
32
|
+
/**
|
|
33
|
+
* Initializes a new instance of the KtAnnotation class.
|
|
34
|
+
* @param options The options to use for this instance.
|
|
35
|
+
*/
|
|
10
36
|
constructor(options) {
|
|
11
37
|
super(options);
|
|
12
38
|
this.class = options.class;
|
|
@@ -32,6 +58,20 @@ export class KtAnnotation extends KtNode {
|
|
|
32
58
|
}
|
|
33
59
|
}
|
|
34
60
|
const createAnnotation = ($class, $arguments, options) => new KtAnnotation({ ...options, class: $class, arguments: $arguments });
|
|
61
|
+
/**
|
|
62
|
+
* Factory for creating annotation nodes. The `write` function writes one or more annotations to a builder,
|
|
63
|
+
* each followed by a line break when `multiline` is set and by a space otherwise.
|
|
64
|
+
*
|
|
65
|
+
* @param $class The annotation class. See `KtAnnotation.class`.
|
|
66
|
+
* @param $arguments The arguments of the annotation. See `KtAnnotation.arguments`.
|
|
67
|
+
* @param options The settings of the annotation. See `KtAnnotation` for the available properties.
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* ktAnnotation('JsonProperty', ['"user_id"'], { target: 'field' });
|
|
71
|
+
* // Emits:
|
|
72
|
+
* // @field:JsonProperty("user_id")
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
35
75
|
export const ktAnnotation = Object.assign(createAnnotation, {
|
|
36
76
|
write: writeKtAnnotations,
|
|
37
77
|
});
|
|
@@ -7,14 +7,47 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
7
7
|
name?: Nullable<string>;
|
|
8
8
|
value: KtValue<TBuilder>;
|
|
9
9
|
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Represents an argument that is passed to a call or an annotation, such as `42` or `timeout = 30`.
|
|
12
|
+
*
|
|
13
|
+
* Written in this order: the name followed by ` = ` when a name is set, then the value.
|
|
14
|
+
*
|
|
15
|
+
* @template TBuilder The type of the source builder the argument is written to.
|
|
16
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
17
|
+
* @see ktArgument
|
|
18
|
+
*/
|
|
10
19
|
export declare class KtArgument<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the parameter that the value is passed to, written before ` = ` to pass the value by name. `null` or an
|
|
22
|
+
* empty name passes the value by position instead.
|
|
23
|
+
*/
|
|
11
24
|
name: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* The value of the argument. A string is written verbatim, while other nodes write their own Kotlin code.
|
|
27
|
+
*/
|
|
12
28
|
value: KtValue<TBuilder>;
|
|
29
|
+
/**
|
|
30
|
+
* Initializes a new instance of the KtArgument class.
|
|
31
|
+
* @param options The options to use for this instance.
|
|
32
|
+
*/
|
|
13
33
|
constructor(options: Options<TBuilder, TInjects>);
|
|
14
34
|
protected onWrite(builder: TBuilder): void;
|
|
15
35
|
}
|
|
16
36
|
declare const createArgument: <TBuilder extends SourceBuilder>(value: Options<TBuilder>['value'], options?: Prettify<Omit<Options<TBuilder>, 'value'>>) => KtArgument<TBuilder>;
|
|
17
37
|
declare const createNamedArgument: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], value: Options<TBuilder>['value'], options?: Prettify<Omit<Options<TBuilder>, 'value' | 'name'>>) => KtArgument<TBuilder>;
|
|
38
|
+
/**
|
|
39
|
+
* Factory for creating argument nodes. The `named` function creates an argument with a name, and the `write` function
|
|
40
|
+
* writes a list of arguments in parentheses, or `()` when the list is empty.
|
|
41
|
+
*
|
|
42
|
+
* @param value The value of the argument. A string is written verbatim.
|
|
43
|
+
* @param options The settings of the argument. See `KtArgument` for the available properties.
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* ktArgument('30', { name: 'timeout' });
|
|
47
|
+
* // Emits:
|
|
48
|
+
* // timeout = 30
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
18
51
|
export declare const ktArgument: typeof createArgument & {
|
|
19
52
|
named: typeof createNamedArgument;
|
|
20
53
|
write: typeof writeKtArguments;
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { KtNode } from '../node.js';
|
|
2
2
|
import { writeKtArguments } from '../utils/write-kt-arguments.js';
|
|
3
3
|
import { writeKtNode } from '../utils/write-kt-node.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents an argument that is passed to a call or an annotation, such as `42` or `timeout = 30`.
|
|
6
|
+
*
|
|
7
|
+
* Written in this order: the name followed by ` = ` when a name is set, then the value.
|
|
8
|
+
*
|
|
9
|
+
* @template TBuilder The type of the source builder the argument is written to.
|
|
10
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
11
|
+
* @see ktArgument
|
|
12
|
+
*/
|
|
4
13
|
export class KtArgument extends KtNode {
|
|
14
|
+
/**
|
|
15
|
+
* The name of the parameter that the value is passed to, written before ` = ` to pass the value by name. `null` or an
|
|
16
|
+
* empty name passes the value by position instead.
|
|
17
|
+
*/
|
|
5
18
|
name;
|
|
19
|
+
/**
|
|
20
|
+
* The value of the argument. A string is written verbatim, while other nodes write their own Kotlin code.
|
|
21
|
+
*/
|
|
6
22
|
value;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes a new instance of the KtArgument class.
|
|
25
|
+
* @param options The options to use for this instance.
|
|
26
|
+
*/
|
|
7
27
|
constructor(options) {
|
|
8
28
|
super(options);
|
|
9
29
|
this.name = options?.name ?? null;
|
|
@@ -23,6 +43,19 @@ export class KtArgument extends KtNode {
|
|
|
23
43
|
}
|
|
24
44
|
const createArgument = (value, options) => new KtArgument({ ...options, value });
|
|
25
45
|
const createNamedArgument = (name, value, options) => new KtArgument({ ...options, value, name });
|
|
46
|
+
/**
|
|
47
|
+
* Factory for creating argument nodes. The `named` function creates an argument with a name, and the `write` function
|
|
48
|
+
* writes a list of arguments in parentheses, or `()` when the list is empty.
|
|
49
|
+
*
|
|
50
|
+
* @param value The value of the argument. A string is written verbatim.
|
|
51
|
+
* @param options The settings of the argument. See `KtArgument` for the available properties.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* ktArgument('30', { name: 'timeout' });
|
|
55
|
+
* // Emits:
|
|
56
|
+
* // timeout = 30
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
26
59
|
export const ktArgument = Object.assign(createArgument, {
|
|
27
60
|
named: createNamedArgument,
|
|
28
61
|
write: writeKtArguments,
|
|
@@ -9,14 +9,56 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
9
9
|
arguments?: Nullable<Nullable<KtArgument<TBuilder> | KtValue<TBuilder>>[]>;
|
|
10
10
|
infix?: boolean;
|
|
11
11
|
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Represents a call of a function, such as `listOf(1, 2)` or `client.get("/pets")`.
|
|
14
|
+
*
|
|
15
|
+
* Written in this order: the path with its segments joined by dots, then the arguments in parentheses. With `infix` set
|
|
16
|
+
* and a single argument, the call is written in infix form without parentheses instead.
|
|
17
|
+
*
|
|
18
|
+
* @template TBuilder The type of the source builder the call is written to.
|
|
19
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
20
|
+
* @see ktCall
|
|
21
|
+
*/
|
|
12
22
|
export declare class KtCall<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
23
|
+
/**
|
|
24
|
+
* The segments of the callee, joined with dots, such as `client` and `get` for `client.get`. With more than two
|
|
25
|
+
* segments, the first segment is written on its own line and each following segment is indented on a new line,
|
|
26
|
+
* starting with a dot.
|
|
27
|
+
*/
|
|
13
28
|
path: (KtType<TBuilder> | KtValue<TBuilder>)[];
|
|
29
|
+
/**
|
|
30
|
+
* The arguments written in parentheses after the path, such as `(1, 2)`. An empty list writes `()`, while `null`
|
|
31
|
+
* omits the parentheses entirely, which turns the call into a plain property access.
|
|
32
|
+
*/
|
|
14
33
|
arguments: (KtArgument<TBuilder> | KtValue<TBuilder>)[] | null;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the call is written in infix form, such as `a plus b`. Infix form requires exactly one argument and a path
|
|
36
|
+
* with more than one segment, and only the first and the last path segment are written in that form. Otherwise the
|
|
37
|
+
* normal call form is used.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
15
40
|
infix: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Initializes a new instance of the KtCall class.
|
|
43
|
+
* @param options The options to use for this instance.
|
|
44
|
+
*/
|
|
16
45
|
constructor(options: Options<TBuilder, TInjects>);
|
|
17
46
|
protected onWrite(builder: TBuilder): void;
|
|
18
47
|
}
|
|
19
48
|
declare const createCall: <TBuilder extends SourceBuilder>(path: Options<TBuilder>['path'] | ArrayItem<Options<TBuilder>['path']>, args?: Options<TBuilder>['arguments'], options?: Prettify<Omit<Options<TBuilder>, 'path' | 'arguments'>>) => KtCall<TBuilder>;
|
|
49
|
+
/**
|
|
50
|
+
* Factory for creating call nodes. The `write` function writes one or more call nodes to a builder.
|
|
51
|
+
*
|
|
52
|
+
* @param path The segments of the callee. A single segment can be passed without an array.
|
|
53
|
+
* @param args The arguments of the call. `null` or `undefined` writes the call without parentheses.
|
|
54
|
+
* @param options The settings of the call. See `KtCall` for the available properties.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* ktCall(['client', 'get'], ['"/pets"']);
|
|
58
|
+
* // Emits:
|
|
59
|
+
* // client.get("/pets")
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
20
62
|
export declare const ktCall: typeof createCall & {
|
|
21
63
|
write: typeof writeKtNodes;
|
|
22
64
|
};
|
|
@@ -2,10 +2,39 @@ import { notNullish, } from '@goast/core';
|
|
|
2
2
|
import { KtNode } from '../node.js';
|
|
3
3
|
import { writeKtNode, writeKtNodes } from '../utils/write-kt-node.js';
|
|
4
4
|
import { ktArgument } from './argument.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a call of a function, such as `listOf(1, 2)` or `client.get("/pets")`.
|
|
7
|
+
*
|
|
8
|
+
* Written in this order: the path with its segments joined by dots, then the arguments in parentheses. With `infix` set
|
|
9
|
+
* and a single argument, the call is written in infix form without parentheses instead.
|
|
10
|
+
*
|
|
11
|
+
* @template TBuilder The type of the source builder the call is written to.
|
|
12
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
13
|
+
* @see ktCall
|
|
14
|
+
*/
|
|
5
15
|
export class KtCall extends KtNode {
|
|
16
|
+
/**
|
|
17
|
+
* The segments of the callee, joined with dots, such as `client` and `get` for `client.get`. With more than two
|
|
18
|
+
* segments, the first segment is written on its own line and each following segment is indented on a new line,
|
|
19
|
+
* starting with a dot.
|
|
20
|
+
*/
|
|
6
21
|
path;
|
|
22
|
+
/**
|
|
23
|
+
* The arguments written in parentheses after the path, such as `(1, 2)`. An empty list writes `()`, while `null`
|
|
24
|
+
* omits the parentheses entirely, which turns the call into a plain property access.
|
|
25
|
+
*/
|
|
7
26
|
arguments;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the call is written in infix form, such as `a plus b`. Infix form requires exactly one argument and a path
|
|
29
|
+
* with more than one segment, and only the first and the last path segment are written in that form. Otherwise the
|
|
30
|
+
* normal call form is used.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
8
33
|
infix;
|
|
34
|
+
/**
|
|
35
|
+
* Initializes a new instance of the KtCall class.
|
|
36
|
+
* @param options The options to use for this instance.
|
|
37
|
+
*/
|
|
9
38
|
constructor(options) {
|
|
10
39
|
super(options);
|
|
11
40
|
this.path = options.path.filter(notNullish);
|
|
@@ -39,6 +68,19 @@ export class KtCall extends KtNode {
|
|
|
39
68
|
}
|
|
40
69
|
}
|
|
41
70
|
const createCall = (path, args, options) => new KtCall({ ...options, path: Array.isArray(path) ? path : [path], arguments: args });
|
|
71
|
+
/**
|
|
72
|
+
* Factory for creating call nodes. The `write` function writes one or more call nodes to a builder.
|
|
73
|
+
*
|
|
74
|
+
* @param path The segments of the callee. A single segment can be passed without an array.
|
|
75
|
+
* @param args The arguments of the call. `null` or `undefined` writes the call without parentheses.
|
|
76
|
+
* @param options The settings of the call. See `KtCall` for the available properties.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* ktCall(['client', 'get'], ['"/pets"']);
|
|
80
|
+
* // Emits:
|
|
81
|
+
* // client.get("/pets")
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
42
84
|
export const ktCall = Object.assign(createCall, {
|
|
43
85
|
write: writeKtNodes,
|
|
44
86
|
});
|
|
@@ -29,26 +29,122 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
29
29
|
companionObject?: Nullable<KtObject<TBuilder>>;
|
|
30
30
|
members?: Nullable<Nullable<KtClassMember<TBuilder>>[]>;
|
|
31
31
|
}>;
|
|
32
|
+
/**
|
|
33
|
+
* The kinds of class that are written as a keyword before `class`, such as `data` for `data class`.
|
|
34
|
+
*/
|
|
32
35
|
export type KtClassKind = 'data' | 'value' | 'annotation' | 'sealed';
|
|
36
|
+
/**
|
|
37
|
+
* The nodes that can be written as members of a class body. Other append values are written as-is.
|
|
38
|
+
*/
|
|
33
39
|
export type KtClassMember<TBuilder extends SourceBuilder> = KtConstructor<TBuilder> | KtEnum<TBuilder> | KtInitBlock<TBuilder> | KtInterface<TBuilder> | KtProperty<TBuilder> | KtFunction<TBuilder> | KtClass<TBuilder> | AppendValue<TBuilder>;
|
|
40
|
+
/**
|
|
41
|
+
* Represents a Kotlin class declaration, such as `data class PetDto(val id: Long)`.
|
|
42
|
+
*
|
|
43
|
+
* Written in this order: the doc comment, annotations, modifiers, the `class` keyword and name, generics, the primary
|
|
44
|
+
* constructor, the inheritance list, then the body. The modifiers are written in the order access modifier, `open`,
|
|
45
|
+
* `abstract`, class kind. The body is written in braces only when it has members, a companion object or a primary
|
|
46
|
+
* constructor body.
|
|
47
|
+
*
|
|
48
|
+
* @template TBuilder The type of the source builder the class is written to.
|
|
49
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
50
|
+
* @see ktClass
|
|
51
|
+
*/
|
|
34
52
|
export declare class KtClass<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
53
|
+
/**
|
|
54
|
+
* The KDoc comment written above the class, or `null` to omit it. Descriptions of generic parameters and primary
|
|
55
|
+
* constructor parameters are merged into it as `@param` tags, and property descriptions of primary constructor
|
|
56
|
+
* parameters are merged into it as `@property` tags.
|
|
57
|
+
*/
|
|
35
58
|
doc: KtDoc<TBuilder> | null;
|
|
59
|
+
/**
|
|
60
|
+
* The annotations written above the class, each on its own line.
|
|
61
|
+
*/
|
|
36
62
|
annotations: KtAnnotation<TBuilder>[];
|
|
63
|
+
/**
|
|
64
|
+
* The visibility modifier written before the `class` keyword, or `null` to omit it. Kotlin classes are public by
|
|
65
|
+
* default, so `null` writes a public class.
|
|
66
|
+
*/
|
|
37
67
|
accessModifier: KtAccessModifier | null;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the class is written with the `open` modifier, which allows other classes to extend it.
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
38
72
|
open: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the class is written with the `abstract` modifier, placed after `open` when both are set.
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
39
77
|
abstract: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The kind of the class, written as a keyword before `class`, such as `data` for `data class`. `null` writes a
|
|
80
|
+
* regular class.
|
|
81
|
+
*/
|
|
40
82
|
classKind: KtClassKind | null;
|
|
83
|
+
/**
|
|
84
|
+
* The class name, written verbatim after the `class` keyword.
|
|
85
|
+
*/
|
|
41
86
|
name: string;
|
|
87
|
+
/**
|
|
88
|
+
* The type parameters written in angle brackets after the name, such as `<T, U>`. Plain strings are written as-is,
|
|
89
|
+
* while described parameters also add a `@param` tag to the doc comment.
|
|
90
|
+
*/
|
|
42
91
|
generics: (KtGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
92
|
+
/**
|
|
93
|
+
* The primary constructor written in parentheses after the name, or `null` to omit it. Only its annotations, access
|
|
94
|
+
* modifier and parameters are written in the header, while its body is written as an `init` block in the class body.
|
|
95
|
+
*/
|
|
43
96
|
primaryConstructor: KtConstructor<TBuilder> | null;
|
|
97
|
+
/**
|
|
98
|
+
* The base class written after `:` in the inheritance list, or `null` to omit it. When the primary constructor
|
|
99
|
+
* delegates to `super`, its arguments are written after the base class, such as `Bar(x)`.
|
|
100
|
+
*/
|
|
44
101
|
extends: KtType<TBuilder> | null;
|
|
102
|
+
/**
|
|
103
|
+
* The further supertypes written in the inheritance list after `:`, separated by commas. When a base class is also
|
|
104
|
+
* set, they follow it after a comma.
|
|
105
|
+
*/
|
|
45
106
|
implements: KtType<TBuilder>[];
|
|
107
|
+
/**
|
|
108
|
+
* The members written in the class body, in the given order. Properties without a doc comment or annotations are
|
|
109
|
+
* written without blank lines between them, while other members are set off by blank lines.
|
|
110
|
+
*/
|
|
46
111
|
members: KtClassMember<TBuilder>[];
|
|
112
|
+
/**
|
|
113
|
+
* The companion object written first in the class body, or `null` to omit it. It is written before the `init` block
|
|
114
|
+
* of the primary constructor and before the members.
|
|
115
|
+
*/
|
|
47
116
|
companionObject: Nullable<KtObject<TBuilder>>;
|
|
117
|
+
/**
|
|
118
|
+
* Initializes a new instance of the KtClass class.
|
|
119
|
+
* @param options The options to use for this instance.
|
|
120
|
+
*/
|
|
48
121
|
constructor(options: Options<TBuilder, TInjects>);
|
|
49
122
|
protected onWrite(builder: TBuilder): void;
|
|
50
123
|
}
|
|
51
124
|
declare const createClass: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => KtClass<TBuilder>;
|
|
125
|
+
/**
|
|
126
|
+
* Factory for creating class nodes. The `write` function writes one or more class nodes to a builder.
|
|
127
|
+
*
|
|
128
|
+
* @param name The name of the class.
|
|
129
|
+
* @param options The settings of the class. See `KtClass` for the available properties.
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* ktClass('PetDto', {
|
|
133
|
+
* annotations: [ktAnnotation('Serializable')],
|
|
134
|
+
* classKind: 'data',
|
|
135
|
+
* primaryConstructor: ktConstructor([
|
|
136
|
+
* ktParameter.class('id', 'Long', { property: 'readonly' }),
|
|
137
|
+
* ktParameter.class('name', 'String', { property: 'readonly' }),
|
|
138
|
+
* ]),
|
|
139
|
+
* members: [ktProperty('tag', { type: 'String?' })],
|
|
140
|
+
* });
|
|
141
|
+
* // Emits:
|
|
142
|
+
* // @Serializable
|
|
143
|
+
* // data class PetDto(val id: Long, val name: String) {
|
|
144
|
+
* // val tag: String?
|
|
145
|
+
* // }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
52
148
|
export declare const ktClass: typeof createClass & {
|
|
53
149
|
write: typeof writeKtNodes;
|
|
54
150
|
};
|
|
@@ -7,20 +7,87 @@ import { ktArgument } from './argument.js';
|
|
|
7
7
|
import { ktDoc } from './doc.js';
|
|
8
8
|
import { ktGenericParameter } from './generic-parameter.js';
|
|
9
9
|
import { ktInitBlock } from './init-block.js';
|
|
10
|
+
/**
|
|
11
|
+
* Represents a Kotlin class declaration, such as `data class PetDto(val id: Long)`.
|
|
12
|
+
*
|
|
13
|
+
* Written in this order: the doc comment, annotations, modifiers, the `class` keyword and name, generics, the primary
|
|
14
|
+
* constructor, the inheritance list, then the body. The modifiers are written in the order access modifier, `open`,
|
|
15
|
+
* `abstract`, class kind. The body is written in braces only when it has members, a companion object or a primary
|
|
16
|
+
* constructor body.
|
|
17
|
+
*
|
|
18
|
+
* @template TBuilder The type of the source builder the class is written to.
|
|
19
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
20
|
+
* @see ktClass
|
|
21
|
+
*/
|
|
10
22
|
export class KtClass extends KtNode {
|
|
23
|
+
/**
|
|
24
|
+
* The KDoc comment written above the class, or `null` to omit it. Descriptions of generic parameters and primary
|
|
25
|
+
* constructor parameters are merged into it as `@param` tags, and property descriptions of primary constructor
|
|
26
|
+
* parameters are merged into it as `@property` tags.
|
|
27
|
+
*/
|
|
11
28
|
doc;
|
|
29
|
+
/**
|
|
30
|
+
* The annotations written above the class, each on its own line.
|
|
31
|
+
*/
|
|
12
32
|
annotations;
|
|
33
|
+
/**
|
|
34
|
+
* The visibility modifier written before the `class` keyword, or `null` to omit it. Kotlin classes are public by
|
|
35
|
+
* default, so `null` writes a public class.
|
|
36
|
+
*/
|
|
13
37
|
accessModifier;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the class is written with the `open` modifier, which allows other classes to extend it.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
14
42
|
open;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the class is written with the `abstract` modifier, placed after `open` when both are set.
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
15
47
|
abstract;
|
|
48
|
+
/**
|
|
49
|
+
* The kind of the class, written as a keyword before `class`, such as `data` for `data class`. `null` writes a
|
|
50
|
+
* regular class.
|
|
51
|
+
*/
|
|
16
52
|
classKind;
|
|
53
|
+
/**
|
|
54
|
+
* The class name, written verbatim after the `class` keyword.
|
|
55
|
+
*/
|
|
17
56
|
name;
|
|
57
|
+
/**
|
|
58
|
+
* The type parameters written in angle brackets after the name, such as `<T, U>`. Plain strings are written as-is,
|
|
59
|
+
* while described parameters also add a `@param` tag to the doc comment.
|
|
60
|
+
*/
|
|
18
61
|
generics;
|
|
62
|
+
/**
|
|
63
|
+
* The primary constructor written in parentheses after the name, or `null` to omit it. Only its annotations, access
|
|
64
|
+
* modifier and parameters are written in the header, while its body is written as an `init` block in the class body.
|
|
65
|
+
*/
|
|
19
66
|
primaryConstructor;
|
|
67
|
+
/**
|
|
68
|
+
* The base class written after `:` in the inheritance list, or `null` to omit it. When the primary constructor
|
|
69
|
+
* delegates to `super`, its arguments are written after the base class, such as `Bar(x)`.
|
|
70
|
+
*/
|
|
20
71
|
extends;
|
|
72
|
+
/**
|
|
73
|
+
* The further supertypes written in the inheritance list after `:`, separated by commas. When a base class is also
|
|
74
|
+
* set, they follow it after a comma.
|
|
75
|
+
*/
|
|
21
76
|
implements;
|
|
77
|
+
/**
|
|
78
|
+
* The members written in the class body, in the given order. Properties without a doc comment or annotations are
|
|
79
|
+
* written without blank lines between them, while other members are set off by blank lines.
|
|
80
|
+
*/
|
|
22
81
|
members;
|
|
82
|
+
/**
|
|
83
|
+
* The companion object written first in the class body, or `null` to omit it. It is written before the `init` block
|
|
84
|
+
* of the primary constructor and before the members.
|
|
85
|
+
*/
|
|
23
86
|
companionObject;
|
|
87
|
+
/**
|
|
88
|
+
* Initializes a new instance of the KtClass class.
|
|
89
|
+
* @param options The options to use for this instance.
|
|
90
|
+
*/
|
|
24
91
|
constructor(options) {
|
|
25
92
|
super(options);
|
|
26
93
|
this.doc = options.doc ?? null;
|
|
@@ -95,6 +162,29 @@ export class KtClass extends KtNode {
|
|
|
95
162
|
}
|
|
96
163
|
}
|
|
97
164
|
const createClass = (name, options) => new KtClass({ ...options, name });
|
|
165
|
+
/**
|
|
166
|
+
* Factory for creating class nodes. The `write` function writes one or more class nodes to a builder.
|
|
167
|
+
*
|
|
168
|
+
* @param name The name of the class.
|
|
169
|
+
* @param options The settings of the class. See `KtClass` for the available properties.
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* ktClass('PetDto', {
|
|
173
|
+
* annotations: [ktAnnotation('Serializable')],
|
|
174
|
+
* classKind: 'data',
|
|
175
|
+
* primaryConstructor: ktConstructor([
|
|
176
|
+
* ktParameter.class('id', 'Long', { property: 'readonly' }),
|
|
177
|
+
* ktParameter.class('name', 'String', { property: 'readonly' }),
|
|
178
|
+
* ]),
|
|
179
|
+
* members: [ktProperty('tag', { type: 'String?' })],
|
|
180
|
+
* });
|
|
181
|
+
* // Emits:
|
|
182
|
+
* // @Serializable
|
|
183
|
+
* // data class PetDto(val id: Long, val name: String) {
|
|
184
|
+
* // val tag: String?
|
|
185
|
+
* // }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
98
188
|
export const ktClass = Object.assign(createClass, {
|
|
99
189
|
write: writeKtNodes,
|
|
100
190
|
});
|