-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
2,744 additions
and
3,464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:convert'; | ||
import 'dart:typed_data'; | ||
|
||
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; | ||
|
||
extension UsagesExt on pb.Usages { | ||
Uint8List toBuffer() => _toStorage().writeToBuffer(); | ||
String toDebugJson() => | ||
const JsonEncoder.withIndent(' ').convert(_toStorage().writeToJsonMap()); | ||
|
||
pb_storage.Usages _toStorage() { | ||
final definitions = | ||
[...calls, ...instances].map((e) => e.definition).toList(); | ||
final uris = [...calls, ...instances] | ||
.expand((e) => [ | ||
e.definition.identifier.uri, | ||
...e.references.map( | ||
(e) => e.location.uri, | ||
) | ||
]) | ||
.toList(); | ||
return pb_storage.Usages( | ||
metadata: metadata, | ||
definitions: definitions, | ||
uris: uris, | ||
instances: instances.map((e) => e.toStorage(definitions, uris)), | ||
calls: calls.map((e) => e.toStorage(definitions, uris)), | ||
); | ||
} | ||
} | ||
|
||
extension UsageExt on pb.Usage { | ||
pb_storage.Usage toStorage( | ||
List<pb_shared.Definition> definitions, List<String> uris) => | ||
pb_storage.Usage( | ||
definition: definitions.indexOf(definition), | ||
references: references.map((e) => e.toStorage(uris)), | ||
); | ||
} | ||
|
||
extension ReferenceExt on pb.Reference { | ||
pb_storage.Reference toStorage(List<String> uris) => pb_storage.Reference( | ||
arguments: hasArguments() ? arguments : null, | ||
fields: hasFields() ? fields : null, | ||
loadingUnit: loadingUnit, | ||
location: location.toStorage(uris), | ||
); | ||
} | ||
|
||
extension LocationExt on pb.Location { | ||
pb_storage.Location toStorage(List<String> uris) => pb_storage.Location( | ||
column: column, | ||
line: line, | ||
uri: uris.indexOf(uri), | ||
); | ||
} | ||
|
||
extension UsagesStorageExt on pb_storage.Usages { | ||
pb.Usages toApi() => pb.Usages( | ||
metadata: metadata, | ||
calls: calls.map((e) => e.toApi(definitions, uris)), | ||
instances: instances.map((e) => e.toApi(definitions, uris)), | ||
); | ||
} | ||
|
||
extension UsageStorageExt on pb_storage.Usage { | ||
pb.Usage toApi(List<pb_shared.Definition> definitions, List<String> uris) => | ||
pb.Usage( | ||
definition: definitions[definition], | ||
references: references.map((e) => e.toApi(uris)), | ||
); | ||
} | ||
|
||
extension ReferenceStorageExt on pb_storage.Reference { | ||
pb.Reference toApi(List<String> uris) => pb.Reference( | ||
arguments: hasArguments() ? arguments : null, | ||
fields: hasFields() ? fields : null, | ||
loadingUnit: loadingUnit, | ||
location: location.toApi(uris), | ||
); | ||
} | ||
|
||
extension LocationStorageExt on pb_storage.Location { | ||
pb.Location toApi(List<String> uris) => pb.Location( | ||
column: column, | ||
line: line, | ||
uri: uris[uri], | ||
); | ||
} | ||
|
||
extension FieldValueExt on pb_shared.FieldValue { | ||
Object toObject() => switch (whichValue()) { | ||
pb_shared.FieldValue_Value.intValue => intValue, | ||
pb_shared.FieldValue_Value.doubleValue => doubleValue, | ||
pb_shared.FieldValue_Value.boolValue => boolValue, | ||
pb_shared.FieldValue_Value.stringValue => stringValue, | ||
pb_shared.FieldValue_Value.notSet => throw ArgumentError(), | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.