writeProxyApi method
void
writeProxyApi(
- SwiftOptions generatorOptions,
- Root root,
- Indent indent,
- AstProxyApi api, {
- required String dartPackageName,
override
Writes a single Proxy Api to indent
.
Implementation
@override
void writeProxyApi(
SwiftOptions generatorOptions,
Root root,
Indent indent,
AstProxyApi api, {
required String dartPackageName,
}) {
final TypeDeclaration apiAsTypeDeclaration = TypeDeclaration(
baseName: api.name,
isNullable: false,
associatedProxyApi: api,
);
final String swiftApiDelegateName =
'${hostProxyApiPrefix}Delegate${api.name}';
final String type =
api.hasMethodsRequiringImplementation() ? 'protocol' : 'open class';
indent.writeScoped('$type $swiftApiDelegateName {', '}', () {
_writeProxyApiConstructorDelegateMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
_writeProxyApiAttachedFieldDelegateMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
if (api.hasCallbackConstructor()) {
_writeProxyApiUnattachedFieldDelegateMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
}
_writeProxyApiHostMethodDelegateMethods(
indent,
api,
apiAsTypeDeclaration: apiAsTypeDeclaration,
);
});
indent.newln();
final String swiftApiProtocolName =
'${hostProxyApiPrefix}Protocol${api.name}';
indent.writeScoped('protocol $swiftApiProtocolName {', '}', () {
_writeProxyApiFlutterMethods(
indent,
api,
generatorOptions: generatorOptions,
apiAsTypeDeclaration: apiAsTypeDeclaration,
dartPackageName: dartPackageName,
writeBody: false,
);
});
indent.newln();
final String swiftApiName = '$hostProxyApiPrefix${api.name}';
indent.writeScoped(
'final class $swiftApiName: $swiftApiProtocolName {', '}', () {
indent.writeln(
'unowned let pigeonRegistrar: ${proxyApiRegistrarName(generatorOptions)}',
);
indent.writeln('let pigeonDelegate: $swiftApiDelegateName');
_writeProxyApiInheritedApiMethods(indent, api);
indent.writeScoped(
'init(pigeonRegistrar: ${proxyApiRegistrarName(generatorOptions)}, delegate: $swiftApiDelegateName) {',
'}',
() {
indent.writeln('self.pigeonRegistrar = pigeonRegistrar');
indent.writeln('self.pigeonDelegate = delegate');
},
);
if (api.hasAnyHostMessageCalls()) {
_writeProxyApiMessageHandlerMethod(
indent,
api,
generatorOptions: generatorOptions,
apiAsTypeDeclaration: apiAsTypeDeclaration,
swiftApiName: swiftApiName,
dartPackageName: dartPackageName,
);
indent.newln();
}
_writeProxyApiNewInstanceMethod(
indent,
api,
generatorOptions: generatorOptions,
apiAsTypeDeclaration: apiAsTypeDeclaration,
newInstanceMethodName: '${classMemberNamePrefix}newInstance',
dartPackageName: dartPackageName,
);
_writeProxyApiFlutterMethods(
indent,
api,
generatorOptions: generatorOptions,
apiAsTypeDeclaration: apiAsTypeDeclaration,
dartPackageName: dartPackageName,
);
});
}