Skip to content

Commit bc521ee

Browse files
scheglovCommit Queue
authored andcommitted
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 <scheglov@google.com> Reviewed-by: Jaime Wren <jwren@google.com>
1 parent 8c270c4 commit bc521ee

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkg/analyzer/lib/dart/element/element2.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,25 @@ abstract class InterfaceElement2 implements InstanceElement2 {
13251325
required NullabilitySuffix nullabilitySuffix,
13261326
});
13271327

1328+
/// Returns the element representing the method that results from looking up
1329+
/// the given [methodName] in this class with respect to the given [library],
1330+
/// ignoring abstract methods, or `null` if the look up fails.
1331+
///
1332+
/// The behavior of this method is defined by the Dart Language Specification
1333+
/// in section 16.15.1:
1334+
/// <blockquote>
1335+
/// The result of looking up method <i>m</i> in class <i>C</i> with respect to
1336+
/// library <i>L</i> is: If <i>C</i> declares an instance method named
1337+
/// <i>m</i> that is accessible to <i>L</i>, then that method is the result of
1338+
/// the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
1339+
/// result of the lookup is the result of looking up method <i>m</i> in
1340+
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
1341+
/// failed.
1342+
/// </blockquote>
1343+
// TODO(scheglov): Deprecate and remove it.
1344+
MethodElement2? lookUpConcreteMethod(
1345+
String methodName, LibraryElement2 library);
1346+
13281347
/// Returns the element representing the method that results from looking up
13291348
/// the given [methodName] in the superclass of this class with respect to the
13301349
/// given [library], or `null` if the look up fails.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6447,6 +6447,13 @@ abstract class InterfaceElementImpl2 extends InstanceElementImpl2
64476447
firstFragment.instantiate(
64486448
typeArguments: typeArguments, nullabilitySuffix: nullabilitySuffix);
64496449

6450+
@override
6451+
MethodElement2? lookUpConcreteMethod(
6452+
String methodName, LibraryElement2 library) {
6453+
return _implementationsOfMethod2(methodName).firstWhereOrNull(
6454+
(method) => !method.isAbstract && method.isAccessibleIn2(library));
6455+
}
6456+
64506457
PropertyAccessorElement2? lookUpInheritedConcreteGetter(
64516458
String getterName, LibraryElement2 library) {
64526459
return _implementationsOfGetter2(getterName).firstWhereOrNull((getter) =>

0 commit comments

Comments
 (0)