Skip to content

Commit

Permalink
[element model] tidy library name access in null_closures
Browse files Browse the repository at this point in the history
Bug: dart-lang/linter#5099
Change-Id: I1a20ca5349a2bc9af03a1e7705c73ebbc70009bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388421
Auto-Submit: Phil Quitslund <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
  • Loading branch information
pq authored and Commit Queue committed Oct 4, 2024
1 parent 450c196 commit 6f6b8b7
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions pkg/linter/lib/src/rules/null_closures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,30 +225,23 @@ class _Visitor extends SimpleAstVisitor<void> {

if (type is! InterfaceType) return null;

NonNullableFunction? getMethod(String? library, String className) {
if (library == null) return null;
NonNullableFunction? getMethod(String? libraryName, String className) {
if (libraryName == null) return null;
return possibleMethods
.lookup(NonNullableFunction(library, className, methodName));
.lookup(NonNullableFunction(libraryName, className, methodName));
}

var element = type.element3;
if (element.isSynthetic) return null;

var method = getMethod(element.libraryName, element.name);
if (method != null) {
return method;
}
var method = getMethod(element.library2.name, element.name);
if (method != null) return method;

for (var supertype in element.allSupertypes) {
var superElement = supertype.element3;
method = getMethod(superElement.libraryName, superElement.name);
method = getMethod(superElement.library2.name, superElement.name);
if (method != null) return method;
}
return null;
}
}

extension on InterfaceElement2 {
String? get libraryName =>
library2.firstFragment.libraryFragment.element.name;
}

0 comments on commit 6f6b8b7

Please sign in to comment.