@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.
Files changed (132) hide show
  1. package/dist/src/assets.d.ts +17 -0
  2. package/dist/src/assets.js +17 -0
  3. package/dist/src/ast/common.d.ts +4 -0
  4. package/dist/src/ast/node.d.ts +11 -0
  5. package/dist/src/ast/node.js +11 -0
  6. package/dist/src/ast/nodes/annotation.d.ts +44 -0
  7. package/dist/src/ast/nodes/annotation.js +40 -0
  8. package/dist/src/ast/nodes/argument.d.ts +33 -0
  9. package/dist/src/ast/nodes/argument.js +33 -0
  10. package/dist/src/ast/nodes/call.d.ts +42 -0
  11. package/dist/src/ast/nodes/call.js +42 -0
  12. package/dist/src/ast/nodes/class.d.ts +96 -0
  13. package/dist/src/ast/nodes/class.js +90 -0
  14. package/dist/src/ast/nodes/collection-literal.d.ts +35 -0
  15. package/dist/src/ast/nodes/collection-literal.js +35 -0
  16. package/dist/src/ast/nodes/constructor.d.ts +65 -0
  17. package/dist/src/ast/nodes/constructor.js +62 -0
  18. package/dist/src/ast/nodes/doc-tag.d.ts +41 -0
  19. package/dist/src/ast/nodes/doc-tag.js +41 -0
  20. package/dist/src/ast/nodes/doc.d.ts +44 -0
  21. package/dist/src/ast/nodes/doc.js +44 -0
  22. package/dist/src/ast/nodes/enum-value.d.ts +50 -0
  23. package/dist/src/ast/nodes/enum-value.js +47 -0
  24. package/dist/src/ast/nodes/enum.d.ts +67 -0
  25. package/dist/src/ast/nodes/enum.js +64 -0
  26. package/dist/src/ast/nodes/function.d.ts +105 -0
  27. package/dist/src/ast/nodes/function.js +105 -0
  28. package/dist/src/ast/nodes/generic-parameter.d.ts +37 -0
  29. package/dist/src/ast/nodes/generic-parameter.js +37 -0
  30. package/dist/src/ast/nodes/init-block.d.ts +32 -0
  31. package/dist/src/ast/nodes/init-block.js +32 -0
  32. package/dist/src/ast/nodes/interface.d.ts +73 -0
  33. package/dist/src/ast/nodes/interface.js +68 -0
  34. package/dist/src/ast/nodes/lambda-type.d.ts +42 -0
  35. package/dist/src/ast/nodes/lambda-type.js +42 -0
  36. package/dist/src/ast/nodes/lambda.d.ts +41 -0
  37. package/dist/src/ast/nodes/lambda.js +41 -0
  38. package/dist/src/ast/nodes/object.d.ts +66 -0
  39. package/dist/src/ast/nodes/object.js +62 -0
  40. package/dist/src/ast/nodes/parameter.d.ts +68 -0
  41. package/dist/src/ast/nodes/parameter.js +68 -0
  42. package/dist/src/ast/nodes/property.d.ts +152 -0
  43. package/dist/src/ast/nodes/property.js +148 -0
  44. package/dist/src/ast/nodes/reference.d.ts +107 -0
  45. package/dist/src/ast/nodes/reference.js +75 -0
  46. package/dist/src/ast/nodes/string.d.ts +57 -0
  47. package/dist/src/ast/nodes/string.js +57 -0
  48. package/dist/src/ast/nodes/types.d.ts +9 -0
  49. package/dist/src/ast/references/jackson.d.ts +67 -0
  50. package/dist/src/ast/references/jackson.js +59 -0
  51. package/dist/src/ast/references/jakarta.d.ts +13 -0
  52. package/dist/src/ast/references/jakarta.js +13 -0
  53. package/dist/src/ast/references/java.d.ts +19 -0
  54. package/dist/src/ast/references/java.js +19 -0
  55. package/dist/src/ast/references/kotlin.d.ts +28 -0
  56. package/dist/src/ast/references/kotlin.js +28 -0
  57. package/dist/src/ast/references/kotlinx.d.ts +8 -0
  58. package/dist/src/ast/references/kotlinx.js +8 -0
  59. package/dist/src/ast/references/okhttp3.d.ts +8 -0
  60. package/dist/src/ast/references/okhttp3.js +8 -0
  61. package/dist/src/ast/references/reactor.d.ts +8 -0
  62. package/dist/src/ast/references/reactor.js +8 -0
  63. package/dist/src/ast/references/spring-reactive.d.ts +18 -0
  64. package/dist/src/ast/references/spring-reactive.js +18 -0
  65. package/dist/src/ast/references/spring.d.ts +27 -0
  66. package/dist/src/ast/references/spring.js +27 -0
  67. package/dist/src/ast/references/swagger.d.ts +13 -0
  68. package/dist/src/ast/references/swagger.js +13 -0
  69. package/dist/src/ast/utils/get-kotlin-builder-options.d.ts +10 -0
  70. package/dist/src/ast/utils/get-kotlin-builder-options.js +10 -0
  71. package/dist/src/ast/utils/to-kt-node.d.ts +40 -0
  72. package/dist/src/ast/utils/write-kt-annotations.d.ts +13 -0
  73. package/dist/src/ast/utils/write-kt-annotations.js +13 -0
  74. package/dist/src/ast/utils/write-kt-arguments.d.ts +15 -0
  75. package/dist/src/ast/utils/write-kt-arguments.js +15 -0
  76. package/dist/src/ast/utils/write-kt-enum-values.d.ts +13 -0
  77. package/dist/src/ast/utils/write-kt-enum-values.js +13 -0
  78. package/dist/src/ast/utils/write-kt-generic-parameters.d.ts +10 -0
  79. package/dist/src/ast/utils/write-kt-generic-parameters.js +10 -0
  80. package/dist/src/ast/utils/write-kt-members.d.ts +16 -0
  81. package/dist/src/ast/utils/write-kt-members.js +16 -0
  82. package/dist/src/ast/utils/write-kt-node.d.ts +29 -0
  83. package/dist/src/ast/utils/write-kt-node.js +24 -0
  84. package/dist/src/ast/utils/write-kt-parameters.d.ts +13 -0
  85. package/dist/src/ast/utils/write-kt-parameters.js +13 -0
  86. package/dist/src/common-results.d.ts +9 -0
  87. package/dist/src/config.d.ts +72 -0
  88. package/dist/src/config.js +5 -0
  89. package/dist/src/file-builder.d.ts +91 -0
  90. package/dist/src/file-builder.js +81 -0
  91. package/dist/src/generators/file-generator.d.ts +12 -0
  92. package/dist/src/generators/file-generator.js +7 -0
  93. package/dist/src/generators/models/args.d.ts +233 -0
  94. package/dist/src/generators/models/model-generator.d.ts +25 -0
  95. package/dist/src/generators/models/model-generator.js +14 -0
  96. package/dist/src/generators/models/models-generator.d.ts +15 -0
  97. package/dist/src/generators/models/models-generator.js +15 -0
  98. package/dist/src/generators/models/models.d.ts +93 -2
  99. package/dist/src/generators/models/models.js +5 -0
  100. package/dist/src/generators/services/okhttp3-clients/args.d.ts +138 -0
  101. package/dist/src/generators/services/okhttp3-clients/models.d.ts +83 -0
  102. package/dist/src/generators/services/okhttp3-clients/models.js +5 -0
  103. package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +33 -0
  104. package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +20 -0
  105. package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts +21 -0
  106. package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +21 -0
  107. package/dist/src/generators/services/okhttp3-clients/refs.d.ts +25 -0
  108. package/dist/src/generators/services/okhttp3-clients/refs.js +7 -0
  109. package/dist/src/generators/services/spring-controllers/args.d.ts +169 -0
  110. package/dist/src/generators/services/spring-controllers/models.d.ts +120 -0
  111. package/dist/src/generators/services/spring-controllers/models.js +4 -0
  112. package/dist/src/generators/services/spring-controllers/refs.d.ts +9 -0
  113. package/dist/src/generators/services/spring-controllers/refs.js +9 -0
  114. package/dist/src/generators/services/spring-controllers/spring-controller-generator.d.ts +29 -0
  115. package/dist/src/generators/services/spring-controllers/spring-controller-generator.js +19 -0
  116. package/dist/src/generators/services/spring-controllers/spring-controllers-generator.d.ts +22 -0
  117. package/dist/src/generators/services/spring-controllers/spring-controllers-generator.js +22 -0
  118. package/dist/src/generators/services/spring-reactive-web-clients/args.d.ts +224 -0
  119. package/dist/src/generators/services/spring-reactive-web-clients/models.d.ts +86 -0
  120. package/dist/src/generators/services/spring-reactive-web-clients/models.js +4 -0
  121. package/dist/src/generators/services/spring-reactive-web-clients/refs.d.ts +7 -0
  122. package/dist/src/generators/services/spring-reactive-web-clients/refs.js +7 -0
  123. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +36 -0
  124. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +25 -0
  125. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.d.ts +20 -0
  126. package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.js +20 -0
  127. package/dist/src/import-collection.d.ts +64 -0
  128. package/dist/src/import-collection.js +46 -0
  129. package/dist/src/types.d.ts +4 -0
  130. package/dist/src/utils.d.ts +52 -0
  131. package/dist/src/utils.js +52 -0
  132. package/package.json +2 -2
