emit method
void
emit(
- StringBuffer buffer, {
- required InspectionCache cache,
- required AppType appType,
- String moduleParentPrefix = "",
override
Emits a Dart source for this entry during interface generation.
Implementation
@override
void emit(
StringBuffer buffer, {
required InspectionCache cache,
required AppType appType,
String moduleParentPrefix = "",
}) {
final String moduleName = instantiatingModule.name;
final InstantiatedMethod? initMethod = __init__;
buffer.writeln("/// ## $name");
emitDoc(buffer);
emitSource(buffer);
final String pythonFfiInstanceName = switch (appType) {
AppType.console => "PythonFfiDart.instance",
AppType.flutter => "PythonFfi.instance",
};
buffer.writeln("""
final class $sanitizedName extends PythonClass {
factory $sanitizedName(""");
final List<Transform> argumentsTransforms =
initMethod?.emitArguments(buffer, cache: cache).toList() ??
<Transform>[];
buffer.writeln("""
) =>
$pythonFfiInstanceName.importClass(
"$moduleParentPrefix$moduleName",
"$name",
$sanitizedName.from,""");
if (initMethod != null) {
initMethod._emitCallArgs(buffer, transforms: argumentsTransforms);
} else {
buffer.writeln("<Object?>[],");
}
initMethod?._emitCallKwargs(buffer, transforms: argumentsTransforms);
buffer.writeln("""
);
$sanitizedName.from(super.pythonClass) : super.from();
""");
final Set<String> memberNames = <String>{name, "__init__"};
_emitFunctionFields(
buffer,
memberNames: memberNames,
cache: cache,
appType: appType,
parentEntry: this,
);
_emitGettersSetters(
buffer,
memberNames: memberNames,
cache: cache,
parentEntry: this,
);
buffer.writeln("}");
}