From bc521ee54eb1834ee01299b7b286cbfc53768cc7 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 30 Dec 2024 15:27:10 -0800 Subject: [PATCH] Elements. Add InterfaceElement2.lookUpConcreteMethod() It is used by an external client. Change-Id: Ie4ad55bbe622aaa5466b6a2f787208af232f56fd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402342 Commit-Queue: Konstantin Shcheglov Reviewed-by: Jaime Wren --- pkg/analyzer/lib/dart/element/element2.dart | 19 +++++++++++++++++++ .../lib/src/dart/element/element.dart | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/analyzer/lib/dart/element/element2.dart b/pkg/analyzer/lib/dart/element/element2.dart index 186d23c29f51..9ce0316f66f6 100644 --- a/pkg/analyzer/lib/dart/element/element2.dart +++ b/pkg/analyzer/lib/dart/element/element2.dart @@ -1325,6 +1325,25 @@ abstract class InterfaceElement2 implements InstanceElement2 { required NullabilitySuffix nullabilitySuffix, }); + /// Returns the element representing the method that results from looking up + /// the given [methodName] in this class with respect to the given [library], + /// ignoring abstract methods, or `null` if the look up fails. + /// + /// The behavior of this method is defined by the Dart Language Specification + /// in section 16.15.1: + ///
+ /// The result of looking up method m in class C with respect to + /// library L is: If C declares an instance method named + /// m that is accessible to L, then that method is the result of + /// the lookup. Otherwise, if C has a superclass S, then the + /// result of the lookup is the result of looking up method m in + /// S with respect to L. Otherwise, we say that the lookup has + /// failed. + ///
+ // TODO(scheglov): Deprecate and remove it. + MethodElement2? lookUpConcreteMethod( + String methodName, LibraryElement2 library); + /// Returns the element representing the method that results from looking up /// the given [methodName] in the superclass of this class with respect to the /// given [library], or `null` if the look up fails. diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index bad91e59ac74..37a3e757552c 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -6447,6 +6447,13 @@ abstract class InterfaceElementImpl2 extends InstanceElementImpl2 firstFragment.instantiate( typeArguments: typeArguments, nullabilitySuffix: nullabilitySuffix); + @override + MethodElement2? lookUpConcreteMethod( + String methodName, LibraryElement2 library) { + return _implementationsOfMethod2(methodName).firstWhereOrNull( + (method) => !method.isAbstract && method.isAccessibleIn2(library)); + } + PropertyAccessorElement2? lookUpInheritedConcreteGetter( String getterName, LibraryElement2 library) { return _implementationsOfGetter2(getterName).firstWhereOrNull((getter) =>