@@ -22,20 +22,93 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
22
22
  members?: Nullable<Nullable<KtInterfaceMember<TBuilder>>[]>;
23
23
  companionObject?: Nullable<KtObject<TBuilder>>;
24
24
  }>;
25
+ /**
26
+ * A member that can be written in the body of an interface: an enum, an interface, a property, a function, a class,
27
+ * or any appended value.
28
+ * @template TBuilder The type of the builder that the member is written to.
29
+ */
25
30
  export type KtInterfaceMember<TBuilder extends SourceBuilder> = KtEnum<TBuilder> | KtInterface<TBuilder> | KtProperty<TBuilder> | KtFunction<TBuilder> | KtClass<TBuilder> | AppendValue<TBuilder>;
31
+ /**
32
+ * Represents a Kotlin interface declaration, such as `private interface Foo<T> : Bar, Baz { ... }`.
33
+ *
34
+ * Written in this order: the KDoc comment, the annotations, the access modifier, the `interface` keyword, the name, the
35
+ * generic parameters, the super-interfaces, then the body. The body is only written when there are members or a
36
+ * companion object. The descriptions of generic parameters are merged into the KDoc comment as `@param` tags.
37
+ *
38
+ * @template TBuilder The type of the source builder the interface is written to.
39
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
40
+ * @see ktInterface
41
+ */
26
42
  export declare class KtInterface<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
