Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Commit

Permalink
fix bugs such that JsonCodable works
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 committed Oct 23, 2024
1 parent fcfa68a commit 26cb1a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
20 changes: 11 additions & 9 deletions pkgs/_analyzer_macros/lib/macro_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,17 @@ class AnalyzerMacroExecutionResult
if (augmentResponse.typeAugmentations?.isNotEmpty == true) {
// TODO: Handle multiple type augmentations, or augmentations where the
// target is itself a member of a type and not the type.
final entry = augmentResponse.typeAugmentations!.entries.single;
if (entry.key != target.qualifiedName.name) {
throw UnimplementedError(
'Type augmentations are only implemented when the type is the '
'target of the augmentation.');
}
for (final augmentation in entry.value) {
declarations.add(macros_api_v1.DeclarationCode.fromParts(
await _resolveNames(augmentation.code)));
for (final entry in augmentResponse.typeAugmentations!.entries) {
if (entry.key != target.qualifiedName.name) {
throw UnimplementedError(
'Type augmentations are only implemented when the type is the '
'target of the augmentation, expected '
'${target.qualifiedName.name} but got ${entry.key}');
}
for (final augmentation in entry.value) {
declarations.add(macros_api_v1.DeclarationCode.fromParts(
await _resolveNames(augmentation.code)));
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkgs/_macro_client/lib/src/builder_impls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,15 @@ Augmentation _buildFunctionAugmentation(
';'
else ...[
' ',
body,
...body.code,
]
];
return Augmentation(code: [
for (var part in parts)
switch (part) {
Code() => part,
String() => Code.string(part),
// TODO: All maps will pass this check...
Code() => part,
_ => throw StateError('Unexpected code kind $part'),
},
]);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_model/lib/src/dart_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension QualifiedNameExtension on QualifiedName {
extension ParentInterface on Member {
QualifiedName get parentInterface {
final self = MacroScope.current.model.qualifiedNameOf(node)!;
return QualifiedName(uri: self.uri, name: self.name);
return QualifiedName(uri: self.uri, name: self.scope);
}
}

Expand Down

0 comments on commit 26cb1a7

Please sign in to comment.