Skip to content

Commit

Permalink
Elements. Add InterfaceElement2.lookUpConcreteMethod()
Browse files Browse the repository at this point in the history
It is used by an external client.

Change-Id: Ie4ad55bbe622aaa5466b6a2f787208af232f56fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402342
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Jaime Wren <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Dec 30, 2024
1 parent 8c270c4 commit bc521ee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/// <blockquote>
/// The result of looking up method <i>m</i> in class <i>C</i> with respect to
/// library <i>L</i> is: If <i>C</i> declares an instance method named
/// <i>m</i> that is accessible to <i>L</i>, then that method is the result of
/// the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
/// result of the lookup is the result of looking up method <i>m</i> in
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
/// failed.
/// </blockquote>
// 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.
Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down

0 comments on commit bc521ee

Please sign in to comment.