Skip to content

Commit 330cc91

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Use Impl types in ElementsTypesMixin.
Change the methods in `ElementsTypesMixin` so that their return types are all "Impl" types rather than analyzer public API types. This doesn't change the analyzer public API because `ElementsTypesMixin` is only used in tests internal to `package:analyzer`. This change allows `type_constraint_gatherer_test.dart` to represent all its types using `TypeImpl` rather than `DartType` without using type casts, which will in turn pave the way for switching the shared type constraint gathering code to using `TypeImpl` rather than `DartType`. This is part of a larger arc of work to change the analyzer's use of the shared code so that the type parameters it supplies are not part of the analyzer public API (See #59763). Change-Id: I9d15e9dd77f73271166b8e12de4d6f0a104cbb19 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403926 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent eafaa11 commit 330cc91

File tree

6 files changed

+74
-77
lines changed

6 files changed

+74
-77
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10959,7 +10959,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl
1095910959
}
1096010960

1096110961
@override
10962-
DartType instantiate({
10962+
TypeImpl instantiate({
1096310963
required List<DartType> typeArguments,
1096410964
required NullabilitySuffix nullabilitySuffix,
1096510965
}) {

pkg/analyzer/test/generated/elements_types_mixin.dart

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import 'package:analyzer/dart/analysis/features.dart';
99
import 'package:analyzer/dart/element/element.dart';
1010
import 'package:analyzer/dart/element/nullability_suffix.dart';
1111
import 'package:analyzer/dart/element/type.dart';
12-
import 'package:analyzer/dart/element/type_provider.dart';
1312
import 'package:analyzer/source/line_info.dart';
1413
import 'package:analyzer/source/source.dart';
1514
import 'package:analyzer/src/dart/analysis/session.dart';
1615
import 'package:analyzer/src/dart/element/element.dart';
1716
import 'package:analyzer/src/dart/element/type.dart';
17+
import 'package:analyzer/src/dart/element/type_provider.dart';
1818
import 'package:analyzer/src/dart/element/type_schema.dart';
1919
import 'package:analyzer/src/dart/element/type_system.dart';
2020
import 'package:analyzer/src/generated/engine.dart';
@@ -23,99 +23,99 @@ import 'package:analyzer/src/summary2/reference.dart';
2323
import 'package:test/test.dart';
2424

2525
mixin ElementsTypesMixin {
26-
InterfaceType get boolNone {
26+
InterfaceTypeImpl get boolNone {
2727
var element = typeProvider.boolElement;
2828
return interfaceTypeNone(element);
2929
}
3030

31-
InterfaceType get boolQuestion {
31+
InterfaceTypeImpl get boolQuestion {
3232
var element = typeProvider.boolElement;
3333
return interfaceTypeQuestion(element);
3434
}
3535

36-
InterfaceType get doubleNone {
36+
InterfaceTypeImpl get doubleNone {
3737
var element = typeProvider.doubleType.element;
3838
return interfaceTypeNone(element);
3939
}
4040

41-
InterfaceType get doubleQuestion {
41+
InterfaceTypeImpl get doubleQuestion {
4242
var element = typeProvider.doubleType.element;
4343
return interfaceTypeQuestion(element);
4444
}
4545

46-
DartType get dynamicType => DynamicTypeImpl.instance;
46+
TypeImpl get dynamicType => DynamicTypeImpl.instance;
4747

48-
InterfaceType get functionNone {
48+
InterfaceTypeImpl get functionNone {
4949
var element = typeProvider.functionType.element;
5050
return interfaceTypeNone(element);
5151
}
5252

53-
InterfaceType get functionQuestion {
53+
InterfaceTypeImpl get functionQuestion {
5454
var element = typeProvider.functionType.element;
5555
return interfaceTypeQuestion(element);
5656
}
5757

58-
InterfaceType get intNone {
58+
InterfaceTypeImpl get intNone {
5959
var element = typeProvider.intType.element;
6060
return interfaceTypeNone(element);
6161
}
6262

63-
InterfaceType get intQuestion {
63+
InterfaceTypeImpl get intQuestion {
6464
var element = typeProvider.intType.element;
6565
return interfaceTypeQuestion(element);
6666
}
6767

68-
DartType get invalidType => InvalidTypeImpl.instance;
68+
TypeImpl get invalidType => InvalidTypeImpl.instance;
6969

7070
NeverTypeImpl get neverNone => NeverTypeImpl.instance;
7171

7272
NeverTypeImpl get neverQuestion => NeverTypeImpl.instanceNullable;
7373

7474
InterfaceTypeImpl get nullNone {
7575
var element = typeProvider.nullType.element;
76-
return interfaceTypeNone(element) as InterfaceTypeImpl;
76+
return interfaceTypeNone(element);
7777
}
7878

79-
InterfaceType get numNone {
79+
InterfaceTypeImpl get numNone {
8080
var element = typeProvider.numType.element;
8181
return interfaceTypeNone(element);
8282
}
8383

84-
InterfaceType get numQuestion {
84+
InterfaceTypeImpl get numQuestion {
8585
var element = typeProvider.numType.element;
8686
return interfaceTypeQuestion(element);
8787
}
8888

89-
InterfaceType get objectNone {
89+
InterfaceTypeImpl get objectNone {
9090
var element = typeProvider.objectType.element;
9191
return interfaceTypeNone(element);
9292
}
9393

94-
InterfaceType get objectQuestion {
94+
InterfaceTypeImpl get objectQuestion {
9595
var element = typeProvider.objectType.element;
9696
return interfaceTypeQuestion(element);
9797
}
9898

99-
InterfaceType get recordNone {
99+
InterfaceTypeImpl get recordNone {
100100
var element = typeProvider.recordElement;
101101
return interfaceTypeNone(element);
102102
}
103103

104-
InterfaceType get stringNone {
104+
InterfaceTypeImpl get stringNone {
105105
var element = typeProvider.stringType.element;
106106
return interfaceTypeNone(element);
107107
}
108108

109-
InterfaceType get stringQuestion {
109+
InterfaceTypeImpl get stringQuestion {
110110
var element = typeProvider.stringType.element;
111111
return interfaceTypeQuestion(element);
112112
}
113113

114114
LibraryElementImpl get testLibrary => throw UnimplementedError();
115115

116-
TypeProvider get typeProvider;
116+
TypeProviderImpl get typeProvider;
117117

118-
DartType get unknownInferredType => UnknownInferredType.instance;
118+
TypeImpl get unknownInferredType => UnknownInferredType.instance;
119119

120120
VoidTypeImpl get voidNone => VoidTypeImpl.instance;
121121

@@ -149,7 +149,7 @@ mixin ElementsTypesMixin {
149149
return fragment;
150150
}
151151

152-
InterfaceType comparableNone(DartType type) {
152+
InterfaceTypeImpl comparableNone(DartType type) {
153153
var coreLibrary = typeProvider.intElement.library;
154154
var element = coreLibrary.getClass('Comparable')!;
155155
return element.instantiate(
@@ -158,7 +158,7 @@ mixin ElementsTypesMixin {
158158
);
159159
}
160160

161-
InterfaceType comparableQuestion(DartType type) {
161+
InterfaceTypeImpl comparableQuestion(DartType type) {
162162
var coreLibrary = typeProvider.intElement.library;
163163
var element = coreLibrary.getClass('Comparable')!;
164164
return element.instantiate(
@@ -271,32 +271,32 @@ mixin ElementsTypesMixin {
271271
return typeProvider.futureElement.instantiate(
272272
typeArguments: [type],
273273
nullabilitySuffix: NullabilitySuffix.none,
274-
) as InterfaceTypeImpl;
274+
);
275275
}
276276

277277
InterfaceTypeImpl futureOrNone(DartType type) {
278278
return typeProvider.futureOrElement.instantiate(
279279
typeArguments: [type],
280280
nullabilitySuffix: NullabilitySuffix.none,
281-
) as InterfaceTypeImpl;
281+
);
282282
}
283283

284284
InterfaceTypeImpl futureOrQuestion(DartType type) {
285285
return typeProvider.futureOrElement.instantiate(
286286
typeArguments: [type],
287287
nullabilitySuffix: NullabilitySuffix.question,
288-
) as InterfaceTypeImpl;
288+
);
289289
}
290290

291291
InterfaceTypeImpl futureQuestion(DartType type) {
292292
return typeProvider.futureElement.instantiate(
293293
typeArguments: [type],
294294
nullabilitySuffix: NullabilitySuffix.question,
295-
) as InterfaceTypeImpl;
295+
);
296296
}
297297

298-
InterfaceType interfaceType(
299-
InterfaceElement element, {
298+
InterfaceTypeImpl interfaceType(
299+
InterfaceElementImpl element, {
300300
List<DartType> typeArguments = const [],
301301
required NullabilitySuffix nullabilitySuffix,
302302
}) {
@@ -306,8 +306,8 @@ mixin ElementsTypesMixin {
306306
);
307307
}
308308

309-
InterfaceType interfaceTypeNone(
310-
InterfaceElement element, {
309+
InterfaceTypeImpl interfaceTypeNone(
310+
InterfaceElementImpl element, {
311311
List<DartType> typeArguments = const [],
312312
}) {
313313
return element.instantiate(
@@ -316,8 +316,8 @@ mixin ElementsTypesMixin {
316316
);
317317
}
318318

319-
InterfaceType interfaceTypeQuestion(
320-
InterfaceElement element, {
319+
InterfaceTypeImpl interfaceTypeQuestion(
320+
InterfaceElementImpl element, {
321321
List<DartType> typeArguments = const [],
322322
}) {
323323
return element.instantiate(
@@ -326,14 +326,14 @@ mixin ElementsTypesMixin {
326326
);
327327
}
328328

329-
InterfaceType iterableNone(DartType type) {
329+
InterfaceTypeImpl iterableNone(DartType type) {
330330
return typeProvider.iterableElement.instantiate(
331331
typeArguments: [type],
332332
nullabilitySuffix: NullabilitySuffix.none,
333333
);
334334
}
335335

336-
InterfaceType iterableQuestion(DartType type) {
336+
InterfaceTypeImpl iterableQuestion(DartType type) {
337337
return typeProvider.iterableElement.instantiate(
338338
typeArguments: [type],
339339
nullabilitySuffix: NullabilitySuffix.question,
@@ -371,28 +371,28 @@ mixin ElementsTypesMixin {
371371
return library;
372372
}
373373

374-
InterfaceType listNone(DartType type) {
374+
InterfaceTypeImpl listNone(DartType type) {
375375
return typeProvider.listElement.instantiate(
376376
typeArguments: [type],
377377
nullabilitySuffix: NullabilitySuffix.none,
378378
);
379379
}
380380

381-
InterfaceType listQuestion(DartType type) {
381+
InterfaceTypeImpl listQuestion(DartType type) {
382382
return typeProvider.listElement.instantiate(
383383
typeArguments: [type],
384384
nullabilitySuffix: NullabilitySuffix.question,
385385
);
386386
}
387387

388-
InterfaceType mapNone(DartType key, DartType value) {
388+
InterfaceTypeImpl mapNone(DartType key, DartType value) {
389389
return typeProvider.mapElement.instantiate(
390390
typeArguments: [key, value],
391391
nullabilitySuffix: NullabilitySuffix.none,
392392
);
393393
}
394394

395-
InterfaceType mapQuestion(DartType key, DartType value) {
395+
InterfaceTypeImpl mapQuestion(DartType key, DartType value) {
396396
return typeProvider.mapElement.instantiate(
397397
typeArguments: [key, value],
398398
nullabilitySuffix: NullabilitySuffix.question,
@@ -451,7 +451,7 @@ mixin ElementsTypesMixin {
451451
return parameter;
452452
}
453453

454-
ParameterElement namedRequiredParameter({
454+
ParameterElementImpl namedRequiredParameter({
455455
required String name,
456456
required DartType type,
457457
bool isCovariant = false,
@@ -590,8 +590,8 @@ mixin ElementsTypesMixin {
590590
return fragment;
591591
}
592592

593-
DartType typeAliasTypeNone(
594-
TypeAliasElement element, {
593+
TypeImpl typeAliasTypeNone(
594+
TypeAliasElementImpl element, {
595595
List<DartType> typeArguments = const [],
596596
}) {
597597
return element.instantiate(

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,10 @@ class InterfaceTypeImplTest extends AbstractTypeSystemTest with StringTypes {
11161116
nullabilitySuffix: NullabilitySuffix.none,
11171117
);
11181118

1119-
var B = class_(name: 'B', interfaces: [AofC],);
1119+
var B = class_(
1120+
name: 'B',
1121+
interfaces: [AofC],
1122+
);
11201123
var targetType = interfaceTypeNone(B);
11211124
var result = targetType.asInstanceOf(A);
11221125
expect(result, AofC);
@@ -1540,7 +1543,7 @@ A<int>?
15401543
}
15411544

15421545
void test_hashCode() {
1543-
ClassElement classA = class_(name: 'A');
1546+
var classA = class_(name: 'A');
15441547
InterfaceType typeA = interfaceTypeNone(classA);
15451548
expect(0 == typeA.hashCode, isFalse);
15461549
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import 'package:_fe_analyzer_shared/src/flow_analysis/factory_type_test_helper.dart';
66
import 'package:analyzer/dart/element/type.dart';
7-
import 'package:analyzer/dart/element/type_provider.dart';
87
import 'package:analyzer/src/dart/element/type.dart';
8+
import 'package:analyzer/src/dart/element/type_provider.dart';
99
import 'package:analyzer/src/dart/element/type_system.dart';
1010
import 'package:test/test.dart' as test;
1111
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -22,7 +22,7 @@ main() {
2222
@reflectiveTest
2323
class FactorTypeTest with FactorTypeTestMixin<DartType>, ElementsTypesMixin {
2424
@override
25-
late final TypeProvider typeProvider;
25+
late final TypeProviderImpl typeProvider;
2626

2727
late final TypeSystemImpl typeSystem;
2828

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// ignore_for_file: analyzer_use_new_elements
66

7-
import 'package:analyzer/dart/element/element.dart';
87
import 'package:analyzer/dart/element/type.dart';
98
import 'package:analyzer/src/dart/element/element.dart';
109
import 'package:analyzer/src/dart/element/least_upper_bound.dart';
@@ -157,13 +156,10 @@ class PathToObjectTest extends AbstractTypeSystemTest {
157156
// \ /
158157
// E
159158
//
160-
ClassElement classA = class_(name: "A");
161-
ClassElement classB =
162-
class_(name: "B", superType: interfaceTypeNone(classA));
163-
ClassElement classC =
164-
class_(name: "C", superType: interfaceTypeNone(classA));
165-
ClassElement classD =
166-
class_(name: "D", superType: interfaceTypeNone(classC));
159+
var classA = class_(name: "A");
160+
var classB = class_(name: "B", superType: interfaceTypeNone(classA));
161+
var classC = class_(name: "C", superType: interfaceTypeNone(classA));
162+
var classD = class_(name: "D", superType: interfaceTypeNone(classC));
167163
ClassElementImpl classE =
168164
class_(name: "E", superType: interfaceTypeNone(classB));
169165
classE.interfaces = <InterfaceType>[interfaceTypeNone(classD)];
@@ -225,11 +221,9 @@ class PathToObjectTest extends AbstractTypeSystemTest {
225221
// |
226222
// C
227223
//
228-
ClassElement classA = class_(name: "A");
229-
ClassElement classB =
230-
class_(name: "B", superType: interfaceTypeNone(classA));
231-
ClassElement classC =
232-
class_(name: "C", superType: interfaceTypeNone(classB));
224+
var classA = class_(name: "A");
225+
var classB = class_(name: "B", superType: interfaceTypeNone(classA));
226+
var classC = class_(name: "C", superType: interfaceTypeNone(classB));
233227
expect(_toElement(classA), 2);
234228
expect(_toElement(classB), 3);
235229
expect(_toElement(classC), 4);
@@ -355,7 +349,7 @@ class PathToObjectTest extends AbstractTypeSystemTest {
355349
expect(_toElement(M), 4);
356350
}
357351

358-
int _toElement(InterfaceElement element) {
352+
int _toElement(InterfaceElementImpl element) {
359353
var type = interfaceTypeNone(element);
360354
return _toType(type);
361355
}

0 commit comments

Comments
 (0)