Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0d1fe0f

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committedMay 13, 2025
analyzer: Remove unnecessary InheritanceManager3 from LinterContext
Work towards #50986 At the same time, migrate `redeclare_verifier` from InheritanceManager3, so that the impl is the same as the `annotate_redeclares` lint rule. Change-Id: I9c5c77dcf50aa54820473874327bc3a7b93fd987 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428380 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
1 parent 3dc9d8d commit 0d1fe0f

File tree

6 files changed

+9
-35
lines changed

6 files changed

+9
-35
lines changed
 

‎pkg/analysis_server_plugin/lib/src/plugin_server.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
2727
import 'package:analyzer/src/dart/analysis/analysis_options.dart';
2828
import 'package:analyzer/src/dart/analysis/byte_store.dart';
2929
import 'package:analyzer/src/dart/analysis/file_content_cache.dart';
30-
import 'package:analyzer/src/dart/analysis/session.dart';
3130
import 'package:analyzer/src/dart/element/type_system.dart';
3231
import 'package:analyzer/src/ignore_comments/ignore_info.dart';
3332
import 'package:analyzer/src/lint/linter.dart';
@@ -347,8 +346,6 @@ class PluginServer {
347346
currentUnit,
348347
libraryResult.element2.typeProvider,
349348
libraryResult.element2.typeSystem as TypeSystemImpl,
350-
(analysisContext.currentSession as AnalysisSessionImpl)
351-
.inheritanceManager,
352349
// TODO(srawlins): Support 'package' parameter.
353350
null,
354351
);

‎pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ class LibraryAnalyzer {
408408
definingContextUnit,
409409
_typeProvider,
410410
_typeSystem,
411-
_inheritance,
412411
workspacePackage,
413412
);
414413

