Skip to content

Commit 3a8415d

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate src/dart/resolver/method_invocation_resolver.dart
Change-Id: I8c325be4b42677c70c6085b683b9fb9cb8193a14 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415822 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent dc3ecf2 commit 3a8415d

File tree

1 file changed

+56
-59
lines changed

1 file changed

+56
-59
lines changed

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

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
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/flow_analysis/flow_analysis.dart';
86
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
9-
import 'package:analyzer/dart/element/element.dart';
107
import 'package:analyzer/dart/element/element2.dart';
118
import 'package:analyzer/dart/element/type.dart';
129
import 'package:analyzer/error/listener.dart';
@@ -101,17 +98,17 @@ class MethodInvocationResolver with ScopeHelpers {
10198
}
10299

103100
if (receiver is SimpleIdentifierImpl) {
104-
var receiverElement = receiver.element?.asElement;
105-
if (receiverElement is PrefixElementImpl) {
101+
var receiverElement = receiver.element;
102+
if (receiverElement is PrefixElementImpl2) {
106103
return _resolveReceiverPrefix(
107104
node, receiverElement, nameNode, name, whyNotPromotedArguments,
108105
contextType: contextType);
109106
}
110107
}
111108

112109
if (receiver is IdentifierImpl) {
113-
var receiverElement = receiver.element?.asElement;
114-
if (receiverElement is ExtensionElementImpl) {
110+
var receiverElement = receiver.element;
111+
if (receiverElement is ExtensionElementImpl2) {
115112
return _resolveExtensionMember(node, receiver, receiverElement,
116113
nameNode, name, whyNotPromotedArguments,
117114
contextType: contextType);
@@ -131,12 +128,12 @@ class MethodInvocationResolver with ScopeHelpers {
131128
}
132129

133130
if (receiver is IdentifierImpl) {
134-
var element = receiver.element?.asElement;
135-
if (element is InterfaceElement) {
131+
var element = receiver.element;
132+
if (element is InterfaceElement2) {
136133
return _resolveReceiverTypeLiteral(
137-
node, element.asElement2, nameNode, name, whyNotPromotedArguments,
134+
node, element, nameNode, name, whyNotPromotedArguments,
138135
contextType: contextType);
139-
} else if (element is TypeAliasElement) {
136+
} else if (element is TypeAliasElement2) {
140137
var aliasedType = element.aliasedType;
141138
if (aliasedType is InterfaceType) {
142139
return _resolveReceiverTypeLiteral(node, aliasedType.element3,
@@ -201,8 +198,8 @@ class MethodInvocationResolver with ScopeHelpers {
201198
}
202199

203200
bool _hasMatchingObjectMethod(
204-
MethodElement target, NodeListImpl<ExpressionImpl> arguments) {
205-
return arguments.length == target.parameters.length &&
201+
MethodElement2 target, NodeListImpl<ExpressionImpl> arguments) {
202+
return arguments.length == target.formalParameters.length &&
206203
!arguments.any((e) => e is NamedExpression);
207204
}
208205

@@ -213,27 +210,27 @@ class MethodInvocationResolver with ScopeHelpers {
213210

214211
void _reportInstanceAccessToStaticMember(
215212
SimpleIdentifier nameNode,
216-
ExecutableElement element,
213+
ExecutableElement2 element,
217214
bool nullReceiver,
218215
) {
219-
var enclosingElement = element.enclosingElement3;
216+
var enclosingElement = element.enclosingElement2!;
220217
if (nullReceiver) {
221218
if (_resolver.enclosingExtension != null) {
222219
_resolver.errorReporter.atNode(
223220
nameNode,
224221
CompileTimeErrorCode
225222
.UNQUALIFIED_REFERENCE_TO_STATIC_MEMBER_OF_EXTENDED_TYPE,
226-
arguments: [enclosingElement.displayName],
223+
arguments: [enclosingElement.displayString2()],
227224
);
228225
} else {
229226
_resolver.errorReporter.atNode(
230227
nameNode,
231228
CompileTimeErrorCode.UNQUALIFIED_REFERENCE_TO_NON_LOCAL_STATIC_MEMBER,
232-
arguments: [enclosingElement.displayName],
229+
arguments: [enclosingElement.displayString2()],
233230
);
234231
}
235-
} else if (enclosingElement is ExtensionElement &&
236-
enclosingElement.name == null) {
232+
} else if (enclosingElement is ExtensionElement2 &&
233+
enclosingElement.name3 == null) {
237234
_resolver.errorReporter.atNode(
238235
nameNode,
239236
CompileTimeErrorCode
@@ -252,8 +249,8 @@ class MethodInvocationResolver with ScopeHelpers {
252249
arguments: [
253250
nameNode.name,
254251
element.kind.displayName,
255-
enclosingElement.name!,
256-
enclosingElement is MixinElement
252+
enclosingElement.name3!,
253+
enclosingElement is MixinElement2
257254
? 'mixin'
258255
: enclosingElement.kind.displayName,
259256
],
@@ -284,7 +281,7 @@ class MethodInvocationResolver with ScopeHelpers {
284281
}
285282

286283
void _reportStaticAccessToInstanceMember(
287-
ExecutableElement element, SimpleIdentifier nameNode) {
284+
ExecutableElement2 element, SimpleIdentifier nameNode) {
288285
if (!element.isStatic) {
289286
_resolver.errorReporter.atNode(
290287
nameNode,
@@ -368,21 +365,21 @@ class MethodInvocationResolver with ScopeHelpers {
368365
FunctionExpressionInvocationImpl? _resolveExtensionMember(
369366
MethodInvocationImpl node,
370367
Identifier receiver,
371-
ExtensionElementImpl extension,
368+
ExtensionElementImpl2 extension,
372369
SimpleIdentifierImpl nameNode,
373370
String name,
374371
List<WhyNotPromotedGetter> whyNotPromotedArguments,
375372
{required TypeImpl contextType}) {
376-
var getter = extension.getGetter(name);
373+
var getter = extension.getGetter2(name);
377374
if (getter != null) {
378-
nameNode.element = getter.asElement2;
375+
nameNode.element = getter;
379376
_reportStaticAccessToInstanceMember(getter, nameNode);
380377
return _rewriteAsFunctionExpressionInvocation(node, getter.returnType);
381378
}
382379

383-
var method = extension.getMethod(name);
380+
var method = extension.getMethod2(name);
384381
if (method != null) {
385-
nameNode.element = method.asElement2;
382+
nameNode.element = method;
386383
_reportStaticAccessToInstanceMember(method, nameNode);
387384
_setResolution(node, method.type, whyNotPromotedArguments,
388385
contextType: contextType);
@@ -397,7 +394,7 @@ class MethodInvocationResolver with ScopeHelpers {
397394
_resolver.errorReporter.atNode(
398395
nameNode,
399396
CompileTimeErrorCode.UNDEFINED_EXTENSION_METHOD,
400-
arguments: [name, extension.name!],
397+
arguments: [name, extension.name3!],
401398
);
402399
return null;
403400
}
@@ -473,8 +470,7 @@ class MethodInvocationResolver with ScopeHelpers {
473470
node.recordStaticType(InvalidTypeImpl.instance, resolver: _resolver);
474471
} else if (target != null &&
475472
!target.isStatic &&
476-
_hasMatchingObjectMethod(
477-
target.asElement, node.argumentList.arguments)) {
473+
_hasMatchingObjectMethod(target, node.argumentList.arguments)) {
478474
nameNode.element = target;
479475
rawType = target.type;
480476
nameNode.setPseudoExpressionStaticType(target.type);
@@ -630,7 +626,7 @@ class MethodInvocationResolver with ScopeHelpers {
630626
element = scopeLookupResult.setter2;
631627
if (element != null) {
632628
// If the scope lookup reveals a setter, but no getter, then we may still
633-
// find the getter by looking up the inheritence chain (via
629+
// find the getter by looking up the inheritance chain (via
634630
// TypePropertyResolver, via `_resolveReceiverType`). However, if the
635631
// setter that was found is either top-level, or declared in an extension,
636632
// or is static, then we do not keep searching for the getter; this
@@ -646,7 +642,7 @@ class MethodInvocationResolver with ScopeHelpers {
646642
whyNotPromotedArguments: whyNotPromotedArguments,
647643
contextType: contextType);
648644
var receiverTypeName = switch (receiverType) {
649-
InterfaceTypeImpl() => receiverType.element.name,
645+
InterfaceTypeImpl() => receiverType.element3.name3!,
650646
FunctionType() => 'Function',
651647
_ => '<unknown>',
652648
};
@@ -678,24 +674,26 @@ class MethodInvocationResolver with ScopeHelpers {
678674
/// process, then returns that new node. Otherwise, returns `null`.
679675
FunctionExpressionInvocationImpl? _resolveReceiverPrefix(
680676
MethodInvocationImpl node,
681-
PrefixElementImpl prefix,
677+
PrefixElementImpl2 prefix,
682678
SimpleIdentifierImpl nameNode,
683679
String name,
684680
List<WhyNotPromotedGetter> whyNotPromotedArguments,
685681
{required TypeImpl contextType}) {
686682
// Note: prefix?.bar is reported as an error in ElementResolver.
687683

688-
if (name == FunctionElement.LOAD_LIBRARY_NAME) {
684+
if (name == TopLevelFunctionElement.LOAD_LIBRARY_NAME) {
689685
var imports = prefix.imports;
690-
if (imports.length == 1 &&
691-
imports[0].prefix is DeferredImportElementPrefix) {
692-
var importedLibrary = imports[0].importedLibrary;
693-
var element = importedLibrary?.loadLibraryFunction;
694-
if (element != null) {
695-
nameNode.element = element.asElement2;
696-
_setResolution(node, element.type, whyNotPromotedArguments,
697-
contextType: contextType);
698-
return null;
686+
if (imports.length == 1) {
687+
var firstPrefix = imports[0].prefix2;
688+
if (firstPrefix != null && firstPrefix.isDeferred) {
689+
var importedLibrary = imports[0].importedLibrary;
690+
var element = importedLibrary?.loadLibraryFunction;
691+
if (element != null) {
692+
nameNode.element = element.asElement2;
693+
_setResolution(node, element.type, whyNotPromotedArguments,
694+
contextType: contextType);
695+
return null;
696+
}
699697
}
700698
}
701699
}
@@ -725,7 +723,7 @@ class MethodInvocationResolver with ScopeHelpers {
725723

726724
_reportUndefinedFunction(
727725
node,
728-
prefix: prefix.name,
726+
prefix: prefix.name3,
729727
name: name,
730728
whyNotPromotedArguments: whyNotPromotedArguments,
731729
contextType: contextType,
@@ -826,7 +824,7 @@ class MethodInvocationResolver with ScopeHelpers {
826824

827825
var callFunctionType = result.callFunctionType;
828826
if (callFunctionType != null) {
829-
assert(name == FunctionElement.CALL_METHOD_NAME);
827+
assert(name == MethodElement2.CALL_METHOD_NAME);
830828
_setResolution(node, callFunctionType, whyNotPromotedArguments,
831829
contextType: contextType);
832830
// TODO(scheglov): Replace this with using FunctionType directly.
@@ -837,7 +835,7 @@ class MethodInvocationResolver with ScopeHelpers {
837835
}
838836

839837
if (receiverType.isDartCoreFunction &&
840-
name == FunctionElement.CALL_METHOD_NAME) {
838+
name == MethodElement2.CALL_METHOD_NAME) {
841839
_setResolution(node, DynamicTypeImpl.instance, whyNotPromotedArguments,
842840
contextType: contextType);
843841
nameNode.element = null;
@@ -852,9 +850,9 @@ class MethodInvocationResolver with ScopeHelpers {
852850
return _rewriteAsFunctionExpressionInvocation(node, recordField.type);
853851
}
854852

855-
var target = result.getter2?.asElement;
853+
var target = result.getter2;
856854
if (target != null) {
857-
nameNode.element = target.asElement2;
855+
nameNode.element = target;
858856

859857
if (target.isStatic) {
860858
_reportInstanceAccessToStaticMember(
@@ -864,7 +862,7 @@ class MethodInvocationResolver with ScopeHelpers {
864862
);
865863
}
866864

867-
if (target is PropertyAccessorElement) {
865+
if (target is PropertyAccessorElement2) {
868866
return _rewriteAsFunctionExpressionInvocation(node, target.returnType);
869867
}
870868
_setResolution(node, target.type, whyNotPromotedArguments,
@@ -882,7 +880,7 @@ class MethodInvocationResolver with ScopeHelpers {
882880

883881
String receiverClassName = '<unknown>';
884882
if (receiverType is InterfaceTypeImpl) {
885-
receiverClassName = receiverType.element.name;
883+
receiverClassName = receiverType.element3.name3!;
886884
} else if (receiverType is FunctionType) {
887885
receiverClassName = 'Function';
888886
}
@@ -971,9 +969,9 @@ class MethodInvocationResolver with ScopeHelpers {
971969
var target = node.target;
972970
if (target == null) {
973971
functionExpression = node.methodName;
974-
var element = node.methodName.element?.asElement;
975-
if (element is ExecutableElement &&
976-
element.enclosingElement3 is InstanceElement &&
972+
var element = node.methodName.element;
973+
if (element is ExecutableElement2 &&
974+
element.enclosingElement2 is InstanceElement2 &&
977975
!element.isStatic) {
978976
targetType = _resolver.flowAnalysis.flow
979977
?.propertyGet(
@@ -982,14 +980,13 @@ class MethodInvocationResolver with ScopeHelpers {
982980
? CascadePropertyTarget.singleton
983981
: ThisPropertyTarget.singleton,
984982
node.methodName.name,
985-
element.asElement2,
983+
element,
986984
SharedTypeView(getterReturnType))
987985
?.unwrapTypeView() ??
988986
targetType;
989987
}
990988
} else {
991-
if (target is SimpleIdentifierImpl &&
992-
target.element?.asElement is PrefixElement) {
989+
if (target is SimpleIdentifierImpl && target.element is PrefixElement2) {
993990
functionExpression = PrefixedIdentifierImpl(
994991
prefix: target,
995992
period: node.operator!,
@@ -1126,10 +1123,10 @@ class MethodInvocationResolver with ScopeHelpers {
11261123
/// Checks whether the given [expression] is a reference to a class. If it is
11271124
/// then the element representing the class is returned, otherwise `null` is
11281125
/// returned.
1129-
static InterfaceElement? getTypeReference(Expression expression) {
1126+
static InterfaceElement2? getTypeReference(Expression expression) {
11301127
if (expression is Identifier) {
1131-
var staticElement = expression.element?.asElement;
1132-
if (staticElement is InterfaceElement) {
1128+
var staticElement = expression.element;
1129+
if (staticElement is InterfaceElement2) {
11331130
return staticElement;
11341131
}
11351132
}

0 commit comments

Comments
 (0)