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) =>