| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library services.src.index.local_index; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_server/src/provisional/index/index_core.dart'; | |
| 10 import 'package:analysis_server/src/services/index/index.dart'; | |
| 11 import 'package:analysis_server/src/services/index/store/split_store.dart'; | |
| 12 import 'package:analyzer/dart/element/element.dart'; | |
| 13 import 'package:analyzer/src/generated/engine.dart'; | |
| 14 import 'package:analyzer/src/generated/source.dart'; | |
| 15 | |
| 16 /** | |
| 17 * A local implementation of [Index]. | |
| 18 */ | |
| 19 class LocalIndex extends Index { | |
| 20 /** | |
| 21 * The index contributors used by this index. | |
| 22 */ | |
| 23 List<IndexContributor> contributors = <IndexContributor>[]; | |
| 24 | |
| 25 SplitIndexStore _store; | |
| 26 | |
| 27 LocalIndex(NodeManager nodeManager) { | |
| 28 // TODO(scheglov) get IndexObjectManager(s) as a parameter | |
| 29 _store = new SplitIndexStore( | |
| 30 nodeManager, <IndexObjectManager>[new DartUnitIndexObjectManager()]); | |
| 31 } | |
| 32 | |
| 33 @override | |
| 34 String get statistics => _store.statistics; | |
| 35 | |
| 36 @override | |
| 37 void clear() { | |
| 38 _store.clear(); | |
| 39 } | |
| 40 | |
| 41 /** | |
| 42 * Returns all relations with [Element]s with the given [name]. | |
| 43 */ | |
| 44 Future<Map<List<String>, List<InspectLocation>>> findElementsByName( | |
| 45 String name) { | |
| 46 return _store.inspect_getElementRelations(name); | |
| 47 } | |
| 48 | |
| 49 /** | |
| 50 * Returns a `Future<List<Location>>` that completes with the list of | |
| 51 * [LocationImpl]s of the given [relationship] with the given [indexable]. | |
| 52 * | |
| 53 * For example, if the [indexable] represents a function element and the | |
| 54 * [relationship] is the `is-invoked-by` relationship, then the locations | |
| 55 * will be all of the places where the function is invoked. | |
| 56 */ | |
| 57 @override | |
| 58 Future<List<LocationImpl>> getRelationships( | |
| 59 IndexableObject indexable, RelationshipImpl relationship) { | |
| 60 return _store.getRelationships(indexable, relationship); | |
| 61 } | |
| 62 | |
| 63 @override | |
| 64 List<Element> getTopLevelDeclarations(ElementNameFilter nameFilter) { | |
| 65 return _store.getTopLevelDeclarations(nameFilter); | |
| 66 } | |
| 67 | |
| 68 @override | |
| 69 void index(AnalysisContext context, Object object) { | |
| 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 } | |
| 85 } | |
| 86 | |
| 87 @override | |
| 88 void recordRelationship( | |
| 89 IndexableObject indexable, Relationship relationship, Location location) { | |
| 90 _store.recordRelationship(indexable, relationship, location); | |
| 91 } | |
| 92 | |
| 93 @override | |
| 94 void removeContext(AnalysisContext context) { | |
| 95 _store.removeContext(context); | |
| 96 } | |
| 97 | |
| 98 @override | |
| 99 void removeSource(AnalysisContext context, Source source) { | |
| 100 _store.removeSource(context, source); | |
| 101 } | |
| 102 | |
| 103 @override | |
| 104 void removeSources(AnalysisContext context, SourceContainer container) { | |
| 105 _store.removeSources(context, container); | |
| 106 } | |
| 107 | |
| 108 @override | |
| 109 void run() { | |
| 110 // NO-OP for the local index | |
| 111 } | |
| 112 | |
| 113 @override | |
| 114 void stop() { | |
| 115 // NO-OP for the local index | |
| 116 } | |
| 117 } | |
| OLD | NEW |