toJson method
Implementation
Map<String, dynamic> toJson() {
final identifiers = <Identifier>{
...calls.map((call) => call.definition.identifier),
...instances.map((instance) => instance.definition.identifier),
}.asMapToIndices;
final uris = <String>{
...identifiers.keys.map((e) => e.importUri),
...calls.expand((call) => [
call.definition.location.uri,
...call.references.map((reference) => reference.location.uri),
]),
...instances.expand((instance) => [
instance.definition.location.uri,
...instance.references.map((reference) => reference.location.uri),
]),
}.asMapToIndices;
final constants = {
...calls.expand((e) => e.references
.map((e) => e.arguments?.constArguments)
.whereType<ConstArguments>()
.expand((e) => {...e.named.values, ...e.positional.values})),
...instances.expand((element) => element.references).expand((e) => {
...e.instanceConstant.fields.values,
e.instanceConstant,
})
}.flatten().asMapToIndices;
return {
'metadata': metadata.toJson(),
'uris': uris.keys.toList(),
'ids': identifiers.keys
.map((identifier) => identifier.toJson(uris))
.toList(),
'constants':
constants.keys.map((constant) => constant.toJson(constants)).toList(),
if (calls.isNotEmpty)
'calls': calls
.map((reference) => reference.toJson(identifiers, uris, constants))
.toList(),
if (instances.isNotEmpty)
'instances': instances
.map((reference) => reference.toJson(identifiers, uris, constants))
.toList(),
};
}