@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
@@ -6,12 +6,47 @@ type Injects = never;
6
6
  type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<typeof KtNode<TBuilder, TInjects | Injects>, {
7
7
  elements: Nullable<Nullable<KtValue<TBuilder>>[]>;
8
8
  }>;
9
+ /**
10
+ * Represents a Kotlin collection literal, such as `["read", "write"]`. Kotlin accepts collection literals only inside
11
+ * annotation arguments.
12
+ *
13
+ * Written in this order: the opening bracket, the elements separated by commas, then the closing bracket.
14
+ *
15
+ * @template TBuilder The type of the source builder the collection literal is written to.
16
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
17
+ * @see ktCollectionLiteral
18
+ */
9
19
  export declare class KtCollectionLiteral<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
20
+ /**
21
+ * The elements written between the brackets, in the given order. Nullish elements are dropped before counting.
22
+ * Literals with more than two elements are written one element per line, shorter ones on a single line.
23
+ */
10
24
  elements: KtValue<TBuilder>[];
25
+ /**
26
+ * Initializes a new instance of the KtCollectionLiteral class.
27
+ * @param options The options to use for this instance.
28
+ */
11
29
  constructor(options: Options<TBuilder, TInjects>);
12
30
  protected onWrite(builder: TBuilder): void;
13
31
  }
14
32
  declare const createCollectionLiteral: <TBuilder extends SourceBuilder>(elements: Options<TBuilder>['elements'], options?: Omit<Options<TBuilder>, 'elements'>) => KtCollectionLiteral<TBuilder>;
33
+ /**
34
+ * Factory for creating collection literal nodes. The `write` function writes one or more collection literals to a
35
+ * builder.
36
+ *
37
+ * @param elements The elements of the literal. Nullish elements are dropped.
38
+ * @param options The settings of the literal, which only contain the injection points. See `KtCollectionLiteral`.
39
+ * @example
40
+ * ```ts
41
+ * ktCollectionLiteral(['"read"', '"write"', '"admin"']);
42
+ * // Emits:
43
+ * // [
44
+ * // "read",
45
+ * // "write",
46
+ * // "admin"
47
+ * // ]
48
+ * ```
49
+ */
15
50
  export declare const ktCollectionLiteral: typeof createCollectionLiteral & {
16
51
  write: typeof writeKtNodes;
17
52
  };
@@ -1,8 +1,26 @@
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 collection literal, such as `["read", "write"]`. Kotlin accepts collection literals only inside
6
+ * annotation arguments.
7
+ *
8
+ * Written in this order: the opening bracket, the elements separated by commas, then the closing bracket.
9
+ *
10
+ * @template TBuilder The type of the source builder the collection literal is written to.
11
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
12
+ * @see ktCollectionLiteral
13
+ */
4
14
  export class KtCollectionLiteral extends KtNode {
15
+ /**
16
+ * The elements written between the brackets, in the given order. Nullish elements are dropped before counting.
17
+ * Literals with more than two elements are written one element per line, shorter ones on a single line.
18
+ */
5
19
  elements;
20
+ /**
21
+ * Initializes a new instance of the KtCollectionLiteral class.
22
+ * @param options The options to use for this instance.
23
+ */
6
24
  constructor(options) {
7
25
  super(options);
8
26
  this.elements = options.elements?.filter(notNullish) ?? [];
@@ -15,6 +33,23 @@ export class KtCollectionLiteral extends KtNode {
15
33
  }
16
34
  }
17
35
  const createCollectionLiteral = (elements, options) => new KtCollectionLiteral({ ...options, elements });
36
+ /**
37
+ * Factory for creating collection literal nodes. The `write` function writes one or more collection literals to a
38
+ * builder.
39
+ *
40
+ * @param elements The elements of the literal. Nullish elements are dropped.
41
+ * @param options The settings of the literal, which only contain the injection points. See `KtCollectionLiteral`.
42
+ * @example
43
+ * ```ts
44
+ * ktCollectionLiteral(['"read"', '"write"', '"admin"']);
45
+ * // Emits:
46
+ * // [
47
+ * // "read",
48
+ * // "write",
49
+ * // "admin"
50
+ * // ]
51
+ * ```
52
+ */
18
53
  export const ktCollectionLiteral = Object.assign(createCollectionLiteral, {
19
54
  write: writeKtNodes,
20
55
  });
@@ -15,20 +15,85 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
15
15
  delegateTarget?: Nullable<KtDelegateTarget>;
16
16
  delegateArguments?: Nullable<Nullable<KtArgument<TBuilder> | KtValue<TBuilder>>[]>;
17
17
  }>;
