Skip to content

Commit 1a812bb

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Deprecate TypeProvider.setType
[email protected] Change-Id: I522066c919b5eef9640243c8b08435756d9481f6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117597 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 4b6ab33 commit 1a812bb

File tree

8 files changed

+23
-33
lines changed

8 files changed

+23
-33
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ class AssistProcessor extends BaseProcessor {
661661
InstanceCreationExpression creation = node.thisOrAncestorOfType();
662662
if (creation == null ||
663663
node.offset > creation.argumentList.offset ||
664-
creation.staticType.element != typeProvider.setType.element) {
664+
creation.staticType.element != typeProvider.setElement) {
665665
// TODO(brianwilkerson) Consider also accepting uses of LinkedHashSet.
666666
_coverageMarker();
667667
return;
@@ -718,7 +718,7 @@ class AssistProcessor extends BaseProcessor {
718718
if (parent is VariableDeclaration) {
719719
AstNode parent2 = parent.parent;
720720
if (parent2 is VariableDeclarationList &&
721-
parent2.type?.type?.element == typeProvider.setType.element) {
721+
parent2.type?.type?.element == typeProvider.setElement) {
722722
return true;
723723
}
724724
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
14121412
nodeType is InterfaceType && nodeType.typeArguments.isNotEmpty
14131413
? nodeType.typeArguments[0]
14141414
: _typeProvider.dynamicType;
1415-
InterfaceType setType = _typeProvider.setType.instantiate([elementType]);
1415+
InterfaceType setType = _typeProvider.setType2(elementType);
14161416
return new DartObjectImpl(setType, new SetState(set));
14171417
}
14181418
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,7 +4340,7 @@ class ResolverVisitor extends ScopedVisitor {
43404340
if (literalResolution.kind == _LiteralResolutionKind.set) {
43414341
if (typeArguments != null && typeArguments.length == 1) {
43424342
var elementType = typeArguments[0].type;
4343-
literalType = typeProvider.setType.instantiate([elementType]);
4343+
literalType = typeProvider.setType2(elementType);
43444344
} else {
43454345
literalType = typeAnalyzer.inferSetTypeDownwards(
43464346
node, literalResolution.contextType);
@@ -4776,7 +4776,7 @@ class ResolverVisitor extends ScopedVisitor {
47764776
NodeList<TypeAnnotation> arguments = typeArgumentList.arguments;
47774777
if (arguments.length == 1) {
47784778
return _LiteralResolution(_LiteralResolutionKind.set,
4779-
typeProvider.setType.instantiate([arguments[0].type]));
4779+
typeProvider.setType2(arguments[0].type));
47804780
} else if (arguments.length == 2) {
47814781
return _LiteralResolution(
47824782
_LiteralResolutionKind.map,
@@ -6737,6 +6737,7 @@ abstract class TypeProvider {
67376737
ClassElement get setElement;
67386738

67396739
/// Return the type representing the built-in type 'Set'.
6740+
@Deprecated('Use setType2() instead.')
67406741
InterfaceType get setType;
67416742

67426743
/// Return the type representing the built-in type 'StackTrace'.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,9 +1042,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
10421042
(node as SetOrMapLiteralImpl).becomeSet();
10431043
var elementType = _getType(typeArguments[0]) ?? _dynamicType;
10441044
_recordStaticType(
1045-
node,
1046-
_nonNullable(
1047-
_typeProvider.setType.instantiate(<DartType>[elementType])));
1045+
node, _nonNullable(_typeProvider.setType2(elementType)));
10481046
return;
10491047
} else if (typeArguments.length == 2) {
10501048
(node as SetOrMapLiteralImpl).becomeMap();
@@ -1066,7 +1064,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
10661064
} else if (literalType.element == _typeProvider.mapType.element) {
10671065
(node as SetOrMapLiteralImpl).becomeMap();
10681066
} else {
1069-
assert(literalType.element == _typeProvider.setType.element);
1067+
assert(literalType.element == _typeProvider.setElement);
10701068
(node as SetOrMapLiteralImpl).becomeSet();
10711069
}
10721070
if (_strictInference &&

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,7 @@ class ExprBuilder {
10201020
var valueType = typeArguments == null
10211021
? resynthesizer.typeProvider.dynamicType
10221022
: typeArguments.arguments[0].type;
1023-
staticType =
1024-
resynthesizer.typeProvider.setType.instantiate([valueType]);
1023+
staticType = resynthesizer.typeProvider.setType2(valueType);
10251024
}
10261025
} else {
10271026
for (var i = 0; i < elements.length; ++i) {

pkg/analyzer/test/src/dart/constant/evaluation_test.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,7 @@ const c = {'a' : 1, ...{'b' : 2, 'c' : 3}, 'd' : 4};
994994
const c = {1, if (1 < 0) 2 else 3, 4};
995995
''');
996996
DartObjectImpl result = _evaluateConstant('c');
997-
expect(
998-
result.type, typeProvider.setType.instantiate([typeProvider.intType]));
997+
expect(result.type, typeProvider.setType2(typeProvider.intType));
999998
expect(result.toSetValue().map((e) => e.toIntValue()), [1, 3, 4]);
1000999
}
10011000

@@ -1004,8 +1003,7 @@ const c = {1, if (1 < 0) 2 else 3, 4};
10041003
const c = {1, if (1 < 0) 2, 3};
10051004
''');
10061005
DartObjectImpl result = _evaluateConstant('c');
1007-
expect(
1008-
result.type, typeProvider.setType.instantiate([typeProvider.intType]));
1006+
expect(result.type, typeProvider.setType2(typeProvider.intType));
10091007
expect(result.toSetValue().map((e) => e.toIntValue()), [1, 3]);
10101008
}
10111009

@@ -1014,8 +1012,7 @@ const c = {1, if (1 < 0) 2, 3};
10141012
const c = {1, if (1 > 0) 2 else 3, 4};
10151013
''');
10161014
DartObjectImpl result = _evaluateConstant('c');
1017-
expect(
1018-
result.type, typeProvider.setType.instantiate([typeProvider.intType]));
1015+
expect(result.type, typeProvider.setType2(typeProvider.intType));
10191016
expect(result.toSetValue().map((e) => e.toIntValue()), [1, 2, 4]);
10201017
}
10211018

@@ -1024,8 +1021,7 @@ const c = {1, if (1 > 0) 2 else 3, 4};
10241021
const c = {1, if (1 > 0) 2, 3};
10251022
''');
10261023
DartObjectImpl result = _evaluateConstant('c');
1027-
expect(
1028-
result.type, typeProvider.setType.instantiate([typeProvider.intType]));
1024+
expect(result.type, typeProvider.setType2(typeProvider.intType));
10291025
expect(result.toSetValue().map((e) => e.toIntValue()), [1, 2, 3]);
10301026
}
10311027

@@ -1034,8 +1030,7 @@ const c = {1, if (1 > 0) 2, 3};
10341030
const c = {1, if (1 > 0) if (2 > 1) 2, 3};
10351031
''');
10361032
DartObjectImpl result = _evaluateConstant('c');
1037-
expect(
1038-
result.type, typeProvider.setType.instantiate([typeProvider.intType]));
1033+
expect(result.type, typeProvider.setType2(typeProvider.intType));
10391034
expect(result.toSetValue().map((e) => e.toIntValue()), [1, 2, 3]);
10401035
}
10411036

@@ -1044,8 +1039,7 @@ const c = {1, if (1 > 0) if (2 > 1) 2, 3};
10441039
const c = {1, ...{2, 3}, 4};
10451040
''');
10461041
DartObjectImpl result = _evaluateConstant('c');
1047-
expect(
1048-
result.type, typeProvider.setType.instantiate([typeProvider.intType]));
1042+
expect(result.type, typeProvider.setType2(typeProvider.intType));
10491043
expect(result.toSetValue().map((e) => e.toIntValue()), [1, 2, 3, 4]);
10501044
}
10511045
}

pkg/analyzer/test/src/dart/constant/value_test.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +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+
import 'package:analyzer/dart/element/type.dart';
56
import 'package:analyzer/src/generated/constant.dart';
67
import 'package:analyzer/src/generated/resolver.dart';
78
import 'package:analyzer/src/generated/testing/test_type_provider.dart';
@@ -415,16 +416,14 @@ class DartObjectImplTest extends EngineTestCase {
415416
}
416417

417418
void test_getValue_set_empty() {
418-
Object result = _setValue().toSetValue();
419-
_assertInstanceOfObjectArray(result);
420-
Set<Object> set = result as Set<Object>;
419+
DartObjectImpl object = _setValue(_typeProvider.intType, null);
420+
Set<DartObject> set = object.toSetValue();
421421
expect(set, hasLength(0));
422422
}
423423

424424
void test_getValue_set_valid() {
425-
Object result = _setValue(new Set.from([_intValue(23)])).toSetValue();
426-
_assertInstanceOfObjectArray(result);
427-
Set<Object> set = result as Set<Object>;
425+
DartObjectImpl object = _setValue(_typeProvider.intType, {_intValue(23)});
426+
Set<DartObject> set = object.toSetValue();
428427
expect(set, hasLength(1));
429428
}
430429

@@ -1942,9 +1941,8 @@ class DartObjectImplTest extends EngineTestCase {
19421941
return new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE);
19431942
}
19441943

1945-
DartObjectImpl _setValue([Set<DartObjectImpl> elements]) {
1946-
return new DartObjectImpl(_typeProvider.setType,
1947-
new SetState(elements ?? new Set<DartObjectImpl>()));
1944+
DartObjectImpl _setValue(DartType type, Set<DartObjectImpl> elements) {
1945+
return DartObjectImpl(type, SetState(elements ?? Set<DartObjectImpl>()));
19481946
}
19491947

19501948
DartObjectImpl _stringValue(String value) {

pkg/dev_compiler/lib/src/analyzer/code_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4462,7 +4462,7 @@ class CodeGenerator extends Object
44624462
return _emitConstList(type.typeArguments[0],
44634463
value.toListValue().map(_emitDartObject).toList());
44644464
}
4465-
if (type.element == types.setType.element) {
4465+
if (type.element == types.setElement) {
44664466
return _emitConstSet(type.typeArguments[0],
44674467
value.toSetValue().map(_emitDartObject).toList());
44684468
}

0 commit comments

Comments
 (0)