Skip to content

Commit b80fdcb

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ErrorDetectionHelpers.
Change-Id: I50b08924a4be96210378a9ad56a9d671a030d5f9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395800 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 58f9beb commit b80fdcb

File tree

11 files changed

+91
-39
lines changed

11 files changed

+91
-39
lines changed

pkg/analysis_server/lib/src/cider/local_library_contributor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
167167
if (element.isGetter) {
168168
if (variable is FieldElement) {
169169
builder.suggestField(
170-
variable.asElement2 as FieldElement2,
170+
variable.asElement2,
171171
inheritanceDistance: 0.0,
172172
);
173173
}
@@ -281,7 +281,7 @@ class LibraryElementSuggestionBuilder extends GeneralizingElementVisitor<void> {
281281
}
282282
} else {
283283
builder.suggestStaticField(
284-
field.asElement2 as FieldElement2,
284+
field.asElement2,
285285
prefix: prefix,
286286
);
287287
}

pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,13 +1218,13 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
12181218
case EnumConstantSuggestion():
12191219
if (suggestion.includeEnumName) {
12201220
suggestEnumConstant(
1221-
suggestion.element.asElement2 as FieldElement2,
1221+
suggestion.element.asElement2,
12221222
suggestion.completion,
12231223
relevance: relevance,
12241224
);
12251225
} else {
12261226
suggestField(
1227-
suggestion.element.asElement2 as FieldElement2,
1227+
suggestion.element.asElement2,
12281228
inheritanceDistance: 0.0,
12291229
relevance: relevance,
12301230
);
@@ -1246,7 +1246,7 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
12461246
var fieldElement = suggestion.element;
12471247
if (fieldElement.isEnumConstant) {
12481248
suggestEnumConstant(
1249-
fieldElement.asElement2 as FieldElement2,
1249+
fieldElement.asElement2,
12501250
suggestion.completion,
12511251
relevance: relevance,
12521252
);
@@ -1259,7 +1259,7 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
12591259
? fieldElement.declaration.asElement2
12601260
: fieldElement.asElement2;
12611261
suggestField(
1262-
field as FieldElement2,
1262+
field,
12631263
inheritanceDistance: inheritanceDistance,
12641264
relevance: relevance,
12651265
);
@@ -1320,7 +1320,7 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
13201320
request.featureComputer,
13211321
);
13221322
suggestMethod(
1323-
suggestion.element.asElement2 as MethodElement2,
1323+
suggestion.element.asElement2,
13241324
kind: kind,
13251325
inheritanceDistance: inheritanceDistance,
13261326
relevance: relevance,
@@ -1387,7 +1387,7 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
13871387
request.featureComputer,
13881388
);
13891389
suggestSetStateMethod(
1390-
suggestion.element.asElement2 as MethodElement2,
1390+
suggestion.element.asElement2,
13911391
kind: suggestion.kind,
13921392
completion: suggestion.completion,
13931393
displayText: suggestion.displayText,
@@ -1397,7 +1397,7 @@ extension SuggestionBuilderExtension on SuggestionBuilder {
13971397
);
13981398
case StaticFieldSuggestion():
13991399
suggestStaticField(
1400-
suggestion.element.asElement2 as FieldElement2,
1400+
suggestion.element.asElement2,
14011401
prefix: suggestion.prefix,
14021402
relevance: relevance,
14031403
completion: suggestion.completion,

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ lib/src/error/required_parameters_verifier.dart
112112
lib/src/error/unused_local_elements_verifier.dart
113113
lib/src/generated/element_resolver.dart
114114
lib/src/generated/element_walker.dart
115-
lib/src/generated/error_detection_helpers.dart
116115
lib/src/generated/error_verifier.dart
117116
lib/src/generated/exhaustiveness.dart
118117
lib/src/generated/ffi_verifier.dart

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ final class BinaryExpressionImpl extends ExpressionImpl
18291829

18301830
@experimental
18311831
@override
1832-
MethodElement2? get element => staticElement?.asElement2 as MethodElement2?;
1832+
MethodElement2? get element => staticElement?.asElement2;
18331833

18341834
@override
18351835
Token get endToken => _rightOperand.endToken;
@@ -10137,7 +10137,7 @@ final class IndexExpressionImpl extends ExpressionImpl
1013710137

1013810138
@experimental
1013910139
@override
10140-
MethodElement2? get element => staticElement?.asElement2 as MethodElement2?;
10140+
MethodElement2? get element => staticElement?.asElement2;
1014110141

1014210142
@override
1014310143
Token get endToken => rightBracket;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,7 +3524,7 @@ class EnumElementImpl extends InterfaceElementImpl
35243524

35253525
@override
35263526
List<FieldElement2> get constants2 =>
3527-
constants.map((e) => e.asElement2 as FieldElement2).toList();
3527+
constants.map((e) => e.asElement2).toList();
35283528

35293529
@override
35303530
EnumElementImpl2 get element {
@@ -3583,7 +3583,7 @@ class EnumElementImpl2 extends InterfaceElementImpl2
35833583

35843584
@override
35853585
List<FieldElement2> get constants2 =>
3586-
constants.map((e) => e.asElement2 as FieldElement2).toList();
3586+
constants.map((e) => e.asElement2).toList();
35873587

35883588
@override
35893589
T? accept2<T>(ElementVisitor2<T> visitor) {
@@ -4048,8 +4048,7 @@ class ExtensionTypeElementImpl2 extends InterfaceElementImpl2
40484048
ConstructorElement2 get primaryConstructor2 => primaryConstructor.element;
40494049

40504050
@override
4051-
FieldElement2 get representation2 =>
4052-
representation.asElement2 as FieldElement2;
4051+
FieldElement2 get representation2 => representation.asElement2;
40534052

40544053
@override
40554054
T? accept2<T>(ElementVisitor2<T> visitor) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ class FieldMember extends VariableMember
589589
@override
590590
Source? get source => _declaration.source;
591591

592-
FieldElement2 get _element2 => declaration.asElement2 as FieldElement2;
592+
FieldElement2 get _element2 => declaration.asElement2;
593593

594594
@override
595595
T? accept<T>(ElementVisitor<T> visitor) => visitor.visitFieldElement(this);
@@ -1000,7 +1000,7 @@ class MethodMember extends ExecutableMember
10001000
Source get source => _declaration.source!;
10011001

10021002
@override
1003-
MethodElement2 get _element2 => declaration.asElement2 as MethodElement2;
1003+
MethodElement2 get _element2 => declaration.asElement2;
10041004

10051005
@override
10061006
T? accept<T>(ElementVisitor<T> visitor) => visitor.visitMethodElement(this);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:_fe_analyzer_shared/src/flow_analysis/flow_analysis.dart';
66
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
77
import 'package:analyzer/dart/element/element.dart';
8+
import 'package:analyzer/dart/element/element2.dart';
89
import 'package:analyzer/dart/element/type.dart';
910
import 'package:analyzer/error/error.dart';
1011
import 'package:analyzer/error/listener.dart';
@@ -23,6 +24,7 @@ import 'package:analyzer/src/error/codes.dart';
2324
import 'package:analyzer/src/generated/resolver.dart';
2425
import 'package:analyzer/src/generated/scope_helpers.dart';
2526
import 'package:analyzer/src/generated/super_context.dart';
27+
import 'package:analyzer/src/utilities/extensions/element.dart';
2628

2729
class PropertyElementResolver with ScopeHelpers {
2830
final ResolverVisitor _resolver;
@@ -944,7 +946,15 @@ class PropertyElementResolverResult {
944946
return readElementRequested ?? readElementRecovery;
945947
}
946948

949+
Element2? get readElement2 {
950+
return readElement.asElement2;
951+
}
952+
947953
Element? get writeElement {
948954
return writeElementRequested ?? writeElementRecovery;
949955
}
956+
957+
Element2? get writeElement2 {
958+
return writeElement.asElement2;
959+
}
950960
}

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ import 'package:_fe_analyzer_shared/src/flow_analysis/flow_analysis.dart';
66
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
77
import 'package:analyzer/dart/ast/ast.dart';
88
import 'package:analyzer/dart/ast/syntactic_entity.dart';
9-
import 'package:analyzer/dart/element/element.dart';
9+
import 'package:analyzer/dart/element/element2.dart';
1010
import 'package:analyzer/dart/element/nullability_suffix.dart';
1111
import 'package:analyzer/dart/element/type.dart';
1212
import 'package:analyzer/diagnostic/diagnostic.dart';
1313
import 'package:analyzer/error/error.dart';
1414
import 'package:analyzer/error/listener.dart';
1515
import 'package:analyzer/src/dart/ast/extensions.dart';
16+
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1617
import 'package:analyzer/src/dart/element/type.dart';
1718
import 'package:analyzer/src/dart/element/type_system.dart';
1819
import 'package:analyzer/src/error/codes.dart';
20+
import 'package:analyzer/src/utilities/extensions/object.dart';
1921

2022
/// Methods useful in detecting errors. This mixin exists to allow code to be
2123
/// more easily shared between the two visitors that do the majority of error
2224
/// reporting (ResolverVisitor and ErrorVerifier).
2325
mixin ErrorDetectionHelpers {
2426
ErrorReporter get errorReporter;
2527

28+
InheritanceManager3 get inheritance;
29+
2630
bool get strictCasts;
2731

2832
TypeSystemImpl get typeSystem;
@@ -61,7 +65,7 @@ mixin ErrorDetectionHelpers {
6165
whyNotPromoted}) {
6266
_checkForArgumentTypeNotAssignableForArgument(
6367
argument: argument is NamedExpression ? argument.expression : argument,
64-
parameter: argument.staticParameterElement,
68+
parameter: argument.correspondingParameter,
6569
promoteParameterToNullable: promoteParameterToNullable,
6670
whyNotPromoted: whyNotPromoted,
6771
);
@@ -166,7 +170,7 @@ mixin ErrorDetectionHelpers {
166170
/// See [CompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE], and
167171
/// [CompileTimeErrorCode.FIELD_INITIALIZER_NOT_ASSIGNABLE].
168172
void checkForFieldInitializerNotAssignable(
169-
ConstructorFieldInitializer initializer, FieldElement fieldElement,
173+
ConstructorFieldInitializer initializer, FieldElement2 fieldElement,
170174
{required bool isConstConstructor,
171175
required Map<SharedTypeView<DartType>, NonPromotionReason> Function()?
172176
whyNotPromoted}) {
@@ -256,13 +260,13 @@ mixin ErrorDetectionHelpers {
256260

257261
void checkIndexExpressionIndex(
258262
Expression index, {
259-
required ExecutableElement? readElement,
260-
required ExecutableElement? writeElement,
263+
required ExecutableElement2? readElement,
264+
required ExecutableElement2? writeElement,
261265
required Map<SharedTypeView<DartType>, NonPromotionReason> Function()?
262266
whyNotPromoted,
263267
}) {
264-
if (readElement is MethodElement) {
265-
var parameters = readElement.parameters;
268+
if (readElement is MethodElement2) {
269+
var parameters = readElement.formalParameters;
266270
if (parameters.isNotEmpty) {
267271
_checkForArgumentTypeNotAssignableForArgument(
268272
argument: index,
@@ -273,8 +277,8 @@ mixin ErrorDetectionHelpers {
273277
}
274278
}
275279

276-
if (writeElement is MethodElement) {
277-
var parameters = writeElement.parameters;
280+
if (writeElement is MethodElement2) {
281+
var parameters = writeElement.formalParameters;
278282
if (parameters.isNotEmpty) {
279283
_checkForArgumentTypeNotAssignableForArgument(
280284
argument: index,
@@ -309,7 +313,7 @@ mixin ErrorDetectionHelpers {
309313
/// > Let `e` be an expression whose static type is an interface type that has
310314
/// > a method named `call`. In the case where the context type for `e`
311315
/// > is a function type or the type `Function`, `e` is treated as `e.call`.
312-
MethodElement? getImplicitCallMethod(
316+
MethodElement2? getImplicitCallMethod(
313317
DartType type, DartType context, SyntacticEntity errorNode) {
314318
var visitedTypes = {type};
315319
while (type is TypeParameterType) {
@@ -326,19 +330,26 @@ mixin ErrorDetectionHelpers {
326330
if (typeSystem.acceptsFunctionType(context) &&
327331
type is InterfaceType &&
328332
type.nullabilitySuffix != NullabilitySuffix.question) {
329-
return type.lookUpMethod2(
330-
FunctionElement.CALL_METHOD_NAME, type.element.library);
333+
return inheritance
334+
.getMember3(
335+
type,
336+
Name.forLibrary(
337+
type.element3.library2,
338+
MethodElement2.CALL_METHOD_NAME,
339+
),
340+
)
341+
.ifTypeOrNull();
331342
} else {
332343
return null;
333344
}
334345
}
335346

336347
/// Return the variable element represented by the given [expression], or
337348
/// `null` if there is no such element.
338-
VariableElement? getVariableElement(Expression? expression) {
349+
VariableElement2? getVariableElement(Expression? expression) {
339350
if (expression is Identifier) {
340-
var element = expression.staticElement;
341-
if (element is VariableElement) {
351+
var element = expression.element;
352+
if (element is VariableElement2) {
342353
return element;
343354
}
344355
}
@@ -347,7 +358,7 @@ mixin ErrorDetectionHelpers {
347358

348359
void _checkForArgumentTypeNotAssignableForArgument({
349360
required Expression argument,
350-
required ParameterElement? parameter,
361+
required FormalParameterElement? parameter,
351362
required bool promoteParameterToNullable,
352363
Map<SharedTypeView<DartType>, NonPromotionReason> Function()?
353364
whyNotPromoted,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
312312
assert(_enclosingExecutable.element == null);
313313
}
314314

315+
@override
316+
InheritanceManager3 get inheritance => _inheritanceManager;
317+
315318
@override
316319
bool get strictCasts => options.strictCasts;
317320

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import 'package:analyzer/dart/ast/syntactic_entity.dart';
2222
import 'package:analyzer/dart/ast/token.dart';
2323
import 'package:analyzer/dart/ast/visitor.dart';
2424
import 'package:analyzer/dart/element/element.dart';
25+
import 'package:analyzer/dart/element/element2.dart';
2526
import 'package:analyzer/dart/element/scope.dart';
2627
import 'package:analyzer/dart/element/type.dart';
2728
import 'package:analyzer/dart/element/type_provider.dart';
@@ -86,6 +87,7 @@ import 'package:analyzer/src/generated/utilities_dart.dart';
8687
import 'package:analyzer/src/generated/variable_type_provider.dart';
8788
import 'package:analyzer/src/task/inference_error.dart';
8889
import 'package:analyzer/src/util/ast_data_extractor.dart';
90+
import 'package:analyzer/src/utilities/extensions/element.dart';
8991
import 'package:analyzer/src/utilities/extensions/object.dart';
9092

9193
/// Function determining which source files should have inference logging
@@ -181,6 +183,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
181183
AugmentableElement? enclosingAugmentation;
182184

183185
/// The manager for the inheritance mappings.
186+
@override
184187
final InheritanceManager3 inheritance;
185188

186189
/// The feature set that is enabled for the current unit.
@@ -1452,8 +1455,9 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
14521455
var whyNotPromoted = flowAnalysis.flow?.whyNotPromoted(node.index);
14531456
checkIndexExpressionIndex(
14541457
node.index,
1455-
readElement: hasRead ? result.readElement as ExecutableElement? : null,
1456-
writeElement: result.writeElement as ExecutableElement?,
1458+
readElement:
1459+
hasRead ? result.readElement2 as ExecutableElement2? : null,
1460+
writeElement: result.writeElement2 as ExecutableElement2?,
14571461
whyNotPromoted: whyNotPromoted,
14581462
);
14591463

@@ -2379,7 +2383,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
23792383
var whyNotPromoted = flowAnalysis.flow?.whyNotPromoted(expression);
23802384
if (fieldElement != null) {
23812385
var enclosingConstructor = enclosingFunction as ConstructorElement;
2382-
checkForFieldInitializerNotAssignable(node, fieldElement,
2386+
checkForFieldInitializerNotAssignable(node, fieldElement.asElement2,
23832387
isConstConstructor: enclosingConstructor.isConst,
23842388
whyNotPromoted: whyNotPromoted);
23852389
}
@@ -3033,7 +3037,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
30333037
var whyNotPromoted = flowAnalysis.flow?.whyNotPromoted(node.index);
30343038
checkIndexExpressionIndex(
30353039
node.index,
3036-
readElement: result.readElement as ExecutableElement?,
3040+
readElement: result.readElement2 as ExecutableElement2?,
30373041
writeElement: null,
30383042
whyNotPromoted: whyNotPromoted,
30393043
);
@@ -4155,7 +4159,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
41554159

41564160
var callReference = ImplicitCallReferenceImpl(
41574161
expression: expression,
4158-
staticElement: callMethod,
4162+
staticElement: callMethod.asElement,
41594163
typeArguments: null,
41604164
typeArgumentTypes: typeArgumentTypes,
41614165
);

0 commit comments

Comments
 (0)