Skip to content

Commit a1fdfb8

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Move ClassElement.thisType to API.
[email protected], [email protected] Change-Id: Ib1b85e01159e93adbab8b3e186f30e939d462739 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117766 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 4102e63 commit a1fdfb8

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ abstract class ClassElement
175175
/// guard against infinite loops.
176176
InterfaceType get supertype;
177177

178+
/// Return the type of `this` expression for this class.
179+
///
180+
/// For a class like `class MyClass<T, U> {}` the returned type is equivalent
181+
/// to the type `MyClass<T, U>`. So, the type arguments are the types of the
182+
/// type parameters, and either `none` or `star` nullability suffix is used
183+
/// for the type arguments, and the returned type depending on the
184+
/// nullability status of the declaring library.
185+
InterfaceType get thisType;
186+
178187
@override
179188
InterfaceType get type;
180189

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ abstract class AbstractClassElementImpl extends ElementImpl
121121
@override
122122
List<InterfaceType> get superclassConstraints => const <InterfaceType>[];
123123

124-
/// Return the type of `this` expression for this class.
125-
///
126-
/// For a class like `class MyClass<T, U> {}` the returned type is equivalent
127-
/// to the type `MyClass<T, U>`. So, the type arguments are the types of the
128-
/// type parameters, and either `none` or `star` nullability suffix is used
129-
/// for the type arguments, and the returned type depending on the
130-
/// nullability status of the declaring library.
124+
@override
131125
InterfaceType get thisType {
132126
if (_thisType == null) {
133127
var nullabilitySuffix = library.isNonNullableByDefault

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class ClassElementHandle extends ElementHandle implements ClassElement {
117117
@override
118118
InterfaceType get supertype => actualElement.supertype;
119119

120+
@override
121+
InterfaceType get thisType => actualElement.thisType;
122+
120123
@override
121124
InterfaceType get type => actualElement.type;
122125

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6303,7 +6303,6 @@ class TypeNameResolver {
63036303
/// otherwise.
63046304
List<DartType> _inferTypeArgumentsForRedirectedConstructor(
63056305
TypeName node, ClassElement typeElement) {
6306-
var typeElementImpl = AbstractClassElementImpl.getImpl(typeElement);
63076306
AstNode constructorName = node.parent;
63086307
AstNode enclosingConstructor = constructorName?.parent;
63096308
TypeSystem ts = typeSystem;
@@ -6312,15 +6311,14 @@ class TypeNameResolver {
63126311
enclosingConstructor.redirectedConstructor == constructorName &&
63136312
ts is Dart2TypeSystem) {
63146313
ClassOrMixinDeclaration enclosingClassNode = enclosingConstructor.parent;
6315-
ClassElementImpl enclosingClassElement =
6316-
enclosingClassNode.declaredElement;
6317-
if (enclosingClassElement == typeElementImpl) {
6318-
return typeElementImpl.thisType.typeArguments;
6314+
var enclosingClassElement = enclosingClassNode.declaredElement;
6315+
if (enclosingClassElement == typeElement) {
6316+
return typeElement.thisType.typeArguments;
63196317
} else {
63206318
return ts.inferGenericFunctionOrType(
6321-
typeParameters: typeElementImpl.typeParameters,
6319+
typeParameters: typeElement.typeParameters,
63226320
parameters: const [],
6323-
declaredReturnType: typeElementImpl.thisType,
6321+
declaredReturnType: typeElement.thisType,
63246322
argumentTypes: const [],
63256323
contextReturnType: enclosingClassElement.thisType,
63266324
);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
169169
DartType inferListType(ListLiteral node, {bool downwards: false}) {
170170
DartType contextType = InferenceContext.getContext(node);
171171

172-
ClassElementImpl element = _typeProvider.listElement;
172+
var element = _typeProvider.listElement;
173173
var typeParameters = element.typeParameters;
174174
var genericElementType = typeParameters[0].instantiate(
175175
nullabilitySuffix: _noneOrStarSuffix,
@@ -226,7 +226,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
226226
return null;
227227
}
228228

229-
ClassElementImpl element = _typeProvider.mapElement;
229+
var element = _typeProvider.mapElement;
230230
var typeArguments =
231231
(_typeSystem as Dart2TypeSystem).inferGenericFunctionOrType(
232232
typeParameters: element.typeParameters,
@@ -250,7 +250,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
250250
return null;
251251
}
252252

253-
ClassElementImpl element = _typeProvider.setElement;
253+
var element = _typeProvider.setElement;
254254
var typeArguments =
255255
(_typeSystem as Dart2TypeSystem).inferGenericFunctionOrType(
256256
typeParameters: element.typeParameters,
@@ -2114,7 +2114,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
21142114
List<_InferredCollectionElementTypeInformation> inferredTypes) {
21152115
DartType dynamicType = _typeProvider.dynamicType;
21162116

2117-
ClassElementImpl element = _typeProvider.mapElement;
2117+
var element = _typeProvider.mapElement;
21182118
var typeParameters = element.typeParameters;
21192119
var genericKeyType = typeParameters[0].instantiate(
21202120
nullabilitySuffix: _noneOrStarSuffix,
@@ -2152,7 +2152,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<void> {
21522152
List<_InferredCollectionElementTypeInformation> inferredTypes) {
21532153
DartType dynamicType = _typeProvider.dynamicType;
21542154

2155-
ClassElementImpl element = _typeProvider.setElement;
2155+
var element = _typeProvider.setElement;
21562156
var typeParameters = element.typeParameters;
21572157
var genericElementType = typeParameters[0].instantiate(
21582158
nullabilitySuffix: _noneOrStarSuffix,

0 commit comments

Comments
 (0)