| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library services.src.index.local_index; | 5 library services.src.index.local_index; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/analysis/index/index_core.dart'; | 9 import 'package:analysis_server/analysis/index_core.dart'; |
| 10 import 'package:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
| 11 import 'package:analysis_server/src/services/index/index_contributor.dart' | |
| 12 as oldContributors; | |
| 13 import 'package:analysis_server/src/services/index/store/split_store.dart'; | 11 import 'package:analysis_server/src/services/index/store/split_store.dart'; |
| 14 import 'package:analyzer/src/generated/ast.dart'; | |
| 15 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/html.dart'; | |
| 18 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 19 | 15 |
| 20 /** | 16 /** |
| 21 * A local implementation of [Index]. | 17 * A local implementation of [Index]. |
| 22 */ | 18 */ |
| 23 class LocalIndex extends Index { | 19 class LocalIndex extends Index { |
| 24 /** | 20 /** |
| 25 * The index contributors used by this index. | 21 * The index contributors used by this index. |
| 26 */ | 22 */ |
| 27 List<IndexContributor> contributors; | 23 List<IndexContributor> contributors = <IndexContributor>[]; |
| 28 | 24 |
| 29 SplitIndexStore _store; | 25 SplitIndexStore _store; |
| 30 | 26 |
| 31 LocalIndex(NodeManager nodeManager) { | 27 LocalIndex(NodeManager nodeManager) { |
| 32 // TODO(scheglov) get IndexObjectManager(s) as a parameter | 28 // TODO(scheglov) get IndexObjectManager(s) as a parameter |
| 33 _store = new SplitIndexStore(nodeManager, | 29 _store = new SplitIndexStore( |
| 34 <IndexObjectManager>[new DartUnitIndexObjectManager()]); | 30 nodeManager, <IndexObjectManager>[new DartUnitIndexObjectManager()]); |
| 35 } | 31 } |
| 36 | 32 |
| 37 @override | 33 @override |
| 38 String get statistics => _store.statistics; | 34 String get statistics => _store.statistics; |
| 39 | 35 |
| 40 @override | 36 @override |
| 41 void clear() { | 37 void clear() { |
| 42 _store.clear(); | 38 _store.clear(); |
| 43 } | 39 } |
| 44 | 40 |
| 45 /** | 41 /** |
| 46 * Returns all relations with [Element]s with the given [name]. | 42 * Returns all relations with [Element]s with the given [name]. |
| 47 */ | 43 */ |
| 48 Future<Map<List<String>, List<InspectLocation>>> findElementsByName( | 44 Future<Map<List<String>, List<InspectLocation>>> findElementsByName( |
| 49 String name) { | 45 String name) { |
| 50 return _store.inspect_getElementRelations(name); | 46 return _store.inspect_getElementRelations(name); |
| 51 } | 47 } |
| 52 | 48 |
| 53 /** | 49 /** |
| 54 * Returns a `Future<List<Location>>` that completes with the list of | 50 * Returns a `Future<List<Location>>` that completes with the list of |
| 55 * [LocationImpl]s of the given [relationship] with the given [element]. | 51 * [LocationImpl]s of the given [relationship] with the given [indexable]. |
| 56 * | 52 * |
| 57 * For example, if the [element] represents a function and the [relationship] | 53 * For example, if the [indexable] represents a function element and the |
| 58 * is the `is-invoked-by` relationship, then the locations will be all of the | 54 * [relationship] is the `is-invoked-by` relationship, then the locations |
| 59 * places where the function is invoked. | 55 * will be all of the places where the function is invoked. |
| 60 */ | 56 */ |
| 61 @override | 57 @override |
| 62 Future<List<LocationImpl>> getRelationships( | 58 Future<List<LocationImpl>> getRelationships( |
| 63 IndexableObject indexable, RelationshipImpl relationship) { | 59 IndexableObject indexable, RelationshipImpl relationship) { |
| 64 return _store.getRelationships(indexable, relationship); | 60 return _store.getRelationships(indexable, relationship); |
| 65 } | 61 } |
| 66 | 62 |
| 67 @override | 63 @override |
| 68 List<Element> getTopLevelDeclarations(ElementNameFilter nameFilter) { | 64 List<Element> getTopLevelDeclarations(ElementNameFilter nameFilter) { |
| 69 return _store.getTopLevelDeclarations(nameFilter); | 65 return _store.getTopLevelDeclarations(nameFilter); |
| 70 } | 66 } |
| 71 | 67 |
| 72 @override | 68 @override |
| 73 void indexHtmlUnit(AnalysisContext context, HtmlUnit unit) { | 69 void index(AnalysisContext context, Object object) { |
| 74 oldContributors.indexHtmlUnit(_store, context, unit); | 70 // about to index |
| 71 bool mayIndex = _store.aboutToIndex(context, object); |
| 72 if (!mayIndex) { |
| 73 return; |
| 74 } |
| 75 // do index |
| 76 try { |
| 77 for (IndexContributor contributor in contributors) { |
| 78 contributor.contributeTo(_store, context, object); |
| 79 } |
| 80 _store.doneIndex(); |
| 81 } catch (e) { |
| 82 _store.cancelIndex(); |
| 83 rethrow; |
| 84 } |
| 75 } | 85 } |
| 76 | 86 |
| 77 @override | 87 @override |
| 78 void indexUnit(AnalysisContext context, CompilationUnit unit) { | |
| 79 oldContributors.indexDartUnit(_store, context, unit); | |
| 80 } | |
| 81 | |
| 82 @override | |
| 83 void recordRelationship( | 88 void recordRelationship( |
| 84 IndexableObject indexable, Relationship relationship, Location location) { | 89 IndexableObject indexable, Relationship relationship, Location location) { |
| 85 _store.recordRelationship(indexable, relationship, location); | 90 _store.recordRelationship(indexable, relationship, location); |
| 86 } | 91 } |
| 87 | 92 |
| 88 @override | 93 @override |
| 89 void removeContext(AnalysisContext context) { | 94 void removeContext(AnalysisContext context) { |
| 90 _store.removeContext(context); | 95 _store.removeContext(context); |
| 91 } | 96 } |
| 92 | 97 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 103 @override | 108 @override |
| 104 void run() { | 109 void run() { |
| 105 // NO-OP for the local index | 110 // NO-OP for the local index |
| 106 } | 111 } |
| 107 | 112 |
| 108 @override | 113 @override |
| 109 void stop() { | 114 void stop() { |
| 110 // NO-OP for the local index | 115 // NO-OP for the local index |
| 111 } | 116 } |
| 112 } | 117 } |
| OLD | NEW |