Skip to content

Commit 391cec1

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate dart_type_utilities
Bug: #59548 Change-Id: I97c256658d374e141fac2e0f9a571d2b0c4ef9c4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399262 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent a348c85 commit 391cec1

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ lib/src/extensions.dart
22
lib/src/rules/invalid_runtime_check_with_js_interop_types.dart
33
lib/src/rules/unnecessary_overrides.dart
44
lib/src/rules/use_late_for_private_fields_and_variables.dart
5-
lib/src/util/dart_type_utilities.dart

pkg/linter/lib/src/util/dart_type_utilities.dart

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/ast/ast.dart';
6-
import 'package:analyzer/dart/element/element.dart';
76
import 'package:analyzer/dart/element/element2.dart';
87
import 'package:analyzer/dart/element/type.dart';
98
import 'package:analyzer/src/dart/element/type.dart'; // ignore: implementation_imports
@@ -14,29 +13,30 @@ import '../extensions.dart';
1413

1514
bool argumentsMatchParameters(
1615
NodeList<Expression> arguments, NodeList<FormalParameter> parameters) {
17-
var namedParameters = <String, Element?>{};
18-
var namedArguments = <String, Element>{};
19-
var positionalParameters = <Element?>[];
20-
var positionalArguments = <Element>[];
16+
var namedParameters = <String, Element2?>{};
17+
var namedArguments = <String, Element2>{};
18+
var positionalParameters = <Element2?>[];
19+
var positionalArguments = <Element2>[];
2120
for (var parameter in parameters) {
2221
var identifier = parameter.name;
22+
var parameterElement = parameter.declaredFragment?.element;
2323
if (identifier != null) {
2424
if (parameter.isNamed) {
25-
namedParameters[identifier.lexeme] = parameter.declaredElement;
25+
namedParameters[identifier.lexeme] = parameterElement;
2626
} else {
27-
positionalParameters.add(parameter.declaredElement);
27+
positionalParameters.add(parameterElement);
2828
}
2929
}
3030
}
3131
for (var argument in arguments) {
3232
if (argument is NamedExpression) {
33-
var element = argument.expression.canonicalElement;
33+
var element = argument.expression.canonicalElement2;
3434
if (element == null) {
3535
return false;
3636
}
3737
namedArguments[argument.name.label.name] = element;
3838
} else {
39-
var element = argument.canonicalElement;
39+
var element = argument.canonicalElement2;
4040
if (element == null) {
4141
return false;
4242
}
@@ -64,15 +64,12 @@ bool argumentsMatchParameters(
6464

6565
/// Returns whether the canonical elements of [element1] and [element2] are
6666
/// equal.
67-
bool canonicalElementsAreEqual(Element? element1, Element? element2) =>
68-
element1?.canonicalElement == element2?.canonicalElement;
69-
70-
bool canonicalElementsAreEqual2(Element2? element1, Element2? element2) =>
67+
bool canonicalElementsAreEqual(Element2? element1, Element2? element2) =>
7168
element1?.canonicalElement2 == element2?.canonicalElement2;
7269

7370
/// Returns whether the canonical elements from two nodes are equal.
7471
///
75-
/// As in, [AstNodeNullableExtension.canonicalElement], the two nodes must be
72+
/// As in, [AstNodeNullableExtension.canonicalElement2], the two nodes must be
7673
/// [Expression]s in order to be compared (otherwise `false` is returned).
7774
///
7875
/// The two nodes must both be a [SimpleIdentifier], [PrefixedIdentifier], or
@@ -104,24 +101,23 @@ bool canonicalElementsFromIdentifiersAreEqual(
104101

105102
if (expression1 is SimpleIdentifier) {
106103
return expression2 is SimpleIdentifier &&
107-
canonicalElementsAreEqual2(getWriteOrReadElement(expression1),
104+
canonicalElementsAreEqual(getWriteOrReadElement(expression1),
108105
getWriteOrReadElement(expression2));
109106
}
110107

111108
if (expression1 is PrefixedIdentifier) {
112109
return expression2 is PrefixedIdentifier &&
113-
canonicalElementsAreEqual(expression1.prefix.staticElement,
114-
expression2.prefix.staticElement) &&
115-
canonicalElementsAreEqual2(
116-
getWriteOrReadElement(expression1.identifier),
110+
canonicalElementsAreEqual(
111+
expression1.prefix.element, expression2.prefix.element) &&
112+
canonicalElementsAreEqual(getWriteOrReadElement(expression1.identifier),
117113
getWriteOrReadElement(expression2.identifier));
118114
}
119115

120116
if (expression1 is PropertyAccess && expression2 is PropertyAccess) {
121117
var target1 = expression1.target;
122118
var target2 = expression2.target;
123119
return canonicalElementsFromIdentifiersAreEqual(target1, target2) &&
124-
canonicalElementsAreEqual2(
120+
canonicalElementsAreEqual(
125121
getWriteOrReadElement(expression1.propertyName),
126122
getWriteOrReadElement(expression2.propertyName));
127123
}
@@ -179,8 +175,8 @@ bool typesAreUnrelated(
179175
promotedLeftType, promotedRightType);
180176
} else if (promotedLeftType is TypeParameterType &&
181177
promotedRightType is TypeParameterType) {
182-
return typesAreUnrelated(typeSystem, promotedLeftType.element.bound,
183-
promotedRightType.element.bound);
178+
return typesAreUnrelated(typeSystem, promotedLeftType.element3.bound,
179+
promotedRightType.element3.bound);
184180
} else if (promotedLeftType is FunctionType) {
185181
if (_isFunctionTypeUnrelatedToType(promotedLeftType, promotedRightType)) {
186182
return true;
@@ -202,9 +198,11 @@ bool _isFunctionTypeUnrelatedToType(FunctionType type1, DartType type2) {
202198
return false;
203199
}
204200
if (type2 is InterfaceType) {
205-
var element2 = type2.element;
206-
if (element2 is ClassElement &&
207-
element2.lookUpConcreteMethod('call', element2.library) != null) {
201+
var element2 = type2.element3;
202+
if (element2 is ClassElement2 &&
203+
element2.thisType
204+
.lookUpMethod3('call', element2.library2, concrete: true) !=
205+
null) {
208206
return false;
209207
}
210208
}
@@ -236,8 +234,8 @@ class InterfaceTypeDefinition {
236234
extension on TypeSystem {
237235
bool interfaceTypesAreUnrelated(
238236
InterfaceType leftType, InterfaceType rightType) {
239-
var leftElement = leftType.element;
240-
var rightElement = rightType.element;
237+
var leftElement = leftType.element3;
238+
var rightElement = rightType.element3;
241239
if (leftElement == rightElement) {
242240
// In this case, [leftElement] and [rightElement] represent the same
243241
// class, modulo generics, e.g. `List<int>` and `List<dynamic>`. Now we
@@ -264,7 +262,7 @@ extension on TypeSystem {
264262

265263
// Unrelated Enums have the same supertype, but they are not the same element, so
266264
// they are unrelated.
267-
if (sameSupertypes && leftElement is EnumElement) {
265+
if (sameSupertypes && leftElement is EnumElement2) {
268266
return true;
269267
}
270268

0 commit comments

Comments
 (0)