18
+ /**
19
+ * The constructor that a constructor delegates to, written after `:` as `this(...)` or `super(...)`.
20
+ */
18
21
  export type KtDelegateTarget = 'this' | 'super';
22
+ /**
23
+ * Represents a constructor of a Kotlin class. A secondary constructor is written in the class body, while a primary
24
+ * constructor is written in the class header.
25
+ *
26
+ * Written in this order as a secondary constructor: annotations, access modifier, the `constructor` keyword,
27
+ * parameters, the delegation, then the body. As a primary constructor, only the annotations, the access modifier,
28
+ * and the parameters are written in the header, and the containing class writes the body as an `init` block.
29
+ *
30
+ * @template TBuilder The type of the source builder the constructor is written to.
31
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
32
+ * @see ktConstructor
33
+ */
19
34
  export declare class KtConstructor<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
35
+ /**
36
+ * The visibility modifier written before the `constructor` keyword, or `null` to omit it. For a primary
37
+ * constructor, a set modifier also makes the `constructor` keyword appear in the header, such as
38
+ * `Foo private constructor(x: Int)`.
39
+ */
20
40
  accessModifier: KtAccessModifier | null;
41
+ /**
42
+ * The annotations written above a secondary constructor, each on its own line. For a primary constructor they are
43
+ * written inline before the parameters, separated by spaces.
44
+ */
21
45
  annotations: KtAnnotation<TBuilder>[];
46
+ /**
47
+ * The parameters written in parentheses after the `constructor` keyword. A parameter with a `property` also
48
+ * declares a property of the class when it is part of a primary constructor. A secondary constructor always writes
49
+ * the parentheses, while a primary constructor omits them when there is nothing to write.
50
+ */
22
51
  parameters: (KtParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
52
+ /**
53
+ * The statements written inside the braces of a secondary constructor, or `null` for empty braces. A primary
54
+ * constructor does not write its body here, since the containing class writes it as an `init` block.
55
+ */
23
56
  body: AppendValue<TBuilder> | null;
57
+ /**
58
+ * The constructor that is called before the body, written as ` : this(...)` or ` : super(...)`, or `null` to omit
59
+ * the delegation. A primary constructor writes no delegation itself, so the containing class writes `super` after
60
+ * its base class instead.
61
+ */
24
62
  delegateTarget: KtDelegateTarget | null;
63
+ /**
64
+ * The arguments written in parentheses after the delegation target, such as `(42, true)`. Only written when
65
+ * `delegateTarget` is set, and an empty list writes `()`.
66
+ */
25
67
  delegateArguments: (KtArgument<TBuilder> | KtValue<TBuilder>)[];
68
+ /**
69
+ * Initializes a new instance of the KtConstructor class.
70
+ * @param options The options to use for this instance.
71
+ */
26
72
  constructor(options: Options<TBuilder, TInjects>);
27
73
  protected onWrite(builder: TBuilder): void;
28
74
  writeAsPrimary(builder: TBuilder): void;
29
75
  protected onWriteAsPrimary(builder: TBuilder): void;
30
76
  }
31
77
  declare const createConstructor: <TBuilder extends SourceBuilder>(parameters?: Options<TBuilder>['parameters'], body?: Options<TBuilder>['body'], options?: Prettify<Omit<Options<TBuilder>, 'parameters' | 'body'>>) => KtConstructor<TBuilder>;
