Add TypeProvider.xyzType2() for platform classes with type parameters.

R=brianwilkerson@google.com

Change-Id: I8a25ec94f8cf7cb7b252d8ecbcc0c1bb15ae6bae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117444
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2019-09-16 22:50:52 +00:00 committed by commit-bot@chromium.org
parent 035c428b31
commit 93980b75ce
4 changed files with 195 additions and 2 deletions

View file

@ -48,8 +48,11 @@ class TypeProviderImpl extends TypeProviderBase {
ClassElement _futureElement;
ClassElement _futureOrElement;
ClassElement _iterableElement;
ClassElement _listElement;
ClassElement _mapElement;
ClassElement _setElement;
ClassElement _streamElement;
ClassElement _symbolElement;
InterfaceType _boolType;
InterfaceType _deprecatedType;
@ -190,6 +193,7 @@ class TypeProviderImpl extends TypeProviderBase {
return _iterableDynamicType;
}
@override
ClassElement get iterableElement {
return _iterableElement ??= _getClassElement(_coreLibrary, 'Iterable');
}
@ -210,12 +214,18 @@ class TypeProviderImpl extends TypeProviderBase {
return _iterableType;
}
@override
ClassElement get listElement {
return _listElement ??= _getClassElement(_coreLibrary, 'List');
}
@override
InterfaceType get listType {
_listType ??= _getType(_coreLibrary, "List");
return _listType;
}
@override
ClassElement get mapElement {
return _mapElement ??= _getClassElement(_coreLibrary, 'Map');
}
@ -265,6 +275,11 @@ class TypeProviderImpl extends TypeProviderBase {
return _objectType;
}
@override
ClassElement get setElement {
return _setElement ??= _getClassElement(_coreLibrary, 'Set');
}
@override
InterfaceType get setType {
return _setType ??= _getType(_coreLibrary, "Set");
@ -286,6 +301,7 @@ class TypeProviderImpl extends TypeProviderBase {
return _streamDynamicType;
}
@override
ClassElement get streamElement {
return _streamElement ??= _getClassElement(_asyncLibrary, 'Stream');
}
@ -302,6 +318,11 @@ class TypeProviderImpl extends TypeProviderBase {
return _stringType;
}
@override
ClassElement get symbolElement {
return _symbolElement ??= _getClassElement(_coreLibrary, 'Symbol');
}
@override
InterfaceType get symbolType {
_symbolType ??= _getType(_coreLibrary, "Symbol");
@ -317,6 +338,62 @@ class TypeProviderImpl extends TypeProviderBase {
@override
VoidType get voidType => VoidTypeImpl.instance;
@override
InterfaceType futureOrType2(DartType valueType) {
return futureOrElement.instantiate(
typeArguments: [valueType],
nullabilitySuffix: _nullabilitySuffix,
);
}
@override
InterfaceType futureType2(DartType valueType) {
return futureElement.instantiate(
typeArguments: [valueType],
nullabilitySuffix: _nullabilitySuffix,
);
}
@override
InterfaceType iterableType2(DartType elementType) {
return iterableElement.instantiate(
typeArguments: [elementType],
nullabilitySuffix: _nullabilitySuffix,
);
}
@override
InterfaceType listType2(DartType elementType) {
return listElement.instantiate(
typeArguments: [elementType],
nullabilitySuffix: _nullabilitySuffix,
);
}
@override
InterfaceType mapType2(DartType keyType, DartType valueType) {
return mapElement.instantiate(
typeArguments: [keyType, valueType],
nullabilitySuffix: _nullabilitySuffix,
);
}
@override
InterfaceType setType2(DartType elementType) {
return setElement.instantiate(
typeArguments: [elementType],
nullabilitySuffix: _nullabilitySuffix,
);
}
@override
InterfaceType streamType2(DartType elementType) {
return streamElement.instantiate(
typeArguments: [elementType],
nullabilitySuffix: _nullabilitySuffix,
);
}
TypeProviderImpl withNullability(NullabilitySuffix nullabilitySuffix) {
if (_nullabilitySuffix == nullabilitySuffix) {
return this;

View file

@ -6658,9 +6658,15 @@ abstract class TypeProvider {
/// Return the type representing 'Future<dynamic>'.
InterfaceType get futureDynamicType;
/// Return the element representing the built-in class 'Future'.
ClassElement get futureElement;
/// Return the type representing 'Future<Null>'.
InterfaceType get futureNullType;
/// Return the element representing the built-in class 'FutureOr'.
ClassElement get futureOrElement;
/// Return the type representing 'FutureOr<Null>'.
InterfaceType get futureOrNullType;
@ -6676,15 +6682,24 @@ abstract class TypeProvider {
/// Return the type representing the type 'Iterable<dynamic>'.
InterfaceType get iterableDynamicType;
/// Return the element representing the built-in class 'Iterable'.
ClassElement get iterableElement;
/// Return the type representing the type 'Iterable<Object>'.
InterfaceType get iterableObjectType;
/// Return the type representing the built-in type 'Iterable'.
InterfaceType get iterableType;
/// Return the element representing the built-in class 'List'.
ClassElement get listElement;
/// Return the type representing the built-in type 'List'.
InterfaceType get listType;
/// Return the element representing the built-in class 'Map'.
ClassElement get mapElement;
/// Return the type representing 'Map<Object, Object>'.
InterfaceType get mapObjectObjectType;
@ -6710,6 +6725,9 @@ abstract class TypeProvider {
/// Return the type representing the built-in type 'Object'.
InterfaceType get objectType;
/// Return the element representing the built-in class 'Set'.
ClassElement get setElement;
/// Return the type representing the built-in type 'Set'.
InterfaceType get setType;
@ -6719,12 +6737,18 @@ abstract class TypeProvider {
/// Return the type representing 'Stream<dynamic>'.
InterfaceType get streamDynamicType;
/// Return the element representing the built-in class 'Stream'.
ClassElement get streamElement;
/// Return the type representing the built-in type 'Stream'.
InterfaceType get streamType;
/// Return the type representing the built-in type 'String'.
InterfaceType get stringType;
/// Return the element representing the built-in class 'Symbol'.
ClassElement get symbolElement;
/// Return the type representing the built-in type 'Symbol'.
InterfaceType get symbolType;
@ -6734,6 +6758,14 @@ abstract class TypeProvider {
/// Return the type representing the built-in type `void`.
VoidType get voidType;
/// Return the instantiation of the built-in class 'FutureOr' with the
/// given [valueType]. The type has the nullability suffix of this provider.
InterfaceType futureOrType2(DartType valueType);
/// Return the instantiation of the built-in class 'Future' with the
/// given [valueType]. The type has the nullability suffix of this provider.
InterfaceType futureType2(DartType valueType);
/// Return 'true' if [id] is the name of a getter on
/// the Object type.
bool isObjectGetter(String id);
@ -6745,6 +6777,27 @@ abstract class TypeProvider {
/// Return 'true' if [id] is the name of a method on
/// the Object type.
bool isObjectMethod(String id);
/// Return the instantiation of the built-in class 'Iterable' with the
/// given [elementType]. The type has the nullability suffix of this provider.
InterfaceType iterableType2(DartType elementType);
/// Return the instantiation of the built-in class 'List' with the
/// given [elementType]. The type has the nullability suffix of this provider.
InterfaceType listType2(DartType elementType);
/// Return the instantiation of the built-in class 'List' with the
/// given [keyType] and [valueType]. The type has the nullability suffix of
/// this provider.
InterfaceType mapType2(DartType keyType, DartType valueType);
/// Return the instantiation of the built-in class 'Set' with the
/// given [elementType]. The type has the nullability suffix of this provider.
InterfaceType setType2(DartType elementType);
/// Return the instantiation of the built-in class 'Stream' with the
/// given [elementType]. The type has the nullability suffix of this provider.
InterfaceType streamType2(DartType elementType);
}
/// Modes in which [TypeResolverVisitor] works.

View file

@ -23,13 +23,17 @@ class TestTypeProvider extends TypeProviderImpl {
context ??= _MockAnalysisContext();
var sdkElements = MockSdkElements(context, nullabilitySuffix);
return TestTypeProvider._(
nullabilitySuffix,
sdkElements.coreLibrary,
sdkElements.asyncLibrary,
);
}
TestTypeProvider._(LibraryElement coreLibrary, LibraryElement asyncLibrary)
: super(coreLibrary, asyncLibrary);
TestTypeProvider._(
NullabilitySuffix nullabilitySuffix,
LibraryElement coreLibrary,
LibraryElement asyncLibrary,
) : super(coreLibrary, asyncLibrary, nullabilitySuffix: nullabilitySuffix);
}
class _MockAnalysisContext implements AnalysisContext {

View file

@ -5580,10 +5580,16 @@ class TypeProviderForLink extends TypeProviderBase {
InterfaceType get futureDynamicType =>
_futureDynamicType ??= futureType.instantiate(<DartType>[dynamicType]);
@override
ClassElement get futureElement => futureType.element;
@override
InterfaceType get futureNullType =>
_futureNullType ??= futureType.instantiate(<DartType>[nullType]);
@override
ClassElement get futureOrElement => futureOrType.element;
@override
InterfaceType get futureOrNullType =>
_futureOrNullType ??= futureOrType.instantiate(<DartType>[nullType]);
@ -5604,6 +5610,9 @@ class TypeProviderForLink extends TypeProviderBase {
InterfaceType get iterableDynamicType => _iterableDynamicType ??=
iterableType.instantiate(<DartType>[dynamicType]);
@override
ClassElement get iterableElement => iterableType.element;
@override
InterfaceType get iterableObjectType =>
_iterableObjectType ??= iterableType.instantiate(<DartType>[objectType]);
@ -5612,10 +5621,16 @@ class TypeProviderForLink extends TypeProviderBase {
InterfaceType get iterableType =>
_iterableType ??= _buildInterfaceType(_linker.coreLibrary, 'Iterable');
@override
ClassElement get listElement => listType.element;
@override
InterfaceType get listType =>
_listType ??= _buildInterfaceType(_linker.coreLibrary, 'List');
@override
ClassElement get mapElement => mapType.element;
@override
InterfaceType get mapObjectObjectType => _mapObjectObjectType ??=
mapType.instantiate(<DartType>[objectType, objectType]);
@ -5645,6 +5660,9 @@ class TypeProviderForLink extends TypeProviderBase {
InterfaceType get objectType =>
_objectType ??= _buildInterfaceType(_linker.coreLibrary, 'Object');
@override
ClassElement get setElement => setType.element;
@override
InterfaceType get setType =>
_setType ??= _buildInterfaceType(_linker.coreLibrary, 'Set');
@ -5657,6 +5675,9 @@ class TypeProviderForLink extends TypeProviderBase {
InterfaceType get streamDynamicType =>
_streamDynamicType ??= streamType.instantiate(<DartType>[dynamicType]);
@override
ClassElement get streamElement => streamType.element;
@override
InterfaceType get streamType =>
_streamType ??= _buildInterfaceType(_linker.asyncLibrary, 'Stream');
@ -5665,6 +5686,9 @@ class TypeProviderForLink extends TypeProviderBase {
InterfaceType get stringType =>
_stringType ??= _buildInterfaceType(_linker.coreLibrary, 'String');
@override
ClassElement get symbolElement => symbolType.element;
@override
InterfaceType get symbolType =>
_symbolType ??= _buildInterfaceType(_linker.coreLibrary, 'Symbol');
@ -5676,6 +5700,41 @@ class TypeProviderForLink extends TypeProviderBase {
@override
VoidType get voidType => VoidTypeImpl.instance;
@override
InterfaceType futureOrType2(DartType valueType) {
return futureOrType.instantiate([valueType]);
}
@override
InterfaceType futureType2(DartType valueType) {
return futureType.instantiate([valueType]);
}
@override
InterfaceType iterableType2(DartType elementType) {
return iterableType.instantiate([elementType]);
}
@override
InterfaceType listType2(DartType elementType) {
return listType.instantiate([elementType]);
}
@override
InterfaceType mapType2(DartType keyType, DartType valueType) {
return mapType.instantiate([keyType, valueType]);
}
@override
InterfaceType setType2(DartType elementType) {
return setType.instantiate([elementType]);
}
@override
InterfaceType streamType2(DartType elementType) {
return streamType.instantiate([elementType]);
}
InterfaceType _buildInterfaceType(
LibraryElementForLink library, String name) {
return library.getContainedName(name).buildType((int i) {