Skip to content

Commit 9d96cd9

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ElementsTypesMixin, part#4
Change-Id: I66c188d2c8502c753fdc1c64d1f2759022b86bc9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409820 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 49ee851 commit 9d96cd9

15 files changed

+623
-481
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
954954
MethodMember.from(element.getMethod(methodName), this);
955955

956956
@override
957-
MethodElement2? getMethod2(String methodName) {
957+
MethodElement2OrMember? getMethod2(String methodName) {
958958
return getMethod(methodName)?.asElement2;
959959
}
960960

pkg/analyzer/test/generated/elements_types_mixin.dart

Lines changed: 123 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import 'package:test/test.dart';
2323
mixin ElementsTypesMixin {
2424
InterfaceTypeImpl get boolNone {
2525
var element = typeProvider.boolElement2;
26-
return interfaceTypeNone2(element);
26+
return interfaceTypeNone(element);
2727
}
2828

2929
InterfaceTypeImpl get boolQuestion {
@@ -33,7 +33,7 @@ mixin ElementsTypesMixin {
3333

3434
InterfaceTypeImpl get doubleNone {
3535
var element = typeProvider.doubleElement2;
36-
return interfaceTypeNone2(element);
36+
return interfaceTypeNone(element);
3737
}
3838

3939
InterfaceTypeImpl get doubleQuestion {
@@ -45,7 +45,7 @@ mixin ElementsTypesMixin {
4545

4646
InterfaceTypeImpl get functionNone {
4747
var element = typeProvider.functionElement2;
48-
return interfaceTypeNone2(element);
48+
return interfaceTypeNone(element);
4949
}
5050

5151
InterfaceTypeImpl get functionQuestion {
@@ -55,7 +55,7 @@ mixin ElementsTypesMixin {
5555

5656
InterfaceTypeImpl get intNone {
5757
var element = typeProvider.intElement2;
58-
return interfaceTypeNone2(element);
58+
return interfaceTypeNone(element);
5959
}
6060

6161
InterfaceTypeImpl get intQuestion {
@@ -71,12 +71,12 @@ mixin ElementsTypesMixin {
7171

7272
InterfaceTypeImpl get nullNone {
7373
var element = typeProvider.nullElement2;
74-
return interfaceTypeNone2(element);
74+
return interfaceTypeNone(element);
7575
}
7676

7777
InterfaceTypeImpl get numNone {
7878
var element = typeProvider.numElement2;
79-
return interfaceTypeNone2(element);
79+
return interfaceTypeNone(element);
8080
}
8181

8282
InterfaceTypeImpl get numQuestion {
@@ -86,7 +86,7 @@ mixin ElementsTypesMixin {
8686

8787
InterfaceTypeImpl get objectNone {
8888
var element = typeProvider.objectElement2;
89-
return interfaceTypeNone2(element);
89+
return interfaceTypeNone(element);
9090
}
9191

9292
InterfaceTypeImpl get objectQuestion {
@@ -96,12 +96,12 @@ mixin ElementsTypesMixin {
9696

9797
InterfaceTypeImpl get recordNone {
9898
var element = typeProvider.recordElement2;
99-
return interfaceTypeNone2(element);
99+
return interfaceTypeNone(element);
100100
}
101101

102102
InterfaceTypeImpl get stringNone {
103103
var element = typeProvider.stringElement2;
104-
return interfaceTypeNone2(element);
104+
return interfaceTypeNone(element);
105105
}
106106

107107
InterfaceTypeImpl get stringQuestion {
@@ -200,10 +200,21 @@ mixin ElementsTypesMixin {
200200
required String name,
201201
required List<ConstFieldElementImpl> constants,
202202
}) {
203-
var element = EnumElementImpl(name, 0);
204-
EnumElementImpl2(Reference.root(), element);
205-
element.enclosingElement3 = testLibrary.definingCompilationUnit;
206-
element.fields = constants;
203+
var fragment = EnumElementImpl(name, 0);
204+
EnumElementImpl2(Reference.root(), fragment);
205+
fragment.enclosingElement3 = testLibrary.definingCompilationUnit;
206+
fragment.fields = constants;
207+
return fragment;
208+
}
209+
210+
EnumElementImpl2 enum_2({
211+
required String name,
212+
required List<ConstFieldElementImpl> constants,
213+
}) {
214+
var fragment = EnumElementImpl(name, 0);
215+
var element = EnumElementImpl2(Reference.root(), fragment);
216+
fragment.enclosingElement3 = testLibrary.definingCompilationUnit;
217+
fragment.fields = constants;
207218
return element;
208219
}
209220

@@ -256,6 +267,32 @@ mixin ElementsTypesMixin {
256267
return fragment;
257268
}
258269

270+
ExtensionTypeElementImpl2 extensionType2(
271+
String name, {
272+
String representationName = 'it',
273+
required TypeImpl representationType,
274+
List<TypeParameterElementImpl2> typeParameters = const [],
275+
List<InterfaceType> interfaces = const [],
276+
}) {
277+
var fragment = ExtensionTypeElementImpl(name, -1);
278+
fragment.enclosingElement3 = testLibrary.definingCompilationUnit;
279+
fragment.typeParameters = typeParameters.map((e) => e.asElement).toList();
280+
fragment.interfaces = interfaces;
281+
282+
var field = FieldElementImpl(representationName, -1);
283+
field.type = representationType;
284+
fragment.fields = [field];
285+
286+
var element = ExtensionTypeElementImpl2(Reference.root(), fragment);
287+
element
288+
..representation = field
289+
..typeErasure = representationType
290+
..interfaces = fragment.interfaces
291+
..fields = fragment.fields;
292+
293+
return element;
294+
}
295+
259296
FunctionTypeImpl functionType({
260297
required List<TypeParameterElementImpl2> typeParameters,
261298
required List<FormalParameterElementImpl> formalParameters,
@@ -336,16 +373,6 @@ mixin ElementsTypesMixin {
336373
}
337374

338375
InterfaceTypeImpl interfaceTypeNone(
339-
InterfaceElementImpl element, {
340-
List<DartType> typeArguments = const [],
341-
}) {
342-
return element.instantiate(
343-
typeArguments: typeArguments,
344-
nullabilitySuffix: NullabilitySuffix.none,
345-
);
346-
}
347-
348-
InterfaceTypeImpl interfaceTypeNone2(
349376
InterfaceElementImpl2 element, {
350377
List<DartType> typeArguments = const [],
351378
}) {
@@ -485,6 +512,29 @@ mixin ElementsTypesMixin {
485512
return fragment;
486513
}
487514

515+
MixinElementImpl2 mixin_2({
516+
required String name,
517+
bool isAugmentation = false,
518+
List<TypeParameterElementImpl2> typeParameters = const [],
519+
List<InterfaceType>? constraints,
520+
List<InterfaceType> interfaces = const [],
521+
}) {
522+
var fragment = MixinElementImpl(name, 0);
523+
fragment.isAugmentation = isAugmentation;
524+
fragment.enclosingElement3 = testLibrary.definingCompilationUnit;
525+
fragment.typeParameters = typeParameters.map((e) => e.asElement).toList();
526+
fragment.superclassConstraints = constraints ?? [typeProvider.objectType];
527+
fragment.interfaces = interfaces;
528+
fragment.constructors = const <ConstructorElementImpl>[];
529+
530+
var element = MixinElementImpl2(Reference.root(), fragment);
531+
element.superclassConstraints = fragment.superclassConstraints;
532+
element.interfaces = fragment.interfaces;
533+
element.methods = fragment.methods;
534+
535+
return element;
536+
}
537+
488538
FormalParameterElementImpl namedParameter({
489539
required String name,
490540
required TypeImpl type,
@@ -714,6 +764,31 @@ class _MockSource implements Source {
714764
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
715765
}
716766

767+
extension ClassElementImpl2Extension on ClassElementImpl2 {
768+
void addAugmentations(List<ClassElementImpl> augmentations) {
769+
var augmentationTarget = fragments.last;
770+
for (var augmentation in augmentations) {
771+
expect(augmentation.isAugmentation, isTrue);
772+
augmentationTarget.augmentation = augmentation;
773+
augmentation.augmentationTargetAny = augmentationTarget;
774+
augmentationTarget = augmentation;
775+
776+
expect(augmentation.typeParameters, isEmpty,
777+
reason: 'Not supported in tests');
778+
779+
interfaces = [
780+
...interfaces,
781+
...augmentation.interfaces,
782+
];
783+
784+
mixins = [
785+
...mixins,
786+
...augmentation.mixins,
787+
];
788+
}
789+
}
790+
}
791+
717792
extension ClassElementImplExtension on ClassElementImpl {
718793
void addAugmentations(List<ClassElementImpl> augmentations) {
719794
var augmentationTarget = this;
@@ -744,6 +819,31 @@ extension ClassElementImplExtension on ClassElementImpl {
744819
}
745820
}
746821

822+
extension MixinElementImpl2Extension on MixinElementImpl2 {
823+
void addAugmentations(List<MixinElementImpl> augmentations) {
824+
var augmentationTarget = fragments.last;
825+
for (var augmentation in augmentations) {
826+
expect(augmentation.isAugmentation, isTrue);
827+
augmentationTarget.augmentation = augmentation;
828+
augmentation.augmentationTargetAny = augmentationTarget;
829+
augmentationTarget = augmentation;
830+
831+
expect(augmentation.typeParameters, isEmpty,
832+
reason: 'Not supported in tests');
833+
834+
superclassConstraints = [
835+
...superclassConstraints,
836+
...augmentation.superclassConstraints,
837+
];
838+
839+
interfaces = [
840+
...interfaces,
841+
...augmentation.interfaces,
842+
];
843+
}
844+
}
845+
}
846+
747847
extension MixinElementImplExtension on MixinElementImpl {
748848
void addAugmentations(List<MixinElementImpl> augmentations) {
749849
var augmentationTarget = this;

pkg/analyzer/test/src/dart/element/always_exhaustive_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,33 @@ class IsAlwaysExhaustiveTest extends AbstractTypeSystemTest {
3939
}
4040

4141
test_class_sealed() {
42-
var A = class_(name: 'A', isSealed: true);
42+
var A = class_2(name: 'A', isSealed: true);
4343
isAlwaysExhaustive(interfaceTypeNone(A));
44-
isAlwaysExhaustive(interfaceTypeQuestion(A));
44+
isAlwaysExhaustive(interfaceTypeQuestion2(A));
4545
}
4646

4747
test_enum() {
48-
var E = enum_(name: 'E', constants: []);
48+
var E = enum_2(name: 'E', constants: []);
4949
isAlwaysExhaustive(interfaceTypeNone(E));
50-
isAlwaysExhaustive(interfaceTypeQuestion(E));
50+
isAlwaysExhaustive(interfaceTypeQuestion2(E));
5151
}
5252

5353
test_extensionType() {
5454
isAlwaysExhaustive(
5555
interfaceTypeNone(
56-
extensionType('A', representationType: boolNone),
56+
extensionType2('A', representationType: boolNone),
5757
),
5858
);
5959

6060
isAlwaysExhaustive(
6161
interfaceTypeNone(
62-
extensionType('A', representationType: boolQuestion),
62+
extensionType2('A', representationType: boolQuestion),
6363
),
6464
);
6565

6666
isNotAlwaysExhaustive(
6767
interfaceTypeNone(
68-
extensionType('A', representationType: intNone),
68+
extensionType2('A', representationType: intNone),
6969
),
7070
);
7171
}

pkg/analyzer/test/src/dart/element/class_hierarchy_test.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:analyzer/dart/element/type.dart';
77
import 'package:analyzer/src/dart/element/class_hierarchy.dart';
88
import 'package:analyzer/src/dart/element/element.dart';
99
import 'package:analyzer/src/dart/element/type.dart';
10-
import 'package:analyzer/src/utilities/extensions/element.dart';
1110
import 'package:test/test.dart';
1211
import 'package:test_reflective_loader/test_reflective_loader.dart';
1312

@@ -60,7 +59,7 @@ class ClassHierarchyTest extends AbstractTypeSystemTest
6059
}
6160

6261
mixin _AbstractClassHierarchyMixin on ElementsTypesMixin {
63-
late ClassElementImpl A;
62+
late ClassElementImpl2 A;
6463

6564
void _assertErrors(List<ClassHierarchyError> errors, List<String> expected) {
6665
expect(
@@ -93,20 +92,20 @@ mixin _AbstractClassHierarchyMixin on ElementsTypesMixin {
9392
var specifiedInterfaces = typeArguments
9493
.map((e) => interfaceTypeNone(A, typeArguments: [e]))
9594
.toList();
96-
var X = class_(name: 'X', interfaces: specifiedInterfaces);
95+
var X = class_2(name: 'X', interfaces: specifiedInterfaces);
9796

9897
var classHierarchy = ClassHierarchy();
9998

100-
var actualInterfaces = classHierarchy.implementedInterfaces(X.asElement2);
99+
var actualInterfaces = classHierarchy.implementedInterfaces(X);
101100
_assertInterfaces(actualInterfaces, interfaces);
102101

103-
var actualErrors = classHierarchy.errors(X.asElement2);
102+
var actualErrors = classHierarchy.errors(X);
104103
_assertErrors(actualErrors, errors);
105104
}
106105

107106
void _createSharedElements() {
108107
var T = typeParameter('T');
109-
A = class_(name: 'A', typeParameters: [T]);
108+
A = class_2(name: 'A', typeParameters: [T]);
110109
}
111110

112111
String _interfaceString(InterfaceType interface) {

0 commit comments

Comments
 (0)