Skip to content

Commit aea57de

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate GenericInferrer.
Change-Id: I53d92413b892effbe453f8f446aea3464f349e9b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415323 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent f1be302 commit aea57de

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
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 'dart:math' as math;
86

97
import 'package:_fe_analyzer_shared/src/type_inference/shared_inference_log.dart';
108
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
119
import 'package:analyzer/dart/ast/syntactic_entity.dart';
12-
import 'package:analyzer/dart/element/element.dart';
1310
import 'package:analyzer/dart/element/element2.dart';
1411
import 'package:analyzer/dart/element/type.dart';
1512
import 'package:analyzer/error/listener.dart' show ErrorReporter;
@@ -26,7 +23,6 @@ import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
2623
import 'package:analyzer/src/error/codes.dart'
2724
show CompileTimeErrorCode, WarningCode;
2825
import 'package:analyzer/src/generated/inference_log.dart';
29-
import 'package:analyzer/src/utilities/extensions/element.dart';
3026
import 'package:collection/collection.dart';
3127

3228
/// Tracks upper and lower type bounds for a set of type parameters.
@@ -149,7 +145,8 @@ class GenericInferrer {
149145
/// type is a subtype of the [parameterType].
150146
void constrainArgument(
151147
TypeImpl argumentType, TypeImpl parameterType, String parameterName,
152-
{InterfaceElement? genericClass, required AstNodeImpl? nodeForTesting}) {
148+
{InterfaceElementImpl? genericClass,
149+
required AstNodeImpl? nodeForTesting}) {
153150
var origin = TypeConstraintFromArgument(
154151
argumentType: SharedTypeView(argumentType),
155152
parameterType: SharedTypeView(parameterType),
@@ -167,7 +164,7 @@ class GenericInferrer {
167164
/// Applies all the argument constraints implied by [parameters] and
168165
/// [argumentTypes].
169166
void constrainArguments(
170-
{InterfaceElement? genericClass,
167+
{InterfaceElementImpl? genericClass,
171168
required List<ParameterElementMixin> parameters,
172169
required List<TypeImpl> argumentTypes,
173170
required AstNodeImpl? nodeForTesting}) {
@@ -187,7 +184,7 @@ class GenericInferrer {
187184
/// Applies all the argument constraints implied by [parameters] and
188185
/// [argumentTypes].
189186
void constrainArguments2(
190-
{InterfaceElement? genericClass,
187+
{InterfaceElementImpl? genericClass,
191188
required List<FormalParameterElementMixin> parameters,
192189
required List<TypeImpl> argumentTypes,
193190
required AstNodeImpl? nodeForTesting}) {
@@ -560,7 +557,7 @@ class GenericInferrer {
560557
}
561558
}
562559

563-
String _elementStr(Element element) {
560+
String _elementStr(ElementImpl element) {
564561
return element.getDisplayString();
565562
}
566563

@@ -719,7 +716,7 @@ class GenericInferrer {
719716
} else if (errorEntity is Annotation) {
720717
if (genericMetadataIsEnabled) {
721718
// Only report an error if generic metadata is valid syntax.
722-
var element = errorEntity.name.element?.asElement;
719+
var element = errorEntity.name.element;
723720
if (element != null && !element.hasOptionalTypeArgs) {
724721
String constructorName = errorEntity.constructorName == null
725722
? errorEntity.name.name
@@ -732,9 +729,9 @@ class GenericInferrer {
732729
}
733730
}
734731
} else if (errorEntity is SimpleIdentifier) {
735-
var element = errorEntity.element?.asElement;
732+
var element = errorEntity.element;
736733
if (element != null) {
737-
if (element is VariableElement) {
734+
if (element is VariableElement2) {
738735
// For variable elements, we check their type and possible alias type.
739736
var type = element.type;
740737
var typeElement = type is InterfaceType ? type.element3 : null;
@@ -861,3 +858,12 @@ class GenericInferrer {
861858
return messageLines.join('\n');
862859
}
863860
}
861+
862+
extension on Element2 {
863+
bool get hasOptionalTypeArgs {
864+
if (this case Annotatable annotatable) {
865+
return annotatable.metadata2.hasOptionalTypeArgs;
866+
}
867+
return false;
868+
}
869+
}

0 commit comments

Comments
 (0)