Skip to content

Commit c36dac8

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ReplaceTopBottomVisitor.
Change-Id: I2784d949aad4c0cbd9c0e34ed570c1a97bfb6228 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403949 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 2dec4fe commit c36dac8

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
// ignore_for_file: analyzer_use_new_elements
6-
75
import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart';
86
import 'package:analyzer/dart/element/type.dart';
97
import 'package:analyzer/src/dart/element/element.dart';
@@ -42,7 +40,7 @@ class ReplaceTopBottomVisitor {
4240
var alias = type.alias;
4341
if (alias != null) {
4442
return _instantiatedTypeAlias(type, alias, variance);
45-
} else if (type is InterfaceType) {
43+
} else if (type is InterfaceTypeImpl) {
4644
return _interfaceType(type, variance);
4745
} else if (type is FunctionType) {
4846
return _functionType(type, variance);
@@ -53,7 +51,7 @@ class ReplaceTopBottomVisitor {
5351
DartType _functionType(FunctionType type, Variance variance) {
5452
var newReturnType = process(type.returnType, variance);
5553

56-
var newParameters = type.parameters.map((parameter) {
54+
var newParameters = type.formalParameters.map((parameter) {
5755
return parameter.copyWith(
5856
type: process(
5957
parameter.type,
@@ -62,9 +60,9 @@ class ReplaceTopBottomVisitor {
6260
);
6361
}).toList();
6462

65-
return FunctionTypeImpl(
66-
typeFormals: type.typeFormals,
67-
parameters: newParameters,
63+
return FunctionTypeImpl.v2(
64+
typeParameters: type.typeParameters,
65+
formalParameters: newParameters,
6866
returnType: newReturnType,
6967
nullabilitySuffix: type.nullabilitySuffix,
7068
);
@@ -75,15 +73,15 @@ class ReplaceTopBottomVisitor {
7573
InstantiatedTypeAliasElement alias,
7674
Variance variance,
7775
) {
78-
var aliasElement = alias.element;
76+
var aliasElement = alias.element2;
7977
var aliasArguments = alias.typeArguments;
8078

81-
var typeParameters = aliasElement.typeParameters;
79+
var typeParameters = aliasElement.typeParameters2;
8280
assert(typeParameters.length == aliasArguments.length);
8381

8482
var newTypeArguments = <DartType>[];
8583
for (var i = 0; i < typeParameters.length; i++) {
86-
var typeParameter = typeParameters[i] as TypeParameterElementImpl;
84+
var typeParameter = typeParameters[i] as TypeParameterElementImpl2;
8785
newTypeArguments.add(
8886
process(
8987
aliasArguments[i],
@@ -98,8 +96,8 @@ class ReplaceTopBottomVisitor {
9896
);
9997
}
10098

101-
DartType _interfaceType(InterfaceType type, Variance variance) {
102-
var typeParameters = type.element.typeParameters;
99+
InterfaceTypeImpl _interfaceType(InterfaceTypeImpl type, Variance variance) {
100+
var typeParameters = type.element3.typeParameters2;
103101
if (typeParameters.isEmpty) {
104102
return type;
105103
}
@@ -113,8 +111,8 @@ class ReplaceTopBottomVisitor {
113111
newTypeArguments.add(newTypeArgument);
114112
}
115113

116-
return InterfaceTypeImpl(
117-
element: type.element,
114+
return InterfaceTypeImpl.v2(
115+
element: type.element3,
118116
nullabilitySuffix: type.nullabilitySuffix,
119117
typeArguments: newTypeArguments,
120118
);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,20 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
611611
}
612612
}
613613

614+
factory InterfaceTypeImpl.v2({
615+
required InterfaceElementImpl2 element,
616+
required List<DartType> typeArguments,
617+
required NullabilitySuffix nullabilitySuffix,
618+
InstantiatedTypeAliasElement? alias,
619+
}) {
620+
return InterfaceTypeImpl(
621+
element: element.asElement,
622+
typeArguments: typeArguments,
623+
nullabilitySuffix: nullabilitySuffix,
624+
alias: alias,
625+
);
626+
}
627+
614628
InterfaceTypeImpl._({
615629
required this.element,
616630
required this.typeArguments,

pkg/analyzer/test/generated/elements_types_mixin.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,14 @@ mixin ElementsTypesMixin {
580580
required List<TypeParameterElementImpl> typeParameters,
581581
required DartType aliasedType,
582582
}) {
583-
var element = TypeAliasElementImpl(name, 0);
584-
element.enclosingElement3 = testLibrary.definingCompilationUnit;
585-
element.typeParameters = typeParameters;
586-
element.aliasedType = aliasedType;
587-
return element;
583+
var fragment = TypeAliasElementImpl(name, 0);
584+
fragment.enclosingElement3 = testLibrary.definingCompilationUnit;
585+
fragment.typeParameters = typeParameters;
586+
fragment.aliasedType = aliasedType;
587+
588+
TypeAliasElementImpl2(Reference.root(), fragment);
589+
590+
return fragment;
588591
}
589592

590593
DartType typeAliasTypeNone(

0 commit comments

Comments
 (0)