writeProxyApi method
void
writeProxyApi(
- KotlinOptions generatorOptions,
- Root root,
- Indent indent,
- AstProxyApi api, {
- required String dartPackageName,
override
Writes a single Proxy Api to indent
.
Implementation
@override
void writeProxyApi(
KotlinOptions generatorOptions,
Root root,
Indent indent,
AstProxyApi api, {
required String dartPackageName,
}) {
final String kotlinApiName = '$hostProxyApiPrefix${api.name}';
addDocumentationComments(
indent,
api.documentationComments,
_docCommentSpec,
);
indent.writeln('@Suppress("UNCHECKED_CAST")');
// The API only needs to be abstract if there are methods to override.
final String classModifier =
api.hasMethodsRequiringImplementation() ? 'abstract' : 'open';
indent.writeScoped(
'$classModifier class $kotlinApiName(open val pigeonRegistrar: ${proxyApiRegistrarName(generatorOptions)}) {',
'}',
() {
final String fullKotlinClassName =
api.kotlinOptions?.fullClassName ?? api.name;
final TypeDeclaration apiAsTypeDeclaration = TypeDeclaration(
baseName: api.name,
isNullable: false,
associatedProxyApi: api,
);
_writeProxyApiConstructorAbstractMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
_writeProxyApiAttachedFieldAbstractMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
if (api.hasCallbackConstructor()) {
_writeProxyApiUnattachedFieldAbstractMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
}
_writeProxyApiHostMethodAbstractMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
if (api.constructors.isNotEmpty ||
api.attachedFields.isNotEmpty ||
api.hostMethods.isNotEmpty) {
indent.writeScoped('companion object {', '}', () {
_writeProxyApiMessageHandlerMethod(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
kotlinApiName: kotlinApiName,
dartPackageName: dartPackageName,
fullKotlinClassName: fullKotlinClassName,
generatorOptions: generatorOptions,
);
});
indent.newln();
}
_writeProxyApiNewInstanceMethod(
indent,
api,
generatorOptions: generatorOptions,
apiAsTypeDeclaration: apiAsTypeDeclaration,
newInstanceMethodName: '${classMemberNamePrefix}newInstance',
dartPackageName: dartPackageName,
);
_writeProxyApiFlutterMethods(
indent,
api,
generatorOptions: generatorOptions,
apiAsTypeDeclaration: apiAsTypeDeclaration,
dartPackageName: dartPackageName,
);
_writeProxyApiInheritedApiMethods(indent, api);
},
);
}