Skip to content

Commit 2565d07

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Include 'kind' into ManifestElement, print it.
As noted in https://dart-review.googlesource.com/c/sdk/+/429540, without it the output was somewhat confusing. Change-Id: I18e263718fde482367af496e11e133937a946435 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429681 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 61c3582 commit 2565d07

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

pkg/analyzer/lib/src/fine/manifest_context.dart

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ final class ManifestElement {
9292
/// The URI of the library that declares the element.
9393
final Uri libraryUri;
9494

95+
/// The kind, mostly to distinguish fields and getters.
96+
final ManifestElementKind kind;
97+
9598
/// The top-level element name.
9699
final String topLevelName;
97100

@@ -103,6 +106,7 @@ final class ManifestElement {
103106

104107
ManifestElement({
105108
required this.libraryUri,
109+
required this.kind,
106110
required this.topLevelName,
107111
required this.memberName,
108112
required this.id,
@@ -111,20 +115,22 @@ final class ManifestElement {
111115
factory ManifestElement.read(SummaryDataReader reader) {
112116
return ManifestElement(
113117
libraryUri: reader.readUri(),
118+
kind: reader.readEnum(ManifestElementKind.values),
114119
topLevelName: reader.readStringUtf8(),
115120
memberName: reader.readOptionalStringUtf8(),
116121
id: reader.readOptionalObject(() => ManifestItemId.read(reader)),
117122
);
118123
}
119124

120125
@override
121-
int get hashCode => Object.hash(libraryUri, topLevelName, memberName);
126+
int get hashCode => Object.hash(libraryUri, kind, topLevelName, memberName);
122127

123128
@override
124129
bool operator ==(Object other) {
125130
if (identical(this, other)) return true;
126131
return other is ManifestElement &&
127132
other.libraryUri == libraryUri &&
133+
other.kind == kind &&
128134
other.topLevelName == topLevelName &&
129135
other.memberName == memberName;
130136
}
@@ -146,6 +152,9 @@ final class ManifestElement {
146152
if (givenLibraryUri != libraryUri) {
147153
return false;
148154
}
155+
if (ManifestElementKind.of(element) != kind) {
156+
return false;
157+
}
149158
if (givenTopLevelElement.lookupName != topLevelName) {
150159
return false;
151160
}
@@ -162,6 +171,7 @@ final class ManifestElement {
162171

163172
void write(BufferedSink sink) {
164173
sink.writeUri(libraryUri);
174+
sink.writeEnum(kind);
165175
sink.writeStringUtf8(topLevelName);
166176
sink.writeOptionalStringUtf8(memberName);
167177
id.writeOptional(sink);
@@ -181,6 +191,7 @@ final class ManifestElement {
181191

182192
return ManifestElement(
183193
libraryUri: topLevelElement.library2!.uri,
194+
kind: ManifestElementKind.of(element),
184195
topLevelName: topLevelElement.lookupName!,
185196
memberName: memberElement?.lookupName,
186197
id: context.getElementId(element),
@@ -192,6 +203,55 @@ final class ManifestElement {
192203
}
193204
}
194205

206+
/// Note, "instance" means inside [InstanceElement], not as "not static".
207+
enum ManifestElementKind {
208+
class_,
209+
enum_,
210+
mixin_,
211+
topLevelVariable,
212+
topLevelGetter,
213+
topLevelSetter,
214+
topLevelFunction,
215+
instanceField,
216+
instanceGetter,
217+
instanceSetter,
218+
instanceMethod,
219+
interfaceConstructor;
220+
221+
static ManifestElementKind of(Element element) {
222+
switch (element) {
223+
case ClassElement():
224+
return ManifestElementKind.class_;
225+
case EnumElement():
226+
return ManifestElementKind.enum_;
227+
case MixinElement():
228+
return ManifestElementKind.mixin_;
229+
case TopLevelVariableElement():
230+
return ManifestElementKind.topLevelVariable;
231+
case GetterElement():
232+
if (element.enclosingElement is LibraryElement) {
233+
return ManifestElementKind.topLevelGetter;
234+
}
235+
return ManifestElementKind.instanceGetter;
236+
case SetterElement():
237+
if (element.enclosingElement is LibraryElement) {
238+
return ManifestElementKind.topLevelSetter;
239+
}
240+
return ManifestElementKind.instanceSetter;
241+
case TopLevelFunctionElement():
242+
return ManifestElementKind.topLevelFunction;
243+
case FieldElement():
244+
return ManifestElementKind.instanceField;
245+
case MethodElement():
246+
return ManifestElementKind.instanceMethod;
247+
case ConstructorElement():
248+
return ManifestElementKind.interfaceConstructor;
249+
default:
250+
throw StateError('Unexpected (${element.runtimeType}) $element');
251+
}
252+
}
253+
}
254+
195255
class MatchContext {
196256
final MatchContext? parent;
197257

pkg/analyzer/test/src/dart/analysis/driver_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34373,7 +34373,7 @@ const b = 0 + a;
3437334373
tokenBuffer: 0+a
3437434374
tokenLengthList: [1, 1, 1]
3437534375
elements
34376-
[0] (dart:core, num, +) #M2
34376+
[0] (dart:core, instanceMethod, num, +) #M2
3437734377
elementIndexList
3437834378
0 = null
3437934379
5 = element 0
@@ -34402,9 +34402,9 @@ const b = 0 + a;
3440234402
tokenBuffer: 0+a
3440334403
tokenLengthList: [1, 1, 1]
3440434404
elements
34405-
[0] (package:test/test.dart, a) <null>
34406-
[1] (package:test/test.dart, a) <null>
34407-
[2] (dart:core, num, +) #M2
34405+
[0] (package:test/test.dart, topLevelGetter, a) <null>
34406+
[1] (package:test/test.dart, topLevelVariable, a) <null>
34407+
[2] (dart:core, instanceMethod, num, +) #M2
3440834408
elementIndexList
3440934409
5 = element 0
3441034410
13 = element 1
@@ -34441,9 +34441,9 @@ const b = 1 + a;
3444134441
tokenBuffer: 1+a
3444234442
tokenLengthList: [1, 1, 1]
3444334443
elements
34444-
[0] (package:test/test.dart, a) <null>
34445-
[1] (package:test/test.dart, a) <null>
34446-
[2] (dart:core, num, +) #M4
34444+
[0] (package:test/test.dart, topLevelGetter, a) <null>
34445+
[1] (package:test/test.dart, topLevelVariable, a) <null>
34446+
[2] (dart:core, instanceMethod, num, +) #M4
3444734447
elementIndexList
3444834448
5 = element 0
3444934449
13 = element 1
@@ -34465,7 +34465,7 @@ const b = 1 + a;
3446534465
tokenBuffer: 1+a
3446634466
tokenLengthList: [1, 1, 1]
3446734467
elements
34468-
[0] (dart:core, num, +) #M4
34468+
[0] (dart:core, instanceMethod, num, +) #M4
3446934469
elementIndexList
3447034470
0 = null
3447134471
5 = element 0

pkg/analyzer/test/src/dart/analysis/result_printer.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ class LibraryManifestPrinter {
11051105
void _writelnElement(ManifestElement element) {
11061106
var parts = [
11071107
element.libraryUri,
1108+
element.kind.name,
11081109
element.topLevelName,
11091110
if (element.memberName case var memberName?) memberName,
11101111
];

0 commit comments

Comments
 (0)