Skip to content

Commit e68d688

Browse files
srawlinsCommit Queue
authored andcommitted
DAS: Migrate from InheritanceManager3 in completion code
Change-Id: I097889fb2baaf71e99d765bcc076f1091383fbb0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429580 Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 93146ec commit e68d688

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
3131
import 'package:analyzer/src/dart/analysis/file_state.dart';
3232
import 'package:analyzer/src/dart/analysis/results.dart';
3333
import 'package:analyzer/src/dart/analysis/session.dart';
34-
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
3534
import 'package:analyzer/src/dartdoc/dartdoc_directive_info.dart';
3635
import 'package:analyzer/src/generated/source.dart' show SourceFactory;
3736
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
@@ -403,10 +402,6 @@ class DartCompletionRequest {
403402
return opType.includeIdentifiers;
404403
}
405404

406-
InheritanceManager3 get inheritanceManager {
407-
return analysisSession.inheritanceManager;
408-
}
409-
410405
/// Answer the [DartType] for Object in dart:core
411406
InterfaceType get objectType => libraryElement.typeProvider.objectType;
412407

pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ class DeclarationHelper {
10231023
return;
10241024
}
10251025
var referencingInterface = _referencingInterfaceFor(element);
1026-
var members = request.inheritanceManager.getInheritedMap(element);
1026+
var members = element.inheritedMembers;
10271027
for (var member in members.values) {
10281028
switch (member) {
10291029
case MethodElement():
@@ -1060,8 +1060,8 @@ class DeclarationHelper {
10601060
var substitution = Substitution.fromInterfaceType(type);
10611061
var map =
10621062
onlySuper
1063-
? request.inheritanceManager.getInheritedConcreteMap(type.element3)
1064-
: request.inheritanceManager.getInterface2(type.element3).map2;
1063+
? type.element3.inheritedConcreteMembers
1064+
: type.element3.interfaceMembers;
10651065

10661066
var membersByName = <String, List<ExecutableElement>>{};
10671067
for (var rawMember in map.values) {

pkg/analysis_server/lib/src/services/completion/dart/override_helper.dart

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:analysis_server/src/services/completion/dart/completion_state.da
99
import 'package:analysis_server/src/services/completion/dart/suggestion_collector.dart';
1010
import 'package:analyzer/dart/element/element.dart';
1111
import 'package:analyzer/source/source_range.dart';
12-
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1312

1413
/// A helper class that produces candidate suggestions for overrides of
1514
/// inherited methods.
@@ -20,43 +19,34 @@ class OverrideHelper {
2019
/// The suggestion collector to which suggestions will be added.
2120
final SuggestionCollector collector;
2221

23-
/// The inheritance manager used to compute the set of methods that can be
24-
/// overridden.
25-
final InheritanceManager3 inheritanceManager;
26-
2722
/// Initialize a newly created helper to add suggestions to the [collector].
28-
OverrideHelper({required this.state, required this.collector})
29-
: inheritanceManager = state.request.inheritanceManager;
23+
OverrideHelper({required this.state, required this.collector});
3024

3125
void computeOverridesFor({
3226
required InterfaceElement interfaceElement,
3327
required SourceRange replacementRange,
3428
required bool skipAt,
3529
}) {
36-
var interface = inheritanceManager.getInterface2(interfaceElement);
37-
var interfaceMap = interface.map2;
38-
var namesToOverride = _namesToOverride(
39-
interfaceElement.library2.uri,
40-
interface,
41-
);
30+
var namesToOverride = _namesToOverride(interfaceElement);
4231

43-
// Build suggestions
32+
// Build suggestions.
4433
for (var name in namesToOverride) {
45-
var element = interfaceMap[name];
34+
var element = interfaceElement.interfaceMembers[name];
4635
// Gracefully degrade if the overridden element has not been resolved.
4736
if (element != null) {
4837
if (_hasNonVirtualAnnotation(element)) {
4938
continue;
5039
}
5140

52-
var invokeSuper = interface.isSuperImplemented(name);
5341
var matcherScore = math.max(
5442
math.max(
5543
state.matcher.score('override'),
5644
state.matcher.score('operator'),
5745
),
5846
state.matcher.score(element.displayName),
5947
);
48+
var invokeSuper =
49+
interfaceElement.getInheritedConcreteMember(name) != null;
6050
if (matcherScore != -1) {
6151
collector.addSuggestion(
6252
OverrideSuggestion(
@@ -83,19 +73,26 @@ class OverrideHelper {
8373
return element.metadata2.hasNonVirtual;
8474
}
8575

86-
/// Return the list of names that belong to the [interface] of a class, but
87-
/// are not yet declared in the class.
88-
List<Name> _namesToOverride(Uri libraryUri, Interface interface) {
76+
/// Returns the list of names that belong to [interfaceElement], but are not
77+
/// yet declared in the class.
78+
List<Name> _namesToOverride(InterfaceElement interfaceElement) {
8979
var namesToOverride = <Name>[];
90-
for (var name in interface.map2.keys) {
80+
var libraryUri = interfaceElement.library2.uri;
81+
var memberNames = interfaceElement.interfaceMembers.keys;
82+
for (var name in memberNames) {
9183
if (name.isAccessibleFor(libraryUri)) {
9284
// TODO(brianwilkerson): When the user is typing the name of an
9385
// inherited member, the map will contain a key matching the current
9486
// prefix. If the name is the only thing typed (that is, the field
9587
// declaration consists of a single identifier), and that identifier
9688
// matches the name of an overridden member, then the override should
9789
// still be suggested.
98-
if (!interface.declared2.containsKey(name)) {
90+
var declaredElement =
91+
interfaceElement.getGetter(name.name) ??
92+
interfaceElement.getMethod(name.name) ??
93+
// `getSetter` accepts names without trailing `=` characters.
94+
interfaceElement.getSetter(name.forGetter.name);
95+
if (declaredElement == null) {
9996
namesToOverride.add(name);
10097
}
10198
}

0 commit comments

Comments
 (0)