43
+ /**
44
+ * The KDoc comment written above the interface, or `null` to omit it. The descriptions of the generic parameters are
45
+ * added to it as `@param` tags.
46
+ */
27
47
  doc: KtDoc<TBuilder> | null;
48
+ /**
49
+ * The annotations written above the interface, each on a line of its own.
50
+ */
28
51
  annotations: KtAnnotation<TBuilder>[];
52
+ /**
53
+ * The visibility written before the `interface` keyword, such as `private`. `null` writes no visibility keyword.
54
+ */
29
55
  accessModifier: KtAccessModifier | null;
56
+ /**
57
+ * The interface name written after the `interface` keyword.
58
+ */
30
59
  name: string;
60
+ /**
61
+ * The generic parameters written in angle brackets after the name, such as `<T, U>`. Plain strings are written as
62
+ * they are. Described parameters also add a `@param` tag to the KDoc comment.
63
+ */
31
64
  generics: (KtGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
65
+ /**
66
+ * The super-interfaces written after ` : ` as a comma-separated list, such as `Bar, Baz`. The clause is omitted when
67
+ * the list is empty.
68
+ */
32
69
  extends: KtType<TBuilder>[];
70
+ /**
71
+ * The members written in the body, in the given order. Properties without a doc comment or annotations are written
72
+ * without blank lines between them, other members are set off by blank lines.
73
+ */
33
74
  members: KtInterfaceMember<TBuilder>[];
75
+ /**
76
+ * The companion object written first in the body, with the `companion` modifier. Setting it writes the body even when
77
+ * there are no other members.
78
+ */
34
79
  companionObject: KtObject<TBuilder> | null;
80
+ /**
81
+ * Initializes a new instance of the KtInterface class.
82
+ * @param options The options to use for this instance.
83
+ */
35
84
  constructor(options: Options<TBuilder, TInjects>);
36
85
  protected onWrite(builder: TBuilder): void;
37
86
  }
