@goast/kotlin 0.7.0-beta.2 → 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
@@ -3,18 +3,71 @@ import { KtNode } from '../node.js';
3
3
  import { writeKtNode } from '../utils/write-kt-node.js';
4
4
  import { writeKtParameters } from '../utils/write-kt-parameters.js';
5
5
  import { ktAnnotation } from './annotation.js';
6
+ /**
7
+ * Represents a Kotlin parameter of a function or a class constructor. A class constructor parameter can also declare
8
+ * a property.
9
+ *
10
+ * Written in this order: the annotations, each on a line of its own, the modifiers, `val` or `var` for a property, the
11
+ * name, the type after a colon, then the default value after an equals sign.
12
+ *
13
+ * @template TBuilder The type of the source builder the parameter is written to.
14
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
15
+ * @see ktParameter
16
+ */
6
17
  export class KtParameter extends KtNode {
18
+ /**
19
+ * The name of the parameter, written before the colon.
20
+ */
7
21
  name;
22
+ /**
23
+ * The type of the parameter, written after the colon, such as `Int` in `x: Int`.
24
+ */
8
25
  type;
26
+ /**
27
+ * The annotations written above the parameter, each on a line of its own. A parameter list with annotations is
28
+ * written with one parameter per line.
29
+ */
9
30
  annotations;
31
+ /**
32
+ * The default value written after ` = `, such as `42` in `x: Int = 42`. `null` writes no default value.
33
+ */
10
34
  default;
35
+ /**
36
+ * Whether the parameter is written with the `vararg` modifier, such as `vararg x: Int`. The modifier is written for a
37
+ * plain parameter as well as for a class property.
38
+ * @default false
39
+ */
11
40
  vararg;
41
+ /**
42
+ * The description of the parameter. It is not written inline. It becomes a `@param` tag in the KDoc comment of the
43
+ * function or class whose parameter list contains the parameter.
44
+ */
12
45
  description;
13
46
  // class parameter options
47
+ /**
48
+ * The visibility written before `val` or `var`, such as `private var x: Int`. Only written when `property` is set.
49
+ */
14
50
  accessModifier;
51
+ /**
52
+ * Whether the parameter declares a property: `readonly` writes `val` and `mutable` writes `var`. `null` writes a
53
+ * plain parameter without either keyword.
54
+ */
15
55
  property;
56
+ /**
57
+ * The description of the property. It is not written inline. It becomes a `@property` tag in the KDoc comment of the
58
+ * class that declares the parameter, when `property` is set.
59
+ */
16
60
  propertyDescription;
61
+ /**
62
+ * Whether the property is written with the `override` modifier, such as `override var x: Int`. Only written when
63
+ * `property` is set.
64
+ * @default false
65
+ */
17
66
  override;
67
+ /**
68
+ * Initializes a new instance of the KtParameter class.
69
+ * @param options The options to use for this instance.
70
+ */
18
71
  constructor(options) {
19
72
  super(options);
20
73
  this.name = options.name;
@@ -57,6 +110,21 @@ export class KtParameter extends KtNode {
57
110
  }
58
111
  const createParameter = (name, type, options) => new KtParameter({ ...options, name, type });
59
112
  const createClassParameter = (name, type, options) => new KtParameter({ ...options, name, type });
113
+ /**
114
+ * Factory for creating parameter nodes. The `class` function creates a class constructor parameter, which can declare a
115
+ * property, and accepts the options for it. The `write` function writes a parenthesized parameter list.
116
+ *
117
+ * @param name The name of the parameter.
118
+ * @param type The type of the parameter.
119
+ * @param options The settings of the parameter. See `KtParameter` for the available properties.
120
+ * @example
121
+ * ```ts
122
+ * ktParameter('x', 'Int', { default: '42', annotations: [ktAnnotation('Inject')] });
123
+ * // Emits:
124
+ * // @Inject
125
+ * // x: Int = 42
126
+ * ```
127
+ */
60
128
  export const ktParameter = Object.assign(createParameter, {
61
129
  class: createClassParameter,
62
130
  write: writeKtParameters,
@@ -13,19 +13,75 @@ type AccessorOptions<TBuilder extends SourceBuilder, TInjects extends string = n
13
13
  body?: Nullable<AppendValue<TBuilder>>;
14
14
  singleExpression?: Nullable<boolean>;
15
15
  }>;
16
+ /**
17
+ * Base class for the getter and setter of a Kotlin property, such as `get() = 42` or `private set`.
18
+ *
19
+ * Written in this order: the annotations, each on a line of its own, the access modifier, then the `get` or `set`
20
+ * keyword. A body follows the keyword: `()` for a getter or `(value)` for a setter, then either ` = ` and the
21
+ * expression, or a braced block on indented lines. Without a body, only the modifier and the keyword are written.
22
+ *
23
+ * @template TBuilder The type of the source builder the accessor is written to.
24
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
25
+ * @see ktProperty.getter
26
+ * @see ktProperty.setter
27
+ */
16
28
  export declare abstract class KtPropertyAccessor<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | AccessorInjects> {
29
+ /**
30
+ * The keyword written for the accessor, `get` or `set`. It also decides the parameter list of the body: `()` for a
31
+ * getter and `(value)` for a setter.
32
+ */
17
33
  abstract get kind(): 'get' | 'set';
34
+ /**
35
+ * The visibility written before the keyword, such as `private` in `private set`. `null` writes no visibility keyword,
36
+ * so the accessor has the visibility of the property.
37
+ */
18
38
  accessModifier: KtAccessModifier | null;
39
+ /**
40
+ * The annotations written above the accessor, each on a line of its own.
41
+ */
19
42
  annotations: KtAnnotation<TBuilder>[];
43
+ /**
44
+ * The code of the accessor, written after the parameter list. `null` writes no body. With `singleExpression` the code
45
+ * follows ` = `, otherwise it is written in braces on indented lines.
46
+ */
20
47
  body: AppendValue<TBuilder> | null;
48
+ /**
49
+ * Whether the body is a single expression written after ` = ` on the same line, such as `get() = 42`. Otherwise the
50
+ * body is written in braces. Has no effect without a body.
51
+ * @default false
52
+ */
21
53
  singleExpression: boolean;
54
+ /**
55
+ * Initializes a new instance of the KtPropertyAccessor class.
56
+ * @param options The options to use for this instance.
57
+ */
22
58
  constructor(options: AccessorOptions<TBuilder, TInjects>);
23
59
  protected onWrite(builder: TBuilder): void;
24
60
  }
61
+ /**
62
+ * Represents the getter of a Kotlin property, written with the `get` keyword. See `KtPropertyAccessor` for the order in
63
+ * which it is written.
64
+ *
65
+ * @template TBuilder The type of the source builder the getter is written to.
66
+ * @see ktProperty.getter
67
+ */
25
68
  export declare class KtPropertyGetter<TBuilder extends SourceBuilder> extends KtPropertyAccessor<TBuilder> {
69
+ /**
70
+ * The keyword of the accessor, always `get`. A body is written with an empty parameter list, such as `get() = 42`.
71
+ */
26
72
  readonly kind: 'get';
27
73
  }
74
+ /**
75
+ * Represents the setter of a Kotlin property, written with the `set` keyword. See `KtPropertyAccessor` for the order in
76
+ * which it is written.
77
+ *
78
+ * @template TBuilder The type of the source builder the setter is written to.
79
+ * @see ktProperty.setter
80
+ */
28
81
  export declare class KtPropertySetter<TBuilder extends SourceBuilder> extends KtPropertyAccessor<TBuilder> {
82
+ /**
83
+ * The keyword of the accessor, always `set`. A body uses the parameter list `(value)`, as in `set(value) = 42`.
84
+ */
29
85
  readonly kind: 'set';
30
86
  }
31
87
  type Injects = 'doc' | 'annotations' | 'modifiers' | 'name' | 'type' | 'default' | 'delegate';
@@ -47,29 +103,125 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
47
103
  override?: Nullable<boolean>;
48
104
  abstract?: Nullable<boolean>;
49
105
  }>;
106
+ /**
107
+ * Represents a Kotlin property declaration, such as `val x: Int = 42` or `var x: Int` with a private setter.
108
+ *
109
+ * Written in this order: the KDoc comment, the annotations, the modifiers, `val` or `var`, the name, the type, the
110
+ * default value or the delegate, then the getter and the setter, indented on lines below. The modifiers are written in
111
+ * the order access modifier, `const`, `lateinit`, `abstract`, `override`, `open`. A property with a setter is always
112
+ * written with `var`. Without a type, `: Any?` is written unless a default value or a getter body is present, in which
113
+ * case no type is written.
114
+ *
115
+ * @template TBuilder The type of the source builder the property is written to.
116
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
117
+ * @see ktProperty
118
+ */
50
119
  export declare class KtProperty<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
120
+ /**
121
+ * The KDoc comment written above the property, or `null` to omit it. Nothing is written when the comment has neither
122
+ * a description nor tags.
123
+ */
51
124
  doc: KtDoc<TBuilder> | null;
125
+ /**
126
+ * The name of the property, written after `val` or `var`.
127
+ */
52
128
  name: string;
129
+ /**
130
+ * The type written after the colon, such as `Int` in `val x: Int`. When it is `null`, `: Any?` is written if there is
131
+ * neither a default value nor a getter body, and no type is written otherwise.
132
+ */
53
133
  type: KtType<TBuilder> | null;
134
+ /**
135
+ * The annotations written above the property, each on a line of its own. The target of an annotation is written as a
136
+ * use-site target, such as `@field:Json` or `@get:Inject`.
137
+ */
54
138
  annotations: KtAnnotation<TBuilder>[];
139
+ /**
140
+ * The visibility written before the other modifiers, such as `private` in `private val x`. `null` writes no
141
+ * visibility keyword.
142
+ */
55
143
  accessModifier: KtAccessModifier | null;
144
+ /**
145
+ * The getter written on an indented line below the property, such as `get() = 42`. `null` writes no getter.
146
+ */
56
147
  getter: KtPropertyGetter<TBuilder> | null;
148
+ /**
149
+ * The setter written on an indented line below the property, such as `private set`. Its presence makes the property
150
+ * `var`. `null` writes no setter.
151
+ */
57
152
  setter: KtPropertySetter<TBuilder> | null;
153
+ /**
154
+ * The initial value written after ` = `, such as `42` in `val x = 42`. `null` writes no initial value.
155
+ */
58
156
  default: KtValue<TBuilder> | null;
157
+ /**
158
+ * The delegate written after ` by `, such as `lazy` in `val x: Int by lazy`. `null` writes no delegation.
159
+ */
59
160
  delegate: KtType<TBuilder> | null;
161
+ /**
162
+ * The arguments written in parentheses after the delegate, such as `(42, true)` in `by lazy(42, true)`. Only written
163
+ * when `delegate` is set. An empty list writes `()`.
164
+ */
60
165
  delegateArguments: (KtArgument<TBuilder> | KtValue<TBuilder>)[] | null;
166
+ /**
167
+ * Whether the property is written with `var` instead of `val`. A property with a setter is always `var`.
168
+ * @default false
169
+ */
61
170
  mutable: boolean;
171
+ /**
172
+ * Whether the property is written with the `const` modifier, such as `const val x`.
173
+ * @default false
174
+ */
62
175
  const: boolean;
176
+ /**
177
+ * Whether the property is written with the `lateinit` modifier, such as `lateinit var x`.
178
+ * @default false
179
+ */
63
180
  lateinit: boolean;
181
+ /**
182
+ * Whether the property is written with the `open` modifier, such as `open val x`.
183
+ * @default false
184
+ */
64
185
  open: boolean;
186
+ /**
187
+ * Whether the property is written with the `override` modifier, such as `override val x`.
188
+ * @default false
189
+ */
65
190
  override: boolean;
191
+ /**
192
+ * Whether the property is written with the `abstract` modifier, such as `abstract val x: Int`.
193
+ * @default false
194
+ */
66
195
  abstract: boolean;
196
+ /**
197
+ * Initializes a new instance of the KtProperty class.
198
+ * @param options The options to use for this instance.
199
+ */
67
200
  constructor(options: Options<TBuilder, TInjects>);
68
201
  protected onWrite(builder: TBuilder): void;
69
202
  }
70
203
  declare const createPropertyGetter: <TBuilder extends SourceBuilder>(options?: AccessorOptions<TBuilder>) => KtPropertyGetter<TBuilder>;
71
204
  declare const createPropertySetter: <TBuilder extends SourceBuilder>(options?: AccessorOptions<TBuilder>) => KtPropertySetter<TBuilder>;
72
205
  declare const createProperty: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => KtProperty<TBuilder>;
206
+ /**
207
+ * Factory for creating property nodes. The `getter` and `setter` functions create the accessors of a property and
208
+ * accept the options of `KtPropertyAccessor`. The `write` function writes one or more property nodes to a builder.
209
+ *
210
+ * @param name The name of the property.
211
+ * @param options The settings of the property. See `KtProperty` for the available properties.
212
+ * @example
213
+ * ```ts
214
+ * ktProperty('count', {
215
+ * type: 'Int',
216
+ * mutable: true,
217
+ * default: '0',
218
+ * setter: ktProperty.setter({ accessModifier: 'private' }),
219
+ * });
220
+ * // Emits:
221
+ * // var count: Int = 0
222
+ * // private set
223
+ * ```
224
+ */
73
225
  export declare const ktProperty: typeof createProperty & {
74
226
  getter: typeof createPropertyGetter;
75
227
  setter: typeof createPropertySetter;
@@ -3,11 +3,43 @@ import { KtNode } from '../node.js';
3
3
  import { writeKtNode, writeKtNodes } from '../utils/write-kt-node.js';
4
4
  import { ktAnnotation } from './annotation.js';
5
5
  import { ktArgument } from './argument.js';
6
+ /**
7
+ * Base class for the getter and setter of a Kotlin property, such as `get() = 42` or `private set`.
8
+ *
9
+ * Written in this order: the annotations, each on a line of its own, the access modifier, then the `get` or `set`
10
+ * keyword. A body follows the keyword: `()` for a getter or `(value)` for a setter, then either ` = ` and the
11
+ * expression, or a braced block on indented lines. Without a body, only the modifier and the keyword are written.
12
+ *
13
+ * @template TBuilder The type of the source builder the accessor is written to.
14
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
15
+ * @see ktProperty.getter
16
+ * @see ktProperty.setter
17
+ */
6
18
  export class KtPropertyAccessor extends KtNode {
19
+ /**
20
+ * The visibility written before the keyword, such as `private` in `private set`. `null` writes no visibility keyword,
21
+ * so the accessor has the visibility of the property.
22
+ */
7
23
  accessModifier;
24
+ /**
25
+ * The annotations written above the accessor, each on a line of its own.
26
+ */
8
27
  annotations;
28
+ /**
29
+ * The code of the accessor, written after the parameter list. `null` writes no body. With `singleExpression` the code
30
+ * follows ` = `, otherwise it is written in braces on indented lines.
31
+ */
9
32
  body;
33
+ /**
34
+ * Whether the body is a single expression written after ` = ` on the same line, such as `get() = 42`. Otherwise the
35
+ * body is written in braces. Has no effect without a body.
36
+ * @default false
37
+ */
10
38
  singleExpression;
39
+ /**
40
+ * Initializes a new instance of the KtPropertyAccessor class.
41
+ * @param options The options to use for this instance.
42
+ */
11
43
  constructor(options) {
12
44
  super(options);
13
45
  this.accessModifier = options.accessModifier ?? null;
@@ -41,29 +73,126 @@ export class KtPropertyAccessor extends KtNode {
41
73
  builder.appendLine();
42
74
  }
43
75
  }
76
+ /**
77
+ * Represents the getter of a Kotlin property, written with the `get` keyword. See `KtPropertyAccessor` for the order in
78
+ * which it is written.
79
+ *
80
+ * @template TBuilder The type of the source builder the getter is written to.
81
+ * @see ktProperty.getter
82
+ */
44
83
  export class KtPropertyGetter extends KtPropertyAccessor {
84
+ /**
85
+ * The keyword of the accessor, always `get`. A body is written with an empty parameter list, such as `get() = 42`.
86
+ */
45
87
  kind = 'get';
46
88
  }
89
+ /**
90
+ * Represents the setter of a Kotlin property, written with the `set` keyword. See `KtPropertyAccessor` for the order in
91
+ * which it is written.
92
+ *
93
+ * @template TBuilder The type of the source builder the setter is written to.
94
+ * @see ktProperty.setter
95
+ */
47
96
  export class KtPropertySetter extends KtPropertyAccessor {
97
+ /**
98
+ * The keyword of the accessor, always `set`. A body uses the parameter list `(value)`, as in `set(value) = 42`.
99
+ */
48
100
  kind = 'set';
49
101
  }
102
+ /**
103
+ * Represents a Kotlin property declaration, such as `val x: Int = 42` or `var x: Int` with a private setter.
104
+ *
105
+ * Written in this order: the KDoc comment, the annotations, the modifiers, `val` or `var`, the name, the type, the
106
+ * default value or the delegate, then the getter and the setter, indented on lines below. The modifiers are written in
107
+ * the order access modifier, `const`, `lateinit`, `abstract`, `override`, `open`. A property with a setter is always
108
+ * written with `var`. Without a type, `: Any?` is written unless a default value or a getter body is present, in which
109
+ * case no type is written.
110
+ *
111
+ * @template TBuilder The type of the source builder the property is written to.
112
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
113
+ * @see ktProperty
114
+ */
50
115
  export class KtProperty extends KtNode {
116
+ /**
117
+ * The KDoc comment written above the property, or `null` to omit it. Nothing is written when the comment has neither
118
+ * a description nor tags.
119
+ */
51
120
  doc;
121
+ /**
122
+ * The name of the property, written after `val` or `var`.
123
+ */
52
124
  name;
125
+ /**
126
+ * The type written after the colon, such as `Int` in `val x: Int`. When it is `null`, `: Any?` is written if there is
127
+ * neither a default value nor a getter body, and no type is written otherwise.
128
+ */
53
129
  type;
130
+ /**
131
+ * The annotations written above the property, each on a line of its own. The target of an annotation is written as a
132
+ * use-site target, such as `@field:Json` or `@get:Inject`.
133
+ */
54
134
  annotations;
135
+ /**
136
+ * The visibility written before the other modifiers, such as `private` in `private val x`. `null` writes no
137
+ * visibility keyword.
138
+ */
55
139
  accessModifier;
140
+ /**
141
+ * The getter written on an indented line below the property, such as `get() = 42`. `null` writes no getter.
142
+ */
56
143
  getter;
144
+ /**
145
+ * The setter written on an indented line below the property, such as `private set`. Its presence makes the property
146
+ * `var`. `null` writes no setter.
147
+ */
57
148
  setter;
149
+ /**
150
+ * The initial value written after ` = `, such as `42` in `val x = 42`. `null` writes no initial value.
151
+ */
58
152
  default;
153
+ /**
154
+ * The delegate written after ` by `, such as `lazy` in `val x: Int by lazy`. `null` writes no delegation.
155
+ */
59
156
  delegate;
157
+ /**
158
+ * The arguments written in parentheses after the delegate, such as `(42, true)` in `by lazy(42, true)`. Only written
159
+ * when `delegate` is set. An empty list writes `()`.
160
+ */
60
161
  delegateArguments;
162
+ /**
163
+ * Whether the property is written with `var` instead of `val`. A property with a setter is always `var`.
164
+ * @default false
165
+ */
61
166
  mutable;
167
+ /**
168
+ * Whether the property is written with the `const` modifier, such as `const val x`.
169
+ * @default false
170
+ */
62
171
  const;
172
+ /**
173
+ * Whether the property is written with the `lateinit` modifier, such as `lateinit var x`.
174
+ * @default false
175
+ */
63
176
  lateinit;
177
+ /**
178
+ * Whether the property is written with the `open` modifier, such as `open val x`.
179
+ * @default false
180
+ */
64
181
  open;
182
+ /**
183
+ * Whether the property is written with the `override` modifier, such as `override val x`.
184
+ * @default false
185
+ */
65
186
  override;
187
+ /**
188
+ * Whether the property is written with the `abstract` modifier, such as `abstract val x: Int`.
189
+ * @default false
190
+ */
66
191
  abstract;
192
+ /**
193
+ * Initializes a new instance of the KtProperty class.
194
+ * @param options The options to use for this instance.
195
+ */
67
196
  constructor(options) {
68
197
  super(options);
69
198
  this.doc = options.doc ?? null;
@@ -137,6 +266,25 @@ export class KtProperty extends KtNode {
137
266
  const createPropertyGetter = (options) => new KtPropertyGetter(options ?? {});
138
267
  const createPropertySetter = (options) => new KtPropertySetter(options ?? {});
139
268
  const createProperty = (name, options) => new KtProperty({ ...options, name });
269
+ /**
270
+ * Factory for creating property nodes. The `getter` and `setter` functions create the accessors of a property and
271
+ * accept the options of `KtPropertyAccessor`. The `write` function writes one or more property nodes to a builder.
272
+ *
273
+ * @param name The name of the property.
274
+ * @param options The settings of the property. See `KtProperty` for the available properties.
275
+ * @example
276
+ * ```ts
277
+ * ktProperty('count', {
278
+ * type: 'Int',
279
+ * mutable: true,
280
+ * default: '0',
281
+ * setter: ktProperty.setter({ accessModifier: 'private' }),
282
+ * });
283
+ * // Emits:
284
+ * // var count: Int = 0
285
+ * // private set
286
+ * ```
287
+ */
140
288
  export const ktProperty = Object.assign(createProperty, {
141
289
  getter: createPropertyGetter,
142
290
  setter: createPropertySetter,
@@ -16,34 +16,141 @@ type _AddImportHandler<T> = {
16
16
  builderClass: abstract new (...args: any) => T;
17
17
  handler: (builder: T, reference: KtReference<any>) => void;
18
18
  };
19
+ /**
20
+ * Represents a reference to a named Kotlin type or declaration, such as `List<String>?` or `Foo::class`.
21
+ *
22
+ * Written in this order: the name, the generic arguments in angle brackets, then one suffix. The suffix is `::class`
23
+ * when `classReference` is set, `::` followed by `subReference` when that is set, or `?` when `nullable` is set. The
24
+ * suffixes exclude each other, so `nullable` has no effect when `classReference` or `subReference` is set.
25
+ *
26
+ * Writing a reference also imports it. When `packageName` is set and the builder is a `KotlinFileBuilder`, the file
27
+ * gets an import for `<packageName>.<name>`, unless the package is the package of the file itself. Imports that match
28
+ * the `globalImports` option of the generator configuration are left out when the import block is written. Builders
29
+ * with no registered handler, such as a plain string builder, only receive the name. The import is added when the
30
+ * reference is written, so use `addImport` or `ktReference.import` to add an import without writing the reference.
31
+ *
32
+ * @template TBuilder The type of the source builder the reference is written to.
33
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
34
+ * @see ktReference
35
+ * @see KtReference.registerAddImportHandler
36
+ */
19
37
  export declare class KtReference<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
20
38
  private static readonly addImportHandlers;
39
+ /**
40
+ * The name written verbatim, such as `List`. When `packageName` is set, the same name is imported.
41
+ */
21
42
  name: string;
43
+ /**
44
+ * The package the name is imported from, such as `com.example.models`. `null` writes the name without an import.
45
+ */
22
46
  packageName: string | null;
47
+ /**
48
+ * The generic arguments written in angle brackets after the name, such as `<String>` in `List<String>`. An empty list
49
+ * writes nothing.
50
+ */
23
51
  generics: KtType<TBuilder>[];
52
+ /**
53
+ * Whether a `?` is written after the name, which makes the type nullable. Ignored when `classReference` or
54
+ * `subReference` is set.
55
+ * @default false
56
+ */
24
57
  nullable: boolean;
58
+ /**
59
+ * Whether the reference is written as a class literal, such as `Foo::class`. Takes precedence over `subReference` and
60
+ * `nullable`.
61
+ * @default false
62
+ */
25
63
  classReference: boolean;
64
+ /**
65
+ * A reference or call written after `::`, such as `Bar` in `Foo::Bar`, or `null` for none. Takes precedence over
66
+ * `nullable`, and `classReference` takes precedence over it.
67
+ */
26
68
  subReference: KtReference<TBuilder> | KtCall<TBuilder> | null;
69
+ /**
70
+ * Initializes a new instance of the KtReference class.
71
+ * @param options The options to use for this instance.
72
+ */
27
73
  constructor(options: Options<TBuilder, TInjects>);
74
+ /**
75
+ * Adds the import for this reference to the builder without writing the reference. Nothing is added when
76
+ * `packageName` is not set, or when no handler is registered for the class of the builder.
77
+ * @param builder The builder to add the import to.
78
+ */
28
79
  addImport(builder: TBuilder): void;
29
80
  protected onWrite(builder: TBuilder): void;
81
+ /**
82
+ * Registers a handler that adds imports for references written to builders of the given class. The handlers are tried
83
+ * in the order they were registered, and the first one whose class matches the builder is used. The handler for
84
+ * `KotlinFileBuilder` is registered first, so it also matches subclasses of that class.
85
+ * @template TBuilder The type of the builder that the handler supports.
86
+ * @param builderClass The class of the builders that the handler applies to.
87
+ * @param handler Adds the import for the reference to the builder.
88
+ */
30
89
  static registerAddImportHandler<TBuilder extends SourceBuilder>(builderClass: _AddImportHandler<TBuilder>['builderClass'], handler: _AddImportHandler<TBuilder>['handler']): void;
31
90
  }
32
91
  declare const createReference: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], packageName?: Options<TBuilder>['packageName'], options?: Prettify<Omit<Options<TBuilder>, 'name' | 'packageName'>>) => KtReference<TBuilder>;
92
+ /**
93
+ * A function that creates references to one fixed name and package, as returned by `ktReference.factory`. Calling it
94
+ * creates the same reference as `ktReference` with that name and package, and takes the same options.
95
+ */
33
96
  export type KtReferenceFactory = (<TBuilder extends SourceBuilder>(options?: Prettify<Omit<Options<TBuilder>, 'name' | 'packageName'>>) => KtReference<TBuilder>) & {
97
+ /**
98
+ * The name that every reference created by this factory is written with.
99
+ */
34
100
  refName: string;
101
+ /**
102
+ * The package that every reference created by this factory is imported from, or `null` for none.
103
+ */
35
104
  packageName: Nullable<string>;
105
+ /**
106
+ * Whether the value is a reference with the name and package of this factory. Use it to check the type of a node.
107
+ */
36
108
  matches: (value: unknown) => value is KtReference<never>;
37
109
  };
110
+ /**
111
+ * A function that creates references to one fixed name and package with generic arguments, as returned by
112
+ * `ktReference.genericFactory`. Its first argument is the tuple of generic arguments, which must match `TGenericCount`.
113
+ *
114
+ * @template TGenericCount The number of generic arguments, or a list of the allowed numbers.
115
+ */
38
116
  export type KtGenericReferenceFactory<TGenericCount extends number | number[]> = (<TBuilder extends SourceBuilder>(generics: TupleWithCount<KtType<TBuilder>, TGenericCount>, options?: Prettify<Omit<Options<TBuilder>, 'name' | 'packageName' | 'generics'>>) => KtReference<TBuilder>) & {
117
+ /**
118
+ * The name that every reference created by this factory is written with.
119
+ */
39
120
  refName: string;
121
+ /**
122
+ * The package that every reference created by this factory is imported from, or `null` for none.
123
+ */
40
124
  packageName: Nullable<string>;
125
+ /**
126
+ * Creates a reference with the name and package of this factory and without generic arguments, for when the arguments
127
+ * are not known or not needed.
128
+ */
41
129
  infer: <TBuilder extends SourceBuilder>(options?: Prettify<Omit<Options<TBuilder>, 'name' | 'packageName' | 'generics'>>) => KtReference<TBuilder>;
130
+ /**
131
+ * Whether the value is a reference with the name and package of this factory. Use it to check the type of a node.
132
+ */
42
133
  matches: (value: unknown) => value is KtReference<never>;
43
134
  };
44
135
  declare const createFactory: (name: string, packageName?: Nullable<string>) => KtReferenceFactory;
45
136
  declare const createGenericFactory: <TGenericCount extends number | number[]>(name: string, packageName?: Nullable<string>) => KtGenericReferenceFactory<TGenericCount>;
46
137
  declare const importRefs: <TBuilder extends SourceBuilder>(builder: TBuilder, references: KtReference<TBuilder>[]) => void;
138
+ /**
139
+ * Factory for creating reference nodes. The `factory` and `genericFactory` functions create factories for one fixed
140
+ * name and package, `import` adds the imports of references without writing them, and `write` writes one or more
141
+ * reference nodes to a builder.
142
+ *
143
+ * @param name The name of the referenced type, such as `List`.
144
+ * @param packageName The package the name is imported from, or `null` to write the name without an import.
145
+ * @param options The settings of the reference. See `KtReference` for the available properties.
146
+ * @example
147
+ * ```ts
148
+ * ktReference('User', 'com.example.models', { generics: ['String'], nullable: true });
149
+ * // Emits:
150
+ * // User<String>?
151
+ * // and adds the import `com.example.models.User` to the file.
152
+ * ```
153
+ */
47
154
  export declare const ktReference: typeof createReference & {
48
155
  factory: typeof createFactory;
49
156
  genericFactory: typeof createGenericFactory;