Skip to content

Commit 4102e63

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Deprecate TypeProvider.listType/mapType
[email protected] Change-Id: I7cef0b752be4ef6a7e4bc5394e14cd64ecb67ab5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117765 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent f1afb34 commit 4102e63

25 files changed

+183
-174
lines changed

pkg/analysis_server/lib/src/services/correction/assist_internal.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class AssistProcessor extends BaseProcessor {
516516
InstanceCreationExpression creation = node.thisOrAncestorOfType();
517517
if (creation == null ||
518518
node.offset > creation.argumentList.offset ||
519-
creation.staticType.element != typeProvider.listType.element ||
519+
creation.staticType.element != typeProvider.listElement ||
520520
creation.constructorName.name != null ||
521521
creation.argumentList.arguments.isNotEmpty) {
522522
_coverageMarker();
@@ -595,7 +595,7 @@ class AssistProcessor extends BaseProcessor {
595595
Future<void> _addProposal_convertMapConstructorToMapLiteral() async {
596596
bool isMapClass(Element element) =>
597597
element is ClassElement &&
598-
(element == typeProvider.mapType.element ||
598+
(element == typeProvider.mapElement ||
599599
(element.name == 'LinkedHashMap' &&
600600
element.library.name == 'dart.collection'));
601601
//
@@ -963,9 +963,8 @@ class AssistProcessor extends BaseProcessor {
963963
// iterable should be List
964964
{
965965
DartType iterableType = iterable.staticType;
966-
InterfaceType listType = typeProvider.listType;
967966
if (iterableType is! InterfaceType ||
968-
iterableType.element != listType.element) {
967+
iterableType.element != typeProvider.listElement) {
969968
_coverageMarker();
970969
return;
971970
}

pkg/analysis_server/lib/src/services/correction/base_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ abstract class BaseProcessor {
413413
ConstructorElement element = creation.staticElement;
414414
if (element == null ||
415415
element.name != 'fromIterable' ||
416-
element.enclosingElement != typeProvider.mapType.element) {
416+
element.enclosingElement != typeProvider.mapElement) {
417417
_coverageMarker();
418418
return null;
419419
}

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
12561256
nodeType is InterfaceType && nodeType.typeArguments.isNotEmpty
12571257
? nodeType.typeArguments[0]
12581258
: _typeProvider.dynamicType;
1259-
InterfaceType listType = _typeProvider.listType.instantiate([elementType]);
1259+
InterfaceType listType = _typeProvider.listType2(elementType);
12601260
return new DartObjectImpl(listType, new ListState(list));
12611261
}
12621262

@@ -1390,8 +1390,7 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
13901390
valueType = typeArguments[1];
13911391
}
13921392
}
1393-
InterfaceType mapType =
1394-
_typeProvider.mapType.instantiate([keyType, valueType]);
1393+
InterfaceType mapType = _typeProvider.mapType2(keyType, valueType);
13951394
return new DartObjectImpl(mapType, new MapState(map));
13961395
} else {
13971396
if (!node.isConst) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,8 +2479,7 @@ class ConstFieldElementImpl_EnumValues extends ConstFieldElementImpl_ofEnum {
24792479
@override
24802480
InterfaceType get type {
24812481
if (_type == null) {
2482-
InterfaceType listType = context.typeProvider.listType;
2483-
return _type = listType.instantiate(<DartType>[_enum.type]);
2482+
return _type = context.typeProvider.listType2(_enum.type);
24842483
}
24852484
return _type;
24862485
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,7 @@ class EnumMemberBuilder extends RecursiveAstVisitor<void> {
23232323
valuesField.isStatic = true;
23242324
valuesField.isConst = true;
23252325
valuesField.isSynthetic = true;
2326-
valuesField.type = _typeProvider.listType.instantiate(<DartType>[enumType]);
2326+
valuesField.type = _typeProvider.listType2(enumType);
23272327
fields.add(valuesField);
23282328
getters.add(_createGetter(valuesField));
23292329
//
@@ -4164,7 +4164,7 @@ class ResolverVisitor extends ScopedVisitor {
41644164
if (typeArguments.arguments.length == 1) {
41654165
DartType elementType = typeArguments.arguments[0].type;
41664166
if (!elementType.isDynamic) {
4167-
listType = typeProvider.listType.instantiate([elementType]);
4167+
listType = typeProvider.listType2(elementType);
41684168
}
41694169
}
41704170
} else {
@@ -4348,7 +4348,7 @@ class ResolverVisitor extends ScopedVisitor {
43484348
if (typeArguments != null && typeArguments.length == 2) {
43494349
var keyType = typeArguments[0].type;
43504350
var valueType = typeArguments[1].type;
4351-
literalType = typeProvider.mapType.instantiate([keyType, valueType]);
4351+
literalType = typeProvider.mapType2(keyType, valueType);
43524352
} else {
43534353
literalType = typeAnalyzer.inferMapTypeDownwards(
43544354
node, literalResolution.contextType);
@@ -4716,8 +4716,8 @@ class ResolverVisitor extends ScopedVisitor {
47164716
} else if (literal.elements.isEmpty) {
47174717
return _LiteralResolution(
47184718
_LiteralResolutionKind.map,
4719-
typeProvider.mapType.instantiate(
4720-
[typeProvider.dynamicType, typeProvider.dynamicType]));
4719+
typeProvider.mapType2(
4720+
typeProvider.dynamicType, typeProvider.dynamicType));
47214721
}
47224722
return _LiteralResolution(_LiteralResolutionKind.ambiguous, null);
47234723
}
@@ -4781,10 +4781,8 @@ class ResolverVisitor extends ScopedVisitor {
47814781
return _LiteralResolution(_LiteralResolutionKind.set,
47824782
typeProvider.setType2(arguments[0].type));
47834783
} else if (arguments.length == 2) {
4784-
return _LiteralResolution(
4785-
_LiteralResolutionKind.map,
4786-
typeProvider.mapType
4787-
.instantiate([arguments[0].type, arguments[1].type]));
4784+
return _LiteralResolution(_LiteralResolutionKind.map,
4785+
typeProvider.mapType2(arguments[0].type, arguments[1].type));
47884786
}
47894787
}
47904788
return _LiteralResolution(_LiteralResolutionKind.ambiguous, null);
@@ -6709,6 +6707,7 @@ abstract class TypeProvider {
67096707
ClassElement get listElement;
67106708

67116709
/// Return the type representing the built-in type 'List'.
6710+
@Deprecated('Use listType2() instead.')
67126711
InterfaceType get listType;
67136712

67146713
/// Return the element representing the built-in class 'Map'.
@@ -6718,6 +6717,7 @@ abstract class TypeProvider {
67186717
InterfaceType get mapObjectObjectType;
67196718

67206719
/// Return the type representing the built-in type 'Map'.
6720+
@Deprecated('Use mapType2() instead.')
67216721
InterfaceType get mapType;
67226722

67236723
/// Return the type representing the built-in type 'Never'.

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -740,14 +740,11 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
740740
}
741741
}
742742
_recordStaticType(
743-
node,
744-
_nonNullable(
745-
_typeProvider.listType.instantiate(<DartType>[staticType])));
743+
node, _nonNullable(_typeProvider.listType2(staticType)));
746744
return;
747745
}
748746

749-
DartType listDynamicType =
750-
_typeProvider.listType.instantiate(<DartType>[_dynamicType]);
747+
DartType listDynamicType = _typeProvider.listType2(_dynamicType);
751748

752749
// If there are no type arguments, try to infer some arguments.
753750
DartType inferred = inferListType(node);
@@ -1049,9 +1046,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
10491046
var keyType = _getType(typeArguments[0]) ?? _dynamicType;
10501047
var valueType = _getType(typeArguments[1]) ?? _dynamicType;
10511048
_recordStaticType(
1052-
node,
1053-
_nonNullable(_typeProvider.mapType
1054-
.instantiate(<DartType>[keyType, valueType])));
1049+
node, _nonNullable(_typeProvider.mapType2(keyType, valueType)));
10551050
return;
10561051
}
10571052
// If we get here, then a nonsense number of type arguments were provided,
@@ -1061,7 +1056,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
10611056
if (literalType.isDynamic) {
10621057
// The literal is ambiguous, and further analysis won't resolve the
10631058
// ambiguity. Leave it as neither a set nor a map.
1064-
} else if (literalType.element == _typeProvider.mapType.element) {
1059+
} else if (literalType.element == _typeProvider.mapElement) {
10651060
(node as SetOrMapLiteralImpl).becomeMap();
10661061
} else {
10671062
assert(literalType.element == _typeProvider.setElement);
@@ -1569,7 +1564,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
15691564
} else if (_typeSystem.isSubtypeOf(
15701565
expressionType, _typeProvider.mapObjectObjectType)) {
15711566
InterfaceType mapType = (expressionType as InterfaceTypeImpl)
1572-
.asInstanceOf(_typeProvider.mapType.element);
1567+
.asInstanceOf(_typeProvider.mapElement);
15731568
List<DartType> typeArguments = mapType.typeArguments;
15741569
return _InferredCollectionElementTypeInformation(
15751570
elementType: null,

pkg/analyzer/lib/src/generated/testing/element_factory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class ElementFactory {
170170
FieldElementImpl valuesField = new FieldElementImpl("values", -1);
171171
valuesField.isStatic = true;
172172
valuesField.isConst = true;
173-
valuesField.type = typeProvider.listType.instantiate(<DartType>[enumType]);
173+
valuesField.type = typeProvider.listType2(enumType);
174174
fields.add(valuesField);
175175
//
176176
// Build the enum constants.

pkg/analyzer/lib/src/summary/expr_builder.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ class ExprBuilder {
895895
var typeArg = typeArguments == null
896896
? resynthesizer.typeProvider.dynamicType
897897
: typeArguments.arguments[0].type;
898-
var staticType = resynthesizer.typeProvider.listType.instantiate([typeArg]);
898+
var staticType = resynthesizer.typeProvider.listType2(typeArg);
899899
_push(AstTestFactory.listLiteral2(Keyword.CONST, typeArguments, elements)
900900
..staticType = staticType);
901901
}
@@ -960,8 +960,7 @@ class ExprBuilder {
960960
var valueType = typeArguments == null
961961
? resynthesizer.typeProvider.dynamicType
962962
: typeArguments.arguments[1].type;
963-
var staticType =
964-
resynthesizer.typeProvider.mapType.instantiate([keyType, valueType]);
963+
var staticType = resynthesizer.typeProvider.mapType2(keyType, valueType);
965964
SetOrMapLiteralImpl literal =
966965
AstTestFactory.setOrMapLiteral(Keyword.CONST, typeArguments, entries);
967966
literal.becomeMap();
@@ -1013,8 +1012,7 @@ class ExprBuilder {
10131012
if (typeArguments.arguments.length == 2) {
10141013
var keyType = typeArguments.arguments[0].type;
10151014
var valueType = typeArguments.arguments[1].type;
1016-
staticType = resynthesizer.typeProvider.mapType
1017-
.instantiate([keyType, valueType]);
1015+
staticType = resynthesizer.typeProvider.mapType2(keyType, valueType);
10181016
} else if (typeArguments.arguments.length == 1) {
10191017
isMap = false;
10201018
var valueType = typeArguments == null

pkg/analyzer/lib/src/task/strong/checker.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ class CodeChecker extends RecursiveAstVisitor {
231231
} else if (element is SpreadElement) {
232232
// Spread expression may be dynamic in which case it's implicitly downcast
233233
// to Map<dynamic, dynamic>
234-
DartType expressionCastType = typeProvider.mapType
235-
.instantiate([DynamicTypeImpl.instance, DynamicTypeImpl.instance]);
234+
DartType expressionCastType = typeProvider.mapType2(
235+
DynamicTypeImpl.instance, DynamicTypeImpl.instance);
236236
checkAssignment(element.expression, expressionCastType);
237237

238238
var exprType = element.expression.staticType;
239239
var asMapType = exprType is InterfaceTypeImpl
240-
? exprType.asInstanceOf(typeProvider.mapType.element)
240+
? exprType.asInstanceOf(typeProvider.mapElement)
241241
: null;
242242

243243
var elementKeyType =

pkg/analyzer/test/generated/static_type_analyzer_test.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -979,19 +979,15 @@ class StaticTypeAnalyzerTest extends EngineTestCase
979979
Expression node = AstTestFactory.listLiteral();
980980
DartType resultType = _analyze(node);
981981
_assertType2(
982-
_typeProvider.listType
983-
.instantiate(<DartType>[_typeProvider.dynamicType]),
984-
resultType);
982+
_typeProvider.listType2(_typeProvider.dynamicType), resultType);
985983
_listener.assertNoErrors();
986984
}
987985

988986
void test_visitListLiteral_nonEmpty() {
989987
// [0]
990988
Expression node = AstTestFactory.listLiteral([_resolvedInteger(0)]);
991989
DartType resultType = _analyze(node);
992-
_assertType2(
993-
_typeProvider.listType.instantiate(<DartType>[_typeProvider.intType]),
994-
resultType);
990+
_assertType2(_typeProvider.listType2(_typeProvider.intType), resultType);
995991
_listener.assertNoErrors();
996992
}
997993

@@ -1001,9 +997,7 @@ class StaticTypeAnalyzerTest extends EngineTestCase
1001997
Expression node = AstTestFactory.listLiteral([identifier]);
1002998
DartType resultType = _analyze(node);
1003999
_assertType2(
1004-
_typeProvider.listType
1005-
.instantiate(<DartType>[_typeProvider.dynamicType]),
1006-
resultType);
1000+
_typeProvider.listType2(_typeProvider.dynamicType), resultType);
10071001
_listener.assertNoErrors();
10081002
}
10091003

@@ -1013,9 +1007,7 @@ class StaticTypeAnalyzerTest extends EngineTestCase
10131007
Expression node = AstTestFactory.listLiteral(
10141008
[_resolvedInteger(0), identifier, _resolvedInteger(1)]);
10151009
DartType resultType = _analyze(node);
1016-
_assertType2(
1017-
_typeProvider.listType.instantiate(<DartType>[_typeProvider.intType]),
1018-
resultType);
1010+
_assertType2(_typeProvider.listType2(_typeProvider.intType), resultType);
10191011
_listener.assertNoErrors();
10201012
}
10211013

@@ -1024,8 +1016,8 @@ class StaticTypeAnalyzerTest extends EngineTestCase
10241016
Expression node = AstTestFactory.setOrMapLiteral(null, null);
10251017
DartType resultType = _analyze(node);
10261018
_assertType2(
1027-
_typeProvider.mapType.instantiate(
1028-
<DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]),
1019+
_typeProvider.mapType2(
1020+
_typeProvider.dynamicType, _typeProvider.dynamicType),
10291021
resultType);
10301022
_listener.assertNoErrors();
10311023
}
@@ -1036,8 +1028,8 @@ class StaticTypeAnalyzerTest extends EngineTestCase
10361028
null, null, [AstTestFactory.mapLiteralEntry("k", _resolvedInteger(0))]);
10371029
DartType resultType = _analyze(node);
10381030
_assertType2(
1039-
_typeProvider.mapType.instantiate(
1040-
<DartType>[_typeProvider.dynamicType, _typeProvider.intType]),
1031+
_typeProvider.mapType2(
1032+
_typeProvider.dynamicType, _typeProvider.intType),
10411033
resultType);
10421034
_listener.assertNoErrors();
10431035
}

0 commit comments

Comments
 (0)