38
87
  declare const createInterface: <TBuilder extends SourceBuilder>(name: KtInterface<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => KtInterface<TBuilder>;
88
+ /**
89
+ * Factory for creating interface nodes. The `write` function writes one or more interface nodes to a builder.
90
+ *
91
+ * @param name The name of the interface.
92
+ * @param options The settings of the interface. See `KtInterface` for the available properties.
93
+ * @example
94
+ * ```ts
95
+ * ktInterface('Foo', {
96
+ * annotations: [ktAnnotation('Deprecated')],
97
+ * accessModifier: 'private',
98
+ * generics: [ktGenericParameter('T')],
99
+ * extends: ['Bar', 'Baz'],
100
+ * members: [ktProperty('x', { type: 'Int' })],
101
+ * companionObject: ktObject(),
102
+ * });
103
+ * // Emits:
104
+ * // @Deprecated
105
+ * // private interface Foo<T> : Bar, Baz {
106
+ * // companion object {}
107
+ * //
108
+ * // val x: Int
109
+ * // }
110
+ * ```
111
+ */
39
112
  export declare const ktInterface: typeof createInterface & {
40
113
  write: typeof writeKtNodes;
41
114
  };
@@ -5,15 +5,59 @@ import { writeKtNodes } from '../utils/write-kt-node.js';
5
5
  import { ktAnnotation } from './annotation.js';
6
6
  import { ktDoc } from './doc.js';
7
7
  import { ktGenericParameter } from './generic-parameter.js';
8
+ /**
9
+ * Represents a Kotlin interface declaration, such as `private interface Foo<T> : Bar, Baz { ... }`.
10
+ *
11
+ * Written in this order: the KDoc comment, the annotations, the access modifier, the `interface` keyword, the name, the
12
+ * generic parameters, the super-interfaces, then the body. The body is only written when there are members or a
13
+ * companion object. The descriptions of generic parameters are merged into the KDoc comment as `@param` tags.
14
+ *
15
+ * @template TBuilder The type of the source builder the interface is written to.
16
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
17
+ * @see ktInterface
18
+ */
8
19
  export class KtInterface extends KtNode {
20
+ /**
21
+ * The KDoc comment written above the interface, or `null` to omit it. The descriptions of the generic parameters are
22
+ * added to it as `@param` tags.
23
+ */
9
24
  doc;
25
+ /**
26
+ * The annotations written above the interface, each on a line of its own.
27
+ */
10
28
  annotations;
29
+ /**
30
+ * The visibility written before the `interface` keyword, such as `private`. `null` writes no visibility keyword.
31
+ */
11
32
  accessModifier;
33
+ /**
34
+ * The interface name written after the `interface` keyword.
35
+ */
12
36
  name;
37
+ /**
38
+ * The generic parameters written in angle brackets after the name, such as `<T, U>`. Plain strings are written as
39
+ * they are. Described parameters also add a `@param` tag to the KDoc comment.
40
+ */
13
41
  generics;
42
+ /**
43
+ * The super-interfaces written after ` : ` as a comma-separated list, such as `Bar, Baz`. The clause is omitted when
44
+ * the list is empty.
45
+ */
14
46
  extends;
47
+ /**
48
+ * The members written in the body, in the given order. Properties without a doc comment or annotations are written
49
+ * without blank lines between them, other members are set off by blank lines.
50
+ */
15
51
  members;
52
+ /**
53
+ * The companion object written first in the body, with the `companion` modifier. Setting it writes the body even when
54
+ * there are no other members.
55
+ */
16
56
  companionObject;
57
+ /**
58
+ * Initializes a new instance of the KtInterface class.
59
+ * @param options The options to use for this instance.
60
+ */
17
61
  constructor(options) {
18
62
  super(options);
19
63
  this.doc = options.doc ?? null;
@@ -65,6 +109,30 @@ export class KtInterface extends KtNode {
65
109
  }
66
110
  }
67
111
  const createInterface = (name, options) => new KtInterface({ ...options, name });
112
+ /**
113
+ * Factory for creating interface nodes. The `write` function writes one or more interface nodes to a builder.
114
+ *
115
+ * @param name The name of the interface.
116
+ * @param options The settings of the interface. See `KtInterface` for the available properties.
117
+ * @example
118
+ * ```ts
119
+ * ktInterface('Foo', {
120
+ * annotations: [ktAnnotation('Deprecated')],
121
+ * accessModifier: 'private',
122
+ * generics: [ktGenericParameter('T')],
123
+ * extends: ['Bar', 'Baz'],
124
+ * members: [ktProperty('x', { type: 'Int' })],
125
+ * companionObject: ktObject(),
126
+ * });
127
+ * // Emits:
128
+ * // @Deprecated
129
+ * // private interface Foo<T> : Bar, Baz {
130
+ * // companion object {}
131
+ * //
132
+ * // val x: Int
133
+ * // }
134
+ * ```
135
+ */
68
136
  export const ktInterface = Object.assign(createInterface, {
69
137
  write: writeKtNodes,
70
138
  });
@@ -9,15 +9,57 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
9
9
  returnType: KtType<TBuilder>;
10
10
  suspend?: boolean;
11
11
  }>;
12
+ /**
13
+ * Represents a Kotlin function type, such as `(Int, String) -> Boolean`.
14
+ *
15
+ * Written in this order: the `suspend` modifier, the receiver type followed by a dot, the parameter types in
16
+ * parentheses, the arrow, then the return type.
17
+ *
18
+ * @template TBuilder The type of the source builder the lambda type is written to.
19
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
20
+ * @see ktLambdaType
21
+ */
12
22
  export declare class KtLambdaType<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
23
+ /**
24
+ * The receiver type written before the parameters, followed by a dot, such as `Foo.(Int) -> Unit`. `null` writes a
25
+ * function type without a receiver.
26
+ */
13
27
  extensionFor: KtType<TBuilder> | null;
28
+ /**
29
+ * The parameter types written in parentheses, separated by commas. An empty list writes `()`. With more than two
30
+ * types, each type is written on a line of its own.
31
+ */
14
32
  parameters: KtType<TBuilder>[];
33
+ /**
34
+ * The return type written after the arrow, such as `Unit` in `() -> Unit`.
35
+ */
15
36
  returnType: KtType<TBuilder>;
37
+ /**
38
+ * Whether the type is written with the `suspend` modifier in front, such as `suspend () -> Unit`.
39
+ * @default false
40
+ */
16
41
  suspend: boolean;
42
+ /**
43
+ * Initializes a new instance of the KtLambdaType class.
44
+ * @param options The options to use for this instance.
45
+ */
17
46
  constructor(options: Options<TBuilder, TInjects>);
18
47
  protected onWrite(builder: TBuilder): void;
19
48
  }
20
49
  declare const createLambdaType: <TBuilder extends SourceBuilder>(parameters: Options<TBuilder>['parameters'], returnType: Options<TBuilder>['returnType'], options?: Omit<Options<TBuilder>, 'parameters' | 'returnType'>) => KtLambdaType<TBuilder>;
50
+ /**
51
+ * Factory for creating lambda type nodes. The `write` function writes one or more lambda type nodes to a builder.
52
+ *
53
+ * @param parameters The types of the parameters, or `null` for none. An empty list writes `()`.
54
+ * @param returnType The return type of the lambda type.
55
+ * @param options The settings of the lambda type. See `KtLambdaType` for the available properties.
56
+ * @example
57
+ * ```ts
58
+ * ktLambdaType(['Int'], 'Unit', { extensionFor: 'Foo' });
59
+ * // Emits:
60
+ * // Foo.(Int) -> Unit
61
+ * ```
62
+ */
21
63
  export declare const ktLambdaType: typeof createLambdaType & {
22
64
  write: typeof writeKtNodes;
23
65
  };
