From 64060a8ddf188fbd4f13e528c53f3c7db4ec23d0 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Wed, 25 Jun 2025 08:57:13 -0700 Subject: [PATCH] vm_service: Assign fields in field initializers This is achieved with just a bit of delicacy around commas, braces, semicolons, and possible super-initializers. There is exactly one case of a statement that needs to remain in the constructor body: `_parseTokenPosTable()`. Additionally I add one helper, `_createServiceObjectListOrNull`, which takes care of some casting and nullability quirks. This also includes one small perf improvement: when `createServiceObject` returns null, we immediately return an empty list, without wrapping it in `List.from`. vm_service: helper for list fields Change-Id: Ic5e36bbfa451bea06edf0d9e684705d392f1ad39 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436540 Commit-Queue: Samuel Rawlins Reviewed-by: Ben Konyi --- pkg/vm_service/lib/src/vm_service.dart | 1660 ++++++++--------- .../tool/dart/generate_dart_client.dart | 14 +- .../tool/dart/generate_dart_common.dart | 79 +- 3 files changed, 858 insertions(+), 895 deletions(-) diff --git a/pkg/vm_service/lib/src/vm_service.dart b/pkg/vm_service/lib/src/vm_service.dart index 0cc0b83f215..e21be0c413b 100644 --- a/pkg/vm_service/lib/src/vm_service.dart +++ b/pkg/vm_service/lib/src/vm_service.dart @@ -90,6 +90,16 @@ dynamic _createSpecificObject( } } +/// Returns a list of `T` using [createServiceObject] if [json] is non-`null`, +/// and `null` otherwise. +List? _createServiceObjectListOrNull( + Object? json, List expectedTypes) { + if (json == null) return null; + final serviceObject = createServiceObject(json, expectedTypes) as List?; + if (serviceObject == null) return []; + return List.from(serviceObject); +} + Future extensionCallHelper( VmService service, String method, Map args) { return service._call(method, args); @@ -2660,22 +2670,19 @@ class AllocationProfile extends Response { this.dateLastServiceGC, }); - AllocationProfile._fromJson(Map json) - : super._fromJson(json) { - members = List.from( - createServiceObject(json['members'], const ['ClassHeapStats']) - as List? ?? - []); - memoryUsage = - createServiceObject(json['memoryUsage'], const ['MemoryUsage']) - as MemoryUsage?; - dateLastAccumulatorReset = json['dateLastAccumulatorReset'] is String - ? int.parse(json['dateLastAccumulatorReset']) - : json['dateLastAccumulatorReset']; - dateLastServiceGC = json['dateLastServiceGC'] is String - ? int.parse(json['dateLastServiceGC']) - : json['dateLastServiceGC']; - } + AllocationProfile._fromJson(super.json) + : members = _createServiceObjectListOrNull( + json['members'], const ['ClassHeapStats']), + memoryUsage = + createServiceObject(json['memoryUsage'], const ['MemoryUsage']) + as MemoryUsage?, + dateLastAccumulatorReset = json['dateLastAccumulatorReset'] is String + ? int.parse(json['dateLastAccumulatorReset']) + : json['dateLastAccumulatorReset'], + dateLastServiceGC = json['dateLastServiceGC'] is String + ? int.parse(json['dateLastServiceGC']) + : json['dateLastServiceGC'], + super._fromJson(); @override String get type => 'AllocationProfile'; @@ -2724,14 +2731,13 @@ class BoundField { this.value, }); - BoundField._fromJson(Map json) { - decl = createServiceObject(json['decl'], const ['FieldRef']) as FieldRef?; - name = - createServiceObject(json['name'], const ['String', 'int']) as dynamic; - value = - createServiceObject(json['value'], const ['InstanceRef', 'Sentinel']) - as dynamic; - } + BoundField._fromJson(Map json) + : decl = + createServiceObject(json['decl'], const ['FieldRef']) as FieldRef?, + name = createServiceObject(json['name'], const ['String', 'int']) + as dynamic, + value = createServiceObject( + json['value'], const ['InstanceRef', 'Sentinel']) as dynamic; Map toJson() => { 'decl': decl?.toJson(), @@ -2777,14 +2783,14 @@ class BoundVariable extends Response { this.scopeEndTokenPos, }); - BoundVariable._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - value = createServiceObject(json['value'], - const ['InstanceRef', 'TypeArgumentsRef', 'Sentinel']) as dynamic; - declarationTokenPos = json['declarationTokenPos'] ?? -1; - scopeStartTokenPos = json['scopeStartTokenPos'] ?? -1; - scopeEndTokenPos = json['scopeEndTokenPos'] ?? -1; - } + BoundVariable._fromJson(super.json) + : name = json['name'] ?? '', + value = createServiceObject(json['value'], + const ['InstanceRef', 'TypeArgumentsRef', 'Sentinel']) as dynamic, + declarationTokenPos = json['declarationTokenPos'] ?? -1, + scopeStartTokenPos = json['scopeStartTokenPos'] ?? -1, + scopeEndTokenPos = json['scopeEndTokenPos'] ?? -1, + super._fromJson(); @override String get type => 'BoundVariable'; @@ -2845,14 +2851,14 @@ class Breakpoint extends Obj { id: id, ); - Breakpoint._fromJson(Map json) : super._fromJson(json) { - breakpointNumber = json['breakpointNumber'] ?? -1; - enabled = json['enabled'] ?? false; - resolved = json['resolved'] ?? false; - isSyntheticAsyncContinuation = json['isSyntheticAsyncContinuation']; - location = createServiceObject(json['location'], - const ['SourceLocation', 'UnresolvedSourceLocation']) as dynamic; - } + Breakpoint._fromJson(super.json) + : breakpointNumber = json['breakpointNumber'] ?? -1, + enabled = json['enabled'] ?? false, + resolved = json['resolved'] ?? false, + isSyntheticAsyncContinuation = json['isSyntheticAsyncContinuation'], + location = createServiceObject(json['location'], + const ['SourceLocation', 'UnresolvedSourceLocation']) as dynamic, + super._fromJson(); @override String get type => 'Breakpoint'; @@ -2913,18 +2919,16 @@ class ClassRef extends ObjRef { id: id, ); - ClassRef._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - library = createServiceObject(json['library'], const ['LibraryRef']) - as LibraryRef?; - typeParameters = json['typeParameters'] == null - ? null - : List.from( - createServiceObject(json['typeParameters'], const ['InstanceRef'])! - as List); - } + ClassRef._fromJson(super.json) + : name = json['name'] ?? '', + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + library = createServiceObject(json['library'], const ['LibraryRef']) + as LibraryRef?, + typeParameters = _createServiceObjectListOrNull( + json['typeParameters'], const ['InstanceRef']), + super._fromJson(); @override String get type => '@Class'; @@ -3062,45 +3066,41 @@ class Class extends Obj implements ClassRef { id: id, ); - Class._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - library = createServiceObject(json['library'], const ['LibraryRef']) - as LibraryRef?; - typeParameters = json['typeParameters'] == null - ? null - : List.from( - createServiceObject(json['typeParameters'], const ['InstanceRef'])! - as List); - error = createServiceObject(json['error'], const ['ErrorRef']) as ErrorRef?; - isAbstract = json['abstract'] ?? false; - isConst = json['const'] ?? false; - isSealed = json['isSealed'] ?? false; - isMixinClass = json['isMixinClass'] ?? false; - isBaseClass = json['isBaseClass'] ?? false; - isInterfaceClass = json['isInterfaceClass'] ?? false; - isFinal = json['isFinal'] ?? false; - traceAllocations = json['traceAllocations'] ?? false; - superClass = - createServiceObject(json['super'], const ['ClassRef']) as ClassRef?; - superType = createServiceObject(json['superType'], const ['InstanceRef']) - as InstanceRef?; - interfaces = List.from( - createServiceObject(json['interfaces'], const ['InstanceRef']) - as List? ?? - []); - mixin = createServiceObject(json['mixin'], const ['InstanceRef']) - as InstanceRef?; - fields = List.from( - createServiceObject(json['fields'], const ['FieldRef']) as List? ?? []); - functions = List.from( - createServiceObject(json['functions'], const ['FuncRef']) as List? ?? - []); - subclasses = List.from( - createServiceObject(json['subclasses'], const ['ClassRef']) as List? ?? - []); - } + Class._fromJson(super.json) + : name = json['name'] ?? '', + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + library = createServiceObject(json['library'], const ['LibraryRef']) + as LibraryRef?, + typeParameters = _createServiceObjectListOrNull( + json['typeParameters'], const ['InstanceRef']), + error = + createServiceObject(json['error'], const ['ErrorRef']) as ErrorRef?, + isAbstract = json['abstract'] ?? false, + isConst = json['const'] ?? false, + isSealed = json['isSealed'] ?? false, + isMixinClass = json['isMixinClass'] ?? false, + isBaseClass = json['isBaseClass'] ?? false, + isInterfaceClass = json['isInterfaceClass'] ?? false, + isFinal = json['isFinal'] ?? false, + traceAllocations = json['traceAllocations'] ?? false, + superClass = + createServiceObject(json['super'], const ['ClassRef']) as ClassRef?, + superType = + createServiceObject(json['superType'], const ['InstanceRef']) + as InstanceRef?, + interfaces = _createServiceObjectListOrNull( + json['interfaces'], const ['InstanceRef']), + mixin = createServiceObject(json['mixin'], const ['InstanceRef']) + as InstanceRef?, + fields = _createServiceObjectListOrNull( + json['fields'], const ['FieldRef']), + functions = _createServiceObjectListOrNull( + json['functions'], const ['FuncRef']), + subclasses = _createServiceObjectListOrNull( + json['subclasses'], const ['ClassRef']), + super._fromJson(); @override String get type => 'Class'; @@ -3174,14 +3174,14 @@ class ClassHeapStats extends Response { this.instancesCurrent, }); - ClassHeapStats._fromJson(Map json) : super._fromJson(json) { - classRef = - createServiceObject(json['class'], const ['ClassRef']) as ClassRef?; - accumulatedSize = json['accumulatedSize'] ?? -1; - bytesCurrent = json['bytesCurrent'] ?? -1; - instancesAccumulated = json['instancesAccumulated'] ?? -1; - instancesCurrent = json['instancesCurrent'] ?? -1; - } + ClassHeapStats._fromJson(super.json) + : classRef = + createServiceObject(json['class'], const ['ClassRef']) as ClassRef?, + accumulatedSize = json['accumulatedSize'] ?? -1, + bytesCurrent = json['bytesCurrent'] ?? -1, + instancesAccumulated = json['instancesAccumulated'] ?? -1, + instancesCurrent = json['instancesCurrent'] ?? -1, + super._fromJson(); @override String get type => 'ClassHeapStats'; @@ -3212,11 +3212,10 @@ class ClassList extends Response { this.classes, }); - ClassList._fromJson(Map json) : super._fromJson(json) { - classes = List.from( - createServiceObject(json['classes'], const ['ClassRef']) as List? ?? - []); - } + ClassList._fromJson(super.json) + : classes = _createServiceObjectListOrNull( + json['classes'], const ['ClassRef']), + super._fromJson(); @override String get type => 'ClassList'; @@ -3257,12 +3256,12 @@ class CodeRef extends ObjRef { id: id, ); - CodeRef._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - kind = json['kind'] ?? ''; - function = createServiceObject( - json['function'], const ['FuncRef', 'NativeFunction']) as dynamic; - } + CodeRef._fromJson(super.json) + : name = json['name'] ?? '', + kind = json['kind'] ?? '', + function = createServiceObject( + json['function'], const ['FuncRef', 'NativeFunction']) as dynamic, + super._fromJson(); @override String get type => '@Code'; @@ -3316,12 +3315,12 @@ class Code extends Obj implements CodeRef { id: id, ); - Code._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - kind = json['kind'] ?? ''; - function = createServiceObject( - json['function'], const ['FuncRef', 'NativeFunction']) as dynamic; - } + Code._fromJson(super.json) + : name = json['name'] ?? '', + kind = json['kind'] ?? '', + function = createServiceObject( + json['function'], const ['FuncRef', 'NativeFunction']) as dynamic, + super._fromJson(); @override String get type => 'Code'; @@ -3360,9 +3359,9 @@ class ContextRef extends ObjRef { id: id, ); - ContextRef._fromJson(Map json) : super._fromJson(json) { - length = json['length'] ?? -1; - } + ContextRef._fromJson(super.json) + : length = json['length'] ?? -1, + super._fromJson(); @override String get type => '@Context'; @@ -3410,15 +3409,13 @@ class Context extends Obj implements ContextRef { id: id, ); - Context._fromJson(Map json) : super._fromJson(json) { - length = json['length'] ?? -1; - parent = createServiceObject(json['parent'], const ['ContextRef']) - as ContextRef?; - variables = List.from( - createServiceObject(json['variables'], const ['ContextElement']) - as List? ?? - []); - } + Context._fromJson(super.json) + : length = json['length'] ?? -1, + parent = createServiceObject(json['parent'], const ['ContextRef']) + as ContextRef?, + variables = _createServiceObjectListOrNull( + json['variables'], const ['ContextElement']), + super._fromJson(); @override String get type => 'Context'; @@ -3454,11 +3451,9 @@ class ContextElement { this.value, }); - ContextElement._fromJson(Map json) { - value = - createServiceObject(json['value'], const ['InstanceRef', 'Sentinel']) - as dynamic; - } + ContextElement._fromJson(Map json) + : value = createServiceObject( + json['value'], const ['InstanceRef', 'Sentinel']) as dynamic; Map toJson() => { 'value': value?.toJson(), @@ -3512,21 +3507,18 @@ class CpuSamples extends Response { this.samples, }); - CpuSamples._fromJson(Map json) : super._fromJson(json) { - samplePeriod = json['samplePeriod'] ?? -1; - maxStackDepth = json['maxStackDepth'] ?? -1; - sampleCount = json['sampleCount'] ?? -1; - timeOriginMicros = json['timeOriginMicros'] ?? -1; - timeExtentMicros = json['timeExtentMicros'] ?? -1; - pid = json['pid'] ?? -1; - functions = List.from( - createServiceObject(json['functions'], const ['ProfileFunction']) - as List? ?? - []); - samples = List.from( - createServiceObject(json['samples'], const ['CpuSample']) as List? ?? - []); - } + CpuSamples._fromJson(super.json) + : samplePeriod = json['samplePeriod'] ?? -1, + maxStackDepth = json['maxStackDepth'] ?? -1, + sampleCount = json['sampleCount'] ?? -1, + timeOriginMicros = json['timeOriginMicros'] ?? -1, + timeExtentMicros = json['timeExtentMicros'] ?? -1, + pid = json['pid'] ?? -1, + functions = _createServiceObjectListOrNull( + json['functions'], const ['ProfileFunction']), + samples = _createServiceObjectListOrNull( + json['samples'], const ['CpuSample']), + super._fromJson(); @override String get type => 'CpuSamples'; @@ -3593,20 +3585,17 @@ class CpuSamplesEvent { this.samples, }); - CpuSamplesEvent._fromJson(Map json) { - samplePeriod = json['samplePeriod'] ?? -1; - maxStackDepth = json['maxStackDepth'] ?? -1; - sampleCount = json['sampleCount'] ?? -1; - timeOriginMicros = json['timeOriginMicros'] ?? -1; - timeExtentMicros = json['timeExtentMicros'] ?? -1; - pid = json['pid'] ?? -1; - functions = List.from( - createServiceObject(json['functions'], const ['dynamic']) as List? ?? - []); - samples = List.from( - createServiceObject(json['samples'], const ['CpuSample']) as List? ?? - []); - } + CpuSamplesEvent._fromJson(Map json) + : samplePeriod = json['samplePeriod'] ?? -1, + maxStackDepth = json['maxStackDepth'] ?? -1, + sampleCount = json['sampleCount'] ?? -1, + timeOriginMicros = json['timeOriginMicros'] ?? -1, + timeExtentMicros = json['timeExtentMicros'] ?? -1, + pid = json['pid'] ?? -1, + functions = _createServiceObjectListOrNull( + json['functions'], const ['dynamic']), + samples = _createServiceObjectListOrNull( + json['samples'], const ['CpuSample']); Map toJson() => { 'samplePeriod': samplePeriod ?? -1, @@ -3684,16 +3673,15 @@ class CpuSample { this.classId, }); - CpuSample._fromJson(Map json) { - tid = json['tid'] ?? -1; - timestamp = json['timestamp'] ?? -1; - vmTag = json['vmTag']; - userTag = json['userTag']; - truncated = json['truncated']; - stack = List.from(json['stack']); - identityHashCode = json['identityHashCode']; - classId = json['classId']; - } + CpuSample._fromJson(Map json) + : tid = json['tid'] ?? -1, + timestamp = json['timestamp'] ?? -1, + vmTag = json['vmTag'], + userTag = json['userTag'], + truncated = json['truncated'], + stack = List.from(json['stack']), + identityHashCode = json['identityHashCode'], + classId = json['classId']; Map toJson() => { 'tid': tid ?? -1, @@ -3731,10 +3719,10 @@ class ErrorRef extends ObjRef { id: id, ); - ErrorRef._fromJson(Map json) : super._fromJson(json) { - kind = json['kind'] ?? ''; - message = json['message'] ?? ''; - } + ErrorRef._fromJson(super.json) + : kind = json['kind'] ?? '', + message = json['message'] ?? '', + super._fromJson(); @override String get type => '@Error'; @@ -3791,14 +3779,16 @@ class Error extends Obj implements ErrorRef { id: id, ); - Error._fromJson(Map json) : super._fromJson(json) { - kind = json['kind'] ?? ''; - message = json['message'] ?? ''; - exception = createServiceObject(json['exception'], const ['InstanceRef']) - as InstanceRef?; - stacktrace = createServiceObject(json['stacktrace'], const ['InstanceRef']) - as InstanceRef?; - } + Error._fromJson(super.json) + : kind = json['kind'] ?? '', + message = json['message'] ?? '', + exception = + createServiceObject(json['exception'], const ['InstanceRef']) + as InstanceRef?, + stacktrace = + createServiceObject(json['stacktrace'], const ['InstanceRef']) + as InstanceRef?, + super._fromJson(); @override String get type => 'Error'; @@ -4096,58 +4086,57 @@ class Event extends Response { this.data, }); - Event._fromJson(Map json) : super._fromJson(json) { - kind = json['kind'] ?? ''; - isolateGroup = - createServiceObject(json['isolateGroup'], const ['IsolateGroupRef']) - as IsolateGroupRef?; - isolate = createServiceObject(json['isolate'], const ['IsolateRef']) - as IsolateRef?; - vm = createServiceObject(json['vm'], const ['VMRef']) as VMRef?; - timestamp = json['timestamp'] ?? -1; - breakpoint = createServiceObject(json['breakpoint'], const ['Breakpoint']) - as Breakpoint?; - pauseBreakpoints = json['pauseBreakpoints'] == null - ? null - : List.from( - createServiceObject(json['pauseBreakpoints'], const ['Breakpoint'])! - as List); - topFrame = createServiceObject(json['topFrame'], const ['Frame']) as Frame?; - exception = createServiceObject(json['exception'], const ['InstanceRef']) - as InstanceRef?; - bytes = json['bytes']; - inspectee = createServiceObject(json['inspectee'], const ['InstanceRef']) - as InstanceRef?; - gcType = json['gcType']; - extensionRPC = json['extensionRPC']; - extensionKind = json['extensionKind']; - extensionData = ExtensionData.parse(json['extensionData']); - timelineEvents = json['timelineEvents'] == null - ? null - : List.from(createServiceObject( - json['timelineEvents'], const ['TimelineEvent'])! as List); - updatedStreams = json['updatedStreams'] == null - ? null - : List.from(json['updatedStreams']); - atAsyncSuspension = json['atAsyncSuspension']; - status = json['status']; - reloadFailureReason = json['reloadFailureReason']; - logRecord = createServiceObject(json['logRecord'], const ['LogRecord']) - as LogRecord?; - details = json['details']; - service = json['service']; - method = json['method']; - alias = json['alias']; - flag = json['flag']; - newValue = json['newValue']; - last = json['last']; - updatedTag = json['updatedTag']; - previousTag = json['previousTag']; - cpuSamples = - createServiceObject(json['cpuSamples'], const ['CpuSamplesEvent']) - as CpuSamplesEvent?; - data = json['data']; - } + Event._fromJson(super.json) + : kind = json['kind'] ?? '', + isolateGroup = + createServiceObject(json['isolateGroup'], const ['IsolateGroupRef']) + as IsolateGroupRef?, + isolate = createServiceObject(json['isolate'], const ['IsolateRef']) + as IsolateRef?, + vm = createServiceObject(json['vm'], const ['VMRef']) as VMRef?, + timestamp = json['timestamp'] ?? -1, + breakpoint = + createServiceObject(json['breakpoint'], const ['Breakpoint']) + as Breakpoint?, + pauseBreakpoints = _createServiceObjectListOrNull( + json['pauseBreakpoints'], const ['Breakpoint']), + topFrame = + createServiceObject(json['topFrame'], const ['Frame']) as Frame?, + exception = + createServiceObject(json['exception'], const ['InstanceRef']) + as InstanceRef?, + bytes = json['bytes'], + inspectee = + createServiceObject(json['inspectee'], const ['InstanceRef']) + as InstanceRef?, + gcType = json['gcType'], + extensionRPC = json['extensionRPC'], + extensionKind = json['extensionKind'], + extensionData = ExtensionData.parse(json['extensionData']), + timelineEvents = _createServiceObjectListOrNull( + json['timelineEvents'], const ['TimelineEvent']), + updatedStreams = json['updatedStreams'] == null + ? null + : List.from(json['updatedStreams']), + atAsyncSuspension = json['atAsyncSuspension'], + status = json['status'], + reloadFailureReason = json['reloadFailureReason'], + logRecord = createServiceObject(json['logRecord'], const ['LogRecord']) + as LogRecord?, + details = json['details'], + service = json['service'], + method = json['method'], + alias = json['alias'], + flag = json['flag'], + newValue = json['newValue'], + last = json['last'], + updatedTag = json['updatedTag'], + previousTag = json['previousTag'], + cpuSamples = + createServiceObject(json['cpuSamples'], const ['CpuSamplesEvent']) + as CpuSamplesEvent?, + data = json['data'], + super._fromJson(); @override String get type => 'Event'; @@ -4262,18 +4251,19 @@ class FieldRef extends ObjRef { id: id, ); - FieldRef._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - owner = createServiceObject(json['owner'], const ['ObjRef']) as ObjRef?; - declaredType = - createServiceObject(json['declaredType'], const ['InstanceRef']) - as InstanceRef?; - isConst = json['const'] ?? false; - isFinal = json['final'] ?? false; - isStatic = json['static'] ?? false; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - } + FieldRef._fromJson(super.json) + : name = json['name'] ?? '', + owner = createServiceObject(json['owner'], const ['ObjRef']) as ObjRef?, + declaredType = + createServiceObject(json['declaredType'], const ['InstanceRef']) + as InstanceRef?, + isConst = json['const'] ?? false, + isFinal = json['final'] ?? false, + isStatic = json['static'] ?? false, + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + super._fromJson(); @override String get type => '@Field'; @@ -4368,20 +4358,21 @@ class Field extends Obj implements FieldRef { id: id, ); - Field._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - owner = createServiceObject(json['owner'], const ['ObjRef']) as ObjRef?; - declaredType = - createServiceObject(json['declaredType'], const ['InstanceRef']) - as InstanceRef?; - isConst = json['const'] ?? false; - isFinal = json['final'] ?? false; - isStatic = json['static'] ?? false; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - staticValue = createServiceObject( - json['staticValue'], const ['InstanceRef', 'Sentinel']) as dynamic; - } + Field._fromJson(super.json) + : name = json['name'] ?? '', + owner = createServiceObject(json['owner'], const ['ObjRef']) as ObjRef?, + declaredType = + createServiceObject(json['declaredType'], const ['InstanceRef']) + as InstanceRef?, + isConst = json['const'] ?? false, + isFinal = json['final'] ?? false, + isStatic = json['static'] ?? false, + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + staticValue = createServiceObject( + json['staticValue'], const ['InstanceRef', 'Sentinel']) as dynamic, + super._fromJson(); @override String get type => 'Field'; @@ -4441,12 +4432,11 @@ class Flag { this.valueAsString, }); - Flag._fromJson(Map json) { - name = json['name'] ?? ''; - comment = json['comment'] ?? ''; - modified = json['modified'] ?? false; - valueAsString = json['valueAsString']; - } + Flag._fromJson(Map json) + : name = json['name'] ?? '', + comment = json['comment'] ?? '', + modified = json['modified'] ?? false, + valueAsString = json['valueAsString']; Map toJson() => { 'name': name ?? '', @@ -4473,10 +4463,10 @@ class FlagList extends Response { this.flags, }); - FlagList._fromJson(Map json) : super._fromJson(json) { - flags = List.from( - createServiceObject(json['flags'], const ['Flag']) as List? ?? []); - } + FlagList._fromJson(super.json) + : flags = + _createServiceObjectListOrNull(json['flags'], const ['Flag']), + super._fromJson(); @override String get type => 'FlagList'; @@ -4521,20 +4511,18 @@ class Frame extends Response { this.kind, }); - Frame._fromJson(Map json) : super._fromJson(json) { - index = json['index'] ?? -1; - function = - createServiceObject(json['function'], const ['FuncRef']) as FuncRef?; - code = createServiceObject(json['code'], const ['CodeRef']) as CodeRef?; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - vars = json['vars'] == null - ? null - : List.from( - createServiceObject(json['vars'], const ['BoundVariable'])! - as List); - kind = json['kind']; - } + Frame._fromJson(super.json) + : index = json['index'] ?? -1, + function = createServiceObject(json['function'], const ['FuncRef']) + as FuncRef?, + code = createServiceObject(json['code'], const ['CodeRef']) as CodeRef?, + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + vars = _createServiceObjectListOrNull( + json['vars'], const ['BoundVariable']), + kind = json['kind'], + super._fromJson(); @override String get type => 'Frame'; @@ -4615,19 +4603,21 @@ class FuncRef extends ObjRef { id: id, ); - FuncRef._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - owner = createServiceObject( - json['owner'], const ['LibraryRef', 'ClassRef', 'FuncRef']) as dynamic; - isStatic = json['static'] ?? false; - isConst = json['const'] ?? false; - implicit = json['implicit'] ?? false; - isAbstract = json['abstract'] ?? false; - isGetter = json['isGetter'] ?? false; - isSetter = json['isSetter'] ?? false; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - } + FuncRef._fromJson(super.json) + : name = json['name'] ?? '', + owner = createServiceObject( + json['owner'], const ['LibraryRef', 'ClassRef', 'FuncRef']) + as dynamic, + isStatic = json['static'] ?? false, + isConst = json['const'] ?? false, + implicit = json['implicit'] ?? false, + isAbstract = json['abstract'] ?? false, + isGetter = json['isGetter'] ?? false, + isSetter = json['isSetter'] ?? false, + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + super._fromJson(); @override String get type => '@Function'; @@ -4734,22 +4724,25 @@ class Func extends Obj implements FuncRef { id: id, ); - Func._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - owner = createServiceObject( - json['owner'], const ['LibraryRef', 'ClassRef', 'FuncRef']) as dynamic; - isStatic = json['static'] ?? false; - isConst = json['const'] ?? false; - implicit = json['implicit'] ?? false; - isAbstract = json['abstract'] ?? false; - isGetter = json['isGetter'] ?? false; - isSetter = json['isSetter'] ?? false; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - signature = createServiceObject(json['signature'], const ['InstanceRef']) - as InstanceRef?; - code = createServiceObject(json['code'], const ['CodeRef']) as CodeRef?; - } + Func._fromJson(super.json) + : name = json['name'] ?? '', + owner = createServiceObject( + json['owner'], const ['LibraryRef', 'ClassRef', 'FuncRef']) + as dynamic, + isStatic = json['static'] ?? false, + isConst = json['const'] ?? false, + implicit = json['implicit'] ?? false, + isAbstract = json['abstract'] ?? false, + isGetter = json['isGetter'] ?? false, + isSetter = json['isSetter'] ?? false, + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + signature = + createServiceObject(json['signature'], const ['InstanceRef']) + as InstanceRef?, + code = createServiceObject(json['code'], const ['CodeRef']) as CodeRef?, + super._fromJson(); @override String get type => 'Function'; @@ -4799,11 +4792,11 @@ class IdZone extends Response { this.idAssignmentPolicy, }); - IdZone._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? ''; - backingBufferKind = json['backingBufferKind'] ?? ''; - idAssignmentPolicy = json['idAssignmentPolicy'] ?? ''; - } + IdZone._fromJson(super.json) + : id = json['id'] ?? '', + backingBufferKind = json['backingBufferKind'] ?? '', + idAssignmentPolicy = json['idAssignmentPolicy'] ?? '', + super._fromJson(); @override String get type => 'IdZone'; @@ -5020,50 +5013,44 @@ class InstanceRef extends ObjRef { id: id, ); - InstanceRef._fromJson(Map json) : super._fromJson(json) { - kind = json['kind'] ?? ''; - identityHashCode = json['identityHashCode'] ?? -1; - classRef = - createServiceObject(json['class'], const ['ClassRef']) as ClassRef?; - valueAsString = json['valueAsString']; - valueAsStringIsTruncated = json['valueAsStringIsTruncated']; - length = json['length']; - name = json['name']; - typeClass = - createServiceObject(json['typeClass'], const ['ClassRef']) as ClassRef?; - parameterizedClass = - createServiceObject(json['parameterizedClass'], const ['ClassRef']) - as ClassRef?; - returnType = createServiceObject(json['returnType'], const ['InstanceRef']) - as InstanceRef?; - parameters = json['parameters'] == null - ? null - : List.from( - createServiceObject(json['parameters'], const ['Parameter'])! - as List); - typeParameters = json['typeParameters'] == null - ? null - : List.from( - createServiceObject(json['typeParameters'], const ['InstanceRef'])! - as List); - pattern = createServiceObject(json['pattern'], const ['InstanceRef']) - as InstanceRef?; - closureFunction = - createServiceObject(json['closureFunction'], const ['FuncRef']) - as FuncRef?; - closureContext = - createServiceObject(json['closureContext'], const ['ContextRef']) - as ContextRef?; - closureReceiver = - createServiceObject(json['closureReceiver'], const ['InstanceRef']) - as InstanceRef?; - portId = json['portId']; - allocationLocation = - createServiceObject(json['allocationLocation'], const ['InstanceRef']) - as InstanceRef?; - debugName = json['debugName']; - label = json['label']; - } + InstanceRef._fromJson(super.json) + : kind = json['kind'] ?? '', + identityHashCode = json['identityHashCode'] ?? -1, + classRef = + createServiceObject(json['class'], const ['ClassRef']) as ClassRef?, + valueAsString = json['valueAsString'], + valueAsStringIsTruncated = json['valueAsStringIsTruncated'], + length = json['length'], + name = json['name'], + typeClass = createServiceObject(json['typeClass'], const ['ClassRef']) + as ClassRef?, + parameterizedClass = + createServiceObject(json['parameterizedClass'], const ['ClassRef']) + as ClassRef?, + returnType = + createServiceObject(json['returnType'], const ['InstanceRef']) + as InstanceRef?, + parameters = _createServiceObjectListOrNull( + json['parameters'], const ['Parameter']), + typeParameters = _createServiceObjectListOrNull( + json['typeParameters'], const ['InstanceRef']), + pattern = createServiceObject(json['pattern'], const ['InstanceRef']) + as InstanceRef?, + closureFunction = + createServiceObject(json['closureFunction'], const ['FuncRef']) + as FuncRef?, + closureContext = + createServiceObject(json['closureContext'], const ['ContextRef']) + as ContextRef?, + closureReceiver = + createServiceObject(json['closureReceiver'], const ['InstanceRef']) + as InstanceRef?, + portId = json['portId'], + allocationLocation = createServiceObject( + json['allocationLocation'], const ['InstanceRef']) as InstanceRef?, + debugName = json['debugName'], + label = json['label'], + super._fromJson(); @override String get type => '@Instance'; @@ -5566,96 +5553,90 @@ class Instance extends Obj implements InstanceRef { classRef: classRef, ); - Instance._fromJson(Map json) : super._fromJson(json) { - kind = json['kind'] ?? ''; - identityHashCode = json['identityHashCode'] ?? -1; - classRef = - createServiceObject(json['class'], const ['ClassRef']) as ClassRef?; - valueAsString = json['valueAsString']; - valueAsStringIsTruncated = json['valueAsStringIsTruncated']; - length = json['length']; - offset = json['offset']; - count = json['count']; - name = json['name']; - typeClass = - createServiceObject(json['typeClass'], const ['ClassRef']) as ClassRef?; - parameterizedClass = - createServiceObject(json['parameterizedClass'], const ['ClassRef']) - as ClassRef?; - returnType = createServiceObject(json['returnType'], const ['InstanceRef']) - as InstanceRef?; - parameters = json['parameters'] == null - ? null - : List.from( - createServiceObject(json['parameters'], const ['Parameter'])! - as List); - typeParameters = json['typeParameters'] == null - ? null - : List.from( - createServiceObject(json['typeParameters'], const ['InstanceRef'])! - as List); - fields = json['fields'] == null - ? null - : List.from( - createServiceObject(json['fields'], const ['BoundField'])! as List); - elements = json['elements'] == null - ? null - : List.from( - createServiceObject(json['elements'], const ['dynamic'])! as List); - associations = json['associations'] == null - ? null - : List.from( - _createSpecificObject(json['associations'], MapAssociation.parse)); - bytes = json['bytes']; - mirrorReferent = - createServiceObject(json['mirrorReferent'], const ['ObjRef']) - as ObjRef?; - pattern = createServiceObject(json['pattern'], const ['InstanceRef']) - as InstanceRef?; - closureFunction = - createServiceObject(json['closureFunction'], const ['FuncRef']) - as FuncRef?; - closureContext = - createServiceObject(json['closureContext'], const ['ContextRef']) - as ContextRef?; - closureReceiver = - createServiceObject(json['closureReceiver'], const ['InstanceRef']) - as InstanceRef?; - isCaseSensitive = json['isCaseSensitive']; - isMultiLine = json['isMultiLine']; - propertyKey = - createServiceObject(json['propertyKey'], const ['ObjRef']) as ObjRef?; - propertyValue = - createServiceObject(json['propertyValue'], const ['ObjRef']) as ObjRef?; - target = createServiceObject(json['target'], const ['ObjRef']) as ObjRef?; - typeArguments = - createServiceObject(json['typeArguments'], const ['TypeArgumentsRef']) - as TypeArgumentsRef?; - parameterIndex = json['parameterIndex']; - targetType = createServiceObject(json['targetType'], const ['InstanceRef']) - as InstanceRef?; - bound = createServiceObject(json['bound'], const ['InstanceRef']) - as InstanceRef?; - portId = json['portId']; - allocationLocation = - createServiceObject(json['allocationLocation'], const ['InstanceRef']) - as InstanceRef?; - debugName = json['debugName']; - label = json['label']; - callback = createServiceObject(json['callback'], const ['InstanceRef']) - as InstanceRef?; - callbackAddress = - createServiceObject(json['callbackAddress'], const ['InstanceRef']) - as InstanceRef?; - allEntries = createServiceObject(json['allEntries'], const ['InstanceRef']) - as InstanceRef?; - value = createServiceObject(json['value'], const ['InstanceRef']) - as InstanceRef?; - token = createServiceObject(json['token'], const ['InstanceRef']) - as InstanceRef?; - detach = createServiceObject(json['detach'], const ['InstanceRef']) - as InstanceRef?; - } + Instance._fromJson(super.json) + : kind = json['kind'] ?? '', + identityHashCode = json['identityHashCode'] ?? -1, + classRef = + createServiceObject(json['class'], const ['ClassRef']) as ClassRef?, + valueAsString = json['valueAsString'], + valueAsStringIsTruncated = json['valueAsStringIsTruncated'], + length = json['length'], + offset = json['offset'], + count = json['count'], + name = json['name'], + typeClass = createServiceObject(json['typeClass'], const ['ClassRef']) + as ClassRef?, + parameterizedClass = + createServiceObject(json['parameterizedClass'], const ['ClassRef']) + as ClassRef?, + returnType = + createServiceObject(json['returnType'], const ['InstanceRef']) + as InstanceRef?, + parameters = _createServiceObjectListOrNull( + json['parameters'], const ['Parameter']), + typeParameters = _createServiceObjectListOrNull( + json['typeParameters'], const ['InstanceRef']), + fields = _createServiceObjectListOrNull( + json['fields'], const ['BoundField']), + elements = _createServiceObjectListOrNull( + json['elements'], const ['dynamic']), + associations = json['associations'] == null + ? null + : List.from(_createSpecificObject( + json['associations'], MapAssociation.parse)), + bytes = json['bytes'], + mirrorReferent = + createServiceObject(json['mirrorReferent'], const ['ObjRef']) + as ObjRef?, + pattern = createServiceObject(json['pattern'], const ['InstanceRef']) + as InstanceRef?, + closureFunction = + createServiceObject(json['closureFunction'], const ['FuncRef']) + as FuncRef?, + closureContext = + createServiceObject(json['closureContext'], const ['ContextRef']) + as ContextRef?, + closureReceiver = + createServiceObject(json['closureReceiver'], const ['InstanceRef']) + as InstanceRef?, + isCaseSensitive = json['isCaseSensitive'], + isMultiLine = json['isMultiLine'], + propertyKey = createServiceObject(json['propertyKey'], const ['ObjRef']) + as ObjRef?, + propertyValue = + createServiceObject(json['propertyValue'], const ['ObjRef']) + as ObjRef?, + target = + createServiceObject(json['target'], const ['ObjRef']) as ObjRef?, + typeArguments = createServiceObject( + json['typeArguments'], const ['TypeArgumentsRef']) + as TypeArgumentsRef?, + parameterIndex = json['parameterIndex'], + targetType = + createServiceObject(json['targetType'], const ['InstanceRef']) + as InstanceRef?, + bound = createServiceObject(json['bound'], const ['InstanceRef']) + as InstanceRef?, + portId = json['portId'], + allocationLocation = createServiceObject( + json['allocationLocation'], const ['InstanceRef']) as InstanceRef?, + debugName = json['debugName'], + label = json['label'], + callback = createServiceObject(json['callback'], const ['InstanceRef']) + as InstanceRef?, + callbackAddress = + createServiceObject(json['callbackAddress'], const ['InstanceRef']) + as InstanceRef?, + allEntries = + createServiceObject(json['allEntries'], const ['InstanceRef']) + as InstanceRef?, + value = createServiceObject(json['value'], const ['InstanceRef']) + as InstanceRef?, + token = createServiceObject(json['token'], const ['InstanceRef']) + as InstanceRef?, + detach = createServiceObject(json['detach'], const ['InstanceRef']) + as InstanceRef?, + super._fromJson(); @override String get type => 'Instance'; @@ -5777,13 +5758,13 @@ class IsolateRef extends Response { this.isolateGroupId, }); - IsolateRef._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? ''; - number = json['number'] ?? ''; - name = json['name'] ?? ''; - isSystemIsolate = json['isSystemIsolate'] ?? false; - isolateGroupId = json['isolateGroupId'] ?? ''; - } + IsolateRef._fromJson(super.json) + : id = json['id'] ?? '', + number = json['number'] ?? '', + name = json['name'] ?? '', + isSystemIsolate = json['isSystemIsolate'] ?? false, + isolateGroupId = json['isolateGroupId'] ?? '', + super._fromJson(); @override String get type => '@Isolate'; @@ -5904,37 +5885,32 @@ class Isolate extends Response implements IsolateRef { this.extensionRPCs, }); - Isolate._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? ''; - number = json['number'] ?? ''; - name = json['name'] ?? ''; - isSystemIsolate = json['isSystemIsolate'] ?? false; - isolateGroupId = json['isolateGroupId'] ?? ''; - isolateFlags = List.from( - createServiceObject(json['isolateFlags'], const ['IsolateFlag']) - as List? ?? - []); - startTime = json['startTime'] ?? -1; - runnable = json['runnable'] ?? false; - livePorts = json['livePorts'] ?? -1; - pauseOnExit = json['pauseOnExit'] ?? false; - pauseEvent = - createServiceObject(json['pauseEvent'], const ['Event']) as Event?; - rootLib = createServiceObject(json['rootLib'], const ['LibraryRef']) - as LibraryRef?; - libraries = List.from( - createServiceObject(json['libraries'], const ['LibraryRef']) as List? ?? - []); - breakpoints = List.from( - createServiceObject(json['breakpoints'], const ['Breakpoint']) - as List? ?? - []); - error = createServiceObject(json['error'], const ['Error']) as Error?; - exceptionPauseMode = json['exceptionPauseMode'] ?? ''; - extensionRPCs = json['extensionRPCs'] == null - ? null - : List.from(json['extensionRPCs']); - } + Isolate._fromJson(super.json) + : id = json['id'] ?? '', + number = json['number'] ?? '', + name = json['name'] ?? '', + isSystemIsolate = json['isSystemIsolate'] ?? false, + isolateGroupId = json['isolateGroupId'] ?? '', + isolateFlags = _createServiceObjectListOrNull( + json['isolateFlags'], const ['IsolateFlag']), + startTime = json['startTime'] ?? -1, + runnable = json['runnable'] ?? false, + livePorts = json['livePorts'] ?? -1, + pauseOnExit = json['pauseOnExit'] ?? false, + pauseEvent = + createServiceObject(json['pauseEvent'], const ['Event']) as Event?, + rootLib = createServiceObject(json['rootLib'], const ['LibraryRef']) + as LibraryRef?, + libraries = _createServiceObjectListOrNull( + json['libraries'], const ['LibraryRef']), + breakpoints = _createServiceObjectListOrNull( + json['breakpoints'], const ['Breakpoint']), + error = createServiceObject(json['error'], const ['Error']) as Error?, + exceptionPauseMode = json['exceptionPauseMode'] ?? '', + extensionRPCs = json['extensionRPCs'] == null + ? null + : List.from(json['extensionRPCs']), + super._fromJson(); @override String get type => 'Isolate'; @@ -5989,10 +5965,9 @@ class IsolateFlag { this.valueAsString, }); - IsolateFlag._fromJson(Map json) { - name = json['name'] ?? ''; - valueAsString = json['valueAsString'] ?? ''; - } + IsolateFlag._fromJson(Map json) + : name = json['name'] ?? '', + valueAsString = json['valueAsString'] ?? ''; Map toJson() => { 'name': name ?? '', @@ -6030,12 +6005,12 @@ class IsolateGroupRef extends Response { this.isSystemIsolateGroup, }); - IsolateGroupRef._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? ''; - number = json['number'] ?? ''; - name = json['name'] ?? ''; - isSystemIsolateGroup = json['isSystemIsolateGroup'] ?? false; - } + IsolateGroupRef._fromJson(super.json) + : id = json['id'] ?? '', + number = json['number'] ?? '', + name = json['name'] ?? '', + isSystemIsolateGroup = json['isSystemIsolateGroup'] ?? false, + super._fromJson(); @override String get type => '@IsolateGroup'; @@ -6094,15 +6069,14 @@ class IsolateGroup extends Response implements IsolateGroupRef { this.isolates, }); - IsolateGroup._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? ''; - number = json['number'] ?? ''; - name = json['name'] ?? ''; - isSystemIsolateGroup = json['isSystemIsolateGroup'] ?? false; - isolates = List.from( - createServiceObject(json['isolates'], const ['IsolateRef']) as List? ?? - []); - } + IsolateGroup._fromJson(super.json) + : id = json['id'] ?? '', + number = json['number'] ?? '', + name = json['name'] ?? '', + isSystemIsolateGroup = json['isSystemIsolateGroup'] ?? false, + isolates = _createServiceObjectListOrNull( + json['isolates'], const ['IsolateRef']), + super._fromJson(); @override String get type => 'IsolateGroup'; @@ -6141,13 +6115,10 @@ class InboundReferences extends Response { this.references, }); - InboundReferences._fromJson(Map json) - : super._fromJson(json) { - references = List.from( - createServiceObject(json['references'], const ['InboundReference']) - as List? ?? - []); - } + InboundReferences._fromJson(super.json) + : references = _createServiceObjectListOrNull( + json['references'], const ['InboundReference']), + super._fromJson(); @override String get type => 'InboundReferences'; @@ -6195,12 +6166,13 @@ class InboundReference { this.parentField, }); - InboundReference._fromJson(Map json) { - source = createServiceObject(json['source'], const ['ObjRef']) as ObjRef?; - parentListIndex = json['parentListIndex']; - parentField = createServiceObject( - json['parentField'], const ['FieldRef', 'String', 'int']) as dynamic; - } + InboundReference._fromJson(Map json) + : source = + createServiceObject(json['source'], const ['ObjRef']) as ObjRef?, + parentListIndex = json['parentListIndex'], + parentField = createServiceObject( + json['parentField'], const ['FieldRef', 'String', 'int']) + as dynamic; Map toJson() => { 'source': source?.toJson(), @@ -6233,12 +6205,12 @@ class InstanceSet extends Response { this.instances, }); - InstanceSet._fromJson(Map json) : super._fromJson(json) { - totalCount = json['totalCount'] ?? -1; - instances = List.from(createServiceObject( - (json['instances'] ?? json['samples']!) as List, const ['ObjRef'])! - as List); - } + InstanceSet._fromJson(super.json) + : totalCount = json['totalCount'] ?? -1, + instances = List.from(createServiceObject( + (json['instances'] ?? json['samples']!) as List, + const ['ObjRef'])! as List), + super._fromJson(); @override String get type => 'InstanceSet'; @@ -6274,10 +6246,10 @@ class LibraryRef extends ObjRef { id: id, ); - LibraryRef._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - uri = json['uri'] ?? ''; - } + LibraryRef._fromJson(super.json) + : name = json['name'] ?? '', + uri = json['uri'] ?? '', + super._fromJson(); @override String get type => '@Library'; @@ -6347,25 +6319,21 @@ class Library extends Obj implements LibraryRef { id: id, ); - Library._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - uri = json['uri'] ?? ''; - debuggable = json['debuggable'] ?? false; - dependencies = List.from( - _createSpecificObject(json['dependencies']!, LibraryDependency.parse)); - scripts = List.from( - createServiceObject(json['scripts'], const ['ScriptRef']) as List? ?? - []); - variables = List.from( - createServiceObject(json['variables'], const ['FieldRef']) as List? ?? - []); - functions = List.from( - createServiceObject(json['functions'], const ['FuncRef']) as List? ?? - []); - classes = List.from( - createServiceObject(json['classes'], const ['ClassRef']) as List? ?? - []); - } + Library._fromJson(super.json) + : name = json['name'] ?? '', + uri = json['uri'] ?? '', + debuggable = json['debuggable'] ?? false, + dependencies = List.from(_createSpecificObject( + json['dependencies']!, LibraryDependency.parse)), + scripts = _createServiceObjectListOrNull( + json['scripts'], const ['ScriptRef']), + variables = _createServiceObjectListOrNull( + json['variables'], const ['FieldRef']), + functions = _createServiceObjectListOrNull( + json['functions'], const ['FuncRef']), + classes = _createServiceObjectListOrNull( + json['classes'], const ['ClassRef']), + super._fromJson(); @override String get type => 'Library'; @@ -6428,15 +6396,14 @@ class LibraryDependency { this.hides, }); - LibraryDependency._fromJson(Map json) { - isImport = json['isImport'] ?? false; - isDeferred = json['isDeferred'] ?? false; - prefix = json['prefix'] ?? ''; - target = createServiceObject(json['target'], const ['LibraryRef']) - as LibraryRef?; - shows = json['shows'] == null ? null : List.from(json['shows']); - hides = json['hides'] == null ? null : List.from(json['hides']); - } + LibraryDependency._fromJson(Map json) + : isImport = json['isImport'] ?? false, + isDeferred = json['isDeferred'] ?? false, + prefix = json['prefix'] ?? '', + target = createServiceObject(json['target'], const ['LibraryRef']) + as LibraryRef?, + shows = json['shows'] == null ? null : List.from(json['shows']), + hides = json['hides'] == null ? null : List.from(json['hides']); Map toJson() => { 'isImport': isImport ?? false, @@ -6497,21 +6464,23 @@ class LogRecord extends Response { this.stackTrace, }); - LogRecord._fromJson(Map json) : super._fromJson(json) { - message = createServiceObject(json['message'], const ['InstanceRef']) - as InstanceRef?; - time = json['time'] ?? -1; - level = json['level'] ?? -1; - sequenceNumber = json['sequenceNumber'] ?? -1; - loggerName = createServiceObject(json['loggerName'], const ['InstanceRef']) - as InstanceRef?; - zone = createServiceObject(json['zone'], const ['InstanceRef']) - as InstanceRef?; - error = createServiceObject(json['error'], const ['InstanceRef']) - as InstanceRef?; - stackTrace = createServiceObject(json['stackTrace'], const ['InstanceRef']) - as InstanceRef?; - } + LogRecord._fromJson(super.json) + : message = createServiceObject(json['message'], const ['InstanceRef']) + as InstanceRef?, + time = json['time'] ?? -1, + level = json['level'] ?? -1, + sequenceNumber = json['sequenceNumber'] ?? -1, + loggerName = + createServiceObject(json['loggerName'], const ['InstanceRef']) + as InstanceRef?, + zone = createServiceObject(json['zone'], const ['InstanceRef']) + as InstanceRef?, + error = createServiceObject(json['error'], const ['InstanceRef']) + as InstanceRef?, + stackTrace = + createServiceObject(json['stackTrace'], const ['InstanceRef']) + as InstanceRef?, + super._fromJson(); @override String get type => 'LogRecord'; @@ -6550,13 +6519,12 @@ class MapAssociation { this.value, }); - MapAssociation._fromJson(Map json) { - key = createServiceObject(json['key'], const ['InstanceRef', 'Sentinel']) - as dynamic; - value = - createServiceObject(json['value'], const ['InstanceRef', 'Sentinel']) - as dynamic; - } + MapAssociation._fromJson(Map json) + : key = + createServiceObject(json['key'], const ['InstanceRef', 'Sentinel']) + as dynamic, + value = createServiceObject( + json['value'], const ['InstanceRef', 'Sentinel']) as dynamic; Map toJson() => { 'key': key?.toJson(), @@ -6595,11 +6563,11 @@ class MemoryUsage extends Response { this.heapUsage, }); - MemoryUsage._fromJson(Map json) : super._fromJson(json) { - externalUsage = json['externalUsage'] ?? -1; - heapCapacity = json['heapCapacity'] ?? -1; - heapUsage = json['heapUsage'] ?? -1; - } + MemoryUsage._fromJson(super.json) + : externalUsage = json['externalUsage'] ?? -1, + heapCapacity = json['heapCapacity'] ?? -1, + heapUsage = json['heapUsage'] ?? -1, + super._fromJson(); @override String get type => 'MemoryUsage'; @@ -6655,16 +6623,17 @@ class Message extends Response { this.location, }); - Message._fromJson(Map json) : super._fromJson(json) { - index = json['index'] ?? -1; - name = json['name'] ?? ''; - messageObjectId = json['messageObjectId'] ?? ''; - size = json['size'] ?? -1; - handler = - createServiceObject(json['handler'], const ['FuncRef']) as FuncRef?; - location = createServiceObject(json['location'], const ['SourceLocation']) - as SourceLocation?; - } + Message._fromJson(super.json) + : index = json['index'] ?? -1, + name = json['name'] ?? '', + messageObjectId = json['messageObjectId'] ?? '', + size = json['size'] ?? -1, + handler = + createServiceObject(json['handler'], const ['FuncRef']) as FuncRef?, + location = + createServiceObject(json['location'], const ['SourceLocation']) + as SourceLocation?, + super._fromJson(); @override String get type => 'Message'; @@ -6707,10 +6676,10 @@ class Microtask extends Response { this.stackTrace, }); - Microtask._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? -1; - stackTrace = json['stackTrace'] ?? ''; - } + Microtask._fromJson(super.json) + : id = json['id'] ?? -1, + stackTrace = json['stackTrace'] ?? '', + super._fromJson(); @override String get type => 'Microtask'; @@ -6745,9 +6714,8 @@ class NativeFunction { this.name, }); - NativeFunction._fromJson(Map json) { - name = json['name'] ?? ''; - } + NativeFunction._fromJson(Map json) + : name = json['name'] ?? ''; Map toJson() => { 'name': name ?? '', @@ -6783,9 +6751,9 @@ class NullValRef extends InstanceRef { ), ); - NullValRef._fromJson(Map json) : super._fromJson(json) { - valueAsString = json['valueAsString'] ?? ''; - } + NullValRef._fromJson(super.json) + : valueAsString = json['valueAsString'] ?? '', + super._fromJson(); @override String get type => '@Null'; @@ -6835,9 +6803,9 @@ class NullVal extends Instance implements NullValRef { ), ); - NullVal._fromJson(Map json) : super._fromJson(json) { - valueAsString = json['valueAsString'] ?? ''; - } + NullVal._fromJson(super.json) + : valueAsString = json['valueAsString'] ?? '', + super._fromJson(); @override String get type => 'Null'; @@ -6881,10 +6849,10 @@ class ObjRef extends Response { this.fixedId, }); - ObjRef._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? ''; - fixedId = json['fixedId']; - } + ObjRef._fromJson(super.json) + : id = json['id'] ?? '', + fixedId = json['fixedId'], + super._fromJson(); @override String get type => '@Object'; @@ -6953,13 +6921,13 @@ class Obj extends Response implements ObjRef { this.size, }); - Obj._fromJson(Map json) : super._fromJson(json) { - id = json['id'] ?? ''; - fixedId = json['fixedId']; - classRef = - createServiceObject(json['class'], const ['ClassRef']) as ClassRef?; - size = json['size']; - } + Obj._fromJson(super.json) + : id = json['id'] ?? '', + fixedId = json['fixedId'], + classRef = + createServiceObject(json['class'], const ['ClassRef']) as ClassRef?, + size = json['size'], + super._fromJson(); @override String get type => 'Object'; @@ -7011,14 +6979,13 @@ class Parameter { this.required, }); - Parameter._fromJson(Map json) { - parameterType = - createServiceObject(json['parameterType'], const ['InstanceRef']) - as InstanceRef?; - fixed = json['fixed'] ?? false; - name = json['name']; - required = json['required']; - } + Parameter._fromJson(Map json) + : parameterType = + createServiceObject(json['parameterType'], const ['InstanceRef']) + as InstanceRef?, + fixed = json['fixed'] ?? false, + name = json['name'], + required = json['required']; Map toJson() => { 'parameterType': parameterType?.toJson(), @@ -7070,16 +7037,15 @@ class PerfettoCpuSamples extends Response { this.samples, }); - PerfettoCpuSamples._fromJson(Map json) - : super._fromJson(json) { - samplePeriod = json['samplePeriod'] ?? -1; - maxStackDepth = json['maxStackDepth'] ?? -1; - sampleCount = json['sampleCount'] ?? -1; - timeOriginMicros = json['timeOriginMicros'] ?? -1; - timeExtentMicros = json['timeExtentMicros'] ?? -1; - pid = json['pid'] ?? -1; - samples = json['samples'] ?? ''; - } + PerfettoCpuSamples._fromJson(super.json) + : samplePeriod = json['samplePeriod'] ?? -1, + maxStackDepth = json['maxStackDepth'] ?? -1, + sampleCount = json['sampleCount'] ?? -1, + timeOriginMicros = json['timeOriginMicros'] ?? -1, + timeExtentMicros = json['timeExtentMicros'] ?? -1, + pid = json['pid'] ?? -1, + samples = json['samples'] ?? '', + super._fromJson(); @override String get type => 'PerfettoCpuSamples'; @@ -7123,12 +7089,11 @@ class PerfettoTimeline extends Response { this.timeExtentMicros, }); - PerfettoTimeline._fromJson(Map json) - : super._fromJson(json) { - trace = json['trace'] ?? ''; - timeOriginMicros = json['timeOriginMicros'] ?? -1; - timeExtentMicros = json['timeExtentMicros'] ?? -1; - } + PerfettoTimeline._fromJson(super.json) + : trace = json['trace'] ?? '', + timeOriginMicros = json['timeOriginMicros'] ?? -1, + timeExtentMicros = json['timeExtentMicros'] ?? -1, + super._fromJson(); @override String get type => 'PerfettoTimeline'; @@ -7159,11 +7124,10 @@ class PortList extends Response { this.ports, }); - PortList._fromJson(Map json) : super._fromJson(json) { - ports = List.from( - createServiceObject(json['ports'], const ['InstanceRef']) as List? ?? - []); - } + PortList._fromJson(super.json) + : ports = _createServiceObjectListOrNull( + json['ports'], const ['InstanceRef']), + super._fromJson(); @override String get type => 'PortList'; @@ -7210,14 +7174,13 @@ class ProfileFunction { this.function, }); - ProfileFunction._fromJson(Map json) { - kind = json['kind'] ?? ''; - inclusiveTicks = json['inclusiveTicks'] ?? -1; - exclusiveTicks = json['exclusiveTicks'] ?? -1; - resolvedUrl = json['resolvedUrl'] ?? ''; - function = - createServiceObject(json['function'], const ['dynamic']) as dynamic; - } + ProfileFunction._fromJson(Map json) + : kind = json['kind'] ?? '', + inclusiveTicks = json['inclusiveTicks'] ?? -1, + exclusiveTicks = json['exclusiveTicks'] ?? -1, + resolvedUrl = json['resolvedUrl'] ?? '', + function = + createServiceObject(json['function'], const ['dynamic']) as dynamic; Map toJson() => { 'kind': kind ?? '', @@ -7248,11 +7211,10 @@ class ProtocolList extends Response { this.protocols, }); - ProtocolList._fromJson(Map json) : super._fromJson(json) { - protocols = List.from( - createServiceObject(json['protocols'], const ['Protocol']) as List? ?? - []); - } + ProtocolList._fromJson(super.json) + : protocols = _createServiceObjectListOrNull( + json['protocols'], const ['Protocol']), + super._fromJson(); @override String get type => 'ProtocolList'; @@ -7287,11 +7249,10 @@ class Protocol { this.minor, }); - Protocol._fromJson(Map json) { - protocolName = json['protocolName'] ?? ''; - major = json['major'] ?? -1; - minor = json['minor'] ?? -1; - } + Protocol._fromJson(Map json) + : protocolName = json['protocolName'] ?? '', + major = json['major'] ?? -1, + minor = json['minor'] ?? -1; Map toJson() => { 'protocolName': protocolName ?? '', @@ -7315,11 +7276,10 @@ class ProcessMemoryUsage extends Response { this.root, }); - ProcessMemoryUsage._fromJson(Map json) - : super._fromJson(json) { - root = createServiceObject(json['root'], const ['ProcessMemoryItem']) - as ProcessMemoryItem?; - } + ProcessMemoryUsage._fromJson(super.json) + : root = createServiceObject(json['root'], const ['ProcessMemoryItem']) + as ProcessMemoryItem?, + super._fromJson(); @override String get type => 'ProcessMemoryUsage'; @@ -7358,15 +7318,12 @@ class ProcessMemoryItem { this.children, }); - ProcessMemoryItem._fromJson(Map json) { - name = json['name'] ?? ''; - description = json['description'] ?? ''; - size = json['size'] ?? -1; - children = List.from( - createServiceObject(json['children'], const ['ProcessMemoryItem']) - as List? ?? - []); - } + ProcessMemoryItem._fromJson(Map json) + : name = json['name'] ?? '', + description = json['description'] ?? '', + size = json['size'] ?? -1, + children = _createServiceObjectListOrNull( + json['children'], const ['ProcessMemoryItem']); Map toJson() => { 'name': name ?? '', @@ -7402,13 +7359,11 @@ class QueuedMicrotasks extends Response { this.microtasks, }); - QueuedMicrotasks._fromJson(Map json) - : super._fromJson(json) { - timestamp = json['timestamp'] ?? -1; - microtasks = List.from( - createServiceObject(json['microtasks'], const ['Microtask']) as List? ?? - []); - } + QueuedMicrotasks._fromJson(super.json) + : timestamp = json['timestamp'] ?? -1, + microtasks = _createServiceObjectListOrNull( + json['microtasks'], const ['Microtask']), + super._fromJson(); @override String get type => 'QueuedMicrotasks'; @@ -7436,9 +7391,9 @@ class ReloadReport extends Response { this.success, }); - ReloadReport._fromJson(Map json) : super._fromJson(json) { - success = json['success'] ?? false; - } + ReloadReport._fromJson(super.json) + : success = json['success'] ?? false, + super._fromJson(); @override String get type => 'ReloadReport'; @@ -7487,15 +7442,15 @@ class RetainingObject { this.parentField, }); - RetainingObject._fromJson(Map json) { - value = createServiceObject(json['value'], const ['ObjRef']) as ObjRef?; - parentListIndex = json['parentListIndex']; - parentMapKey = - createServiceObject(json['parentMapKey'], const ['ObjRef']) as ObjRef?; - parentField = - createServiceObject(json['parentField'], const ['String', 'int']) - as dynamic; - } + RetainingObject._fromJson(Map json) + : value = createServiceObject(json['value'], const ['ObjRef']) as ObjRef?, + parentListIndex = json['parentListIndex'], + parentMapKey = + createServiceObject(json['parentMapKey'], const ['ObjRef']) + as ObjRef?, + parentField = + createServiceObject(json['parentField'], const ['String', 'int']) + as dynamic; Map toJson() => { 'value': value?.toJson(), @@ -7533,14 +7488,12 @@ class RetainingPath extends Response { this.elements, }); - RetainingPath._fromJson(Map json) : super._fromJson(json) { - length = json['length'] ?? -1; - gcRootType = json['gcRootType'] ?? ''; - elements = List.from( - createServiceObject(json['elements'], const ['RetainingObject']) - as List? ?? - []); - } + RetainingPath._fromJson(super.json) + : length = json['length'] ?? -1, + gcRootType = json['gcRootType'] ?? '', + elements = _createServiceObjectListOrNull( + json['elements'], const ['RetainingObject']), + super._fromJson(); @override String get type => 'RetainingPath'; @@ -7601,10 +7554,10 @@ class Sentinel extends Response { this.valueAsString, }); - Sentinel._fromJson(Map json) : super._fromJson(json) { - kind = json['kind'] ?? ''; - valueAsString = json['valueAsString'] ?? ''; - } + Sentinel._fromJson(super.json) + : kind = json['kind'] ?? '', + valueAsString = json['valueAsString'] ?? '', + super._fromJson(); @override String get type => 'Sentinel'; @@ -7635,9 +7588,9 @@ class ScriptRef extends ObjRef { id: id, ); - ScriptRef._fromJson(Map json) : super._fromJson(json) { - uri = json['uri'] ?? ''; - } + ScriptRef._fromJson(super.json) + : uri = json['uri'] ?? '', + super._fromJson(); @override String get type => '@Script'; @@ -7727,17 +7680,18 @@ class Script extends Obj implements ScriptRef { id: id, ); - Script._fromJson(Map json) : super._fromJson(json) { - uri = json['uri'] ?? ''; - library = createServiceObject(json['library'], const ['LibraryRef']) - as LibraryRef?; - lineOffset = json['lineOffset']; - columnOffset = json['columnOffset']; - source = json['source']; - tokenPosTable = json['tokenPosTable'] == null - ? null - : List>.from( - json['tokenPosTable']!.map((dynamic list) => List.from(list))); + Script._fromJson(super.json) + : uri = json['uri'] ?? '', + library = createServiceObject(json['library'], const ['LibraryRef']) + as LibraryRef?, + lineOffset = json['lineOffset'], + columnOffset = json['columnOffset'], + source = json['source'], + tokenPosTable = json['tokenPosTable'] == null + ? null + : List>.from(json['tokenPosTable']! + .map((dynamic list) => List.from(list))), + super._fromJson() { _parseTokenPosTable(); } @@ -7808,11 +7762,10 @@ class ScriptList extends Response { this.scripts, }); - ScriptList._fromJson(Map json) : super._fromJson(json) { - scripts = List.from( - createServiceObject(json['scripts'], const ['ScriptRef']) as List? ?? - []); - } + ScriptList._fromJson(super.json) + : scripts = _createServiceObjectListOrNull( + json['scripts'], const ['ScriptRef']), + super._fromJson(); @override String get type => 'ScriptList'; @@ -7861,14 +7814,14 @@ class SourceLocation extends Response { this.column, }); - SourceLocation._fromJson(Map json) : super._fromJson(json) { - script = - createServiceObject(json['script'], const ['ScriptRef']) as ScriptRef?; - tokenPos = json['tokenPos'] ?? -1; - endTokenPos = json['endTokenPos']; - line = json['line']; - column = json['column']; - } + SourceLocation._fromJson(super.json) + : script = createServiceObject(json['script'], const ['ScriptRef']) + as ScriptRef?, + tokenPos = json['tokenPos'] ?? -1, + endTokenPos = json['endTokenPos'], + line = json['line'], + column = json['column'], + super._fromJson(); @override String get type => 'SourceLocation'; @@ -7912,13 +7865,12 @@ class SourceReport extends Response { this.scripts, }); - SourceReport._fromJson(Map json) : super._fromJson(json) { - ranges = List.from( - _createSpecificObject(json['ranges']!, SourceReportRange.parse)); - scripts = List.from( - createServiceObject(json['scripts'], const ['ScriptRef']) as List? ?? - []); - } + SourceReport._fromJson(super.json) + : ranges = List.from( + _createSpecificObject(json['ranges']!, SourceReportRange.parse)), + scripts = _createServiceObjectListOrNull( + json['scripts'], const ['ScriptRef']), + super._fromJson(); @override String get type => 'SourceReport'; @@ -7956,10 +7908,9 @@ class SourceReportCoverage { this.misses, }); - SourceReportCoverage._fromJson(Map json) { - hits = List.from(json['hits']); - misses = List.from(json['misses']); - } + SourceReportCoverage._fromJson(Map json) + : hits = List.from(json['hits']), + misses = List.from(json['misses']); Map toJson() => { 'hits': hits?.map((f) => f).toList(), @@ -8026,21 +7977,21 @@ class SourceReportRange { this.branchCoverage, }); - SourceReportRange._fromJson(Map json) { - scriptIndex = json['scriptIndex'] ?? -1; - startPos = json['startPos'] ?? -1; - endPos = json['endPos'] ?? -1; - compiled = json['compiled'] ?? false; - error = createServiceObject(json['error'], const ['ErrorRef']) as ErrorRef?; - coverage = - _createSpecificObject(json['coverage'], SourceReportCoverage.parse); - possibleBreakpoints = json['possibleBreakpoints'] == null - ? null - : List.from(json['possibleBreakpoints']); - branchCoverage = createServiceObject( - json['branchCoverage'], const ['SourceReportCoverage']) - as SourceReportCoverage?; - } + SourceReportRange._fromJson(Map json) + : scriptIndex = json['scriptIndex'] ?? -1, + startPos = json['startPos'] ?? -1, + endPos = json['endPos'] ?? -1, + compiled = json['compiled'] ?? false, + error = + createServiceObject(json['error'], const ['ErrorRef']) as ErrorRef?, + coverage = + _createSpecificObject(json['coverage'], SourceReportCoverage.parse), + possibleBreakpoints = json['possibleBreakpoints'] == null + ? null + : List.from(json['possibleBreakpoints']), + branchCoverage = createServiceObject( + json['branchCoverage'], const ['SourceReportCoverage']) + as SourceReportCoverage?; Map toJson() => { 'scriptIndex': scriptIndex ?? -1, @@ -8116,24 +8067,17 @@ class Stack extends Response { this.awaiterFrames, }); - Stack._fromJson(Map json) : super._fromJson(json) { - frames = List.from( - createServiceObject(json['frames'], const ['Frame']) as List? ?? []); - asyncCausalFrames = json['asyncCausalFrames'] == null - ? null - : List.from( - createServiceObject(json['asyncCausalFrames'], const ['Frame'])! - as List); - awaiterFrames = json['awaiterFrames'] == null - ? null - : List.from( - createServiceObject(json['awaiterFrames'], const ['Frame'])! - as List); - messages = List.from( - createServiceObject(json['messages'], const ['Message']) as List? ?? - []); - truncated = json['truncated'] ?? false; - } + Stack._fromJson(super.json) + : frames = _createServiceObjectListOrNull( + json['frames'], const ['Frame']), + asyncCausalFrames = _createServiceObjectListOrNull( + json['asyncCausalFrames'], const ['Frame']), + awaiterFrames = _createServiceObjectListOrNull( + json['awaiterFrames'], const ['Frame']), + messages = _createServiceObjectListOrNull( + json['messages'], const ['Message']), + truncated = json['truncated'] ?? false, + super._fromJson(); @override String get type => 'Stack'; @@ -8201,14 +8145,12 @@ class Timeline extends Response { this.timeExtentMicros, }); - Timeline._fromJson(Map json) : super._fromJson(json) { - traceEvents = List.from( - createServiceObject(json['traceEvents'], const ['TimelineEvent']) - as List? ?? - []); - timeOriginMicros = json['timeOriginMicros'] ?? -1; - timeExtentMicros = json['timeExtentMicros'] ?? -1; - } + Timeline._fromJson(super.json) + : traceEvents = _createServiceObjectListOrNull( + json['traceEvents'], const ['TimelineEvent']), + timeOriginMicros = json['timeOriginMicros'] ?? -1, + timeExtentMicros = json['timeExtentMicros'] ?? -1, + super._fromJson(); @override String get type => 'Timeline'; @@ -8269,11 +8211,11 @@ class TimelineFlags extends Response { this.recordedStreams, }); - TimelineFlags._fromJson(Map json) : super._fromJson(json) { - recorderName = json['recorderName'] ?? ''; - availableStreams = List.from(json['availableStreams']); - recordedStreams = List.from(json['recordedStreams']); - } + TimelineFlags._fromJson(super.json) + : recorderName = json['recorderName'] ?? '', + availableStreams = List.from(json['availableStreams']), + recordedStreams = List.from(json['recordedStreams']), + super._fromJson(); @override String get type => 'TimelineFlags'; @@ -8303,9 +8245,9 @@ class Timestamp extends Response { this.timestamp, }); - Timestamp._fromJson(Map json) : super._fromJson(json) { - timestamp = json['timestamp'] ?? -1; - } + Timestamp._fromJson(super.json) + : timestamp = json['timestamp'] ?? -1, + super._fromJson(); @override String get type => 'Timestamp'; @@ -8335,10 +8277,9 @@ class TypeArgumentsRef extends ObjRef { id: id, ); - TypeArgumentsRef._fromJson(Map json) - : super._fromJson(json) { - name = json['name'] ?? ''; - } + TypeArgumentsRef._fromJson(super.json) + : name = json['name'] ?? '', + super._fromJson(); @override String get type => '@TypeArguments'; @@ -8384,12 +8325,11 @@ class TypeArguments extends Obj implements TypeArgumentsRef { id: id, ); - TypeArguments._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - types = List.from( - createServiceObject(json['types'], const ['InstanceRef']) as List? ?? - []); - } + TypeArguments._fromJson(super.json) + : name = json['name'] ?? '', + types = _createServiceObjectListOrNull( + json['types'], const ['InstanceRef']), + super._fromJson(); @override String get type => 'TypeArguments'; @@ -8469,14 +8409,15 @@ class TypeParameters extends Obj implements TypeParametersRef { id: id, ); - TypeParameters._fromJson(Map json) : super._fromJson(json) { - names = createServiceObject(json['names'], const ['InstanceRef']) - as InstanceRef?; - bounds = createServiceObject(json['bounds'], const ['TypeArgumentsRef']) - as TypeArgumentsRef?; - defaults = createServiceObject(json['defaults'], const ['TypeArgumentsRef']) - as TypeArgumentsRef?; - } + TypeParameters._fromJson(super.json) + : names = createServiceObject(json['names'], const ['InstanceRef']) + as InstanceRef?, + bounds = createServiceObject(json['bounds'], const ['TypeArgumentsRef']) + as TypeArgumentsRef?, + defaults = + createServiceObject(json['defaults'], const ['TypeArgumentsRef']) + as TypeArgumentsRef?, + super._fromJson(); @override String get type => 'TypeParameters'; @@ -8547,15 +8488,14 @@ class UnresolvedSourceLocation extends Response { this.column, }); - UnresolvedSourceLocation._fromJson(Map json) - : super._fromJson(json) { - script = - createServiceObject(json['script'], const ['ScriptRef']) as ScriptRef?; - scriptUri = json['scriptUri']; - tokenPos = json['tokenPos']; - line = json['line']; - column = json['column']; - } + UnresolvedSourceLocation._fromJson(super.json) + : script = createServiceObject(json['script'], const ['ScriptRef']) + as ScriptRef?, + scriptUri = json['scriptUri'], + tokenPos = json['tokenPos'], + line = json['line'], + column = json['column'], + super._fromJson(); @override String get type => 'UnresolvedSourceLocation'; @@ -8585,9 +8525,9 @@ class UriList extends Response { this.uris, }); - UriList._fromJson(Map json) : super._fromJson(json) { - uris = List.from(json['uris']); - } + UriList._fromJson(super.json) + : uris = List.from(json['uris']), + super._fromJson(); @override String get type => 'UriList'; @@ -8620,10 +8560,10 @@ class Version extends Response { this.minor, }); - Version._fromJson(Map json) : super._fromJson(json) { - major = json['major'] ?? -1; - minor = json['minor'] ?? -1; - } + Version._fromJson(super.json) + : major = json['major'] ?? -1, + minor = json['minor'] ?? -1, + super._fromJson(); @override String get type => 'Version'; @@ -8651,9 +8591,9 @@ class VMRef extends Response { this.name, }); - VMRef._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - } + VMRef._fromJson(super.json) + : name = json['name'] ?? '', + super._fromJson(); @override String get type => '@VM'; @@ -8726,30 +8666,24 @@ class VM extends Response implements VMRef { this.systemIsolateGroups, }); - VM._fromJson(Map json) : super._fromJson(json) { - name = json['name'] ?? ''; - architectureBits = json['architectureBits'] ?? -1; - hostCPU = json['hostCPU'] ?? ''; - operatingSystem = json['operatingSystem'] ?? ''; - targetCPU = json['targetCPU'] ?? ''; - version = json['version'] ?? ''; - pid = json['pid'] ?? -1; - startTime = json['startTime'] ?? -1; - isolates = List.from( - createServiceObject(json['isolates'], const ['IsolateRef']) as List? ?? - []); - isolateGroups = List.from( - createServiceObject(json['isolateGroups'], const ['IsolateGroupRef']) - as List? ?? - []); - systemIsolates = List.from( - createServiceObject(json['systemIsolates'], const ['IsolateRef']) - as List? ?? - []); - systemIsolateGroups = List.from(createServiceObject( - json['systemIsolateGroups'], const ['IsolateGroupRef']) as List? ?? - []); - } + VM._fromJson(super.json) + : name = json['name'] ?? '', + architectureBits = json['architectureBits'] ?? -1, + hostCPU = json['hostCPU'] ?? '', + operatingSystem = json['operatingSystem'] ?? '', + targetCPU = json['targetCPU'] ?? '', + version = json['version'] ?? '', + pid = json['pid'] ?? -1, + startTime = json['startTime'] ?? -1, + isolates = _createServiceObjectListOrNull( + json['isolates'], const ['IsolateRef']), + isolateGroups = _createServiceObjectListOrNull( + json['isolateGroups'], const ['IsolateGroupRef']), + systemIsolates = _createServiceObjectListOrNull( + json['systemIsolates'], const ['IsolateRef']), + systemIsolateGroups = _createServiceObjectListOrNull( + json['systemIsolateGroups'], const ['IsolateGroupRef']), + super._fromJson(); @override String get type => 'VM'; diff --git a/pkg/vm_service/tool/dart/generate_dart_client.dart b/pkg/vm_service/tool/dart/generate_dart_client.dart index 86386aaca01..3d042c98a87 100644 --- a/pkg/vm_service/tool/dart/generate_dart_client.dart +++ b/pkg/vm_service/tool/dart/generate_dart_client.dart @@ -515,7 +515,19 @@ dynamic _createSpecificObject( } } -Future extensionCallHelper(VmService service, String method, Map args) { +/// Returns a list of `T` using [createServiceObject] if [json] is non-`null`, +/// and `null` otherwise. +List? _createServiceObjectListOrNull( + Object? json, List expectedTypes) { + if (json == null) return null; + final serviceObject = createServiceObject(json, expectedTypes) as List?; + if (serviceObject == null) return []; + return List.from(serviceObject); +} + + +Future extensionCallHelper( + VmService service, String method, Map args) { return service._call(method, args); } diff --git a/pkg/vm_service/tool/dart/generate_dart_common.dart b/pkg/vm_service/tool/dart/generate_dart_common.dart index 5404e8f32d3..28c02060db1 100644 --- a/pkg/vm_service/tool/dart/generate_dart_common.dart +++ b/pkg/vm_service/tool/dart/generate_dart_common.dart @@ -648,18 +648,18 @@ class Type extends Member { gen.writeln(); if (name == 'Response' || name == 'TimelineEvent') { gen.write('$name._fromJson(Map this.json)'); - } else if (superName != null && fields.isEmpty) { - gen.write('$name._fromJson(super.json): super._fromJson()'); + } else if (superName != null) { + gen.write('$name._fromJson(super.json)'); } else { - final superCall = superName == null ? '' : ': super._fromJson(json) '; - gen.write('$name._fromJson(Map json) $superCall'); + gen.write('$name._fromJson(Map json)'); } - if (fields.isEmpty) { - gen.writeln(';'); - } else { - gen.writeln('{'); - } + final bool hasInitializers = fields.isNotEmpty || superName != null; + gen.writeln(hasInitializers ? ':' : ';'); + + // Controls whether we must call `_parseTokenPosTable` in the constructor + // body. + bool mustParseTokenPosTable = false; for (var field in fields) { if (field.type.isSimple || field.type.isEnum) { @@ -675,44 +675,43 @@ class Type extends Member { if (defaultValue != null) { gen.write(' ?? $defaultValue'); } - gen.writeln(';'); // } else if (field.type.isEnum) { // // Parse the enum. // String enumTypeName = field.type.types.first.name; // gen.writeln( - // "${field.generatableName} = _parse${enumTypeName}[json['${field.name}']];"); + // "${field.generatableName} = _parse${enumTypeName}[json['${field.name}']]"); } else if (name == 'Event' && field.name == 'extensionData') { // Special case `Event.extensionData`. gen.writeln( - "extensionData = ExtensionData.parse(json['extensionData']);"); + "extensionData = ExtensionData.parse(json['extensionData'])"); } else if (name == 'Instance' && field.name == 'associations') { // Special case `Instance.associations`. gen.writeln("associations = json['associations'] == null " '? null : List.from(' - "_createSpecificObject(json['associations'], MapAssociation.parse));"); + "_createSpecificObject(json['associations'], MapAssociation.parse))"); } else if (name == 'Instance' && field.name == 'classRef') { // This is populated by `Obj` } else if (name == '_CpuProfile' && field.name == 'codes') { // Special case `_CpuProfile.codes`. gen.writeln('codes = List.from(' - "_createSpecificObject(json['codes']!, CodeRegion.parse));"); + "_createSpecificObject(json['codes']!, CodeRegion.parse))"); } else if (name == '_CpuProfile' && field.name == 'functions') { // Special case `_CpuProfile.functions`. gen.writeln('functions = List.from(' - "_createSpecificObject(json['functions']!, ProfileFunction.parse));"); + "_createSpecificObject(json['functions']!, ProfileFunction.parse))"); } else if (name == 'SourceReport' && field.name == 'ranges') { // Special case `SourceReport.ranges`. gen.writeln('ranges = List.from(' - "_createSpecificObject(json['ranges']!, SourceReportRange.parse));"); + "_createSpecificObject(json['ranges']!, SourceReportRange.parse))"); } else if (name == 'SourceReportRange' && field.name == 'coverage') { // Special case `SourceReportRange.coverage`. gen.writeln('coverage = _createSpecificObject(' - "json['coverage'], SourceReportCoverage.parse);"); + "json['coverage'], SourceReportCoverage.parse)"); } else if (name == 'Library' && field.name == 'dependencies') { // Special case `Library.dependencies`. gen.writeln('dependencies = List.from(' "_createSpecificObject(json['dependencies']!, " - 'LibraryDependency.parse));'); + 'LibraryDependency.parse))'); } else if (name == 'Script' && field.name == 'tokenPosTable') { // Special case `Script.tokenPosTable`. gen.write('tokenPosTable = '); @@ -720,8 +719,8 @@ class Type extends Member { gen.write("json['tokenPosTable'] == null ? null : "); } gen.writeln("List>.from(json['tokenPosTable']!.map" - '((dynamic list) => List.from(list)));'); - gen.writeln('_parseTokenPosTable();'); + '((dynamic list) => List.from(list)))'); + mustParseTokenPosTable = true; } else if (field.type.isArray) { TypeRef fieldType = field.type.types.first; String typesList = typeRefListToString(field.type.types); @@ -729,10 +728,11 @@ class Type extends Member { if (field.optional) { if (fieldType.isListTypeSimple) { gen.writeln('${field.generatableName} = $ref == null ? null : ' - 'List<${fieldType.listTypeArg}>.from($ref);'); + 'List<${fieldType.listTypeArg}>.from($ref)'); } else { - gen.writeln('${field.generatableName} = $ref == null ? null : ' - 'List<${fieldType.listTypeArg}>.from(createServiceObject($ref, $typesList)! as List);'); + gen.writeln( + '${field.generatableName} = _createServiceObjectListOrNull' + '<${fieldType.listTypeArg}>($ref, $typesList)'); } } else { if (fieldType.isListTypeSimple) { @@ -740,20 +740,21 @@ class Type extends Member { // `new` and `old`. Post 3.18, these will be null. if (name == 'ClassHeapStats') { gen.writeln('${field.generatableName} = $ref == null ? null : ' - 'List<${fieldType.listTypeArg}>.from($ref);'); + 'List<${fieldType.listTypeArg}>.from($ref)'); } else { gen.writeln('${field.generatableName} = ' - 'List<${fieldType.listTypeArg}>.from($ref);'); + 'List<${fieldType.listTypeArg}>.from($ref)'); } } else { // Special case `InstanceSet`. Pre 3.20, instances were sent in a // field named 'samples' instead of 'instances'. if (name == 'InstanceSet') { gen.writeln('${field.generatableName} = ' - "List<${fieldType.listTypeArg}>.from(createServiceObject(($ref ?? json['samples']!) as List, $typesList)! as List);"); + "List<${fieldType.listTypeArg}>.from(createServiceObject(($ref ?? json['samples']!) as List, $typesList)! as List)"); } else { - gen.writeln('${field.generatableName} = ' - 'List<${fieldType.listTypeArg}>.from(createServiceObject($ref, $typesList) as List? ?? []);'); + gen.writeln( + '${field.generatableName} = _createServiceObjectListOrNull' + '<${fieldType.listTypeArg}>($ref, $typesList)'); } } } @@ -763,13 +764,26 @@ class Type extends Member { gen.writeln( '${field.generatableName} = ' "createServiceObject(json['${field.name}'], " - '$typesList) as ${field.type.name}$nullable;', + '$typesList) as ${field.type.name}$nullable', ); } + + if (superName != null || field != fields.last) { + gen.write(','); + } } - if (fields.isNotEmpty) { - gen.writeln('}'); + + if (name != 'Response' && name != 'TimelineEvent' && superName != null) { + gen.write('super._fromJson()'); } + if (mustParseTokenPosTable) { + gen.writeln('{'); + gen.writeln('_parseTokenPosTable();'); + gen.write('}'); + } else if (hasInitializers) { + gen.write(';'); + } + gen.writeln(); gen.writeln(); if (name == 'Script') { @@ -1105,6 +1119,9 @@ class TypeField extends Member { if (docs.isNotEmpty) gen.writeDocs(docs); if (optional) gen.write('@optional '); if (overrides || interfaceOverride) gen.write('@override '); + // TODO(srawlins): Most fields could be made final, now that they are + // assigned in field initializers. But this is a breaking change, so take + // care. // Special case where Instance extends Obj, but 'classRef' is not optional // for Instance although it is for Obj. /*if (parent.name == 'Instance' && generatableName == 'classRef') {