diff --git a/pkgs/record_use/lib/src/data_classes/extensions.dart b/pkgs/record_use/lib/src/data_classes/extensions.dart index 34efc474..7c625bf9 100644 --- a/pkgs/record_use/lib/src/data_classes/extensions.dart +++ b/pkgs/record_use/lib/src/data_classes/extensions.dart @@ -16,8 +16,6 @@ extension UsagesExt on pb.Usages { pb_storage.Usages _toStorage() { final usageList = [...calls, ...instances]; - final definitions = - usageList.map((usage) => usage.definition).toSet().toList(); final uris = usageList .expand((usage) => [ usage.definition.identifier.uri, @@ -25,6 +23,10 @@ extension UsagesExt on pb.Usages { ]) .toSet() .toList(); + final definitions = usageList + .map((usage) => usage.definition.toStorage(uris)) + .toSet() + .toList(); return pb_storage.Usages( metadata: metadata, definitions: definitions, @@ -38,9 +40,9 @@ extension UsagesExt on pb.Usages { extension UsageExt on pb.Usage { pb_storage.Usage toStorage( - List definitions, List uris) => + List definitions, List uris) => pb_storage.Usage( - definition: definitions.indexOf(definition), + definition: definitions.indexOf(definition.toStorage(uris)), references: references.map((e) => e.toStorage(uris)), ); } @@ -62,6 +64,23 @@ extension LocationExt on pb.Location { ); } +extension DefinitionExt on pb.Definition { + pb_storage.Definition toStorage(List uris) => pb_storage.Definition( + identifier: identifier.toStorage(uris), + column: column, + line: line, + loadingUnit: hasLoadingUnit() ? loadingUnit : null, + ); +} + +extension IdentifierExt on pb.Identifier { + pb_storage.Identifier toStorage(List uris) => pb_storage.Identifier( + name: name, + parent: hasParent() ? parent : null, + uri: uris.indexOf(uri), + ); +} + extension UsagesStorageExt on pb_storage.Usages { pb.Usages toApi() => pb.Usages( metadata: metadata, @@ -71,9 +90,9 @@ extension UsagesStorageExt on pb_storage.Usages { } extension UsageStorageExt on pb_storage.Usage { - pb.Usage toApi(List definitions, List uris) => + pb.Usage toApi(List definitions, List uris) => pb.Usage( - definition: definitions[definition], + definition: definitions[definition].toApi(uris), references: references.map((e) => e.toApi(uris)), ); } @@ -95,6 +114,23 @@ extension LocationStorageExt on pb_storage.Location { ); } +extension DefinitionStorageExt on pb_storage.Definition { + pb.Definition toApi(List uris) => pb.Definition( + identifier: identifier.toApi(uris), + column: column, + line: line, + loadingUnit: hasLoadingUnit() ? loadingUnit : null, + ); +} + +extension IdentifierStorageExt on pb_storage.Identifier { + pb.Identifier toApi(List uris) => pb.Identifier( + name: name, + parent: hasParent() ? parent : null, + uri: uris[uri], + ); +} + extension FieldValueExt on pb_shared.FieldValue { Object toObject() => switch (whichValue()) { pb_shared.FieldValue_Value.intValue => intValue, diff --git a/pkgs/record_use/lib/src/proto/usages_read.pb.dart b/pkgs/record_use/lib/src/proto/usages_read.pb.dart index a4a474c4..5d897d07 100644 --- a/pkgs/record_use/lib/src/proto/usages_read.pb.dart +++ b/pkgs/record_use/lib/src/proto/usages_read.pb.dart @@ -97,7 +97,7 @@ class Usages extends $pb.GeneratedMessage { class Usage extends $pb.GeneratedMessage { factory Usage({ - $0.Definition? definition, + Definition? definition, $core.Iterable? references, }) { final $result = create(); @@ -121,8 +121,8 @@ class Usage extends $pb.GeneratedMessage { _omitMessageNames ? '' : 'Usage', package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'), createEmptyInstance: create) - ..aOM<$0.Definition>(1, _omitFieldNames ? '' : 'definition', - subBuilder: $0.Definition.create) + ..aOM(1, _omitFieldNames ? '' : 'definition', + subBuilder: Definition.create) ..pc(2, _omitFieldNames ? '' : 'references', $pb.PbFieldType.PM, subBuilder: Reference.create) ..hasRequiredFields = false; @@ -149,9 +149,9 @@ class Usage extends $pb.GeneratedMessage { static Usage? _defaultInstance; @$pb.TagNumber(1) - $0.Definition get definition => $_getN(0); + Definition get definition => $_getN(0); @$pb.TagNumber(1) - set definition($0.Definition v) { + set definition(Definition v) { setField(1, v); } @@ -160,7 +160,7 @@ class Usage extends $pb.GeneratedMessage { @$pb.TagNumber(1) void clearDefinition() => clearField(1); @$pb.TagNumber(1) - $0.Definition ensureDefinition() => $_ensure(0); + Definition ensureDefinition() => $_ensure(0); @$pb.TagNumber(2) $core.List get references => $_getList(1); @@ -391,6 +391,212 @@ class Reference extends $pb.GeneratedMessage { $0.Fields ensureFields() => $_ensure(3); } +class Definition extends $pb.GeneratedMessage { + factory Definition({ + Identifier? identifier, + $core.int? line, + $core.int? column, + $core.String? loadingUnit, + }) { + final $result = create(); + if (identifier != null) { + $result.identifier = identifier; + } + if (line != null) { + $result.line = line; + } + if (column != null) { + $result.column = column; + } + if (loadingUnit != null) { + $result.loadingUnit = loadingUnit; + } + return $result; + } + Definition._() : super(); + factory Definition.fromBuffer($core.List<$core.int> i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromBuffer(i, r); + factory Definition.fromJson($core.String i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromJson(i, r); + + static final $pb.BuilderInfo _i = $pb.BuilderInfo( + _omitMessageNames ? '' : 'Definition', + package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'), + createEmptyInstance: create) + ..aOM(1, _omitFieldNames ? '' : 'identifier', + subBuilder: Identifier.create) + ..a<$core.int>(2, _omitFieldNames ? '' : 'line', $pb.PbFieldType.OU3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'column', $pb.PbFieldType.OU3) + ..aOS(4, _omitFieldNames ? '' : 'loadingUnit') + ..hasRequiredFields = false; + + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + Definition clone() => Definition()..mergeFromMessage(this); + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + Definition copyWith(void Function(Definition) updates) => + super.copyWith((message) => updates(message as Definition)) as Definition; + + $pb.BuilderInfo get info_ => _i; + + @$core.pragma('dart2js:noInline') + static Definition create() => Definition._(); + Definition createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static Definition getDefault() => _defaultInstance ??= + $pb.GeneratedMessage.$_defaultFor(create); + static Definition? _defaultInstance; + + @$pb.TagNumber(1) + Identifier get identifier => $_getN(0); + @$pb.TagNumber(1) + set identifier(Identifier v) { + setField(1, v); + } + + @$pb.TagNumber(1) + $core.bool hasIdentifier() => $_has(0); + @$pb.TagNumber(1) + void clearIdentifier() => clearField(1); + @$pb.TagNumber(1) + Identifier ensureIdentifier() => $_ensure(0); + + @$pb.TagNumber(2) + $core.int get line => $_getIZ(1); + @$pb.TagNumber(2) + set line($core.int v) { + $_setUnsignedInt32(1, v); + } + + @$pb.TagNumber(2) + $core.bool hasLine() => $_has(1); + @$pb.TagNumber(2) + void clearLine() => clearField(2); + + @$pb.TagNumber(3) + $core.int get column => $_getIZ(2); + @$pb.TagNumber(3) + set column($core.int v) { + $_setUnsignedInt32(2, v); + } + + @$pb.TagNumber(3) + $core.bool hasColumn() => $_has(2); + @$pb.TagNumber(3) + void clearColumn() => clearField(3); + + @$pb.TagNumber(4) + $core.String get loadingUnit => $_getSZ(3); + @$pb.TagNumber(4) + set loadingUnit($core.String v) { + $_setString(3, v); + } + + @$pb.TagNumber(4) + $core.bool hasLoadingUnit() => $_has(3); + @$pb.TagNumber(4) + void clearLoadingUnit() => clearField(4); +} + +class Identifier extends $pb.GeneratedMessage { + factory Identifier({ + $core.String? uri, + $core.String? parent, + $core.String? name, + }) { + final $result = create(); + if (uri != null) { + $result.uri = uri; + } + if (parent != null) { + $result.parent = parent; + } + if (name != null) { + $result.name = name; + } + return $result; + } + Identifier._() : super(); + factory Identifier.fromBuffer($core.List<$core.int> i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromBuffer(i, r); + factory Identifier.fromJson($core.String i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromJson(i, r); + + static final $pb.BuilderInfo _i = $pb.BuilderInfo( + _omitMessageNames ? '' : 'Identifier', + package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'), + createEmptyInstance: create) + ..aOS(1, _omitFieldNames ? '' : 'uri') + ..aOS(2, _omitFieldNames ? '' : 'parent') + ..aOS(3, _omitFieldNames ? '' : 'name') + ..hasRequiredFields = false; + + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + Identifier clone() => Identifier()..mergeFromMessage(this); + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + Identifier copyWith(void Function(Identifier) updates) => + super.copyWith((message) => updates(message as Identifier)) as Identifier; + + $pb.BuilderInfo get info_ => _i; + + @$core.pragma('dart2js:noInline') + static Identifier create() => Identifier._(); + Identifier createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static Identifier getDefault() => _defaultInstance ??= + $pb.GeneratedMessage.$_defaultFor(create); + static Identifier? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get uri => $_getSZ(0); + @$pb.TagNumber(1) + set uri($core.String v) { + $_setString(0, v); + } + + @$pb.TagNumber(1) + $core.bool hasUri() => $_has(0); + @$pb.TagNumber(1) + void clearUri() => clearField(1); + + @$pb.TagNumber(2) + $core.String get parent => $_getSZ(1); + @$pb.TagNumber(2) + set parent($core.String v) { + $_setString(1, v); + } + + @$pb.TagNumber(2) + $core.bool hasParent() => $_has(1); + @$pb.TagNumber(2) + void clearParent() => clearField(2); + + @$pb.TagNumber(3) + $core.String get name => $_getSZ(2); + @$pb.TagNumber(3) + set name($core.String v) { + $_setString(2, v); + } + + @$pb.TagNumber(3) + $core.bool hasName() => $_has(2); + @$pb.TagNumber(3) + void clearName() => clearField(3); +} + const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); const _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names'); diff --git a/pkgs/record_use/lib/src/proto/usages_read.pbjson.dart b/pkgs/record_use/lib/src/proto/usages_read.pbjson.dart index a67c0fea..82b4dc57 100644 --- a/pkgs/record_use/lib/src/proto/usages_read.pbjson.dart +++ b/pkgs/record_use/lib/src/proto/usages_read.pbjson.dart @@ -4,7 +4,7 @@ // // @dart = 2.12 -// ignore_for_file: annotate_overrides, camel_case_types, comment_references +// ignore_for_file: annotate_overrides, camel_case_types, comment_references, lines_longer_than_80_chars // ignore_for_file: constant_identifier_names, library_prefixes // ignore_for_file: non_constant_identifier_names, prefer_final_fields // ignore_for_file: unnecessary_import, unnecessary_this, unused_import @@ -59,7 +59,7 @@ const Usage$json = { '3': 1, '4': 1, '5': 11, - '6': '.usages_shared.Definition', + '6': '.usages.Definition', '10': 'definition' }, { @@ -75,9 +75,8 @@ const Usage$json = { /// Descriptor for `Usage`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List usageDescriptor = $convert.base64Decode( - 'CgVVc2FnZRI5CgpkZWZpbml0aW9uGAEgASgLMhkudXNhZ2VzX3NoYXJlZC5EZWZpbml0aW9uUg' - 'pkZWZpbml0aW9uEjEKCnJlZmVyZW5jZXMYAiADKAsyES51c2FnZXMuUmVmZXJlbmNlUgpyZWZl' - 'cmVuY2Vz'); + 'CgVVc2FnZRIyCgpkZWZpbml0aW9uGAEgASgLMhIudXNhZ2VzLkRlZmluaXRpb25SCmRlZmluaX' + 'Rpb24SMQoKcmVmZXJlbmNlcxgCIAMoCzIRLnVzYWdlcy5SZWZlcmVuY2VSCnJlZmVyZW5jZXM='); @$core.Deprecated('Use locationDescriptor instead') const Location$json = { @@ -137,3 +136,56 @@ final $typed_data.Uint8List referenceDescriptor = $convert.base64Decode( '9uEiEKDGxvYWRpbmdfdW5pdBgCIAEoCVILbG9hZGluZ1VuaXQSOAoJYXJndW1lbnRzGAMgASgL' 'MhgudXNhZ2VzX3NoYXJlZC5Bcmd1bWVudHNIAFIJYXJndW1lbnRzEi8KBmZpZWxkcxgEIAEoCz' 'IVLnVzYWdlc19zaGFyZWQuRmllbGRzSABSBmZpZWxkc0ILCglyZWZlcmVuY2U='); + +@$core.Deprecated('Use definitionDescriptor instead') +const Definition$json = { + '1': 'Definition', + '2': [ + { + '1': 'identifier', + '3': 1, + '4': 1, + '5': 11, + '6': '.usages.Identifier', + '10': 'identifier' + }, + {'1': 'line', '3': 2, '4': 1, '5': 13, '10': 'line'}, + {'1': 'column', '3': 3, '4': 1, '5': 13, '10': 'column'}, + { + '1': 'loading_unit', + '3': 4, + '4': 1, + '5': 9, + '9': 0, + '10': 'loadingUnit', + '17': true + }, + ], + '8': [ + {'1': '_loading_unit'}, + ], +}; + +/// Descriptor for `Definition`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List definitionDescriptor = $convert.base64Decode( + 'CgpEZWZpbml0aW9uEjIKCmlkZW50aWZpZXIYASABKAsyEi51c2FnZXMuSWRlbnRpZmllclIKaW' + 'RlbnRpZmllchISCgRsaW5lGAIgASgNUgRsaW5lEhYKBmNvbHVtbhgDIAEoDVIGY29sdW1uEiYK' + 'DGxvYWRpbmdfdW5pdBgEIAEoCUgAUgtsb2FkaW5nVW5pdIgBAUIPCg1fbG9hZGluZ191bml0'); + +@$core.Deprecated('Use identifierDescriptor instead') +const Identifier$json = { + '1': 'Identifier', + '2': [ + {'1': 'uri', '3': 1, '4': 1, '5': 9, '10': 'uri'}, + {'1': 'parent', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'parent', '17': true}, + {'1': 'name', '3': 3, '4': 1, '5': 9, '10': 'name'}, + ], + '8': [ + {'1': '_parent'}, + ], +}; + +/// Descriptor for `Identifier`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List identifierDescriptor = $convert.base64Decode( + 'CgpJZGVudGlmaWVyEhAKA3VyaRgBIAEoCVIDdXJpEhsKBnBhcmVudBgCIAEoCUgAUgZwYXJlbn' + 'SIAQESEgoEbmFtZRgDIAEoCVIEbmFtZUIJCgdfcGFyZW50'); diff --git a/pkgs/record_use/lib/src/proto/usages_read.proto b/pkgs/record_use/lib/src/proto/usages_read.proto index 2cefbb9a..5e113621 100644 --- a/pkgs/record_use/lib/src/proto/usages_read.proto +++ b/pkgs/record_use/lib/src/proto/usages_read.proto @@ -10,7 +10,7 @@ message Usages { } message Usage { - usages_shared.Definition definition = 1; + Definition definition = 1; repeated Reference references = 2; } @@ -29,3 +29,16 @@ message Reference { usages_shared.Fields fields = 4; } } + +message Definition { + Identifier identifier = 1; + uint32 line = 2; + uint32 column = 3; + optional string loading_unit = 4; // Optional, as some loading units are null +} + +message Identifier { + string uri = 1; + optional string parent = 2; + string name = 3; +} diff --git a/pkgs/record_use/lib/src/proto/usages_shared.pb.dart b/pkgs/record_use/lib/src/proto/usages_shared.pb.dart index 9fcecda3..ea404c21 100644 --- a/pkgs/record_use/lib/src/proto/usages_shared.pb.dart +++ b/pkgs/record_use/lib/src/proto/usages_shared.pb.dart @@ -89,212 +89,6 @@ class Metadata extends $pb.GeneratedMessage { void clearVersion() => clearField(2); } -class Definition extends $pb.GeneratedMessage { - factory Definition({ - Identifier? identifier, - $core.int? line, - $core.int? column, - $core.String? loadingUnit, - }) { - final $result = create(); - if (identifier != null) { - $result.identifier = identifier; - } - if (line != null) { - $result.line = line; - } - if (column != null) { - $result.column = column; - } - if (loadingUnit != null) { - $result.loadingUnit = loadingUnit; - } - return $result; - } - Definition._() : super(); - factory Definition.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - factory Definition.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - _omitMessageNames ? '' : 'Definition', - package: const $pb.PackageName(_omitMessageNames ? '' : 'usages_shared'), - createEmptyInstance: create) - ..aOM(1, _omitFieldNames ? '' : 'identifier', - subBuilder: Identifier.create) - ..a<$core.int>(2, _omitFieldNames ? '' : 'line', $pb.PbFieldType.OU3) - ..a<$core.int>(3, _omitFieldNames ? '' : 'column', $pb.PbFieldType.OU3) - ..aOS(4, _omitFieldNames ? '' : 'loadingUnit') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - Definition clone() => Definition()..mergeFromMessage(this); - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - Definition copyWith(void Function(Definition) updates) => - super.copyWith((message) => updates(message as Definition)) as Definition; - - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static Definition create() => Definition._(); - Definition createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); - @$core.pragma('dart2js:noInline') - static Definition getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static Definition? _defaultInstance; - - @$pb.TagNumber(1) - Identifier get identifier => $_getN(0); - @$pb.TagNumber(1) - set identifier(Identifier v) { - setField(1, v); - } - - @$pb.TagNumber(1) - $core.bool hasIdentifier() => $_has(0); - @$pb.TagNumber(1) - void clearIdentifier() => clearField(1); - @$pb.TagNumber(1) - Identifier ensureIdentifier() => $_ensure(0); - - @$pb.TagNumber(2) - $core.int get line => $_getIZ(1); - @$pb.TagNumber(2) - set line($core.int v) { - $_setUnsignedInt32(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasLine() => $_has(1); - @$pb.TagNumber(2) - void clearLine() => clearField(2); - - @$pb.TagNumber(3) - $core.int get column => $_getIZ(2); - @$pb.TagNumber(3) - set column($core.int v) { - $_setUnsignedInt32(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasColumn() => $_has(2); - @$pb.TagNumber(3) - void clearColumn() => clearField(3); - - @$pb.TagNumber(4) - $core.String get loadingUnit => $_getSZ(3); - @$pb.TagNumber(4) - set loadingUnit($core.String v) { - $_setString(3, v); - } - - @$pb.TagNumber(4) - $core.bool hasLoadingUnit() => $_has(3); - @$pb.TagNumber(4) - void clearLoadingUnit() => clearField(4); -} - -class Identifier extends $pb.GeneratedMessage { - factory Identifier({ - $core.String? uri, - $core.String? parent, - $core.String? name, - }) { - final $result = create(); - if (uri != null) { - $result.uri = uri; - } - if (parent != null) { - $result.parent = parent; - } - if (name != null) { - $result.name = name; - } - return $result; - } - Identifier._() : super(); - factory Identifier.fromBuffer($core.List<$core.int> i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromBuffer(i, r); - factory Identifier.fromJson($core.String i, - [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => - create()..mergeFromJson(i, r); - - static final $pb.BuilderInfo _i = $pb.BuilderInfo( - _omitMessageNames ? '' : 'Identifier', - package: const $pb.PackageName(_omitMessageNames ? '' : 'usages_shared'), - createEmptyInstance: create) - ..aOS(1, _omitFieldNames ? '' : 'uri') - ..aOS(2, _omitFieldNames ? '' : 'parent') - ..aOS(3, _omitFieldNames ? '' : 'name') - ..hasRequiredFields = false; - - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' - 'Will be removed in next major version') - Identifier clone() => Identifier()..mergeFromMessage(this); - @$core.Deprecated('Using this can add significant overhead to your binary. ' - 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' - 'Will be removed in next major version') - Identifier copyWith(void Function(Identifier) updates) => - super.copyWith((message) => updates(message as Identifier)) as Identifier; - - $pb.BuilderInfo get info_ => _i; - - @$core.pragma('dart2js:noInline') - static Identifier create() => Identifier._(); - Identifier createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); - @$core.pragma('dart2js:noInline') - static Identifier getDefault() => _defaultInstance ??= - $pb.GeneratedMessage.$_defaultFor(create); - static Identifier? _defaultInstance; - - @$pb.TagNumber(1) - $core.String get uri => $_getSZ(0); - @$pb.TagNumber(1) - set uri($core.String v) { - $_setString(0, v); - } - - @$pb.TagNumber(1) - $core.bool hasUri() => $_has(0); - @$pb.TagNumber(1) - void clearUri() => clearField(1); - - @$pb.TagNumber(2) - $core.String get parent => $_getSZ(1); - @$pb.TagNumber(2) - set parent($core.String v) { - $_setString(1, v); - } - - @$pb.TagNumber(2) - $core.bool hasParent() => $_has(1); - @$pb.TagNumber(2) - void clearParent() => clearField(2); - - @$pb.TagNumber(3) - $core.String get name => $_getSZ(2); - @$pb.TagNumber(3) - set name($core.String v) { - $_setString(2, v); - } - - @$pb.TagNumber(3) - $core.bool hasName() => $_has(2); - @$pb.TagNumber(3) - void clearName() => clearField(3); -} - class Fields extends $pb.GeneratedMessage { factory Fields({ $core.Iterable? fields, diff --git a/pkgs/record_use/lib/src/proto/usages_shared.pbjson.dart b/pkgs/record_use/lib/src/proto/usages_shared.pbjson.dart index 4f42cd49..4b0149e3 100644 --- a/pkgs/record_use/lib/src/proto/usages_shared.pbjson.dart +++ b/pkgs/record_use/lib/src/proto/usages_shared.pbjson.dart @@ -38,60 +38,6 @@ final $typed_data.Uint8List metadataDescriptor = $convert.base64Decode( 'CghNZXRhZGF0YRIdCgdjb21tZW50GAEgASgJSABSB2NvbW1lbnSIAQESGAoHdmVyc2lvbhgCIA' 'EoCVIHdmVyc2lvbkIKCghfY29tbWVudA=='); -@$core.Deprecated('Use definitionDescriptor instead') -const Definition$json = { - '1': 'Definition', - '2': [ - { - '1': 'identifier', - '3': 1, - '4': 1, - '5': 11, - '6': '.usages_shared.Identifier', - '10': 'identifier' - }, - {'1': 'line', '3': 2, '4': 1, '5': 13, '10': 'line'}, - {'1': 'column', '3': 3, '4': 1, '5': 13, '10': 'column'}, - { - '1': 'loading_unit', - '3': 4, - '4': 1, - '5': 9, - '9': 0, - '10': 'loadingUnit', - '17': true - }, - ], - '8': [ - {'1': '_loading_unit'}, - ], -}; - -/// Descriptor for `Definition`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List definitionDescriptor = $convert.base64Decode( - 'CgpEZWZpbml0aW9uEjkKCmlkZW50aWZpZXIYASABKAsyGS51c2FnZXNfc2hhcmVkLklkZW50aW' - 'ZpZXJSCmlkZW50aWZpZXISEgoEbGluZRgCIAEoDVIEbGluZRIWCgZjb2x1bW4YAyABKA1SBmNv' - 'bHVtbhImCgxsb2FkaW5nX3VuaXQYBCABKAlIAFILbG9hZGluZ1VuaXSIAQFCDwoNX2xvYWRpbm' - 'dfdW5pdA=='); - -@$core.Deprecated('Use identifierDescriptor instead') -const Identifier$json = { - '1': 'Identifier', - '2': [ - {'1': 'uri', '3': 1, '4': 1, '5': 9, '10': 'uri'}, - {'1': 'parent', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'parent', '17': true}, - {'1': 'name', '3': 3, '4': 1, '5': 9, '10': 'name'}, - ], - '8': [ - {'1': '_parent'}, - ], -}; - -/// Descriptor for `Identifier`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List identifierDescriptor = $convert.base64Decode( - 'CgpJZGVudGlmaWVyEhAKA3VyaRgBIAEoCVIDdXJpEhsKBnBhcmVudBgCIAEoCUgAUgZwYXJlbn' - 'SIAQESEgoEbmFtZRgDIAEoCVIEbmFtZUIJCgdfcGFyZW50'); - @$core.Deprecated('Use fieldsDescriptor instead') const Fields$json = { '1': 'Fields', diff --git a/pkgs/record_use/lib/src/proto/usages_shared.proto b/pkgs/record_use/lib/src/proto/usages_shared.proto index fea9ef20..03a44866 100644 --- a/pkgs/record_use/lib/src/proto/usages_shared.proto +++ b/pkgs/record_use/lib/src/proto/usages_shared.proto @@ -6,19 +6,6 @@ message Metadata { string version = 2; } -message Definition { - Identifier identifier = 1; - uint32 line = 2; - uint32 column = 3; - optional string loading_unit = 4; // Optional, as some loading units are null -} - -message Identifier { - string uri = 1; - optional string parent = 2; - string name = 3; -} - message Fields { repeated Field fields = 1; } diff --git a/pkgs/record_use/lib/src/proto/usages_storage.pb.dart b/pkgs/record_use/lib/src/proto/usages_storage.pb.dart index 55a43ea8..6087a26a 100644 --- a/pkgs/record_use/lib/src/proto/usages_storage.pb.dart +++ b/pkgs/record_use/lib/src/proto/usages_storage.pb.dart @@ -19,7 +19,7 @@ class Usages extends $pb.GeneratedMessage { factory Usages({ $0.Metadata? metadata, $core.Iterable<$core.String>? uris, - $core.Iterable<$0.Definition>? definitions, + $core.Iterable? definitions, $core.Iterable? calls, $core.Iterable? instances, }) { @@ -56,9 +56,9 @@ class Usages extends $pb.GeneratedMessage { ..aOM<$0.Metadata>(1, _omitFieldNames ? '' : 'metadata', subBuilder: $0.Metadata.create) ..pPS(2, _omitFieldNames ? '' : 'uris') - ..pc<$0.Definition>( + ..pc( 3, _omitFieldNames ? '' : 'definitions', $pb.PbFieldType.PM, - subBuilder: $0.Definition.create) + subBuilder: Definition.create) ..pc(4, _omitFieldNames ? '' : 'calls', $pb.PbFieldType.PM, subBuilder: Usage.create) ..pc(5, _omitFieldNames ? '' : 'instances', $pb.PbFieldType.PM, @@ -104,7 +104,7 @@ class Usages extends $pb.GeneratedMessage { $core.List<$core.String> get uris => $_getList(1); @$pb.TagNumber(3) - $core.List<$0.Definition> get definitions => $_getList(2); + $core.List get definitions => $_getList(2); @$pb.TagNumber(4) $core.List get calls => $_getList(3); @@ -406,6 +406,212 @@ class Reference extends $pb.GeneratedMessage { $0.Fields ensureFields() => $_ensure(3); } +class Definition extends $pb.GeneratedMessage { + factory Definition({ + Identifier? identifier, + $core.int? line, + $core.int? column, + $core.String? loadingUnit, + }) { + final $result = create(); + if (identifier != null) { + $result.identifier = identifier; + } + if (line != null) { + $result.line = line; + } + if (column != null) { + $result.column = column; + } + if (loadingUnit != null) { + $result.loadingUnit = loadingUnit; + } + return $result; + } + Definition._() : super(); + factory Definition.fromBuffer($core.List<$core.int> i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromBuffer(i, r); + factory Definition.fromJson($core.String i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromJson(i, r); + + static final $pb.BuilderInfo _i = $pb.BuilderInfo( + _omitMessageNames ? '' : 'Definition', + package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'), + createEmptyInstance: create) + ..aOM(1, _omitFieldNames ? '' : 'identifier', + subBuilder: Identifier.create) + ..a<$core.int>(2, _omitFieldNames ? '' : 'line', $pb.PbFieldType.OU3) + ..a<$core.int>(3, _omitFieldNames ? '' : 'column', $pb.PbFieldType.OU3) + ..aOS(4, _omitFieldNames ? '' : 'loadingUnit') + ..hasRequiredFields = false; + + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + Definition clone() => Definition()..mergeFromMessage(this); + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + Definition copyWith(void Function(Definition) updates) => + super.copyWith((message) => updates(message as Definition)) as Definition; + + $pb.BuilderInfo get info_ => _i; + + @$core.pragma('dart2js:noInline') + static Definition create() => Definition._(); + Definition createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static Definition getDefault() => _defaultInstance ??= + $pb.GeneratedMessage.$_defaultFor(create); + static Definition? _defaultInstance; + + @$pb.TagNumber(1) + Identifier get identifier => $_getN(0); + @$pb.TagNumber(1) + set identifier(Identifier v) { + setField(1, v); + } + + @$pb.TagNumber(1) + $core.bool hasIdentifier() => $_has(0); + @$pb.TagNumber(1) + void clearIdentifier() => clearField(1); + @$pb.TagNumber(1) + Identifier ensureIdentifier() => $_ensure(0); + + @$pb.TagNumber(2) + $core.int get line => $_getIZ(1); + @$pb.TagNumber(2) + set line($core.int v) { + $_setUnsignedInt32(1, v); + } + + @$pb.TagNumber(2) + $core.bool hasLine() => $_has(1); + @$pb.TagNumber(2) + void clearLine() => clearField(2); + + @$pb.TagNumber(3) + $core.int get column => $_getIZ(2); + @$pb.TagNumber(3) + set column($core.int v) { + $_setUnsignedInt32(2, v); + } + + @$pb.TagNumber(3) + $core.bool hasColumn() => $_has(2); + @$pb.TagNumber(3) + void clearColumn() => clearField(3); + + @$pb.TagNumber(4) + $core.String get loadingUnit => $_getSZ(3); + @$pb.TagNumber(4) + set loadingUnit($core.String v) { + $_setString(3, v); + } + + @$pb.TagNumber(4) + $core.bool hasLoadingUnit() => $_has(3); + @$pb.TagNumber(4) + void clearLoadingUnit() => clearField(4); +} + +class Identifier extends $pb.GeneratedMessage { + factory Identifier({ + $core.int? uri, + $core.String? parent, + $core.String? name, + }) { + final $result = create(); + if (uri != null) { + $result.uri = uri; + } + if (parent != null) { + $result.parent = parent; + } + if (name != null) { + $result.name = name; + } + return $result; + } + Identifier._() : super(); + factory Identifier.fromBuffer($core.List<$core.int> i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromBuffer(i, r); + factory Identifier.fromJson($core.String i, + [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => + create()..mergeFromJson(i, r); + + static final $pb.BuilderInfo _i = $pb.BuilderInfo( + _omitMessageNames ? '' : 'Identifier', + package: const $pb.PackageName(_omitMessageNames ? '' : 'usages'), + createEmptyInstance: create) + ..a<$core.int>(1, _omitFieldNames ? '' : 'uri', $pb.PbFieldType.OU3) + ..aOS(2, _omitFieldNames ? '' : 'parent') + ..aOS(3, _omitFieldNames ? '' : 'name') + ..hasRequiredFields = false; + + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + Identifier clone() => Identifier()..mergeFromMessage(this); + @$core.Deprecated('Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + Identifier copyWith(void Function(Identifier) updates) => + super.copyWith((message) => updates(message as Identifier)) as Identifier; + + $pb.BuilderInfo get info_ => _i; + + @$core.pragma('dart2js:noInline') + static Identifier create() => Identifier._(); + Identifier createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static Identifier getDefault() => _defaultInstance ??= + $pb.GeneratedMessage.$_defaultFor(create); + static Identifier? _defaultInstance; + + @$pb.TagNumber(1) + $core.int get uri => $_getIZ(0); + @$pb.TagNumber(1) + set uri($core.int v) { + $_setUnsignedInt32(0, v); + } + + @$pb.TagNumber(1) + $core.bool hasUri() => $_has(0); + @$pb.TagNumber(1) + void clearUri() => clearField(1); + + @$pb.TagNumber(2) + $core.String get parent => $_getSZ(1); + @$pb.TagNumber(2) + set parent($core.String v) { + $_setString(1, v); + } + + @$pb.TagNumber(2) + $core.bool hasParent() => $_has(1); + @$pb.TagNumber(2) + void clearParent() => clearField(2); + + @$pb.TagNumber(3) + $core.String get name => $_getSZ(2); + @$pb.TagNumber(3) + set name($core.String v) { + $_setString(2, v); + } + + @$pb.TagNumber(3) + $core.bool hasName() => $_has(2); + @$pb.TagNumber(3) + void clearName() => clearField(3); +} + const _omitFieldNames = $core.bool.fromEnvironment('protobuf.omit_field_names'); const _omitMessageNames = $core.bool.fromEnvironment('protobuf.omit_message_names'); diff --git a/pkgs/record_use/lib/src/proto/usages_storage.pbjson.dart b/pkgs/record_use/lib/src/proto/usages_storage.pbjson.dart index 450e2a32..3eca781b 100644 --- a/pkgs/record_use/lib/src/proto/usages_storage.pbjson.dart +++ b/pkgs/record_use/lib/src/proto/usages_storage.pbjson.dart @@ -31,7 +31,7 @@ const Usages$json = { '3': 3, '4': 3, '5': 11, - '6': '.usages_shared.Definition', + '6': '.usages.Definition', '10': 'definitions' }, { @@ -56,10 +56,9 @@ const Usages$json = { /// Descriptor for `Usages`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List usagesDescriptor = $convert.base64Decode( 'CgZVc2FnZXMSMwoIbWV0YWRhdGEYASABKAsyFy51c2FnZXNfc2hhcmVkLk1ldGFkYXRhUghtZX' - 'RhZGF0YRISCgR1cmlzGAIgAygJUgR1cmlzEjsKC2RlZmluaXRpb25zGAMgAygLMhkudXNhZ2Vz' - 'X3NoYXJlZC5EZWZpbml0aW9uUgtkZWZpbml0aW9ucxIjCgVjYWxscxgEIAMoCzINLnVzYWdlcy' - '5Vc2FnZVIFY2FsbHMSKwoJaW5zdGFuY2VzGAUgAygLMg0udXNhZ2VzLlVzYWdlUglpbnN0YW5j' - 'ZXM='); + 'RhZGF0YRISCgR1cmlzGAIgAygJUgR1cmlzEjQKC2RlZmluaXRpb25zGAMgAygLMhIudXNhZ2Vz' + 'LkRlZmluaXRpb25SC2RlZmluaXRpb25zEiMKBWNhbGxzGAQgAygLMg0udXNhZ2VzLlVzYWdlUg' + 'VjYWxscxIrCglpbnN0YW5jZXMYBSADKAsyDS51c2FnZXMuVXNhZ2VSCWluc3RhbmNlcw=='); @$core.Deprecated('Use usageDescriptor instead') const Usage$json = { @@ -140,3 +139,56 @@ final $typed_data.Uint8List referenceDescriptor = $convert.base64Decode( '9uEiEKDGxvYWRpbmdfdW5pdBgCIAEoCVILbG9hZGluZ1VuaXQSOAoJYXJndW1lbnRzGAMgASgL' 'MhgudXNhZ2VzX3NoYXJlZC5Bcmd1bWVudHNIAFIJYXJndW1lbnRzEi8KBmZpZWxkcxgEIAEoCz' 'IVLnVzYWdlc19zaGFyZWQuRmllbGRzSABSBmZpZWxkc0ILCglyZWZlcmVuY2U='); + +@$core.Deprecated('Use definitionDescriptor instead') +const Definition$json = { + '1': 'Definition', + '2': [ + { + '1': 'identifier', + '3': 1, + '4': 1, + '5': 11, + '6': '.usages.Identifier', + '10': 'identifier' + }, + {'1': 'line', '3': 2, '4': 1, '5': 13, '10': 'line'}, + {'1': 'column', '3': 3, '4': 1, '5': 13, '10': 'column'}, + { + '1': 'loading_unit', + '3': 4, + '4': 1, + '5': 9, + '9': 0, + '10': 'loadingUnit', + '17': true + }, + ], + '8': [ + {'1': '_loading_unit'}, + ], +}; + +/// Descriptor for `Definition`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List definitionDescriptor = $convert.base64Decode( + 'CgpEZWZpbml0aW9uEjIKCmlkZW50aWZpZXIYASABKAsyEi51c2FnZXMuSWRlbnRpZmllclIKaW' + 'RlbnRpZmllchISCgRsaW5lGAIgASgNUgRsaW5lEhYKBmNvbHVtbhgDIAEoDVIGY29sdW1uEiYK' + 'DGxvYWRpbmdfdW5pdBgEIAEoCUgAUgtsb2FkaW5nVW5pdIgBAUIPCg1fbG9hZGluZ191bml0'); + +@$core.Deprecated('Use identifierDescriptor instead') +const Identifier$json = { + '1': 'Identifier', + '2': [ + {'1': 'uri', '3': 1, '4': 1, '5': 13, '10': 'uri'}, + {'1': 'parent', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'parent', '17': true}, + {'1': 'name', '3': 3, '4': 1, '5': 9, '10': 'name'}, + ], + '8': [ + {'1': '_parent'}, + ], +}; + +/// Descriptor for `Identifier`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List identifierDescriptor = $convert.base64Decode( + 'CgpJZGVudGlmaWVyEhAKA3VyaRgBIAEoDVIDdXJpEhsKBnBhcmVudBgCIAEoCUgAUgZwYXJlbn' + 'SIAQESEgoEbmFtZRgDIAEoCVIEbmFtZUIJCgdfcGFyZW50'); diff --git a/pkgs/record_use/lib/src/proto/usages_storage.proto b/pkgs/record_use/lib/src/proto/usages_storage.proto index 45486311..bcc90414 100644 --- a/pkgs/record_use/lib/src/proto/usages_storage.proto +++ b/pkgs/record_use/lib/src/proto/usages_storage.proto @@ -6,7 +6,7 @@ import "usages_shared.proto"; message Usages { usages_shared.Metadata metadata = 1; repeated string uris = 2; - repeated usages_shared.Definition definitions = 3; + repeated Definition definitions = 3; repeated Usage calls = 4; repeated Usage instances = 5; } @@ -30,3 +30,16 @@ message Reference { usages_shared.Fields fields = 4; } } + +message Definition { + Identifier identifier = 1; + uint32 line = 2; + uint32 column = 3; + optional string loading_unit = 4; // Optional, as some loading units are null +} + +message Identifier { + uint32 uri = 1; + optional string parent = 2; + string name = 3; +} diff --git a/pkgs/record_use/lib/src/record_use.dart b/pkgs/record_use/lib/src/record_use.dart index 1d36527c..5016691a 100644 --- a/pkgs/record_use/lib/src/record_use.dart +++ b/pkgs/record_use/lib/src/record_use.dart @@ -9,7 +9,6 @@ import 'package:pub_semver/pub_semver.dart'; import 'data_classes/extensions.dart'; import 'proto/usages_read.pb.dart' as pb; -import 'proto/usages_shared.pb.dart' as pb_shared; import 'proto/usages_storage.pb.dart' as pb_storage; class Identifier { @@ -141,7 +140,7 @@ extension type RecordedUsages._(pb.Usages _usages) { pb.Usage? _callTo(Identifier identifier) => _usages.calls.firstWhereOrNull( (call) => _compareIdentifiers(call.definition.identifier, identifier)); - bool _compareIdentifiers(pb_shared.Identifier id1, Identifier id2) => + bool _compareIdentifiers(pb.Identifier id1, Identifier id2) => id1.uri == id2.uri && (id1.hasParent() ? id1.parent : null) == id2.parent && id1.name == id2.name; diff --git a/pkgs/record_use/test/storage_test.dart b/pkgs/record_use/test/storage_test.dart index 94ede726..630e5d37 100644 --- a/pkgs/record_use/test/storage_test.dart +++ b/pkgs/record_use/test/storage_test.dart @@ -12,6 +12,9 @@ import 'testdata/data.dart'; void main() { test('Buffer->Object->Buffer', () { + // File('test/testdata/data.txtpb') + // .writeAsStringSync(recordedUses.toDebugJson()); + // File('test/testdata/data.binpb').writeAsBytesSync(recordedUses.toBuffer()); final recordedUsesPb = File('test/testdata/data.binpb').readAsBytesSync(); expect((RecordedUsages.fromFile(recordedUsesPb) as Usages).toBuffer(), recordedUsesPb); diff --git a/pkgs/record_use/test/testdata/data.binpb b/pkgs/record_use/test/testdata/data.binpb index a069d1c5..8dfb96ba 100644 Binary files a/pkgs/record_use/test/testdata/data.binpb and b/pkgs/record_use/test/testdata/data.binpb differ diff --git a/pkgs/record_use/test/testdata/data.textpb b/pkgs/record_use/test/testdata/data.txtpb similarity index 88% rename from pkgs/record_use/test/testdata/data.textpb rename to pkgs/record_use/test/testdata/data.txtpb index cff8d0c4..32f2a75c 100644 --- a/pkgs/record_use/test/testdata/data.textpb +++ b/pkgs/record_use/test/testdata/data.txtpb @@ -5,15 +5,12 @@ }, "2": [ "file://lib/_internal/js_runtime/lib/js_helper.dart", - "file://benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart", - "file://benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart", - "file://lib/_internal/js_runtime/lib/js_helper.dart", - "file://lib/_internal/js_runtime/lib/js_helper.dart" + "file://benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart" ], "3": [ { "1": { - "1": "file://lib/_internal/js_runtime/lib/js_helper.dart", + "1": 0, "2": "MyClass", "3": "get:loadDeferredLibrary" }, @@ -23,7 +20,7 @@ }, { "1": { - "1": "file://lib/_internal/js_runtime/lib/js_helper.dart", + "1": 0, "3": "MyAnnotation" }, "2": 15,