@@ -2,11 +2,40 @@ 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 { ktParameter } from './parameter.js';
5
+ /**
6
+ * Represents a Kotlin function type, such as `(Int, String) -> Boolean`.
7
+ *
8
+ * Written in this order: the `suspend` modifier, the receiver type followed by a dot, the parameter types in
9
+ * parentheses, the arrow, then the return type.
10
+ *
11
+ * @template TBuilder The type of the source builder the lambda type is written to.
12
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
13
+ * @see ktLambdaType
14
+ */
5
15
  export class KtLambdaType extends KtNode {
16
+ /**
17
+ * The receiver type written before the parameters, followed by a dot, such as `Foo.(Int) -> Unit`. `null` writes a
18
+ * function type without a receiver.
19
+ */
6
20
  extensionFor;
21
+ /**
22
+ * The parameter types written in parentheses, separated by commas. An empty list writes `()`. With more than two
23
+ * types, each type is written on a line of its own.
24
+ */
7
25
  parameters;
26
+ /**
27
+ * The return type written after the arrow, such as `Unit` in `() -> Unit`.
28
+ */
8
29
  returnType;
30
+ /**
31
+ * Whether the type is written with the `suspend` modifier in front, such as `suspend () -> Unit`.
32
+ * @default false
33
+ */
9
34
  suspend;
35
+ /**
36
+ * Initializes a new instance of the KtLambdaType class.
37
+ * @param options The options to use for this instance.
38
+ */
10
39
  constructor(options) {
11
40
  super(options);
12
41
  this.extensionFor = options.extensionFor ?? null;
@@ -39,6 +68,19 @@ export class KtLambdaType extends KtNode {
39
68
  }
40
69
  }
41
70
  const createLambdaType = (parameters, returnType, options) => new KtLambdaType({ ...options, parameters, returnType });
71
+ /**
72
+ * Factory for creating lambda type nodes. The `write` function writes one or more lambda type nodes to a builder.
73
+ *
74
+ * @param parameters The types of the parameters, or `null` for none. An empty list writes `()`.
75
+ * @param returnType The return type of the lambda type.
76
+ * @param options The settings of the lambda type. See `KtLambdaType` for the available properties.
77
+ * @example
78
+ * ```ts
79
+ * ktLambdaType(['Int'], 'Unit', { extensionFor: 'Foo' });
80
+ * // Emits:
81
+ * // Foo.(Int) -> Unit
82
+ * ```
83
+ */
42
84
  export const ktLambdaType = Object.assign(createLambdaType, {
43
85
  write: writeKtNodes,
44
86
  });
@@ -7,14 +7,55 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
7
7
  body?: Nullable<AppendValue<TBuilder>>;
8
8
  singleline?: boolean;
9
9
  }>;
10
+ /**
11
+ * Represents a Kotlin lambda expression, such as `{ a, b -> a + b }`.
12
+ *
13
+ * Written in this order: the opening brace, the parameter names followed by an arrow, the body, then the closing brace.
14
+ * A lambda without a body is always written on one line.
15
+ *
16
+ * @template TBuilder The type of the source builder the lambda is written to.
17
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
18
+ * @see ktLambda
19
+ */
10
20
  export declare class KtLambda<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
21
+ /**
22
+ * The parameter names written after the opening brace, separated by commas and followed by `->`. Without any names,
23
+ * the arrow is omitted and the body follows the opening brace directly.
24
+ */
11
25
  arguments: BasicAppendValue<TBuilder>[];
26
+ /**
27
+ * The statements of the lambda. `null` writes an empty lambda on one line, such as `{ }`.
28
+ */
12
29
  body: AppendValue<TBuilder> | null;
30
+ /**
31
+ * Whether the body is written on the same line as the braces, such as `{ a, b -> a + b }`. Otherwise the body is
32
+ * written on an indented line of its own, between the arrow and the closing brace.
33
+ * @default false
34
+ */
13
35
  singleline: boolean;
36
+ /**
37
+ * Initializes a new instance of the KtLambda class.
38
+ * @param options The options to use for this instance.
39
+ */
14
40
  constructor(options: Options<TBuilder, TInjects>);
15
41
  protected onWrite(builder: TBuilder): void;
16
42
  }
17
43
  declare const createLambda: <TBuilder extends SourceBuilder>(args: Options<TBuilder>['arguments'], body: Options<TBuilder>['body'], options?: Omit<Options<TBuilder>, 'arguments' | 'body'>) => KtLambda<TBuilder>;
