writeHostApi method
void
writeHostApi(
- ArkTSOptions generatorOptions,
- Root root,
- Indent indent,
- Api api, {
- required String dartPackageName,
override
Writes a single Host Api to indent
.
Implementation
@override
void writeHostApi(
ArkTSOptions generatorOptions, Root root, Indent indent, Api api,
{required String dartPackageName}) {
assert(api.location == ApiLocation.host);
if (getCodecClasses(api, root).isNotEmpty) {
_writeCodec(indent, api, root);
}
const List<String> generatedMessages = <String>[
' Generated abstract class from Pigeon that represents a handler of messages from Flutter.'
];
addDocumentationComments(indent, api.documentationComments, _docCommentSpec,
generatorComments: generatedMessages);
indent.write('export abstract class ${api.name} ');
indent.addScoped('{', '}', () {
for (final Method method in api.methods) {
_writeInterfaceMethod(generatorOptions, root, indent, api, method);
}
final String codecName = _getCodecName(api);
indent.writeln('/** The codec used by ${api.name}. */');
indent.write('static getCodec(): MessageCodec<Object>');
indent.addScoped('{', '}', () {
indent.write('return ');
if (getCodecClasses(api, root).isNotEmpty) {
indent.addln('$codecName.INSTANCE;');
} else {
indent.addln('new $_standardMessageCodec();');
}
});
indent.writeln(
'${_docCommentPrefix}Sets up an instance of `${api.name}` to handle messages through the `binaryMessenger`.$_docCommentSuffix');
indent.write(
'static setup(binaryMessenger: BinaryMessenger, api: ${api.name} | null): void ');
indent.addScoped('{', '}', () {
for (final Method method in api.methods) {
_writeMethodSetup(
generatorOptions,
root,
indent,
api,
method,
dartPackageName: dartPackageName,
);
}
});
});
}