From 275cc30e8941b124f88d9faebad880d38893f1f9 Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Thu, 7 Mar 2024 17:14:47 +0800 Subject: [PATCH] [tool/terra] Generate the call_api_impl_params_json.dart --- .../binding/call_api_impl_params_json.dart | 145 +++++++++++++----- tool/terra/parsers/dart_syntax_parser.ts | 11 ++ tool/terra/renderers/callapi_impl_renderer.ts | 79 ++++++++-- ...event_handler_impl_params_json_renderer.ts | 16 +- tool/terra/renderers/utils.ts | 35 ++++- 5 files changed, 212 insertions(+), 74 deletions(-) diff --git a/lib/src/binding/call_api_impl_params_json.dart b/lib/src/binding/call_api_impl_params_json.dart index f51eb9eda..313326db8 100644 --- a/lib/src/binding/call_api_impl_params_json.dart +++ b/lib/src/binding/call_api_impl_params_json.dart @@ -1,447 +1,520 @@ /// GENERATED BY terra, DO NOT MODIFY BY HAND. // ignore_for_file: public_member_api_docs, unused_local_variable, unused_import + import 'package:agora_rtc_engine/src/binding_forward_export.dart'; part 'call_api_impl_params_json.g.dart'; -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerGetDurationJson { const MediaPlayerGetDurationJson(this.duration); @JsonKey(name: 'duration') final int duration; + factory MediaPlayerGetDurationJson.fromJson(Map json) => _$MediaPlayerGetDurationJsonFromJson(json); + Map toJson() => _$MediaPlayerGetDurationJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerGetPlayPositionJson { const MediaPlayerGetPlayPositionJson(this.pos); @JsonKey(name: 'pos') final int pos; + factory MediaPlayerGetPlayPositionJson.fromJson(Map json) => _$MediaPlayerGetPlayPositionJsonFromJson(json); + Map toJson() => _$MediaPlayerGetPlayPositionJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerGetStreamCountJson { const MediaPlayerGetStreamCountJson(this.count); @JsonKey(name: 'count') final int count; + factory MediaPlayerGetStreamCountJson.fromJson(Map json) => _$MediaPlayerGetStreamCountJsonFromJson(json); + Map toJson() => _$MediaPlayerGetStreamCountJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerGetStreamInfoJson { const MediaPlayerGetStreamInfoJson(this.info); @JsonKey(name: 'info') final PlayerStreamInfo info; + factory MediaPlayerGetStreamInfoJson.fromJson(Map json) => _$MediaPlayerGetStreamInfoJsonFromJson(json); + Map toJson() => _$MediaPlayerGetStreamInfoJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerGetMuteJson { const MediaPlayerGetMuteJson(this.muted); @JsonKey(name: 'muted') final bool muted; + factory MediaPlayerGetMuteJson.fromJson(Map json) => _$MediaPlayerGetMuteJsonFromJson(json); + Map toJson() => _$MediaPlayerGetMuteJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerGetPlayoutVolumeJson { const MediaPlayerGetPlayoutVolumeJson(this.volume); @JsonKey(name: 'volume') final int volume; + factory MediaPlayerGetPlayoutVolumeJson.fromJson(Map json) => _$MediaPlayerGetPlayoutVolumeJsonFromJson(json); + Map toJson() => _$MediaPlayerGetPlayoutVolumeJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerGetPublishSignalVolumeJson { const MediaPlayerGetPublishSignalVolumeJson(this.volume); @JsonKey(name: 'volume') final int volume; + factory MediaPlayerGetPublishSignalVolumeJson.fromJson( Map json) => _$MediaPlayerGetPublishSignalVolumeJsonFromJson(json); + Map toJson() => _$MediaPlayerGetPublishSignalVolumeJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MediaPlayerCacheManagerGetCacheDirJson { const MediaPlayerCacheManagerGetCacheDirJson(this.path); @JsonKey(name: 'path') final String path; + factory MediaPlayerCacheManagerGetCacheDirJson.fromJson( Map json) => _$MediaPlayerCacheManagerGetCacheDirJsonFromJson(json); + Map toJson() => _$MediaPlayerCacheManagerGetCacheDirJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterGetMusicChartsJson { const MusicContentCenterGetMusicChartsJson(this.requestId); @JsonKey(name: 'requestId') final String requestId; + factory MusicContentCenterGetMusicChartsJson.fromJson( Map json) => _$MusicContentCenterGetMusicChartsJsonFromJson(json); + Map toJson() => _$MusicContentCenterGetMusicChartsJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterGetMusicCollectionByMusicChartIdJson { const MusicContentCenterGetMusicCollectionByMusicChartIdJson(this.requestId); @JsonKey(name: 'requestId') final String requestId; + factory MusicContentCenterGetMusicCollectionByMusicChartIdJson.fromJson( Map json) => _$MusicContentCenterGetMusicCollectionByMusicChartIdJsonFromJson(json); + Map toJson() => _$MusicContentCenterGetMusicCollectionByMusicChartIdJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterSearchMusicJson { const MusicContentCenterSearchMusicJson(this.requestId); @JsonKey(name: 'requestId') final String requestId; + factory MusicContentCenterSearchMusicJson.fromJson( Map json) => _$MusicContentCenterSearchMusicJsonFromJson(json); + Map toJson() => _$MusicContentCenterSearchMusicJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterPreloadJson { const MusicContentCenterPreloadJson(this.requestId); @JsonKey(name: 'requestId') final String requestId; + factory MusicContentCenterPreloadJson.fromJson(Map json) => _$MusicContentCenterPreloadJsonFromJson(json); + Map toJson() => _$MusicContentCenterPreloadJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterGetCachesJson { const MusicContentCenterGetCachesJson(this.cacheInfo); @JsonKey(name: 'cacheInfo') final List cacheInfo; + factory MusicContentCenterGetCachesJson.fromJson(Map json) => _$MusicContentCenterGetCachesJsonFromJson(json); + Map toJson() => _$MusicContentCenterGetCachesJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterGetLyricJson { const MusicContentCenterGetLyricJson(this.requestId); @JsonKey(name: 'requestId') final String requestId; + factory MusicContentCenterGetLyricJson.fromJson(Map json) => _$MusicContentCenterGetLyricJsonFromJson(json); + Map toJson() => _$MusicContentCenterGetLyricJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterGetSongSimpleInfoJson { const MusicContentCenterGetSongSimpleInfoJson(this.requestId); @JsonKey(name: 'requestId') final String requestId; + factory MusicContentCenterGetSongSimpleInfoJson.fromJson( Map json) => _$MusicContentCenterGetSongSimpleInfoJsonFromJson(json); + Map toJson() => _$MusicContentCenterGetSongSimpleInfoJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class MusicContentCenterGetInternalSongCodeJson { const MusicContentCenterGetInternalSongCodeJson(this.internalSongCode); @JsonKey(name: 'internalSongCode') final int internalSongCode; + factory MusicContentCenterGetInternalSongCodeJson.fromJson( Map json) => _$MusicContentCenterGetInternalSongCodeJsonFromJson(json); + Map toJson() => _$MusicContentCenterGetInternalSongCodeJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class VideoDeviceManagerGetDeviceJson { const VideoDeviceManagerGetDeviceJson(this.deviceIdUTF8); @JsonKey(name: 'deviceIdUTF8') final String deviceIdUTF8; + factory VideoDeviceManagerGetDeviceJson.fromJson(Map json) => _$VideoDeviceManagerGetDeviceJsonFromJson(json); + Map toJson() => _$VideoDeviceManagerGetDeviceJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class VideoDeviceManagerGetCapabilityJson { const VideoDeviceManagerGetCapabilityJson(this.capability); @JsonKey(name: 'capability') final VideoFormat capability; + factory VideoDeviceManagerGetCapabilityJson.fromJson( Map json) => _$VideoDeviceManagerGetCapabilityJsonFromJson(json); + Map toJson() => _$VideoDeviceManagerGetCapabilityJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineQueryCodecCapabilityJson { const RtcEngineQueryCodecCapabilityJson(this.codecInfo); @JsonKey(name: 'codecInfo') final List codecInfo; + factory RtcEngineQueryCodecCapabilityJson.fromJson( Map json) => _$RtcEngineQueryCodecCapabilityJsonFromJson(json); + Map toJson() => _$RtcEngineQueryCodecCapabilityJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineUploadLogFileJson { const RtcEngineUploadLogFileJson(this.requestId); @JsonKey(name: 'requestId') final String requestId; + factory RtcEngineUploadLogFileJson.fromJson(Map json) => _$RtcEngineUploadLogFileJsonFromJson(json); + Map toJson() => _$RtcEngineUploadLogFileJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineGetExtensionPropertyJson { const RtcEngineGetExtensionPropertyJson(this.value); @JsonKey(name: 'value') final String value; + factory RtcEngineGetExtensionPropertyJson.fromJson( Map json) => _$RtcEngineGetExtensionPropertyJsonFromJson(json); + Map toJson() => _$RtcEngineGetExtensionPropertyJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineGetAudioDeviceInfoJson { const RtcEngineGetAudioDeviceInfoJson(this.deviceInfo); @JsonKey(name: 'deviceInfo') final DeviceInfo deviceInfo; + factory RtcEngineGetAudioDeviceInfoJson.fromJson(Map json) => _$RtcEngineGetAudioDeviceInfoJsonFromJson(json); + Map toJson() => _$RtcEngineGetAudioDeviceInfoJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineGetCallIdJson { const RtcEngineGetCallIdJson(this.callId); @JsonKey(name: 'callId') final String callId; + factory RtcEngineGetCallIdJson.fromJson(Map json) => _$RtcEngineGetCallIdJsonFromJson(json); + Map toJson() => _$RtcEngineGetCallIdJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineCreateDataStreamJson { const RtcEngineCreateDataStreamJson(this.streamId); @JsonKey(name: 'streamId') final int streamId; + factory RtcEngineCreateDataStreamJson.fromJson(Map json) => _$RtcEngineCreateDataStreamJsonFromJson(json); + Map toJson() => _$RtcEngineCreateDataStreamJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineGetUserInfoByUserAccountJson { const RtcEngineGetUserInfoByUserAccountJson(this.userInfo); @JsonKey(name: 'userInfo') final UserInfo userInfo; + factory RtcEngineGetUserInfoByUserAccountJson.fromJson( Map json) => _$RtcEngineGetUserInfoByUserAccountJsonFromJson(json); + Map toJson() => _$RtcEngineGetUserInfoByUserAccountJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineGetUserInfoByUidJson { const RtcEngineGetUserInfoByUidJson(this.userInfo); @JsonKey(name: 'userInfo') final UserInfo userInfo; + factory RtcEngineGetUserInfoByUidJson.fromJson(Map json) => _$RtcEngineGetUserInfoByUidJsonFromJson(json); + Map toJson() => _$RtcEngineGetUserInfoByUidJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineExCreateDataStreamExJson { const RtcEngineExCreateDataStreamExJson(this.streamId); @JsonKey(name: 'streamId') final int streamId; + factory RtcEngineExCreateDataStreamExJson.fromJson( Map json) => _$RtcEngineExCreateDataStreamExJsonFromJson(json); + Map toJson() => _$RtcEngineExCreateDataStreamExJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineExGetUserInfoByUserAccountExJson { const RtcEngineExGetUserInfoByUserAccountExJson(this.userInfo); @JsonKey(name: 'userInfo') final UserInfo userInfo; + factory RtcEngineExGetUserInfoByUserAccountExJson.fromJson( Map json) => _$RtcEngineExGetUserInfoByUserAccountExJsonFromJson(json); + Map toJson() => _$RtcEngineExGetUserInfoByUserAccountExJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class RtcEngineExGetUserInfoByUidExJson { const RtcEngineExGetUserInfoByUidExJson(this.userInfo); @JsonKey(name: 'userInfo') final UserInfo userInfo; + factory RtcEngineExGetUserInfoByUidExJson.fromJson( Map json) => _$RtcEngineExGetUserInfoByUidExJsonFromJson(json); + Map toJson() => _$RtcEngineExGetUserInfoByUidExJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class AudioDeviceManagerGetPlaybackDeviceJson { const AudioDeviceManagerGetPlaybackDeviceJson(this.deviceId); @JsonKey(name: 'deviceId') final String deviceId; + factory AudioDeviceManagerGetPlaybackDeviceJson.fromJson( Map json) => _$AudioDeviceManagerGetPlaybackDeviceJsonFromJson(json); + Map toJson() => _$AudioDeviceManagerGetPlaybackDeviceJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class AudioDeviceManagerGetPlaybackDeviceVolumeJson { const AudioDeviceManagerGetPlaybackDeviceVolumeJson(this.volume); @JsonKey(name: 'volume') final int volume; + factory AudioDeviceManagerGetPlaybackDeviceVolumeJson.fromJson( Map json) => _$AudioDeviceManagerGetPlaybackDeviceVolumeJsonFromJson(json); + Map toJson() => _$AudioDeviceManagerGetPlaybackDeviceVolumeJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class AudioDeviceManagerGetRecordingDeviceJson { const AudioDeviceManagerGetRecordingDeviceJson(this.deviceId); @JsonKey(name: 'deviceId') final String deviceId; + factory AudioDeviceManagerGetRecordingDeviceJson.fromJson( Map json) => _$AudioDeviceManagerGetRecordingDeviceJsonFromJson(json); + Map toJson() => _$AudioDeviceManagerGetRecordingDeviceJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class AudioDeviceManagerGetRecordingDeviceVolumeJson { const AudioDeviceManagerGetRecordingDeviceVolumeJson(this.volume); @JsonKey(name: 'volume') final int volume; + factory AudioDeviceManagerGetRecordingDeviceVolumeJson.fromJson( Map json) => _$AudioDeviceManagerGetRecordingDeviceVolumeJsonFromJson(json); + Map toJson() => _$AudioDeviceManagerGetRecordingDeviceVolumeJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class AudioDeviceManagerGetLoopbackDeviceJson { const AudioDeviceManagerGetLoopbackDeviceJson(this.deviceId); @JsonKey(name: 'deviceId') final String deviceId; + factory AudioDeviceManagerGetLoopbackDeviceJson.fromJson( Map json) => _$AudioDeviceManagerGetLoopbackDeviceJsonFromJson(json); + Map toJson() => _$AudioDeviceManagerGetLoopbackDeviceJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class AudioDeviceManagerGetPlaybackDeviceMuteJson { const AudioDeviceManagerGetPlaybackDeviceMuteJson(this.mute); @JsonKey(name: 'mute') final bool mute; + factory AudioDeviceManagerGetPlaybackDeviceMuteJson.fromJson( Map json) => _$AudioDeviceManagerGetPlaybackDeviceMuteJsonFromJson(json); + Map toJson() => _$AudioDeviceManagerGetPlaybackDeviceMuteJsonToJson(this); } -@JsonSerializable(explicitToJson: true) +@JsonSerializable(explicitToJson: true, includeIfNull: false) class AudioDeviceManagerGetRecordingDeviceMuteJson { const AudioDeviceManagerGetRecordingDeviceMuteJson(this.mute); @JsonKey(name: 'mute') final bool mute; + factory AudioDeviceManagerGetRecordingDeviceMuteJson.fromJson( Map json) => _$AudioDeviceManagerGetRecordingDeviceMuteJsonFromJson(json); + Map toJson() => _$AudioDeviceManagerGetRecordingDeviceMuteJsonToJson(this); } diff --git a/tool/terra/parsers/dart_syntax_parser.ts b/tool/terra/parsers/dart_syntax_parser.ts index deb02c763..6cda6f3b7 100644 --- a/tool/terra/parsers/dart_syntax_parser.ts +++ b/tool/terra/parsers/dart_syntax_parser.ts @@ -12,6 +12,7 @@ import { ParseResult, TerraContext } from "@agoraio-extensions/terra-core"; import { setUserdata } from "../renderers/utils"; import path from "path"; +import { getOutVariable } from "@agoraio-extensions/terra_shared_configs"; const userDataKey = "DartSyntaxParser"; @@ -235,6 +236,16 @@ export default function DartSyntaxParser( dartName: _dartTypeName(preParseResult!, method.return_type), }); + // If the `ReturnTypeParser` is applied, the `ReturnTypeParser` phase is executed before the `DartSyntaxParser`. + // Therefore, the parameter associated with the out variable's naming may not be set. + // In such cases, we need to reapply the naming here to ensure consistency. + let outVariable = getOutVariable(method); + if (outVariable) { + setUserdata(outVariable, userDataKey, { + dartName: toDartStyleNaming(outVariable.name), + }); + } + method.parameters.forEach((param) => { setUserdata(param.type, userDataKey, { dartName: _dartTypeName(preParseResult!, param.type), diff --git a/tool/terra/renderers/callapi_impl_renderer.ts b/tool/terra/renderers/callapi_impl_renderer.ts index 630199578..a4d6a236f 100644 --- a/tool/terra/renderers/callapi_impl_renderer.ts +++ b/tool/terra/renderers/callapi_impl_renderer.ts @@ -1,11 +1,9 @@ import { CXXFile, CXXTYPE, - CXXTerraNode, Clazz, MemberFunction, SimpleTypeKind, - Variable, } from "@agoraio-extensions/cxx-parser"; import { ParseResult, @@ -16,28 +14,21 @@ import { _trim, defaultDartHeader, defaultIgnoreForFile, - getBaseClassMethods, getBaseClasses, isCallbackClass, isDartBufferType, - isNeedIgnoreJsonInJsonObject, - isNullableType, isNullableVariable, - isRegisterCallbackFunction, - isUnregisterCallbackFunction, + renderJsonSerializable, + variableToMemberVariable, } from "./utils"; import { dartFileName, dartName, - toDartMemberName, toDartStyleNaming, } from "../parsers/dart_syntax_parser"; -import { renderBufferExtBlock } from "./buffer_ext_renderer"; -import { isNodeMatched } from "../parsers/cud_node_parser"; import { getIrisApiIdValue, getOutVariable, - isOverridedReturnType, } from "@agoraio-extensions/terra_shared_configs"; import { functionSignature, @@ -62,7 +53,6 @@ export default function CallApiImplRenderer( .map((it) => { let clazz = it.asClazz(); let clazzName = dartName(clazz); - console.log(`renderResults clazzName: ${clazzName}`); let methods = clazz.methods; let methodImpls = methods .map((method) => callApiImplBlock(parseResult, clazz, method)) @@ -130,7 +120,7 @@ export default function CallApiImplRenderer( }; }); - return renderResults; + return [...renderResults, callApiImplParamsJsonFile(parseResult, cxxFiles)]; } interface JsonMapInitBlock { @@ -147,7 +137,6 @@ function callApiImplBlock( method: MemberFunction ): string { let className = dartName(clazz); - console.log(`callApiImplBlock className: ${className}`); let methodName = dartName(method); let paramJsonMapBlock = method.parameters.map((param) => { @@ -212,9 +201,6 @@ function callApiImplBlock( paramJsonMapBlock.find((it) => it.addBufferExtBlock) != undefined; let buffersValueInJsonMap = isNeedAddBufferExtBlock ? "buffers" : "null"; - let ttt = getIrisApiIdValue(method).split("_").slice(1).join("_"); - console.log(`callApiImplBlock tt: ${getIrisApiIdValue(method)} ttt: ${ttt}`); - let apiType = `final apiType = \'\${isOverrideClassName ? className : '${className}'}_${getIrisApiIdValue( method ) @@ -291,3 +277,62 @@ ${funcSignature} { ` ); } + +/// Generate the file: lib/src/binding/call_api_impl_params_json.dart +function callApiImplParamsJsonFile( + parseResult: ParseResult, + cxxFiles: CXXFile[] +): RenderResult { + let nodes = cxxFiles.flatMap((cxxFile) => { + return cxxFile.nodes + .filter((it) => it.__TYPE == CXXTYPE.Clazz) + .filter((it) => !isCallbackClass(it.asClazz())); + }); + + let jsonClassContents = nodes + .map((node) => { + let clazz = node.asClazz(); + let className = dartName(clazz); + let methods = clazz.methods; + + return methods + .map((method) => { + let methodName = dartName(method); + let jsonClassName = `${className}${toDartStyleNaming( + methodName, + true + )}Json`; + let output = ""; + let outVariable = getOutVariable(method); + if (outVariable) { + output = renderJsonSerializable( + parseResult, + jsonClassName, + [variableToMemberVariable(outVariable)], + { + forceExplicitNullableType: false, + forceNamingConstructor: false, + } + ); + } + + return output; + }) + .filter((it) => it.length > 0) + .join("\n\n"); + }) + .join("\n\n"); + + return { + file_name: "lib/src/binding/call_api_impl_params_json.dart", + file_content: _trim(` +${defaultDartHeader} + +${defaultIgnoreForFile} + +import 'package:agora_rtc_engine/src/binding_forward_export.dart'; +part 'call_api_impl_params_json.g.dart'; + +${jsonClassContents}`), + }; +} diff --git a/tool/terra/renderers/event_handler_impl_params_json_renderer.ts b/tool/terra/renderers/event_handler_impl_params_json_renderer.ts index 21afa8024..052d39737 100644 --- a/tool/terra/renderers/event_handler_impl_params_json_renderer.ts +++ b/tool/terra/renderers/event_handler_impl_params_json_renderer.ts @@ -1,11 +1,7 @@ import { CXXFile, CXXTYPE, - Clazz, MemberFunction, - MemberVariable, - Struct, - Variable, } from "@agoraio-extensions/cxx-parser"; import { ParseResult, @@ -16,10 +12,10 @@ import { defaultDartHeader, defaultIgnoreForFile, isCallbackClass, - isNeedIgnoreJsonInJsonObject, renderJsonSerializable, + variableToMemberVariable, } from "./utils"; -import { dartFileName, dartName } from "../parsers/dart_syntax_parser"; +import { dartName } from "../parsers/dart_syntax_parser"; import { renderBufferExtBlock } from "./buffer_ext_renderer"; /// Generate the files: @@ -79,11 +75,3 @@ ${subContents} }, ]; } - -function variableToMemberVariable(it: Variable): MemberVariable { - return { - name: it.name, - type: it.type, - user_data: it.user_data, - } as MemberVariable; -} diff --git a/tool/terra/renderers/utils.ts b/tool/terra/renderers/utils.ts index e5dfda631..6b31d3ed1 100644 --- a/tool/terra/renderers/utils.ts +++ b/tool/terra/renderers/utils.ts @@ -127,17 +127,29 @@ export function _trim( export function renderJsonSerializable( parseResult: ParseResult, jsonClassName: string, - memberVariables: MemberVariable[] + memberVariables: MemberVariable[], + options?: { + forceExplicitNullableType: boolean; + forceNamingConstructor: boolean; + } ) { + let forceExplicitNullableType: boolean = + options?.forceExplicitNullableType ?? true; + let forceNamingConstructor: boolean = options?.forceNamingConstructor ?? true; + + let initializeBlock = + memberVariables.length > 0 + ? `${memberVariables.map((it) => `this.${dartName(it)}`).join(",")}` + : ""; + if (forceNamingConstructor && initializeBlock.length) { + initializeBlock = `{${initializeBlock}}`; + } + let output = ` @JsonSerializable(explicitToJson: true, includeIfNull: false) class ${jsonClassName} { const ${jsonClassName}( - ${ - memberVariables.length > 0 - ? `{${memberVariables.map((it) => `this.${dartName(it)}`).join(",")}}` - : "" - } + ${initializeBlock} ); ${memberVariables @@ -153,10 +165,11 @@ export function renderJsonSerializable( let isClazz = actualNode.__TYPE == CXXTYPE.Clazz && dartName(actualNode) == "VideoFrameMetaInfo"; + let nullableSurffix = forceExplicitNullableType ? "?" : ""; return ` ${isClazz ? `@${dartName(actualNode)}Converter()` : ""} @JsonKey(name: '${it.name}'${isIgnoreJson ? ", ignore: true" : ""}) - final ${dartName(it.type)}? ${dartName(it)}; + final ${dartName(it.type)}${nullableSurffix} ${dartName(it)}; `.trim(); }) .join("\n\n")} @@ -198,3 +211,11 @@ extension ${enumName}Ext on ${enumName} { } `; } + +export function variableToMemberVariable(it: Variable): MemberVariable { + return { + name: it.name, + type: it.type, + user_data: it.user_data, + } as MemberVariable; +}