44
+ /**
45
+ * Factory for creating lambda nodes. The `write` function writes one or more lambda nodes to a builder.
46
+ *
47
+ * @param args The parameter names of the lambda, or `null` for none.
48
+ * @param body The statements of the lambda, or `null` for an empty lambda.
49
+ * @param options The settings of the lambda. See `KtLambda` for the available properties.
50
+ * @example
51
+ * ```ts
52
+ * ktLambda(['a'], 'println(a)');
53
+ * // Emits:
54
+ * // { a ->
55
+ * // println(a)
56
+ * // }
57
+ * ```
58
+ */
18
59
  export declare const ktLambda: typeof createLambda & {
19
60
  write: typeof writeKtNodes;
20
61
  };
@@ -1,10 +1,36 @@
1
1
  import { notNullish, } from '@goast/core';
2
2
  import { KtNode } from '../node.js';
3
3
  import { writeKtNodes } from '../utils/write-kt-node.js';
4
+ /**
5
+ * Represents a Kotlin lambda expression, such as `{ a, b -> a + b }`.
6
+ *
7
+ * Written in this order: the opening brace, the parameter names followed by an arrow, the body, then the closing brace.
8
+ * A lambda without a body is always written on one line.
9
+ *
10
+ * @template TBuilder The type of the source builder the lambda is written to.
11
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
12
+ * @see ktLambda
13
+ */
4
14
  export class KtLambda extends KtNode {
15
+ /**
16
+ * The parameter names written after the opening brace, separated by commas and followed by `->`. Without any names,
17
+ * the arrow is omitted and the body follows the opening brace directly.
18
+ */
5
19
  arguments;
20
+ /**
21
+ * The statements of the lambda. `null` writes an empty lambda on one line, such as `{ }`.
22
+ */
6
23
  body;
24
+ /**
25
+ * Whether the body is written on the same line as the braces, such as `{ a, b -> a + b }`. Otherwise the body is
26
+ * written on an indented line of its own, between the arrow and the closing brace.
27
+ * @default false
28
+ */
7
29
  singleline;
30
+ /**
31
+ * Initializes a new instance of the KtLambda class.
32
+ * @param options The options to use for this instance.
33
+ */
8
34
  constructor(options) {
9
35
  super(options);
10
36
  this.arguments = options.arguments?.filter(notNullish) ?? [];
@@ -34,6 +60,21 @@ export class KtLambda extends KtNode {
34
60
  }
35
61
  }
36
62
  const createLambda = (args, body, options) => new KtLambda({ ...options, arguments: args, body });
63
+ /**
64
+ * Factory for creating lambda nodes. The `write` function writes one or more lambda nodes to a builder.
65
+ *
66
+ * @param args The parameter names of the lambda, or `null` for none.
67
+ * @param body The statements of the lambda, or `null` for an empty lambda.
68
+ * @param options The settings of the lambda. See `KtLambda` for the available properties.
69
+ * @example
70
+ * ```ts
71
+ * ktLambda(['a'], 'println(a)');
72
+ * // Emits:
73
+ * // { a ->
74
+ * // println(a)
75
+ * // }
76
+ * ```
77
+ */
37
78
  export const ktLambda = Object.assign(createLambda, {
38
79
  write: writeKtNodes,
39
80
  });
@@ -16,19 +16,85 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
16
16
  members?: Nullable<Nullable<KtObjectMember<TBuilder>>[]>;
17
17
  companion?: Nullable<boolean>;
18
18
  }>;
19
+ /**
20
+ * A member that can be written in the body of an object: an init block, a property, a function, or any appended value.
21
+ * @template TBuilder The type of the builder that the member is written to.
22
+ */
19
23
  export type KtObjectMember<TBuilder extends SourceBuilder> = KtInitBlock<TBuilder> | KtProperty<TBuilder> | KtFunction<TBuilder> | BasicAppendValue<TBuilder>;
24
+ /**
25
+ * Represents a Kotlin `object` declaration or object expression, such as `object Foo : Bar(1, 2), Baz { ... }`.
26
+ *
27
+ * Written in this order: the `data` and `companion` modifiers, the `object` keyword, the name, the supertypes with the
28
+ * base class constructor call, then the body. A named object is followed by a line break. An anonymous object, such as
29
+ * `object : Bar() {}`, is not, so it can be written inside another expression.
30
+ *
31
+ * @template TBuilder The type of the source builder the object is written to.
32
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
33
+ * @see ktObject
34
+ */
20
35
  export declare class KtObject<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
36
+ /**
37
+ * Whether the object is written with the `data` modifier, such as `data object Foo`.
38
+ * @default false
39
+ */
21
40
  data: boolean;
41
+ /**
42
+ * The object name written after the `object` keyword. `null` writes an anonymous object, such as `object : Bar() {}`.
43
+ */
22
44
  name: string | null;
45
+ /**
46
+ * The base class written after ` : `, followed by its constructor call in parentheses, such as `Bar()`. The call is
47
+ * always written, even without arguments. `null` writes no base class.
48
+ */
23
49
  class: KtType<TBuilder> | null;
50
+ /**
51
+ * The arguments written inside the parentheses of the base class constructor call, separated by commas. Only written
52
+ * when `class` is set.
53
+ */
24
54
  classArguments: (KtArgument<TBuilder> | KtValue<TBuilder>)[];