78
+ /**
79
+ * Factory for creating constructor nodes. The `write` function writes one or more constructor nodes to a builder.
80
+ *
81
+ * @param parameters The parameters of the constructor. Pass nothing for a constructor without parameters.
82
+ * @param body The statements of the constructor body, or `null` for an empty body.
83
+ * @param options The settings of the constructor. See `KtConstructor` for the available properties.
84
+ * @example
85
+ * ```ts
86
+ * ktConstructor([ktParameter('x', 'Int')], 'println(x)', {
87
+ * accessModifier: 'private',
88
+ * delegateTarget: 'this',
89
+ * delegateArguments: ['x'],
90
+ * });
91
+ * // Emits:
92
+ * // private constructor(x: Int) : this(x) {
93
+ * // println(x)
94
+ * // }
95
+ * ```
96
+ */
32
97
  export declare const ktConstructor: typeof createConstructor & {
33
98
  write: typeof writeKtNodes;
34
99
  };
@@ -4,13 +4,56 @@ import { writeKtNodes } from '../utils/write-kt-node.js';
4
4
  import { ktAnnotation } from './annotation.js';
5
5
  import { ktArgument } from './argument.js';
6
6
  import { ktParameter } from './parameter.js';
7
+ /**
8
+ * Represents a constructor of a Kotlin class. A secondary constructor is written in the class body, while a primary
9
+ * constructor is written in the class header.
10
+ *
11
+ * Written in this order as a secondary constructor: annotations, access modifier, the `constructor` keyword,
12
+ * parameters, the delegation, then the body. As a primary constructor, only the annotations, the access modifier,
13
+ * and the parameters are written in the header, and the containing class writes the body as an `init` block.
14
+ *
15
+ * @template TBuilder The type of the source builder the constructor is written to.
16
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
17
+ * @see ktConstructor
18
+ */
7
19
  export class KtConstructor extends KtNode {
20
+ /**
21
+ * The visibility modifier written before the `constructor` keyword, or `null` to omit it. For a primary
22
+ * constructor, a set modifier also makes the `constructor` keyword appear in the header, such as
23
+ * `Foo private constructor(x: Int)`.
24
+ */
8
25
  accessModifier;
26
+ /**
27
+ * The annotations written above a secondary constructor, each on its own line. For a primary constructor they are
28
+ * written inline before the parameters, separated by spaces.
29
+ */
9
30
  annotations;
31
+ /**
32
+ * The parameters written in parentheses after the `constructor` keyword. A parameter with a `property` also
33
+ * declares a property of the class when it is part of a primary constructor. A secondary constructor always writes
34
+ * the parentheses, while a primary constructor omits them when there is nothing to write.
35
+ */
10
36
  parameters;
37
+ /**
38
+ * The statements written inside the braces of a secondary constructor, or `null` for empty braces. A primary
39
+ * constructor does not write its body here, since the containing class writes it as an `init` block.
40
+ */
11
41
  body;
42
+ /**
43
+ * The constructor that is called before the body, written as ` : this(...)` or ` : super(...)`, or `null` to omit
44
+ * the delegation. A primary constructor writes no delegation itself, so the containing class writes `super` after
45
+ * its base class instead.
46
+ */
12
47
  delegateTarget;
48
+ /**
49
+ * The arguments written in parentheses after the delegation target, such as `(42, true)`. Only written when
50
+ * `delegateTarget` is set, and an empty list writes `()`.
51
+ */
13
52
  delegateArguments;
53
+ /**
54
+ * Initializes a new instance of the KtConstructor class.
55
+ * @param options The options to use for this instance.
56
+ */
14
57
  constructor(options) {
15
58
  super(options);
16
59
  this.parameters = options.parameters?.filter(notNullish) ?? [];
@@ -71,6 +114,25 @@ export class KtConstructor extends KtNode {
71
114
  }
72
115
  }
73
116
  const createConstructor = (parameters, body, options) => new KtConstructor({ ...options, parameters: parameters ?? undefined, body });
117
+ /**
118
+ * Factory for creating constructor nodes. The `write` function writes one or more constructor nodes to a builder.
119
+ *
120
+ * @param parameters The parameters of the constructor. Pass nothing for a constructor without parameters.
121
+ * @param body The statements of the constructor body, or `null` for an empty body.
122
+ * @param options The settings of the constructor. See `KtConstructor` for the available properties.
123
+ * @example
124
+ * ```ts
125
+ * ktConstructor([ktParameter('x', 'Int')], 'println(x)', {
126
+ * accessModifier: 'private',
127
+ * delegateTarget: 'this',
128
+ * delegateArguments: ['x'],
129
+ * });
130
+ * // Emits:
131
+ * // private constructor(x: Int) : this(x) {
132
+ * // println(x)
133
+ * // }
134
+ * ```
135
+ */
74
136
  export const ktConstructor = Object.assign(createConstructor, {
75
137
  write: writeKtNodes,
76
138
  });
@@ -7,10 +7,34 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
7
7
  args?: Nullable<Nullable<BasicAppendValue<TBuilder>>[]>;
8
8
  description?: Nullable<BasicAppendValue<TBuilder>>;
9
9
  }>;
