@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
|
@@ -25,21 +25,88 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
25
25
|
members?: Nullable<Nullable<KtEnumMember<TBuilder>>[]>;
|
|
26
26
|
companionObject?: Nullable<KtObject<TBuilder>>;
|
|
27
27
|
}>;
|
|
28
|
+
/**
|
|
29
|
+
* The nodes that can be written in the body of an enum class, after the entries. Other append values are written as-is.
|
|
30
|
+
*/
|
|
28
31
|
export type KtEnumMember<TBuilder extends SourceBuilder> = KtConstructor<TBuilder> | KtEnum<TBuilder> | KtInitBlock<TBuilder> | KtInterface<TBuilder> | KtProperty<TBuilder> | KtFunction<TBuilder> | KtClass<TBuilder> | AppendValue<TBuilder>;
|
|
32
|
+
/**
|
|
33
|
+
* Represents a Kotlin enum class, such as `enum class Color(val rgb: Int) { RED(0xFF0000) }`.
|
|
34
|
+
*
|
|
35
|
+
* Written in this order: the doc comment, annotations, the access modifier, `enum class`, the name, the primary
|
|
36
|
+
* constructor, the implemented interfaces, then the body. The body holds the entries, which are followed by a semicolon
|
|
37
|
+
* when members or a companion object are written after them.
|
|
38
|
+
*
|
|
39
|
+
* @template TBuilder The type of the source builder the enum is written to.
|
|
40
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
41
|
+
* @see ktEnum
|
|
42
|
+
*/
|
|
29
43
|
export declare class KtEnum<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
44
|
+
/**
|
|
45
|
+
* The name of the enum class, written verbatim after `enum class`.
|
|
46
|
+
*/
|
|
30
47
|
name: string;
|
|
48
|
+
/**
|
|
49
|
+
* The KDoc comment written above the enum, or `null` to omit it. Descriptions of primary constructor parameters are
|
|
50
|
+
* merged into it as `@param` tags.
|
|
51
|
+
*/
|
|
31
52
|
doc: KtDoc<TBuilder> | null;
|
|
53
|
+
/**
|
|
54
|
+
* The annotations written above the enum, each on its own line.
|
|
55
|
+
*/
|
|
32
56
|
annotations: KtAnnotation<TBuilder>[];
|
|
57
|
+
/**
|
|
58
|
+
* The visibility modifier written before `enum class`, or `null` to omit it. Kotlin declarations are public by
|
|
59
|
+
* default, so `null` writes a public enum.
|
|
60
|
+
*/
|
|
33
61
|
accessModifier: KtAccessModifier | null;
|
|
62
|
+
/**
|
|
63
|
+
* The primary constructor written in parentheses after the name, or `null` to omit it. Its body is written as an
|
|
64
|
+
* `init` block among the members.
|
|
65
|
+
*/
|
|
34
66
|
primaryConstructor: KtConstructor<TBuilder> | null;
|
|
67
|
+
/**
|
|
68
|
+
* The interfaces written after `:`, separated by commas. The clause is omitted when the list is empty.
|
|
69
|
+
*/
|
|
35
70
|
implements: KtType<TBuilder>[];
|
|
71
|
+
/**
|
|
72
|
+
* The entries written at the start of the body, separated by commas, in the given order. The body is omitted when
|
|
73
|
+
* there are neither entries nor members.
|
|
74
|
+
*/
|
|
36
75
|
values: KtEnumValue<TBuilder>[];
|
|
76
|
+
/**
|
|
77
|
+
* The members written in the body after the entries, in the given order. Like class members, they are set off by
|
|
78
|
+
* blank lines.
|
|
79
|
+
*/
|
|
37
80
|
members: KtEnumMember<TBuilder>[];
|
|
81
|
+
/**
|
|
82
|
+
* The companion object written first among the members, or `null` to omit it.
|
|
83
|
+
*/
|
|
38
84
|
companionObject: KtObject<TBuilder> | null;
|
|
85
|
+
/**
|
|
86
|
+
* Initializes a new instance of the KtEnum class.
|
|
87
|
+
* @param options The options to use for this instance.
|
|
88
|
+
*/
|
|
39
89
|
constructor(options: Options<TBuilder, TInjects>);
|
|
40
90
|
protected onWrite(builder: TBuilder): void;
|
|
41
91
|
}
|
|
42
92
|
declare const createEnum: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], values?: Options<TBuilder>['values'], options?: Prettify<Omit<Options<TBuilder>, 'name' | 'values'>>) => KtEnum<TBuilder>;
|
|
93
|
+
/**
|
|
94
|
+
* Factory for creating enum class nodes. The `write` function writes one or more enum nodes to a builder.
|
|
95
|
+
*
|
|
96
|
+
* @param name The name of the enum class.
|
|
97
|
+
* @param values The entries of the enum. See `KtEnum.values`.
|
|
98
|
+
* @param options The settings of the enum. See `KtEnum` for the available properties.
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* ktEnum('Color', [ktEnumValue('RED', { arguments: ['0xFF0000'] })], {
|
|
102
|
+
* primaryConstructor: ktConstructor([ktParameter('rgb', 'Int')]),
|
|
103
|
+
* });
|
|
104
|
+
* // Emits:
|
|
105
|
+
* // enum class Color(rgb: Int) {
|
|
106
|
+
* // RED(0xFF0000)
|
|
107
|
+
* // }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
43
110
|
export declare const ktEnum: typeof createEnum & {
|
|
44
111
|
write: typeof writeKtNodes;
|
|
45
112
|
};
|
|
@@ -6,16 +6,63 @@ import { ktAnnotation } from './annotation.js';
|
|
|
6
6
|
import { ktDoc } from './doc.js';
|
|
7
7
|
import { ktEnumValue } from './enum-value.js';
|
|
8
8
|
import { ktInitBlock } from './init-block.js';
|
|
9
|
+
/**
|
|
10
|
+
* Represents a Kotlin enum class, such as `enum class Color(val rgb: Int) { RED(0xFF0000) }`.
|
|
11
|
+
*
|
|
12
|
+
* Written in this order: the doc comment, annotations, the access modifier, `enum class`, the name, the primary
|
|
13
|
+
* constructor, the implemented interfaces, then the body. The body holds the entries, which are followed by a semicolon
|
|
14
|
+
* when members or a companion object are written after them.
|
|
15
|
+
*
|
|
16
|
+
* @template TBuilder The type of the source builder the enum is written to.
|
|
17
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
18
|
+
* @see ktEnum
|
|
19
|
+
*/
|
|
9
20
|
export class KtEnum extends KtNode {
|
|
21
|
+
/**
|
|
22
|
+
* The name of the enum class, written verbatim after `enum class`.
|
|
23
|
+
*/
|
|
10
24
|
name;
|
|
25
|
+
/**
|
|
26
|
+
* The KDoc comment written above the enum, or `null` to omit it. Descriptions of primary constructor parameters are
|
|
27
|
+
* merged into it as `@param` tags.
|
|
28
|
+
*/
|
|
11
29
|
doc;
|
|
30
|
+
/**
|
|
31
|
+
* The annotations written above the enum, each on its own line.
|
|
32
|
+
*/
|
|
12
33
|
annotations;
|
|
34
|
+
/**
|
|
35
|
+
* The visibility modifier written before `enum class`, or `null` to omit it. Kotlin declarations are public by
|
|
36
|
+
* default, so `null` writes a public enum.
|
|
37
|
+
*/
|
|
13
38
|
accessModifier;
|
|
39
|
+
/**
|
|
40
|
+
* The primary constructor written in parentheses after the name, or `null` to omit it. Its body is written as an
|
|
41
|
+
* `init` block among the members.
|
|
42
|
+
*/
|
|
14
43
|
primaryConstructor;
|
|
44
|
+
/**
|
|
45
|
+
* The interfaces written after `:`, separated by commas. The clause is omitted when the list is empty.
|
|
46
|
+
*/
|
|
15
47
|
implements;
|
|
48
|
+
/**
|
|
49
|
+
* The entries written at the start of the body, separated by commas, in the given order. The body is omitted when
|
|
50
|
+
* there are neither entries nor members.
|
|
51
|
+
*/
|
|
16
52
|
values;
|
|
53
|
+
/**
|
|
54
|
+
* The members written in the body after the entries, in the given order. Like class members, they are set off by
|
|
55
|
+
* blank lines.
|
|
56
|
+
*/
|
|
17
57
|
members;
|
|
58
|
+
/**
|
|
59
|
+
* The companion object written first among the members, or `null` to omit it.
|
|
60
|
+
*/
|
|
18
61
|
companionObject;
|
|
62
|
+
/**
|
|
63
|
+
* Initializes a new instance of the KtEnum class.
|
|
64
|
+
* @param options The options to use for this instance.
|
|
65
|
+
*/
|
|
19
66
|
constructor(options) {
|
|
20
67
|
super(options);
|
|
21
68
|
this.name = options.name;
|
|
@@ -81,6 +128,23 @@ export class KtEnum extends KtNode {
|
|
|
81
128
|
}
|
|
82
129
|
}
|
|
83
130
|
const createEnum = (name, values, options) => new KtEnum({ ...options, name, values: values ?? undefined });
|
|
131
|
+
/**
|
|
132
|
+
* Factory for creating enum class nodes. The `write` function writes one or more enum nodes to a builder.
|
|
133
|
+
*
|
|
134
|
+
* @param name The name of the enum class.
|
|
135
|
+
* @param values The entries of the enum. See `KtEnum.values`.
|
|
136
|
+
* @param options The settings of the enum. See `KtEnum` for the available properties.
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* ktEnum('Color', [ktEnumValue('RED', { arguments: ['0xFF0000'] })], {
|
|
140
|
+
* primaryConstructor: ktConstructor([ktParameter('rgb', 'Int')]),
|
|
141
|
+
* });
|
|
142
|
+
* // Emits:
|
|
143
|
+
* // enum class Color(rgb: Int) {
|
|
144
|
+
* // RED(0xFF0000)
|
|
145
|
+
* // }
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
84
148
|
export const ktEnum = Object.assign(createEnum, {
|
|
85
149
|
write: writeKtNodes,
|
|
86
150
|
});
|
|
@@ -29,30 +29,135 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
29
29
|
override?: Nullable<boolean>;
|
|
30
30
|
abstract?: Nullable<boolean>;
|
|
31
31
|
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Represents a Kotlin function declaration, such as `fun String.greet(name: String): String = "Hello, $name"`.
|
|
34
|
+
*
|
|
35
|
+
* Written in this order: the doc comment, annotations, the modifiers, `fun`, the generics, the receiver type followed
|
|
36
|
+
* by a dot, the name, the parameters, the return type, then the body. The modifiers are written in the order access
|
|
37
|
+
* modifier, `inline`, `infix`, `tailrec`, `suspend`, `open`, `override`, `abstract`, `operator`. A body is omitted for
|
|
38
|
+
* abstract functions and for functions in an interface that have no body.
|
|
39
|
+
*
|
|
40
|
+
* @template TBuilder The type of the source builder the function is written to.
|
|
41
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
42
|
+
* @see ktFunction
|
|
43
|
+
*/
|
|
32
44
|
export declare class KtFunction<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
45
|
+
/**
|
|
46
|
+
* The name of the function, written verbatim after the receiver type, if there is one.
|
|
47
|
+
*/
|
|
33
48
|
name: string;
|
|
49
|
+
/**
|
|
50
|
+
* The type parameters written in angle brackets after `fun`, such as `<T>`. Plain strings are written as-is, while
|
|
51
|
+
* described parameters also add a `@param` tag to the doc comment.
|
|
52
|
+
*/
|
|
34
53
|
generics: (KtGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
54
|
+
/**
|
|
55
|
+
* The parameters written in parentheses after the name. Parameters with a description add a `@param` tag to the doc
|
|
56
|
+
* comment.
|
|
57
|
+
*/
|
|
35
58
|
parameters: (KtParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
|
|
59
|
+
/**
|
|
60
|
+
* The KDoc comment written above the function, or `null` to omit it. Descriptions of generic parameters and function
|
|
61
|
+
* parameters are merged into it as `@param` tags.
|
|
62
|
+
*/
|
|
36
63
|
doc: KtDoc<TBuilder> | null;
|
|
64
|
+
/**
|
|
65
|
+
* The return type written after `:`, or `null` to omit it.
|
|
66
|
+
*/
|
|
37
67
|
returnType: KtType<TBuilder> | null;
|
|
68
|
+
/**
|
|
69
|
+
* The statements written inside the braces, or the expression written after `=` when `singleExpression` is set.
|
|
70
|
+
* `null` writes empty braces. Nothing is written for abstract functions and for interface functions without a body.
|
|
71
|
+
*/
|
|
38
72
|
body: AppendValue<TBuilder> | null;
|
|
73
|
+
/**
|
|
74
|
+
* The visibility modifier written before `fun`, or `null` to omit it.
|
|
75
|
+
*/
|
|
39
76
|
accessModifier: KtAccessModifier | null;
|
|
77
|
+
/**
|
|
78
|
+
* The annotations written above the function, each on its own line.
|
|
79
|
+
*/
|
|
40
80
|
annotations: KtAnnotation<TBuilder>[];
|
|
81
|
+
/**
|
|
82
|
+
* The receiver type written before the name, followed by a dot, such as `String` for `String.greet`. `null` omits it.
|
|
83
|
+
*/
|
|
41
84
|
receiverType: KtType<TBuilder> | null;
|
|
85
|
+
/**
|
|
86
|
+
* The annotations written on the same line directly before the receiver type, such as `@Fancy` in
|
|
87
|
+
* `fun @Fancy String.foo()`. Only written when `receiverType` is set.
|
|
88
|
+
*/
|
|
42
89
|
receiverAnnotations: KtAnnotation<TBuilder>[];
|
|
90
|
+
/**
|
|
91
|
+
* Whether the body is written as a single expression after `=` instead of a block in braces. Only applies when a body
|
|
92
|
+
* is set.
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
43
95
|
singleExpression: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Whether the function is written with the `open` modifier, which allows subclasses to override it.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
44
100
|
open: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the function is written with the `inline` modifier.
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
45
105
|
inline: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Whether the function is written with the `infix` modifier, which allows calls in infix form.
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
46
110
|
infix: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Whether the function is written with the `tailrec` modifier, which turns recursive calls into loops.
|
|
113
|
+
* @default false
|
|
114
|
+
*/
|
|
47
115
|
tailrec: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Whether the function is written with the `suspend` modifier, which makes it a coroutine function.
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
48
120
|
suspend: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the function is written with the `operator` modifier, which allows calls through operator conventions.
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
49
125
|
operator: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Whether the function is written with the `override` modifier, which overrides a member of a supertype.
|
|
128
|
+
* @default false
|
|
129
|
+
*/
|
|
50
130
|
override: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Whether the function is written with the `abstract` modifier. Abstract functions are written without a body.
|
|
133
|
+
* @default false
|
|
134
|
+
*/
|
|
51
135
|
abstract: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Initializes a new instance of the KtFunction class.
|
|
138
|
+
* @param options The options to use for this instance.
|
|
139
|
+
*/
|
|
52
140
|
constructor(options: Options<TBuilder, TInjects>);
|
|
53
141
|
protected onWrite(builder: TBuilder): void;
|
|
54
142
|
}
|
|
55
143
|
declare const createFunction: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => KtFunction<TBuilder>;
|
|
144
|
+
/**
|
|
145
|
+
* Factory for creating function nodes. The `write` function writes one or more function nodes to a builder.
|
|
146
|
+
*
|
|
147
|
+
* @param name The name of the function.
|
|
148
|
+
* @param options The settings of the function. See `KtFunction` for the available properties.
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* ktFunction('greet', {
|
|
152
|
+
* parameters: [ktParameter('name', 'String')],
|
|
153
|
+
* returnType: 'String',
|
|
154
|
+
* body: '"Hello, $name"',
|
|
155
|
+
* singleExpression: true,
|
|
156
|
+
* });
|
|
157
|
+
* // Emits:
|
|
158
|
+
* // fun greet(name: String): String = "Hello, $name"
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
56
161
|
export declare const ktFunction: typeof createFunction & {
|
|
57
162
|
write: typeof writeKtNodes;
|
|
58
163
|
};
|
|
@@ -6,26 +6,114 @@ import { ktDoc } from './doc.js';
|
|
|
6
6
|
import { ktGenericParameter } from './generic-parameter.js';
|
|
7
7
|
import { KtInterface } from './interface.js';
|
|
8
8
|
import { ktParameter } from './parameter.js';
|
|
9
|
+
/**
|
|
10
|
+
* Represents a Kotlin function declaration, such as `fun String.greet(name: String): String = "Hello, $name"`.
|
|
11
|
+
*
|
|
12
|
+
* Written in this order: the doc comment, annotations, the modifiers, `fun`, the generics, the receiver type followed
|
|
13
|
+
* by a dot, the name, the parameters, the return type, then the body. The modifiers are written in the order access
|
|
14
|
+
* modifier, `inline`, `infix`, `tailrec`, `suspend`, `open`, `override`, `abstract`, `operator`. A body is omitted for
|
|
15
|
+
* abstract functions and for functions in an interface that have no body.
|
|
16
|
+
*
|
|
17
|
+
* @template TBuilder The type of the source builder the function is written to.
|
|
18
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
19
|
+
* @see ktFunction
|
|
20
|
+
*/
|
|
9
21
|
export class KtFunction extends KtNode {
|
|
22
|
+
/**
|
|
23
|
+
* The name of the function, written verbatim after the receiver type, if there is one.
|
|
24
|
+
*/
|
|
10
25
|
name;
|
|
26
|
+
/**
|
|
27
|
+
* The type parameters written in angle brackets after `fun`, such as `<T>`. Plain strings are written as-is, while
|
|
28
|
+
* described parameters also add a `@param` tag to the doc comment.
|
|
29
|
+
*/
|
|
11
30
|
generics;
|
|
31
|
+
/**
|
|
32
|
+
* The parameters written in parentheses after the name. Parameters with a description add a `@param` tag to the doc
|
|
33
|
+
* comment.
|
|
34
|
+
*/
|
|
12
35
|
parameters;
|
|
36
|
+
/**
|
|
37
|
+
* The KDoc comment written above the function, or `null` to omit it. Descriptions of generic parameters and function
|
|
38
|
+
* parameters are merged into it as `@param` tags.
|
|
39
|
+
*/
|
|
13
40
|
doc;
|
|
41
|
+
/**
|
|
42
|
+
* The return type written after `:`, or `null` to omit it.
|
|
43
|
+
*/
|
|
14
44
|
returnType;
|
|
45
|
+
/**
|
|
46
|
+
* The statements written inside the braces, or the expression written after `=` when `singleExpression` is set.
|
|
47
|
+
* `null` writes empty braces. Nothing is written for abstract functions and for interface functions without a body.
|
|
48
|
+
*/
|
|
15
49
|
body;
|
|
50
|
+
/**
|
|
51
|
+
* The visibility modifier written before `fun`, or `null` to omit it.
|
|
52
|
+
*/
|
|
16
53
|
accessModifier;
|
|
54
|
+
/**
|
|
55
|
+
* The annotations written above the function, each on its own line.
|
|
56
|
+
*/
|
|
17
57
|
annotations;
|
|
58
|
+
/**
|
|
59
|
+
* The receiver type written before the name, followed by a dot, such as `String` for `String.greet`. `null` omits it.
|
|
60
|
+
*/
|
|
18
61
|
receiverType;
|
|
62
|
+
/**
|
|
63
|
+
* The annotations written on the same line directly before the receiver type, such as `@Fancy` in
|
|
64
|
+
* `fun @Fancy String.foo()`. Only written when `receiverType` is set.
|
|
65
|
+
*/
|
|
19
66
|
receiverAnnotations;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the body is written as a single expression after `=` instead of a block in braces. Only applies when a body
|
|
69
|
+
* is set.
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
20
72
|
singleExpression;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the function is written with the `open` modifier, which allows subclasses to override it.
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
21
77
|
open;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the function is written with the `inline` modifier.
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
22
82
|
inline;
|
|
83
|
+
/**
|
|
84
|
+
* Whether the function is written with the `infix` modifier, which allows calls in infix form.
|
|
85
|
+
* @default false
|
|
86
|
+
*/
|
|
23
87
|
infix;
|
|
88
|
+
/**
|
|
89
|
+
* Whether the function is written with the `tailrec` modifier, which turns recursive calls into loops.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
24
92
|
tailrec;
|
|
93
|
+
/**
|
|
94
|
+
* Whether the function is written with the `suspend` modifier, which makes it a coroutine function.
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
25
97
|
suspend;
|
|
98
|
+
/**
|
|
99
|
+
* Whether the function is written with the `operator` modifier, which allows calls through operator conventions.
|
|
100
|
+
* @default false
|
|
101
|
+
*/
|
|
26
102
|
operator;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the function is written with the `override` modifier, which overrides a member of a supertype.
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
27
107
|
override;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the function is written with the `abstract` modifier. Abstract functions are written without a body.
|
|
110
|
+
* @default false
|
|
111
|
+
*/
|
|
28
112
|
abstract;
|
|
113
|
+
/**
|
|
114
|
+
* Initializes a new instance of the KtFunction class.
|
|
115
|
+
* @param options The options to use for this instance.
|
|
116
|
+
*/
|
|
29
117
|
constructor(options) {
|
|
30
118
|
super(options);
|
|
31
119
|
this.name = options.name;
|
|
@@ -115,6 +203,23 @@ export class KtFunction extends KtNode {
|
|
|
115
203
|
}
|
|
116
204
|
}
|
|
117
205
|
const createFunction = (name, options) => new KtFunction({ ...options, name });
|
|
206
|
+
/**
|
|
207
|
+
* Factory for creating function nodes. The `write` function writes one or more function nodes to a builder.
|
|
208
|
+
*
|
|
209
|
+
* @param name The name of the function.
|
|
210
|
+
* @param options The settings of the function. See `KtFunction` for the available properties.
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* ktFunction('greet', {
|
|
214
|
+
* parameters: [ktParameter('name', 'String')],
|
|
215
|
+
* returnType: 'String',
|
|
216
|
+
* body: '"Hello, $name"',
|
|
217
|
+
* singleExpression: true,
|
|
218
|
+
* });
|
|
219
|
+
* // Emits:
|
|
220
|
+
* // fun greet(name: String): String = "Hello, $name"
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
118
223
|
export const ktFunction = Object.assign(createFunction, {
|
|
119
224
|
write: writeKtNodes,
|
|
120
225
|
});
|
|
@@ -8,14 +8,51 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
|
|
|
8
8
|
description?: Nullable<BasicAppendValue<TBuilder>>;
|
|
9
9
|
constraint?: Nullable<KtType<TBuilder>>;
|
|
10
10
|
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a type parameter of a Kotlin class or function, such as `T : Number` in `class Box<T : Number>`.
|
|
13
|
+
*
|
|
14
|
+
* Written in this order: the name, then ` : ` and the constraint when one is set. The description is not written
|
|
15
|
+
* next to the parameter, but becomes a `@param` tag in the doc comment of the owning class or function.
|
|
16
|
+
*
|
|
17
|
+
* @template TBuilder The type of the source builder the type parameter is written to.
|
|
18
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
19
|
+
* @see ktGenericParameter
|
|
20
|
+
*/
|
|
11
21
|
export declare class KtGenericParameter<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
22
|
+
/**
|
|
23
|
+
* The name of the type parameter, written verbatim.
|
|
24
|
+
*/
|
|
12
25
|
name: string;
|
|
26
|
+
/**
|
|
27
|
+
* The description of the type parameter. It becomes a `@param` tag in the doc comment of the owning class or
|
|
28
|
+
* function, and `null` adds no tag.
|
|
29
|
+
*/
|
|
13
30
|
description: BasicAppendValue<TBuilder> | null;
|
|
31
|
+
/**
|
|
32
|
+
* The upper bound written after ` : `, such as `Number` for `T : Number`, or `null` for an unconstrained parameter.
|
|
33
|
+
*/
|
|
14
34
|
constraint: KtType<TBuilder> | null;
|
|
35
|
+
/**
|
|
36
|
+
* Initializes a new instance of the KtGenericParameter class.
|
|
37
|
+
* @param options The options to use for this instance.
|
|
38
|
+
*/
|
|
15
39
|
constructor(options: Options<TBuilder, TInjects>);
|
|
16
40
|
protected onWrite(builder: TBuilder): void;
|
|
17
41
|
}
|
|
18
42
|
declare const createGenericParameter: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => KtGenericParameter<TBuilder>;
|
|
43
|
+
/**
|
|
44
|
+
* Factory for creating generic parameter nodes. The `write` function writes a list of type parameters in angle
|
|
45
|
+
* brackets, or nothing when the list is empty.
|
|
46
|
+
*
|
|
47
|
+
* @param name The name of the type parameter.
|
|
48
|
+
* @param options The settings of the type parameter. See `KtGenericParameter` for the available properties.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* ktGenericParameter('T', { constraint: 'Number' });
|
|
52
|
+
* // Emits:
|
|
53
|
+
* // T : Number
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
19
56
|
export declare const ktGenericParameter: typeof createGenericParameter & {
|
|
20
57
|
write: typeof writeKtGenericParameters;
|
|
21
58
|
};
|
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
import { KtNode } from '../node.js';
|
|
2
2
|
import { writeKtGenericParameters } from '../utils/write-kt-generic-parameters.js';
|
|
3
3
|
import { writeKtNode } from '../utils/write-kt-node.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a type parameter of a Kotlin class or function, such as `T : Number` in `class Box<T : Number>`.
|
|
6
|
+
*
|
|
7
|
+
* Written in this order: the name, then ` : ` and the constraint when one is set. The description is not written
|
|
8
|
+
* next to the parameter, but becomes a `@param` tag in the doc comment of the owning class or function.
|
|
9
|
+
*
|
|
10
|
+
* @template TBuilder The type of the source builder the type parameter is written to.
|
|
11
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
12
|
+
* @see ktGenericParameter
|
|
13
|
+
*/
|
|
4
14
|
export class KtGenericParameter extends KtNode {
|
|
15
|
+
/**
|
|
16
|
+
* The name of the type parameter, written verbatim.
|
|
17
|
+
*/
|
|
5
18
|
name;
|
|
19
|
+
/**
|
|
20
|
+
* The description of the type parameter. It becomes a `@param` tag in the doc comment of the owning class or
|
|
21
|
+
* function, and `null` adds no tag.
|
|
22
|
+
*/
|
|
6
23
|
description;
|
|
24
|
+
/**
|
|
25
|
+
* The upper bound written after ` : `, such as `Number` for `T : Number`, or `null` for an unconstrained parameter.
|
|
26
|
+
*/
|
|
7
27
|
constraint;
|
|
28
|
+
/**
|
|
29
|
+
* Initializes a new instance of the KtGenericParameter class.
|
|
30
|
+
* @param options The options to use for this instance.
|
|
31
|
+
*/
|
|
8
32
|
constructor(options) {
|
|
9
33
|
super(options);
|
|
10
34
|
this.name = options.name;
|
|
@@ -22,6 +46,19 @@ export class KtGenericParameter extends KtNode {
|
|
|
22
46
|
}
|
|
23
47
|
}
|
|
24
48
|
const createGenericParameter = (name, options) => new KtGenericParameter({ ...options, name });
|
|
49
|
+
/**
|
|
50
|
+
* Factory for creating generic parameter nodes. The `write` function writes a list of type parameters in angle
|
|
51
|
+
* brackets, or nothing when the list is empty.
|
|
52
|
+
*
|
|
53
|
+
* @param name The name of the type parameter.
|
|
54
|
+
* @param options The settings of the type parameter. See `KtGenericParameter` for the available properties.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* ktGenericParameter('T', { constraint: 'Number' });
|
|
58
|
+
* // Emits:
|
|
59
|
+
* // T : Number
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
25
62
|
export const ktGenericParameter = Object.assign(createGenericParameter, {
|
|
26
63
|
write: writeKtGenericParameters,
|
|
27
64
|
});
|
|
@@ -5,12 +5,44 @@ type Injects = never;
|
|
|
5
5
|
type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<typeof KtNode<TBuilder, TInjects | Injects>, {
|
|
6
6
|
body: AppendValue<TBuilder>;
|
|
7
7
|
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Represents a Kotlin `init` block, whose statements run when the enclosing class is instantiated.
|
|
10
|
+
*
|
|
11
|
+
* Written in this order: the `init` keyword, then the body in braces. A body other than an empty string is written on
|
|
12
|
+
* indented lines of its own, while an empty string writes `init {}` on one line.
|
|
13
|
+
*
|
|
14
|
+
* @template TBuilder The type of the source builder the init block is written to.
|
|
15
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
16
|
+
* @see ktInitBlock
|
|
17
|
+
*/
|
|
8
18
|
export declare class KtInitBlock<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
|
|
19
|
+
/**
|
|
20
|
+
* The statements written inside the braces. An empty string writes `init {}` on one line. Any other value is written
|
|
21
|
+
* on indented lines of its own.
|
|
22
|
+
*/
|
|
9
23
|
body: AppendValue<TBuilder>;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes a new instance of the KtInitBlock class.
|
|
26
|
+
* @param options The options to use for this instance.
|
|
27
|
+
*/
|
|
10
28
|
constructor(options: Options<TBuilder, TInjects>);
|
|
11
29
|
protected onWrite(builder: TBuilder): void;
|
|
12
30
|
}
|
|
13
31
|
declare const createInitBlock: <TBuilder extends SourceBuilder>(body: Options<TBuilder>['body'], options?: Prettify<Omit<Options<TBuilder>, 'body'>>) => KtInitBlock<TBuilder>;
|
|
32
|
+
/**
|
|
33
|
+
* Factory for creating init block nodes. The `write` function writes one or more init block nodes to a builder.
|
|
34
|
+
*
|
|
35
|
+
* @param body The statements written inside the braces of the init block. See `KtInitBlock.body`.
|
|
36
|
+
* @param options The settings of the init block. See `KtInitBlock` for the available properties.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* ktInitBlock('println("Hello")');
|
|
40
|
+
* // Emits:
|
|
41
|
+
* // init {
|
|
42
|
+
* // println("Hello")
|
|
43
|
+
* // }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
14
46
|
export declare const ktInitBlock: typeof createInitBlock & {
|
|
15
47
|
write: typeof writeKtNodes;
|
|
16
48
|
};
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import { KtNode } from '../node.js';
|
|
2
2
|
import { writeKtNodes } from '../utils/write-kt-node.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Kotlin `init` block, whose statements run when the enclosing class is instantiated.
|
|
5
|
+
*
|
|
6
|
+
* Written in this order: the `init` keyword, then the body in braces. A body other than an empty string is written on
|
|
7
|
+
* indented lines of its own, while an empty string writes `init {}` on one line.
|
|
8
|
+
*
|
|
9
|
+
* @template TBuilder The type of the source builder the init block is written to.
|
|
10
|
+
* @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
|
|
11
|
+
* @see ktInitBlock
|
|
12
|
+
*/
|
|
3
13
|
export class KtInitBlock extends KtNode {
|
|
14
|
+
/**
|
|
15
|
+
* The statements written inside the braces. An empty string writes `init {}` on one line. Any other value is written
|
|
16
|
+
* on indented lines of its own.
|
|
17
|
+
*/
|
|
4
18
|
body;
|
|
19
|
+
/**
|
|
20
|
+
* Initializes a new instance of the KtInitBlock class.
|
|
21
|
+
* @param options The options to use for this instance.
|
|
22
|
+
*/
|
|
5
23
|
constructor(options) {
|
|
6
24
|
super(options);
|
|
7
25
|
this.body = options.body;
|
|
@@ -11,6 +29,20 @@ export class KtInitBlock extends KtNode {
|
|
|
11
29
|
}
|
|
12
30
|
}
|
|
13
31
|
const createInitBlock = (body, options) => new KtInitBlock({ ...options, body });
|
|
32
|
+
/**
|
|
33
|
+
* Factory for creating init block nodes. The `write` function writes one or more init block nodes to a builder.
|
|
34
|
+
*
|
|
35
|
+
* @param body The statements written inside the braces of the init block. See `KtInitBlock.body`.
|
|
36
|
+
* @param options The settings of the init block. See `KtInitBlock` for the available properties.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* ktInitBlock('println("Hello")');
|
|
40
|
+
* // Emits:
|
|
41
|
+
* // init {
|
|
42
|
+
* // println("Hello")
|
|
43
|
+
* // }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
14
46
|
export const ktInitBlock = Object.assign(createInitBlock, {
|
|
15
47
|
write: writeKtNodes,
|
|
16
48
|
});
|