55
+ /**
56
+ * The interfaces written after the base class, separated by commas, such as `Bar, Baz`. Without a base class, they
57
+ * are written directly after ` : `. The clause is omitted when the list is empty.
58
+ */
25
59
  implements: KtType<TBuilder>[];
60
+ /**
61
+ * The members written in the body, in the given order. Properties without a doc comment or annotations and plain
62
+ * strings are written without blank lines between them, other members are set off by blank lines. An empty list
63
+ * writes `{}` on one line.
64
+ */
26
65
  members: KtObjectMember<TBuilder>[];
66
+ /**
67
+ * Whether the object is written with the `companion` modifier, such as `companion object`.
68
+ * @default false
69
+ */
27
70
  companion: boolean;
71
+ /**
72
+ * Initializes a new instance of the KtObject class.
73
+ * @param options The options to use for this instance.
74
+ */
28
75
  constructor(options: Options<TBuilder, TInjects>);
29
76
  protected onWrite(builder: TBuilder): void;
30
77
  }
31
78
  declare const createObject: <TBuilder extends SourceBuilder>(options?: Options<TBuilder>) => KtObject<TBuilder>;
79
+ /**
80
+ * Factory for creating object nodes. The `write` function writes one or more object nodes to a builder.
81
+ *
82
+ * @param options The settings of the object. See `KtObject` for the available properties.
83
+ * @example
84
+ * ```ts
85
+ * ktObject({
86
+ * name: 'Foo',
87
+ * class: 'Bar',
88
+ * classArguments: ['1', '2'],
89
+ * implements: ['Baz'],
90
+ * members: [ktProperty('x', { type: 'Int', default: '1' })],
91
+ * });
92
+ * // Emits:
93
+ * // object Foo : Bar(1, 2), Baz {
94
+ * // val x: Int = 1
95
+ * // }
96
+ * ```
97
+ */
32
98
  export declare const ktObject: typeof createObject & {
33
99
  write: typeof writeKtNodes;
34
100
  };
@@ -3,14 +3,57 @@ import { KtNode } from '../node.js';
3
3
  import { writeKtMembers } from '../utils/write-kt-members.js';
4
4
  import { writeKtNode, writeKtNodes } from '../utils/write-kt-node.js';
5
5
  import { ktArgument } from './argument.js';
6
+ /**
7
+ * Represents a Kotlin `object` declaration or object expression, such as `object Foo : Bar(1, 2), Baz { ... }`.
8
+ *
9
+ * Written in this order: the `data` and `companion` modifiers, the `object` keyword, the name, the supertypes with the
10
+ * base class constructor call, then the body. A named object is followed by a line break. An anonymous object, such as
11
+ * `object : Bar() {}`, is not, so it can be written inside another expression.
12
+ *
13
+ * @template TBuilder The type of the source builder the object is written to.
14
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
15
+ * @see ktObject
16
+ */
6
17
  export class KtObject extends KtNode {
18
+ /**
19
+ * Whether the object is written with the `data` modifier, such as `data object Foo`.
20
+ * @default false
21
+ */
7
22
  data;
23
+ /**
24
+ * The object name written after the `object` keyword. `null` writes an anonymous object, such as `object : Bar() {}`.
25
+ */
8
26
  name;
27
+ /**
28
+ * The base class written after ` : `, followed by its constructor call in parentheses, such as `Bar()`. The call is
29
+ * always written, even without arguments. `null` writes no base class.
30
+ */
9
31
  class;
32
+ /**
33
+ * The arguments written inside the parentheses of the base class constructor call, separated by commas. Only written
34
+ * when `class` is set.
35
+ */
10
36
  classArguments;
37
+ /**
38
+ * The interfaces written after the base class, separated by commas, such as `Bar, Baz`. Without a base class, they
39
+ * are written directly after ` : `. The clause is omitted when the list is empty.
40
+ */
11
41
  implements;
42
+ /**
43
+ * The members written in the body, in the given order. Properties without a doc comment or annotations and plain
44
+ * strings are written without blank lines between them, other members are set off by blank lines. An empty list
45
+ * writes `{}` on one line.
46
+ */
12
47
  members;
48
+ /**
49
+ * Whether the object is written with the `companion` modifier, such as `companion object`.
50
+ * @default false
51
+ */
13
52
  companion;
53
+ /**
54
+ * Initializes a new instance of the KtObject class.
55
+ * @param options The options to use for this instance.
56
+ */
14
57
  constructor(options) {
15
58
  super(options);
16
59
  this.data = options.data ?? false;
@@ -55,6 +98,25 @@ export class KtObject extends KtNode {
55
98
  }
56
99
  }
57
100
  const createObject = (options) => new KtObject(options ?? {});
101
+ /**
102
+ * Factory for creating object nodes. The `write` function writes one or more object nodes to a builder.
103
+ *
104
+ * @param options The settings of the object. See `KtObject` for the available properties.
105
+ * @example
106
+ * ```ts
107
+ * ktObject({
108
+ * name: 'Foo',
109
+ * class: 'Bar',
110
+ * classArguments: ['1', '2'],
111
+ * implements: ['Baz'],
112
+ * members: [ktProperty('x', { type: 'Int', default: '1' })],
113
+ * });
114
+ * // Emits:
115
+ * // object Foo : Bar(1, 2), Baz {
116
+ * // val x: Int = 1
117
+ * // }
118
+ * ```
119
+ */
58
120
  export const ktObject = Object.assign(createObject, {
59
121
  write: writeKtNodes,
60
122
  });
@@ -17,22 +17,90 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
17
17
  propertyDescription?: Nullable<BasicAppendValue<TBuilder>>;
18
18
  override?: Nullable<boolean>;
19
19
  }>;