10
+ /**
11
+ * Represents a documentation tag, such as `@param x The value.` or `@see Foo`. Tags are written inside the KDoc comment
12
+ * of the declaration that they document.
13
+ *
14
+ * Written in this order: the `@` sign and the tag name, the arguments, then the description. Each part after the tag
15
+ * name is preceded by a space.
16
+ *
17
+ * @template TBuilder The type of the source builder the tag is written to.
18
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
19
+ * @see ktDocTag
20
+ */
10
21
  export declare class KtDocTag<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
22
+ /**
23
+ * The name of the tag, written after the `@` sign, such as `param` or `see`.
24
+ */
11
25
  tag: string;
26
+ /**
27
+ * The arguments written after the tag name, each preceded by a space. For `@param x`, the name `x` is an argument.
28
+ */
12
29
  args: BasicAppendValue<TBuilder>[];
30
+ /**
31
+ * The text written at the end of the tag, preceded by a space, or `null` to omit it.
32
+ */
13
33
  description: BasicAppendValue<TBuilder> | null;
34
+ /**
35
+ * Initializes a new instance of the KtDocTag class.
36
+ * @param options The options to use for this instance.
37
+ */
14
38
  constructor(options: Options<TBuilder, TInjects>);
15
39
  protected onWrite(builder: TBuilder): void;
16
40
  }
