Skip to content

Commit 3729b96

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Use SearchedFiles when searching subtypes for 'analysis.implemented'.
[email protected] Change-Id: I7bba90bd550602588553382fe61c8c41539483ca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113951 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 5d816cb commit 3729b96

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

pkg/analysis_server/lib/src/services/search/search_engine_internal.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class SearchEngineImpl implements SearchEngine {
2323
// TODO(brianwilkerson) Determine whether this await is necessary.
2424
await null;
2525
List<AnalysisDriver> drivers = _drivers.toList();
26+
SearchedFiles searchedFiles = _createSearchedFiles(drivers);
2627

2728
String libraryUriStr = type.librarySource.uri.toString();
2829
bool hasSubtypes = false;
@@ -36,8 +37,8 @@ class SearchEngineImpl implements SearchEngine {
3637
return;
3738
}
3839
for (AnalysisDriver driver in drivers) {
39-
List<SubtypeResult> subtypes =
40-
await driver.search.subtypes(type: type, subtype: subtype);
40+
List<SubtypeResult> subtypes = await driver.search
41+
.subtypes(searchedFiles, type: type, subtype: subtype);
4142
for (SubtypeResult subtype in subtypes) {
4243
hasSubtypes = true;
4344
members.addAll(subtype.libraryUri == libraryUriStr

pkg/analyzer/lib/src/dart/analysis/search.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Search {
141141
/**
142142
* Return direct [SubtypeResult]s for either the [type] or [subtype].
143143
*/
144-
Future<List<SubtypeResult>> subtypes(
144+
Future<List<SubtypeResult>> subtypes(SearchedFiles searchedFiles,
145145
{ClassElement type, SubtypeResult subtype}) async {
146146
String name;
147147
String id;
@@ -162,10 +162,12 @@ class Search {
162162

163163
if (files != null) {
164164
for (FileState file in files) {
165-
AnalysisDriverUnitIndex index = await _driver.getIndex(file.path);
166-
if (index != null) {
167-
var request = new _IndexRequest(index);
168-
request.addSubtypes(id, results, file);
165+
if (searchedFiles.add(file.path, this)) {
166+
AnalysisDriverUnitIndex index = await _driver.getIndex(file.path);
167+
if (index != null) {
168+
var request = new _IndexRequest(index);
169+
request.addSubtypes(id, results, file);
170+
}
169171
}
170172
}
171173
}

pkg/analyzer/test/src/dart/analysis/search_test.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,8 @@ class F {}
13201320
ClassElement a = _findElement('A');
13211321

13221322
// Search by 'type'.
1323-
List<SubtypeResult> subtypes = await driver.search.subtypes(type: a);
1323+
List<SubtypeResult> subtypes =
1324+
await driver.search.subtypes(SearchedFiles(), type: a);
13241325
expect(subtypes, hasLength(3));
13251326

13261327
SubtypeResult b = subtypes.singleWhere((r) => r.name == 'B');
@@ -1341,7 +1342,8 @@ class F {}
13411342

13421343
// Search by 'id'.
13431344
{
1344-
List<SubtypeResult> subtypes = await driver.search.subtypes(subtype: b);
1345+
List<SubtypeResult> subtypes =
1346+
await driver.search.subtypes(SearchedFiles(), subtype: b);
13451347
expect(subtypes, hasLength(1));
13461348
SubtypeResult e = subtypes.singleWhere((r) => r.name == 'E');
13471349
expect(e.members, ['methodE']);
@@ -1390,7 +1392,8 @@ class A {
13901392
ClassElement aClass = aLibrary.getType('A');
13911393

13921394
// Search by 'type'.
1393-
List<SubtypeResult> subtypes = await driver.search.subtypes(type: aClass);
1395+
List<SubtypeResult> subtypes =
1396+
await driver.search.subtypes(SearchedFiles(), type: aClass);
13941397
expect(subtypes, hasLength(3));
13951398

13961399
SubtypeResult t1 = subtypes.singleWhere((r) => r.name == 'T1');
@@ -1465,7 +1468,8 @@ class A {}
14651468
driver.addFile(pathC);
14661469
await scheduler.waitForIdle();
14671470

1468-
List<SubtypeResult> subtypes = await driver.search.subtypes(type: a);
1471+
List<SubtypeResult> subtypes =
1472+
await driver.search.subtypes(SearchedFiles(), type: a);
14691473
expect(subtypes, hasLength(2));
14701474

14711475
SubtypeResult b = subtypes.singleWhere((r) => r.name == 'B');
@@ -1494,7 +1498,7 @@ mixin M on A, B {
14941498
ClassElement b = _findElement('B');
14951499

14961500
{
1497-
var subtypes = await driver.search.subtypes(type: a);
1501+
var subtypes = await driver.search.subtypes(SearchedFiles(), type: a);
14981502
expect(subtypes, hasLength(1));
14991503

15001504
var m = subtypes.singleWhere((r) => r.name == 'M');
@@ -1504,7 +1508,7 @@ mixin M on A, B {
15041508
}
15051509

15061510
{
1507-
var subtypes = await driver.search.subtypes(type: b);
1511+
var subtypes = await driver.search.subtypes(SearchedFiles(), type: b);
15081512
expect(subtypes, hasLength(1));
15091513

15101514
var m = subtypes.singleWhere((r) => r.name == 'M');
@@ -1523,7 +1527,8 @@ class B extends A {}
15231527
''');
15241528
ClassElement a = _findElement('A');
15251529

1526-
List<SubtypeResult> subtypes = await driver.search.subtypes(type: a);
1530+
List<SubtypeResult> subtypes =
1531+
await driver.search.subtypes(SearchedFiles(), type: a);
15271532
expect(subtypes, hasLength(1));
15281533

15291534
SubtypeResult b = subtypes.singleWhere((r) => r.name == 'B');

0 commit comments

Comments
 (0)