@@ -7,6 +7,23 @@ import 'functional.dart';
7
7
import 'generator_tools.dart' ;
8
8
import 'pigeon_lib.dart' show TaskQueueType;
9
9
10
+ /// Documentation open symbol.
11
+ const String _docCommentPrefix = '/**' ;
12
+
13
+ /// Documentation continuation symbol.
14
+ const String _docCommentContinuation = ' *' ;
15
+
16
+ /// Documentation close symbol.
17
+ const String _docCommentSuffix = ' */' ;
18
+
19
+ /// Documentation comment spec.
20
+ const DocumentCommentSpecification _docCommentSpec =
21
+ DocumentCommentSpecification (
22
+ _docCommentPrefix,
23
+ closeCommentToken: _docCommentSuffix,
24
+ blockContinuationToken: _docCommentContinuation,
25
+ );
26
+
10
27
/// Options that control how Kotlin code will be generated.
11
28
class KotlinOptions {
12
29
/// Creates a [KotlinOptions] object
@@ -112,8 +129,12 @@ void _writeHostApi(Indent indent, Api api, Root root) {
112
129
113
130
final String apiName = api.name;
114
131
115
- indent.writeln (
116
- '/** Generated interface from Pigeon that represents a handler of messages from Flutter. */' );
132
+ const List <String > generatedMessages = < String > [
133
+ ' Generated interface from Pigeon that represents a handler of messages from Flutter.'
134
+ ];
135
+ addDocumentationComments (indent, api.documentationComments, _docCommentSpec,
136
+ generatorComments: generatedMessages);
137
+
117
138
indent.write ('interface $apiName ' );
118
139
indent.scoped ('{' , '}' , () {
119
140
for (final Method method in api.methods) {
@@ -132,6 +153,10 @@ void _writeHostApi(Indent indent, Api api, Root root) {
132
153
final String returnType = method.returnType.isVoid
133
154
? ''
134
155
: _nullsafeKotlinTypeForDartType (method.returnType);
156
+
157
+ addDocumentationComments (
158
+ indent, method.documentationComments, _docCommentSpec);
159
+
135
160
if (method.isAsynchronous) {
136
161
argSignature.add ('callback: ($returnType ) -> Unit' );
137
162
indent.writeln ('fun ${method .name }(${argSignature .join (', ' )})' );
@@ -256,8 +281,12 @@ String _getSafeArgumentName(int count, NamedType argument) =>
256
281
/// }
257
282
void _writeFlutterApi (Indent indent, Api api) {
258
283
assert (api.location == ApiLocation .flutter);
259
- indent.writeln (
260
- '/** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */' );
284
+ const List <String > generatedMessages = < String > [
285
+ ' Generated class from Pigeon that represents Flutter messages that can be called from Kotlin.'
286
+ ];
287
+ addDocumentationComments (indent, api.documentationComments, _docCommentSpec,
288
+ generatorComments: generatedMessages);
289
+
261
290
final String apiName = api.name;
262
291
indent.writeln ('@Suppress("UNCHECKED_CAST")' );
263
292
indent.write ('class $apiName (private val binaryMessenger: BinaryMessenger) ' );
@@ -277,6 +306,10 @@ void _writeFlutterApi(Indent indent, Api api) {
277
306
? ''
278
307
: _nullsafeKotlinTypeForDartType (func.returnType);
279
308
String sendArgument;
309
+
310
+ addDocumentationComments (
311
+ indent, func.documentationComments, _docCommentSpec);
312
+
280
313
if (func.arguments.isEmpty) {
281
314
indent.write ('fun ${func .name }(callback: ($returnType ) -> Unit) ' );
282
315
sendArgument = 'null' ;
@@ -430,6 +463,8 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) {
430
463
}
431
464
432
465
void writeEnum (Enum anEnum) {
466
+ addDocumentationComments (
467
+ indent, anEnum.documentationComments, _docCommentSpec);
433
468
indent.write ('enum class ${anEnum .name }(val raw: Int) ' );
434
469
indent.scoped ('{' , '}' , () {
435
470
// We use explicit indexing here as use of the ordinal() method is
@@ -460,6 +495,8 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) {
460
495
461
496
void writeDataClass (Class klass) {
462
497
void writeField (NamedType field) {
498
+ addDocumentationComments (
499
+ indent, field.documentationComments, _docCommentSpec);
463
500
indent.write (
464
501
'val ${field .name }: ${_nullsafeKotlinTypeForDartType (field .type )}' );
465
502
final String defaultNil = field.type.isNullable ? ' = null' : '' ;
@@ -566,8 +603,13 @@ void generateKotlin(KotlinOptions options, Root root, StringSink sink) {
566
603
});
567
604
}
568
605
569
- indent.writeln (
570
- '/** Generated class from Pigeon that represents data sent in messages. */' );
606
+ const List <String > generatedMessages = < String > [
607
+ ' Generated class from Pigeon that represents data sent in messages.'
608
+ ];
609
+ addDocumentationComments (
610
+ indent, klass.documentationComments, _docCommentSpec,
611
+ generatorComments: generatedMessages);
612
+
571
613
indent.write ('data class ${klass .name }(' );
572
614
indent.scoped ('' , '' , () {
573
615
for (final NamedType element in klass.fields) {
0 commit comments