@@ -29,6 +53,23 @@ type _KtDocTagArgsMap<TBuilder extends SourceBuilder> = {
29
53
  type _KtDocTagArgs<TTagName extends StringSuggestions<keyof _KtDocTagArgsMap<TBuilder>>, TBuilder extends SourceBuilder> = TTagName extends keyof _KtDocTagArgsMap<TBuilder> ? _KtDocTagArgsMap<TBuilder>[TTagName] extends (...args: any[]) => any ? ParametersWithOverloads<_KtDocTagArgsMap<TBuilder>[TTagName]> : never : [options?: _KtDocTagOpt<TBuilder>];
30
54
  declare function createDocTag<TTagName extends StringSuggestions<keyof _KtDocTagArgsMap<TBuilder>>, TBuilder extends SourceBuilder>(tag: TTagName, ...args: _KtDocTagArgs<TTagName, TBuilder>): KtDocTag<TBuilder>;
31
55
  declare const writeDocTags: <TBuilder extends SourceBuilder>(builder: TBuilder, nodes: SingleOrMultiple<Nullable<KtAppendValue<TBuilder>>>) => void;
56
+ /**
57
+ * Factory for creating doc tag nodes. The `write` function writes one or more tags to a builder, one per line.
58
+ *
59
+ * The arguments depend on the tag. `param` and `property` take a name and a description, `throws` and `exception` take
60
+ * a class and a description, and `see` and `sample` take an identifier. `suppress` takes no arguments, and tags such as
61
+ * `return` take only a description. Other tags take their arguments as given. A settings object can be passed last.
62
+ *
63
+ * @param tag The name of the tag, written after the `@` sign.
64
+ * @param args The arguments of the tag, followed by an optional settings object. See the description for the arguments
65
+ * of each tag.
66
+ * @example
67
+ * ```ts
68
+ * ktDocTag('param', 'id', 'The identifier of the pet.');
69
+ * // Emits:
70
+ * // @param id The identifier of the pet.
71
+ * ```
72
+ */
32
73
  export declare const ktDocTag: typeof createDocTag & {
33
74
  write: typeof writeDocTags;
34
75
  };
@@ -2,10 +2,34 @@ import { basicAppendValueGroup, notNullish, } from '@goast/core';
2
2
  import { isKotlinAppendValue } from '../../file-builder.js';
3
3
  import { KtNode } from '../node.js';
4
4
  import { writeKtNodes } from '../utils/write-kt-node.js';
5
+ /**
6
+ * Represents a documentation tag, such as `@param x The value.` or `@see Foo`. Tags are written inside the KDoc comment
7
+ * of the declaration that they document.
8
+ *
9
+ * Written in this order: the `@` sign and the tag name, the arguments, then the description. Each part after the tag
10
+ * name is preceded by a space.
11
+ *
12
+ * @template TBuilder The type of the source builder the tag is written to.
13
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
14
+ * @see ktDocTag
15
+ */
5
16
  export class KtDocTag extends KtNode {
17
+ /**
18
+ * The name of the tag, written after the `@` sign, such as `param` or `see`.
19
+ */
6
20
  tag;
21
+ /**
22
+ * The arguments written after the tag name, each preceded by a space. For `@param x`, the name `x` is an argument.
23
+ */
7
24
  args;
25
+ /**
26
+ * The text written at the end of the tag, preceded by a space, or `null` to omit it.
27
+ */
8
28
  description;
29
+ /**
30
+ * Initializes a new instance of the KtDocTag class.
31
+ * @param options The options to use for this instance.
32
+ */
9
33
  constructor(options) {
10
34
  super(options);
11
35
  this.tag = options.tag;
@@ -53,6 +77,23 @@ function createDocTag(tag, ...args) {
53
77
  const writeDocTags = (builder, nodes) => {
54
78
  writeKtNodes(builder, nodes, { separator: '\n' });
55
79
  };
80
+ /**
81
+ * Factory for creating doc tag nodes. The `write` function writes one or more tags to a builder, one per line.
82
+ *
83
+ * The arguments depend on the tag. `param` and `property` take a name and a description, `throws` and `exception` take
84
+ * a class and a description, and `see` and `sample` take an identifier. `suppress` takes no arguments, and tags such as
85
+ * `return` take only a description. Other tags take their arguments as given. A settings object can be passed last.
86
+ *
87
+ * @param tag The name of the tag, written after the `@` sign.
88
+ * @param args The arguments of the tag, followed by an optional settings object. See the description for the arguments
89
+ * of each tag.
90
+ * @example
91
+ * ```ts
92
+ * ktDocTag('param', 'id', 'The identifier of the pet.');
93
+ * // Emits:
94
+ * // @param id The identifier of the pet.
95
+ * ```
96
+ */
56
97
  export const ktDocTag = Object.assign(createDocTag, {
57
98
  write: writeDocTags,
58
99
  });
@@ -9,9 +9,31 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
9
9
  description?: Nullable<BasicAppendValue<TBuilder>>;
10
10
  tags?: Nullable<Nullable<KtDocTag<TBuilder>>[]>;
11
11
  }>;
12
+ /**
13
+ * Represents a KDoc comment block that is written above a declaration. The block is omitted when it has neither a
14
+ * description nor tags.
15
+ *
16
+ * Written in this order: the description, a blank line, then the tags. Every line of the block is prefixed with an
17
+ * asterisk.
18
+ *
19
+ * @template TBuilder The type of the source builder the doc comment is written to.
20
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
21
+ * @see ktDoc
22
+ */
12
23
  export declare class KtDoc<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
24
+ /**
25
+ * The text written at the start of the block, or `null` to write only the tags.
26
+ */
13
27
  description: BasicAppendValue<TBuilder> | null;
28
+ /**
29
+ * The tags written after the description, one per line, such as `@param` or `@see`. Tags that `ktDoc.get` generates
30
+ * from the descriptions of generic and value parameters are placed before these tags.
31
+ */
14
32
  tags: KtDocTag<TBuilder>[];
33
+ /**
34
+ * Initializes a new instance of the KtDoc class.
35
+ * @param options The options to use for this instance.
36
+ */
15
37
  constructor(options: Options<TBuilder, TInjects>);
16
38
  protected onWrite(builder: TBuilder): void;
17
39
  }
@@ -20,6 +42,28 @@ declare function getDoc<TBuilder extends SourceBuilder>(baseDoc: KtDoc<TBuilder>
20
42
  parameters?: Nullable<Nullable<KtParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
21
43
  generics?: Nullable<Nullable<KtGenericParameter<TBuilder> | BasicAppendValue<TBuilder>>[]>;
22
44
  }): KtDoc<TBuilder> | null;
45
+ /**
46
+ * Factory for creating doc comment nodes. The `write` function writes one or more doc comments to a builder. The `get`
47
+ * function returns the doc comment of a declaration with the descriptions of its generic and parameters added as tags,
48
+ * or `null` when there is nothing to write.
49
+ *
50
+ * @param description The text at the start of the block, or `null` for none.
51
+ * @param tags The tags written after the description.
52
+ * @param options The settings of the doc comment. See `KtDoc` for the available properties.
53
+ * @example
54
+ * ```ts
55
+ * ktDoc('Returns the pet with the given id.', [
56
+ * ktDocTag('param', 'id', 'The identifier of the pet.'),
57
+ * ktDocTag('return', 'The pet, or null.'),
58
+ * ]);
59
+ * // Emits a KDoc block with one line per entry, which is closed after the last tag:
60
+ * // /**
61
+ * // * Returns the pet with the given id.
62
+ * // *
63
+ * // * @param id The identifier of the pet.
64
+ * // * @return The pet, or null.
65
+ * ```
66
+ */
23
67
  export declare const ktDoc: typeof createDoc & {
24
68
  write: typeof writeKtNodes;
25
69
  get: typeof getDoc;
@@ -4,9 +4,31 @@ import { writeKtNodes } from '../utils/write-kt-node.js';
4
4
  import { ktDocTag } from './doc-tag.js';
5
5
  import { KtGenericParameter } from './generic-parameter.js';
6
6
  import { KtParameter } from './parameter.js';
7
+ /**
8
+ * Represents a KDoc comment block that is written above a declaration. The block is omitted when it has neither a
9
+ * description nor tags.
10
+ *
11
+ * Written in this order: the description, a blank line, then the tags. Every line of the block is prefixed with an
12
+ * asterisk.
13
+ *
14
+ * @template TBuilder The type of the source builder the doc comment is written to.
15
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
16
+ * @see ktDoc
17
+ */
7
18
  export class KtDoc extends KtNode {
19
+ /**
20
+ * The text written at the start of the block, or `null` to write only the tags.
21
+ */
8
22
  description;
23
+ /**
24
+ * The tags written after the description, one per line, such as `@param` or `@see`. Tags that `ktDoc.get` generates
25
+ * from the descriptions of generic and value parameters are placed before these tags.
26
+ */
9
27
  tags;
28
+ /**
29
+ * Initializes a new instance of the KtDoc class.
30
+ * @param options The options to use for this instance.
31
+ */
10
32
  constructor(options) {
11
33
  super(options);
12
34
  this.description = options.description ?? null;
@@ -51,6 +73,28 @@ function getDoc(baseDoc, options) {
51
73
  doc.tags.splice(0, 0, ...genericTags, ...paramTags, ...propertyTags);
52
74
  return doc;
53
75
  }
76
+ /**
77
+ * Factory for creating doc comment nodes. The `write` function writes one or more doc comments to a builder. The `get`
78
+ * function returns the doc comment of a declaration with the descriptions of its generic and parameters added as tags,
79
+ * or `null` when there is nothing to write.
80
+ *
81
+ * @param description The text at the start of the block, or `null` for none.
82
+ * @param tags The tags written after the description.
83
+ * @param options The settings of the doc comment. See `KtDoc` for the available properties.
84
+ * @example
85
+ * ```ts
86
+ * ktDoc('Returns the pet with the given id.', [
87
+ * ktDocTag('param', 'id', 'The identifier of the pet.'),
88
+ * ktDocTag('return', 'The pet, or null.'),
89
+ * ]);
90
+ * // Emits a KDoc block with one line per entry, which is closed after the last tag:
91
+ * // /**
92
+ * // * Returns the pet with the given id.
93
+ * // *
94
+ * // * @param id The identifier of the pet.
95
+ * // * @return The pet, or null.
96
+ * ```
97
+ */
54
98
  export const ktDoc = Object.assign(createDoc, {
55
99
  write: writeKtNodes,
56
100
  get: getDoc,
@@ -14,17 +14,67 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
14
14
  arguments?: Nullable<Nullable<KtArgument<TBuilder> | AppendValue<TBuilder>>[]>;
15
15
  members?: Nullable<Nullable<KtEnumValueMember<TBuilder>>[]>;
16
16
  }>;
17
+ /**
18
+ * The nodes that can be written in the body of an enum value. Other append values are written as-is.
19
+ */
17
20
  export type KtEnumValueMember<TBuilder extends SourceBuilder> = KtParameter<TBuilder> | KtFunction<TBuilder> | AppendValue<TBuilder>;
21
+ /**
22
+ * Represents a single value, also called an entry, of a Kotlin enum class, such as `RED(0xFF0000)`.
23
+ *
24
+ * Written in this order: the doc comment, annotations, the name, the arguments in parentheses, then the members in
25
+ * braces.
26
+ *
27
+ * @template TBuilder The type of the source builder the enum value is written to.
28
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
29
+ * @see ktEnumValue
30
+ */
18
31
  export declare class KtEnumValue<TBuilder extends SourceBuilder, TInjects extends string = never> extends KtNode<TBuilder, TInjects | Injects> {
32
+ /**
33
+ * The name of the entry, written verbatim.
34
+ */
19
35
  name: string;
36
+ /**
37
+ * The KDoc comment written above the entry, or `null` to omit it.
38
+ */
20
39
  doc: KtDoc<TBuilder> | null;
40
+ /**
41
+ * The annotations written above the entry, each on its own line.
42
+ */
21
43
  annotations: KtAnnotation<TBuilder>[];
44
+ /**
45
+ * The arguments written in parentheses after the name, such as `(0, 1)`. They are passed to the primary
46
+ * constructor of the enum. Nothing is written when the list is empty.
47
+ */
22
48
  arguments: (KtArgument<TBuilder> | AppendValue<TBuilder>)[];
49
+ /**
50
+ * The members written in braces after the entry, such as functions that only this entry overrides. The braces are
51
+ * omitted when there are no members.
52
+ */
23
53
  members: KtEnumValueMember<TBuilder>[];
54
+ /**
55
+ * Initializes a new instance of the KtEnumValue class.
56
+ * @param options The options to use for this instance.
57
+ */
24
58
  constructor(options: Options<TBuilder, TInjects>);
25
59
  protected onWrite(builder: TBuilder): void;
26
60
  }
27
61
  declare const createEnumValue: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], options?: Prettify<Omit<Options<TBuilder>, 'name'>>) => KtEnumValue<TBuilder>;
62
+ /**
63
+ * Factory for creating enum value nodes. The `write` function writes a list of enum values, separated by commas.
64
+ * The list is written with one value per line when there are more than four values, or when any value has arguments,
65
+ * a doc comment, annotations or members. Blank lines separate the values when any value has a doc comment, annotations
66
+ * or members.
67
+ *
68
+ * @param name The name of the entry, written verbatim.
69
+ * @param options The settings of the entry. See `KtEnumValue` for the available properties.
70
+ * @example
71
+ * ```ts
72
+ * ktEnumValue('ADMIN', { annotations: [ktAnnotation('Deprecated')], arguments: ['"admin"'] });
73
+ * // Emits:
74
+ * // @Deprecated
75
+ * // ADMIN("admin")
76
+ * ```
77
+ */
28
78
  export declare const ktEnumValue: typeof createEnumValue & {
29
79
  write: typeof writeKtEnumValues;
30
80
  };
@@ -4,12 +4,43 @@ import { writeKtEnumValues } from '../utils/write-kt-enum-values.js';
4
4
  import { writeKtMembers } from '../utils/write-kt-members.js';
5
5
  import { ktAnnotation } from './annotation.js';
6
6
  import { ktArgument } from './argument.js';
7
+ /**
8
+ * Represents a single value, also called an entry, of a Kotlin enum class, such as `RED(0xFF0000)`.
9
+ *
10
+ * Written in this order: the doc comment, annotations, the name, the arguments in parentheses, then the members in
11
+ * braces.
12
+ *
13
+ * @template TBuilder The type of the source builder the enum value is written to.
14
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
15
+ * @see ktEnumValue
16
+ */
7
17
  export class KtEnumValue extends KtNode {
18
+ /**
19
+ * The name of the entry, written verbatim.
20
+ */
8
21
  name;
22
+ /**
23
+ * The KDoc comment written above the entry, or `null` to omit it.
24
+ */
9
25
  doc;
26
+ /**
27
+ * The annotations written above the entry, each on its own line.
28
+ */
10
29
  annotations;
30
+ /**
31
+ * The arguments written in parentheses after the name, such as `(0, 1)`. They are passed to the primary
32
+ * constructor of the enum. Nothing is written when the list is empty.
33
+ */
11
34
  arguments;
35
+ /**
36
+ * The members written in braces after the entry, such as functions that only this entry overrides. The braces are
37
+ * omitted when there are no members.
38
+ */
12
39
  members;
40
+ /**
41
+ * Initializes a new instance of the KtEnumValue class.
42
+ * @param options The options to use for this instance.
43
+ */
13
44
  constructor(options) {
14
45
  super(options);
15
46
  this.name = options.name;
@@ -44,6 +75,22 @@ export class KtEnumValue extends KtNode {
44
75
  }
45
76
  }
46
77
  const createEnumValue = (name, options) => new KtEnumValue({ ...options, name });
78
+ /**
79
+ * Factory for creating enum value nodes. The `write` function writes a list of enum values, separated by commas.
80
+ * The list is written with one value per line when there are more than four values, or when any value has arguments,
81
+ * a doc comment, annotations or members. Blank lines separate the values when any value has a doc comment, annotations
82
+ * or members.
83
+ *
84
+ * @param name The name of the entry, written verbatim.
85
+ * @param options The settings of the entry. See `KtEnumValue` for the available properties.
86
+ * @example
87
+ * ```ts
88
+ * ktEnumValue('ADMIN', { annotations: [ktAnnotation('Deprecated')], arguments: ['"admin"'] });
89
+ * // Emits:
90
+ * // @Deprecated
91
+ * // ADMIN("admin")
92
+ * ```
93
+ */
47
94
  export const ktEnumValue = Object.assign(createEnumValue, {
48
95
  write: writeKtEnumValues,
49
96
  });