Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: pkg/analysis_server/lib/src/services/search/search_engine_internal.dart

Issue 2962023002: Add SearchEngine.membersOfSubtypes(). (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analysis_server/src/services/search/search_engine.dart'; 7 import 'package:analysis_server/src/services/search/search_engine.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/dart/analysis/driver.dart'; 9 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer/src/dart/analysis/search.dart'; 10 import 'package:analyzer/src/dart/analysis/search.dart';
11 import 'package:analyzer/src/generated/source.dart' show Source, SourceRange; 11 import 'package:analyzer/src/generated/source.dart' show Source, SourceRange;
12 import 'package:meta/meta.dart'; 12 import 'package:meta/meta.dart';
13 13
14 /** 14 /**
15 * A [SearchEngine] implementation. 15 * A [SearchEngine] implementation.
16 */ 16 */
17 class SearchEngineImpl implements SearchEngine { 17 class SearchEngineImpl implements SearchEngine {
18 final Iterable<AnalysisDriver> _drivers; 18 final Iterable<AnalysisDriver> _drivers;
19 19
20 SearchEngineImpl(this._drivers); 20 SearchEngineImpl(this._drivers);
21 21
22 @override 22 @override
23 Future<Set<String>> membersOfSubtypes(ClassElement type) async {
24 List<AnalysisDriver> drivers = _drivers.toList();
25
26 bool hasSubtypes = false;
27 Set<String> visitedIds = new Set<String>();
28 Set<String> members = new Set<String>();
29
30 Future<Null> addMembers(ClassElement type, SubtypeResult subtype) async {
31 if (subtype != null && !visitedIds.add(subtype.id)) {
32 return;
33 }
34 for (AnalysisDriver driver in drivers) {
35 List<SubtypeResult> subtypes =
36 await driver.search.subtypes(type: type, subtype: subtype);
37 for (var subtype in subtypes) {
38 hasSubtypes = true;
39 members.addAll(subtype.members);
40 await addMembers(null, subtype);
41 }
42 }
43 }
44
45 await addMembers(type, null);
46
47 if (!hasSubtypes) {
48 return null;
49 }
50 return members;
51 }
52
53 @override
23 Future<Set<ClassElement>> searchAllSubtypes(ClassElement type) async { 54 Future<Set<ClassElement>> searchAllSubtypes(ClassElement type) async {
24 Set<ClassElement> allSubtypes = new Set<ClassElement>(); 55 Set<ClassElement> allSubtypes = new Set<ClassElement>();
25 56
26 Future<Null> addSubtypes(ClassElement type) async { 57 Future<Null> addSubtypes(ClassElement type) async {
27 List<SearchResult> directResults = await _searchDirectSubtypes(type); 58 List<SearchResult> directResults = await _searchDirectSubtypes(type);
28 for (SearchResult directResult in directResults) { 59 for (SearchResult directResult in directResults) {
29 var directSubtype = directResult.enclosingElement as ClassElement; 60 var directSubtype = directResult.enclosingElement as ClassElement;
30 if (allSubtypes.add(directSubtype)) { 61 if (allSubtypes.add(directSubtype)) {
31 await addSubtypes(directSubtype); 62 await addSubtypes(directSubtype);
32 } 63 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 226 }
196 if (kind == SearchResultKind.WRITE) { 227 if (kind == SearchResultKind.WRITE) {
197 return MatchKind.WRITE; 228 return MatchKind.WRITE;
198 } 229 }
199 if (kind == SearchResultKind.INVOCATION) { 230 if (kind == SearchResultKind.INVOCATION) {
200 return MatchKind.INVOCATION; 231 return MatchKind.INVOCATION;
201 } 232 }
202 return MatchKind.REFERENCE; 233 return MatchKind.REFERENCE;
203 } 234 }
204 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698