@@ -520,7 +519,7 @@ class LibraryAnalyzer {
520519

521520
unit.accept(OverrideVerifier(_inheritance, errorReporter));
522521

523-
unit.accept(RedeclareVerifier(_inheritance, errorReporter));
522+
unit.accept(RedeclareVerifier(errorReporter));
524523

525524
TodoFinder(errorReporter).findIn(unit);
526525
LanguageVersionOverrideVerifier(errorReporter).verify(unit);

‎pkg/analyzer/lib/src/error/redeclare_verifier.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@ import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
77
import 'package:analyzer/dart/element/element.dart';
88
import 'package:analyzer/error/listener.dart';
9-
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
109
import 'package:analyzer/src/error/codes.dart';
1110

1211
/// Instances of the class `RedeclareVerifier` visit all of the members of any
1312
/// extension type declarations in a compilation unit to verify that if they
1413
/// have a redeclare annotation it is being used correctly.
1514
class RedeclareVerifier extends RecursiveAstVisitor<void> {
16-
/// The inheritance manager used to find redeclared members.
17-
final InheritanceManager3 _inheritance;
18-
1915
/// The error reporter used to report errors.
2016
final ErrorReporter _errorReporter;
2117

2218
/// The current extension type.
2319
InterfaceElement? _currentExtensionType;
2420

25-
RedeclareVerifier(this._inheritance, this._errorReporter);
21+
RedeclareVerifier(this._errorReporter);
2622

2723
@override
2824
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {
@@ -69,10 +65,8 @@ class RedeclareVerifier extends RecursiveAstVisitor<void> {
6965
bool _redeclaresMember(ExecutableElement member) {
7066
var currentType = _currentExtensionType;
7167
if (currentType != null) {
72-
var interface = _inheritance.getInterface2(currentType);
73-
var redeclared = interface.redeclared2;
7468
var name = Name.forElement(member);
75-
return redeclared.containsKey(name);
69+
return name != null && currentType.getInheritedMember(name) != null;
7670
}
7771

7872
return false;

‎pkg/analyzer/lib/src/lint/linter.dart

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:analyzer/diagnostic/diagnostic.dart';
1212
import 'package:analyzer/error/error.dart';
1313
import 'package:analyzer/error/listener.dart';
1414
import 'package:analyzer/file_system/file_system.dart';
15-
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1615
import 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
1716
import 'package:analyzer/src/lint/pub.dart';
1817
import 'package:analyzer/src/lint/state.dart';
@@ -234,8 +233,6 @@ abstract class LinterContext {
234233
/// The defining compilation unit of the library under analysis.
235234
LintRuleUnitContext get definingUnit;
236235

237-
InheritanceManager3 get inheritanceManager;
238-
239236
/// Whether the [definingUnit]'s location is in a package's top-level 'lib'
240237
/// directory, including locations deeply nested, and locations in the
241238
/// package-implementation directory, 'lib/src'.
@@ -276,9 +273,6 @@ final class LinterContextWithParsedResults implements LinterContext {
276273
@override
277274
LintRuleUnitContext? currentUnit;
278275

279-
@override
280-
final InheritanceManager3 inheritanceManager = InheritanceManager3();
281-
282276
LinterContextWithParsedResults(this.allUnits, this.definingUnit);
283277

284278
@override
@@ -333,15 +327,11 @@ final class LinterContextWithResolvedResults implements LinterContext {
333327
@override
334328
final TypeSystem typeSystem;
335329

336-
@override
337-
final InheritanceManager3 inheritanceManager;
338-
339330
LinterContextWithResolvedResults(
340331
this.allUnits,
341332
this.definingUnit,
342333
this.typeProvider,
343334
this.typeSystem,
344-
this.inheritanceManager,
345335
this.package,
346336
);
347337

‎pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'package:analyzer/error/listener.dart';
66
import 'package:analyzer/src/dart/ast/ast.dart';
7-
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
87
import 'package:analyzer/src/lint/constants.dart';
98
import 'package:analyzer/src/lint/linter.dart';
109
import 'package:analyzer/src/string_source.dart';
@@ -52,7 +51,6 @@ abstract class AbstractLinterContextTest extends PubPackageResolutionTest {
5251
contextUnit,
5352
result.typeProvider,
5453
result.typeSystem,
55-
InheritanceManager3(),
5654
// TODO(pq): Use a test package or consider passing in `null`.
5755
workspacePackage,
5856
);

‎pkg/linter/lib/src/rules/annotate_redeclares.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ class AnnotateRedeclares extends LintRule {
2626
NodeLintRegistry registry,
2727
LinterContext context,
2828
) {
29-
var visitor = _Visitor(this, context);
29+
var visitor = _Visitor(this);
3030
registry.addExtensionTypeDeclaration(this, visitor);
3131
}
3232
}
3333

3434
class _Visitor extends SimpleAstVisitor<void> {
3535
final LintRule rule;
36-
final LinterContext context;
3736

38-
_Visitor(this.rule, this.context);
37+
_Visitor(this.rule);
3938

4039
@override
4140
void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) {
@@ -60,17 +59,14 @@ class _Visitor extends SimpleAstVisitor<void> {
6059
}
6160
}
6261

63-
/// Return `true` if the [member] redeclares a member from a superinterface.
62+
/// Returns whether the [member] redeclares a member from a superinterface.
6463
bool _redeclaresMember(
6564
ExecutableElement member,
6665
InterfaceElement extensionType,
6766
) {
68-
// TODO(pq): unify with similar logic in `redeclare_verifier` and move to inheritanceManager
69-
var interface = context.inheritanceManager.getInterface2(extensionType);
7067
var memberName = member.name3;
71-
return memberName != null &&
72-
interface.redeclared2.containsKey(
73-
Name.forLibrary(member.library2, memberName),
74-
);
68+
if (memberName == null) return false;
69+
var name = Name.forLibrary(member.library2, memberName);
70+
return extensionType.getInheritedMember(name) != null;
7571
}
7672
}

0 commit comments

Comments
 (0)
Failed to load comments.