Skip to content

Commit 1432e30

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate FieldNameNonPromotabilityInfo.
Change-Id: Ib7f566f3ff93e3a1eee66df7af1cb8639f0cac7f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409200 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent ff3cd6b commit 1432e30

File tree

10 files changed

+105
-76
lines changed

10 files changed

+105
-76
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ import 'package:meta/meta.dart';
9797
// TODO(scheglov): Clean up the list of implicitly analyzed files.
9898
class AnalysisDriver {
9999
/// The version of data format, should be incremented on every format change.
100-
static const int DATA_VERSION = 430;
100+
static const int DATA_VERSION = 431;
101101

102102
/// The number of exception contexts allowed to write. Once this field is
103103
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/element/field_name_non_promotability_info.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
7-
import 'package:analyzer/dart/element/element.dart';
5+
import 'package:analyzer/dart/element/element2.dart';
86
import 'package:analyzer/src/dart/element/element.dart';
97

108
/// Information about why a single private name in a library is non-promotable.
@@ -17,22 +15,23 @@ class FieldNameNonPromotabilityInfo {
1715
/// The set of fields in the library with the given private name that are
1816
/// inherently non-promotable. These fields conflict with promotability of the
1917
/// given private name.
20-
final List<FieldElement> conflictingFields;
18+
final List<FieldElement2> conflictingFields;
2119

2220
/// The set of getters in the library with the given private name that are
2321
/// concrete. These getters conflict with promotability of the given private
2422
/// name.
25-
final List<PropertyAccessorElement> conflictingGetters;
23+
final List<PropertyAccessorElement2> conflictingGetters;
2624

2725
/// The set of concrete classes in the library that contain a getter with the
2826
/// given private name in their interface but not explicitly in their
2927
/// implementation (and hence implicitly contain a `noSuchMethod` forwarder
3028
/// for the getter). These implicit `noSuchMethod` forwarders conflict with
3129
/// promotability of the given private name.
32-
final List<InterfaceElement> conflictingNsmClasses;
30+
final List<InterfaceElement2> conflictingNsmClasses;
3331

34-
FieldNameNonPromotabilityInfo(
35-
{required this.conflictingFields,
36-
required this.conflictingGetters,
37-
required this.conflictingNsmClasses});
32+
FieldNameNonPromotabilityInfo({
33+
required this.conflictingFields,
34+
required this.conflictingGetters,
35+
required this.conflictingNsmClasses,
36+
});
3837
}

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5724,47 +5724,55 @@ class _WhyNotPromotedVisitor
57245724
var fieldNonPromotabilityInfo = library.fieldNameNonPromotabilityInfo;
57255725
var fieldNameInfo = fieldNonPromotabilityInfo[reason.propertyName];
57265726
var messages = <DiagnosticMessage>[];
5727-
void addConflictMessage(
5728-
{required Element conflictingElement,
5729-
required String kind,
5730-
required Element enclosingElement,
5731-
required NonPromotionDocumentationLink link}) {
5727+
void addConflictMessage({
5728+
required Element2 conflictingElement,
5729+
required String kind,
5730+
required Element2 enclosingElement,
5731+
required NonPromotionDocumentationLink link,
5732+
}) {
57325733
var enclosingKindName = enclosingElement.kind.displayName;
5733-
var enclosingName = enclosingElement.name;
5734+
var enclosingName = enclosingElement.name3;
57345735
var message = "'$propertyName' couldn't be promoted because there is a "
57355736
"conflicting $kind in $enclosingKindName '$enclosingName'";
5736-
var nonSyntheticElement = conflictingElement.nonSynthetic;
5737-
messages.add(DiagnosticMessageImpl(
5738-
filePath: nonSyntheticElement.source!.fullName,
5737+
var nonSyntheticElement = conflictingElement.nonSynthetic2;
5738+
var nonSyntheticFragment = nonSyntheticElement.firstFragment;
5739+
var source = nonSyntheticFragment.libraryFragment?.source;
5740+
messages.add(
5741+
DiagnosticMessageImpl(
5742+
filePath: source!.fullName,
57395743
message: message,
5740-
offset: nonSyntheticElement.nameOffset,
5741-
length: nonSyntheticElement.nameLength,
5742-
url: link.url));
5744+
offset: nonSyntheticFragment.nameOffset2!,
5745+
length: nonSyntheticElement.name3!.length,
5746+
url: link.url,
5747+
),
5748+
);
57435749
}
57445750

57455751
if (fieldNameInfo != null) {
57465752
for (var field in fieldNameInfo.conflictingFields) {
57475753
addConflictMessage(
5748-
conflictingElement: field,
5749-
kind: 'non-promotable field',
5750-
enclosingElement: field.enclosingElement3,
5751-
link:
5752-
NonPromotionDocumentationLink.conflictingNonPromotableField);
5754+
conflictingElement: field,
5755+
kind: 'non-promotable field',
5756+
enclosingElement: field.enclosingElement2,
5757+
link: NonPromotionDocumentationLink.conflictingNonPromotableField,
5758+
);
57535759
}
57545760
for (var getter in fieldNameInfo.conflictingGetters) {
57555761
addConflictMessage(
5756-
conflictingElement: getter,
5757-
kind: 'getter',
5758-
enclosingElement: getter.enclosingElement3,
5759-
link: NonPromotionDocumentationLink.conflictingGetter);
5762+
conflictingElement: getter,
5763+
kind: 'getter',
5764+
enclosingElement: getter.enclosingElement2,
5765+
link: NonPromotionDocumentationLink.conflictingGetter,
5766+
);
57605767
}
57615768
for (var nsmClass in fieldNameInfo.conflictingNsmClasses) {
57625769
addConflictMessage(
5763-
conflictingElement: nsmClass,
5764-
kind: 'noSuchMethod forwarder',
5765-
enclosingElement: nsmClass,
5766-
link: NonPromotionDocumentationLink
5767-
.conflictingNoSuchMethodForwarder);
5770+
conflictingElement: nsmClass,
5771+
kind: 'noSuchMethod forwarder',
5772+
enclosingElement: nsmClass,
5773+
link:
5774+
NonPromotionDocumentationLink.conflictingNoSuchMethodForwarder,
5775+
);
57685776
}
57695777
}
57705778
if (reason.fieldPromotionEnabled) {

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:typed_data';
99
import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart';
1010
import 'package:analyzer/dart/analysis/features.dart';
1111
import 'package:analyzer/dart/element/element.dart';
12+
import 'package:analyzer/dart/element/element2.dart';
1213
import 'package:analyzer/dart/element/nullability_suffix.dart';
1314
import 'package:analyzer/dart/element/type.dart';
1415
import 'package:analyzer/source/line_info.dart';
@@ -597,9 +598,9 @@ class LibraryElementLinkedData extends ElementLinkedData<LibraryElementImpl> {
597598
readKey: () => reader.readStringReference(),
598599
readValue: () {
599600
return FieldNameNonPromotabilityInfo(
600-
conflictingFields: reader.readElementList(),
601-
conflictingGetters: reader.readElementList(),
602-
conflictingNsmClasses: reader.readElementList(),
601+
conflictingFields: reader.readElementList2(),
602+
conflictingGetters: reader.readElementList2(),
603+
conflictingNsmClasses: reader.readElementList2(),
603604
);
604605
},
605606
);
@@ -2107,15 +2108,22 @@ class ResolutionReader {
21072108
throw UnimplementedError('memberFlags: $memberFlags');
21082109
}
21092110

2111+
Element2? readElement2() {
2112+
return readElement()?.asElement2;
2113+
}
2114+
21102115
List<T> readElementList<T extends Element>() {
21112116
return _reader.readTypedListCast<T>(readElement);
21122117
}
21132118

2119+
List<T> readElementList2<T extends Element2>() {
2120+
return _reader.readTypedListCast<T>(readElement2);
2121+
}
2122+
21142123
T readEnum<T extends Enum>(List<T> values) {
21152124
return _reader.readEnum(values);
21162125
}
21172126

2118-
21192127
Map<K, V> readMap<K, V>({
21202128
required K Function() readKey,
21212129
required V Function() readValue,
@@ -2418,8 +2426,6 @@ class ResolutionReader {
24182426
return readTypedList(_readInterfaceType);
24192427
}
24202428

2421-
2422-
24232429
List<T> _readNodeList<T>() {
24242430
return readTypedList(() {
24252431
return _readRequiredNode() as T;

pkg/analyzer/lib/src/summary2/bundle_writer.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import 'package:analyzer/src/summary2/data_writer.dart';
2626
import 'package:analyzer/src/summary2/element_flags.dart';
2727
import 'package:analyzer/src/summary2/export.dart';
2828
import 'package:analyzer/src/summary2/reference.dart';
29+
import 'package:analyzer/src/utilities/extensions/element.dart';
2930
import 'package:analyzer/src/utilities/extensions/object.dart';
3031

3132
class BundleWriter {
@@ -400,9 +401,9 @@ class BundleWriter {
400401
_resolutionSink._writeStringReference(key);
401402
},
402403
writeValue: (value) {
403-
_resolutionSink._writeElementList(value.conflictingFields);
404-
_resolutionSink._writeElementList(value.conflictingGetters);
405-
_resolutionSink._writeElementList(value.conflictingNsmClasses);
404+
_resolutionSink._writeElementList2(value.conflictingFields);
405+
_resolutionSink._writeElementList2(value.conflictingGetters);
406+
_resolutionSink._writeElementList2(value.conflictingNsmClasses);
406407
},
407408
);
408409
});
@@ -925,6 +926,11 @@ class ResolutionSink extends _SummaryDataWriter {
925926
}
926927
}
927928

929+
void _writeElementList2(List<Element2> elements2) {
930+
var elements = elements2.map((e) => e.asElement!).toList();
931+
_writeElementList(elements);
932+
}
933+
928934
void _writeFormalParameters(
929935
List<ParameterElement> parameters, {
930936
required bool withAnnotations,

pkg/analyzer/lib/src/summary2/library_builder.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,9 +964,13 @@ class _FieldPromotability extends FieldPromotability<InterfaceElement,
964964
_libraryBuilder.element.fieldNameNonPromotabilityInfo = {
965965
for (var MapEntry(:key, :value) in fieldNonPromotabilityInfo.entries)
966966
key: element_model.FieldNameNonPromotabilityInfo(
967-
conflictingFields: value.conflictingFields,
968-
conflictingGetters: value.conflictingGetters,
969-
conflictingNsmClasses: value.conflictingNsmClasses)
967+
conflictingFields:
968+
value.conflictingFields.map((e) => e.asElement2).toList(),
969+
conflictingGetters:
970+
value.conflictingGetters.map((e) => e.asElement2).toList(),
971+
conflictingNsmClasses:
972+
value.conflictingNsmClasses.map((e) => e.asElement2).toList(),
973+
)
970974
};
971975
}
972976

pkg/analyzer/lib/src/utilities/extensions/element.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ extension FormalParameterElementImplExtension on FormalParameterElementImpl {
436436
}
437437
}
438438

439+
extension InstanceElement2Extension on InstanceElement2 {
440+
InstanceElement get asElement {
441+
return firstFragment as InstanceElement;
442+
}
443+
}
444+
439445
extension InterfaceElement2Extension on InterfaceElement2 {
440446
InterfaceElement get asElement {
441447
return firstFragment as InterfaceElement;

pkg/analyzer/test/src/summary/element_text.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ abstract class _AbstractElementWriter {
176176
for (var entry in info.entries) {
177177
_sink.writelnWithIndent(entry.key);
178178
_sink.withIndent(() {
179-
_elementPrinter.writeElementList(
179+
_elementPrinter.writeElementList2(
180180
'conflictingFields',
181181
entry.value.conflictingFields,
182182
);
183-
_elementPrinter.writeElementList(
183+
_elementPrinter.writeElementList2(
184184
'conflictingGetters',
185185
entry.value.conflictingGetters,
186186
);
187-
_elementPrinter.writeElementList(
187+
_elementPrinter.writeElementList2(
188188
'conflictingNsmClasses',
189189
entry.value.conflictingNsmClasses,
190190
);

0 commit comments

Comments
 (0)