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

Commit 5c53968

Browse files
authored
Make QualifiedName a class type with uri and name fields. (#60)
* Make QualifiedName a class type with uri and name fields. * Fixes issues after merge.
1 parent 50996c1 commit 5c53968

31 files changed

+312
-182
lines changed

goldens/foo/lib/foo.analyzer.json

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,48 @@
3636
"package:foo/foo.dart#Foo": {
3737
"typeParameters": [],
3838
"self": {
39-
"name": "package:foo/foo.dart#Foo",
39+
"name": {
40+
"uri": "package:foo/foo.dart",
41+
"name": "Foo"
42+
},
4043
"instantiation": []
4144
},
4245
"supertypes": [
4346
{
44-
"name": "dart:core#Object",
47+
"name": {
48+
"uri": "dart:core",
49+
"name": "Object"
50+
},
4551
"instantiation": []
4652
}
4753
]
4854
},
4955
"dart:core#Object": {
5056
"typeParameters": [],
5157
"self": {
52-
"name": "dart:core#Object",
58+
"name": {
59+
"uri": "dart:core",
60+
"name": "Object"
61+
},
5362
"instantiation": []
5463
},
5564
"supertypes": []
5665
},
5766
"dart:core#Null": {
5867
"typeParameters": [],
5968
"self": {
60-
"name": "dart:core#Null",
69+
"name": {
70+
"uri": "dart:core",
71+
"name": "Null"
72+
},
6173
"instantiation": []
6274
},
6375
"supertypes": [
6476
{
65-
"name": "dart:core#Object",
77+
"name": {
78+
"uri": "dart:core",
79+
"name": "Object"
80+
},
6681
"instantiation": []
6782
}
6883
]
@@ -74,7 +89,10 @@
7489
}
7590
],
7691
"self": {
77-
"name": "dart:async#Future",
92+
"name": {
93+
"uri": "dart:async",
94+
"name": "Future"
95+
},
7896
"instantiation": [
7997
{
8098
"type": "TypeParameterTypeDesc",
@@ -86,20 +104,29 @@
86104
},
87105
"supertypes": [
88106
{
89-
"name": "dart:core#Object",
107+
"name": {
108+
"uri": "dart:core",
109+
"name": "Object"
110+
},
90111
"instantiation": []
91112
}
92113
]
93114
},
94115
"package:foo/foo.dart#Bar": {
95116
"typeParameters": [],
96117
"self": {
97-
"name": "package:foo/foo.dart#Bar",
118+
"name": {
119+
"uri": "package:foo/foo.dart",
120+
"name": "Bar"
121+
},
98122
"instantiation": []
99123
},
100124
"supertypes": [
101125
{
102-
"name": "dart:core#Object",
126+
"name": {
127+
"uri": "dart:core",
128+
"name": "Object"
129+
},
103130
"instantiation": []
104131
}
105132
]

goldens/foo/lib/foo.cfe.json

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,48 @@
3636
"package:foo/foo.dart#Foo": {
3737
"typeParameters": [],
3838
"self": {
39-
"name": "package:foo/foo.dart#Foo",
39+
"name": {
40+
"uri": "package:foo/foo.dart",
41+
"name": "Foo"
42+
},
4043
"instantiation": []
4144
},
4245
"supertypes": [
4346
{
44-
"name": "dart:core#Object",
47+
"name": {
48+
"uri": "dart:core",
49+
"name": "Object"
50+
},
4551
"instantiation": []
4652
}
4753
]
4854
},
4955
"dart:core#Object": {
5056
"typeParameters": [],
5157
"self": {
52-
"name": "dart:core#Object",
58+
"name": {
59+
"uri": "dart:core",
60+
"name": "Object"
61+
},
5362
"instantiation": []
5463
},
5564
"supertypes": []
5665
},
5766
"dart:core#Null": {
5867
"typeParameters": [],
5968
"self": {
60-
"name": "dart:core#Null",
69+
"name": {
70+
"uri": "dart:core",
71+
"name": "Null"
72+
},
6173
"instantiation": []
6274
},
6375
"supertypes": [
6476
{
65-
"name": "dart:core#Object",
77+
"name": {
78+
"uri": "dart:core",
79+
"name": "Object"
80+
},
6681
"instantiation": []
6782
}
6883
]
@@ -77,7 +92,10 @@
7792
"inner": {
7893
"type": "NamedTypeDesc",
7994
"value": {
80-
"name": "dart:core#Object",
95+
"name": {
96+
"uri": "dart:core",
97+
"name": "Object"
98+
},
8199
"instantiation": []
82100
}
83101
}
@@ -86,7 +104,10 @@
86104
}
87105
],
88106
"self": {
89-
"name": "dart:async#Future",
107+
"name": {
108+
"uri": "dart:async",
109+
"name": "Future"
110+
},
90111
"instantiation": [
91112
{
92113
"type": "TypeParameterTypeDesc",
@@ -98,20 +119,29 @@
98119
},
99120
"supertypes": [
100121
{
101-
"name": "dart:core#Object",
122+
"name": {
123+
"uri": "dart:core",
124+
"name": "Object"
125+
},
102126
"instantiation": []
103127
}
104128
]
105129
},
106130
"package:foo/foo.dart#Bar": {
107131
"typeParameters": [],
108132
"self": {
109-
"name": "package:foo/foo.dart#Bar",
133+
"name": {
134+
"uri": "package:foo/foo.dart",
135+
"name": "Bar"
136+
},
110137
"instantiation": []
111138
},
112139
"supertypes": [
113140
{
114-
"name": "dart:core#Object",
141+
"name": {
142+
"uri": "dart:core",
143+
"name": "Object"
144+
},
115145
"instantiation": []
116146
}
117147
]

pkgs/_analyzer_macros/lib/macro_implementation.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class AnalyzerMacroPackageConfigs implements injected.MacroPackageConfigs {
5454

5555
@override
5656
bool isMacro(Uri uri, String name) =>
57-
_impl._host.isMacro(QualifiedName('$uri#$name'));
57+
_impl._host.isMacro(QualifiedName(uri: '$uri', name: name));
5858
}
5959

6060
class AnalyzerMacroRunner implements injected.MacroRunner {
@@ -65,8 +65,9 @@ class AnalyzerMacroRunner implements injected.MacroRunner {
6565
@override
6666
injected.RunningMacro run(Uri uri, String name) => AnalyzerRunningMacro.run(
6767
_impl,
68-
QualifiedName('$uri#$name'),
69-
_impl._host.lookupMacroImplementation(QualifiedName('$uri#$name'))!);
68+
QualifiedName(uri: '$uri', name: name),
69+
_impl._host
70+
.lookupMacroImplementation(QualifiedName(uri: '$uri', name: name))!);
7071
}
7172

7273
class AnalyzerRunningMacro implements injected.RunningMacro {
@@ -171,7 +172,7 @@ extension MacroTargetExtension on MacroTarget {
171172
final element =
172173
((this as Declaration).identifier as analyzer.IdentifierImpl).element!;
173174
return QualifiedName(
174-
'${element.library!.definingCompilationUnit.source.uri}#'
175-
'${element.displayName}');
175+
uri: '${element.library!.definingCompilationUnit.source.uri}',
176+
name: element.displayName);
176177
}
177178
}

pkgs/_analyzer_macros/lib/query_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class AnalyzerQueryService implements QueryService {
7777
...element.mixins,
7878
];
7979

80-
result.named[asNamedType.name.string] = TypeHierarchyEntry(
80+
result.named[asNamedType.name.asString] = TypeHierarchyEntry(
8181
self: asNamedType,
8282
typeParameters: [
8383
for (final typeParameter in element.typeParameters)

pkgs/_analyzer_macros/lib/src/type_translation.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ final class AnalyzerTypesToMacros extends UnifyingTypeVisitorWithArgument<
7777
model.StaticTypeDesc visitInterfaceType(
7878
InterfaceType type, TypeTranslationContext argument) {
7979
final element = type.element;
80-
final uri = element.librarySource.uri.replace(fragment: element.name);
81-
8280
return model.StaticTypeDesc.namedTypeDesc(model.NamedTypeDesc(
83-
name: model.QualifiedName(uri.toString()),
81+
name: model.QualifiedName(
82+
uri: '${element.librarySource.uri}', name: element.name),
8483
instantiation: [
8584
for (final arg in type.typeArguments)
8685
arg.acceptWithArgument(this, argument),

pkgs/_cfe_macros/lib/macro_implementation.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CfeMacroPackageConfigs implements injected.MacroPackageConfigs {
5454

5555
@override
5656
bool isMacro(Uri uri, String name) =>
57-
_impl._host.isMacro(QualifiedName('$uri#$name'));
57+
_impl._host.isMacro(QualifiedName(uri: '$uri', name: name));
5858
}
5959

6060
class CfeMacroRunner implements injected.MacroRunner {
@@ -65,8 +65,9 @@ class CfeMacroRunner implements injected.MacroRunner {
6565
@override
6666
injected.RunningMacro run(Uri uri, String name) => CfeRunningMacro.run(
6767
_impl,
68-
QualifiedName('$uri#$name'),
69-
_impl._host.lookupMacroImplementation(QualifiedName('$uri#$name'))!);
68+
QualifiedName(uri: '$uri', name: name),
69+
_impl._host
70+
.lookupMacroImplementation(QualifiedName(uri: '$uri', name: name))!);
7071
}
7172

7273
class CfeRunningMacro implements injected.RunningMacro {
@@ -171,7 +172,6 @@ extension MacroTargetExtension on MacroTarget {
171172
QualifiedName get qualifiedName {
172173
final identifier = ((this as Declaration).identifier as cfe.IdentifierImpl)
173174
.resolveIdentifier();
174-
return QualifiedName('${identifier.uri}#'
175-
'${identifier.name}');
175+
return QualifiedName(uri: '${identifier.uri}', name: identifier.name);
176176
}
177177
}

pkgs/_cfe_macros/lib/query_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CfeQueryService implements QueryService {
100100
.accept1(translator, context)
101101
.asNamedTypeDesc;
102102

103-
result.named[asNamedType.name.string] = TypeHierarchyEntry(
103+
result.named[asNamedType.name.asString] = TypeHierarchyEntry(
104104
self: asNamedType,
105105
typeParameters: [
106106
for (final typeParameter in element.typeParameters)

pkgs/_cfe_macros/lib/src/type_translation.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ final class KernelTypeToMacros extends kernel
8888
// Pretend that this is a `FutureOr` class instantiation, which macros use
8989
// to represent `FutureOr` types.
9090
return model.StaticTypeDesc.namedTypeDesc(model.NamedTypeDesc(
91-
name: model.QualifiedName('dart:async#FutureOr'),
91+
name: model.QualifiedName(uri: 'dart:async', name: 'FutureOr'),
9292
instantiation: [
9393
node.typeArgument.accept1(this, arg),
9494
],
@@ -100,10 +100,10 @@ final class KernelTypeToMacros extends kernel
100100
kernel.InterfaceType node, TypeTranslationContext arg) {
101101
final definingClass = node.classNode;
102102
final library = definingClass.enclosingLibrary;
103-
final uri = library.importUri.replace(fragment: definingClass.name);
104103

105104
return model.StaticTypeDesc.namedTypeDesc(model.NamedTypeDesc(
106-
name: model.QualifiedName(uri.toString()),
105+
name: model.QualifiedName(
106+
uri: '${library.importUri}', name: definingClass.name),
107107
instantiation: [
108108
for (final typeArg in node.typeArguments) typeArg.accept1(this, arg),
109109
],

pkgs/_macro_builder/test/macro_builder_test.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ void main() {
1414
group(MacroBuilder, () {
1515
test('bootstrap matches golden', () async {
1616
final script = createBootstrap([
17-
QualifiedName('package:_test_macros/declare_x_macro.dart#DeclareX'),
18-
QualifiedName('package:_test_macros/declare_y_macro.dart#DeclareY'),
1917
QualifiedName(
20-
'package:_more_macros/other_macro.dart#OtherMacroImplementation')
18+
uri: 'package:_test_macros/declare_x_macro.dart', name: 'DeclareX'),
19+
QualifiedName(
20+
uri: 'package:_test_macros/declare_y_macro.dart', name: 'DeclareY'),
21+
QualifiedName(
22+
uri: 'package:_more_macros/other_macro.dart',
23+
name: 'OtherMacroImplementation')
2124
]);
2225

2326
expect(script, '''
@@ -46,7 +49,8 @@ void main(List<String> arguments) {
4649

4750
final bundle = await builder.build(Isolate.packageConfigSync!, [
4851
QualifiedName(
49-
'package:_test_macros/declare_x_macro.dart#DeclareXImplementation')
52+
uri: 'package:_test_macros/declare_x_macro.dart',
53+
name: 'DeclareXImplementation')
5054
]);
5155

5256
expect(File(bundle.executablePath).existsSync(), true);

pkgs/_macro_client/lib/macro_client.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ class MacroClient {
6969
case HostRequestType.augmentRequest:
7070
final macro = macros
7171
.where((m) =>
72-
m.description.annotation.string ==
73-
hostRequest.macroAnnotation.string)
72+
m.description.annotation.equals(hostRequest.macroAnnotation))
7473
.singleOrNull;
7574

7675
if (macro == null) {
7776
_sendResponse(Response.errorResponse(
7877
requestId: hostRequest.id,
7978
ErrorResponse(
8079
error: 'No macro for annotation: '
81-
'${hostRequest.macroAnnotation}')));
80+
'${hostRequest.macroAnnotation.asString}')));
8281
} else {
8382
await Scope.macro.runAsync(() async => _sendResponse(
8483
Response.augmentResponse(

0 commit comments

Comments
 (0)