20
+ /**
21
+ * Represents a Kotlin parameter of a function or a class constructor. A class constructor parameter can also declare
22
+ * a property.
23
+ *
24
+ * Written in this order: the annotations, each on a line of its own, the modifiers, `val` or `var` for a property, the
25
+ * name, the type after a colon, then the default value after an equals sign.
26
+ *
27
+ * @template TBuilder The type of the source builder the parameter is written to.
28
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
29
+ * @see ktParameter
30
+ */
20
31
  export declare class KtParameter<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
32
+ /**
33
+ * The name of the parameter, written before the colon.
34
+ */
21
35
  name: string;
36
+ /**
37
+ * The type of the parameter, written after the colon, such as `Int` in `x: Int`.
38
+ */
22
39
  type: KtType<TBuilder>;
40
+ /**
41
+ * The annotations written above the parameter, each on a line of its own. A parameter list with annotations is
42
+ * written with one parameter per line.
43
+ */
23
44
  annotations: KtAnnotation<TBuilder>[];
45
+ /**
46
+ * The default value written after ` = `, such as `42` in `x: Int = 42`. `null` writes no default value.
47
+ */
24
48
  default: KtValue<TBuilder> | null;
49
+ /**
50
+ * Whether the parameter is written with the `vararg` modifier, such as `vararg x: Int`. The modifier is written for a
51
+ * plain parameter as well as for a class property.
52
+ * @default false
53
+ */
25
54
  vararg: boolean;
55
+ /**
56
+ * The description of the parameter. It is not written inline. It becomes a `@param` tag in the KDoc comment of the
57
+ * function or class whose parameter list contains the parameter.
58
+ */
26
59
  description: BasicAppendValue<TBuilder> | null;
60
+ /**
61
+ * The visibility written before `val` or `var`, such as `private var x: Int`. Only written when `property` is set.
62
+ */
27
63
  accessModifier: KtAccessModifier | null;
64
+ /**
65
+ * Whether the parameter declares a property: `readonly` writes `val` and `mutable` writes `var`. `null` writes a
66
+ * plain parameter without either keyword.
67
+ */
28
68
  property: 'readonly' | 'mutable' | null;
69
+ /**
70
+ * The description of the property. It is not written inline. It becomes a `@property` tag in the KDoc comment of the
71
+ * class that declares the parameter, when `property` is set.
72
+ */
29
73
  propertyDescription: BasicAppendValue<TBuilder> | null;
74
+ /**
75
+ * Whether the property is written with the `override` modifier, such as `override var x: Int`. Only written when
76
+ * `property` is set.
77
+ * @default false
78
+ */
30
79
  override: boolean;
80
+ /**
81
+ * Initializes a new instance of the KtParameter class.
82
+ * @param options The options to use for this instance.
83
+ */
31
84
  constructor(options: Options<TBuilder, TInjects>);
32
85
  protected onWrite(builder: TBuilder): void;
33
86
  }
34
87
  declare const createParameter: <TBuilder extends SourceBuilder>(name: KtParameter<TBuilder>['name'], type: KtParameter<TBuilder>['type'], options?: Prettify<Omit<Options<TBuilder>, 'name' | 'type' | 'accessModifier' | 'property' | 'propertyDescription' | 'override'>>) => KtParameter<TBuilder>;
35
88
  declare const createClassParameter: <TBuilder extends SourceBuilder>(name: KtParameter<TBuilder>['name'], type: KtParameter<TBuilder>['type'], options?: Prettify<Omit<Options<TBuilder>, 'name' | 'type'>>) => KtParameter<TBuilder>;
89
+ /**
90
+ * Factory for creating parameter nodes. The `class` function creates a class constructor parameter, which can declare a
91
+ * property, and accepts the options for it. The `write` function writes a parenthesized parameter list.
92
+ *
93
+ * @param name The name of the parameter.
94
+ * @param type The type of the parameter.
95
+ * @param options The settings of the parameter. See `KtParameter` for the available properties.
96
+ * @example
97
+ * ```ts
98
+ * ktParameter('x', 'Int', { default: '42', annotations: [ktAnnotation('Inject')] });
99
+ * // Emits:
100
+ * // @Inject
101
+ * // x: Int = 42
102
+ * ```
103
+ */
36
104
  export declare const ktParameter: typeof createParameter & {
37
105
  class: typeof createClassParameter;
38
106
  write: typeof writeKtParameters;