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 index; | 5 library engine.src.index.local_index; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:analysis_server/src/index/store/codec.dart'; | 10 import 'package:analyzer/index/index.dart'; |
11 import 'package:analysis_server/src/index/store/separate_file_manager.dart'; | |
12 import 'package:analysis_server/src/index/store/split_store.dart'; | |
13 import 'package:analyzer/src/generated/ast.dart'; | 11 import 'package:analyzer/src/generated/ast.dart'; |
14 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/html.dart'; | 14 import 'package:analyzer/src/generated/html.dart'; |
17 import 'package:analyzer/src/generated/index.dart'; | |
18 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/index/index_contributor.dart' as contributors; |
| 17 import 'package:analyzer/src/index/store/codec.dart'; |
| 18 import 'package:analyzer/src/index/store/memory_node_manager.dart'; |
| 19 import 'package:analyzer/src/index/store/separate_file_manager.dart'; |
| 20 import 'package:analyzer/src/index/store/split_store.dart'; |
19 | 21 |
20 | 22 |
21 Index createLocalFileSplitIndex(Directory directory) { | 23 Index createLocalFileSplitIndex(Directory directory) { |
22 var fileManager = new SeparateFileManager(directory); | 24 var fileManager = new SeparateFileManager(directory); |
23 var stringCodec = new StringCodec(); | 25 var stringCodec = new StringCodec(); |
24 var nodeManager = new FileNodeManager(fileManager, | 26 var nodeManager = new FileNodeManager(fileManager, |
25 AnalysisEngine.instance.logger, stringCodec, new ContextCodec(), | 27 AnalysisEngine.instance.logger, stringCodec, new ContextCodec(), |
26 new ElementCodec(stringCodec), new RelationshipCodec(stringCodec)); | 28 new ElementCodec(stringCodec), new RelationshipCodec(stringCodec)); |
27 return new LocalIndex(nodeManager); | 29 return new LocalIndex(nodeManager); |
28 } | 30 } |
29 | 31 |
30 | 32 |
| 33 Index createLocalMemorySplitIndex() { |
| 34 return new LocalIndex(new MemoryNodeManager()); |
| 35 } |
| 36 |
| 37 |
31 /** | 38 /** |
32 * A local implementation of [Index]. | 39 * A local implementation of [Index]. |
33 */ | 40 */ |
34 class LocalIndex extends Index { | 41 class LocalIndex extends Index { |
35 SplitIndexStore _store; | 42 SplitIndexStore _store; |
36 | 43 |
37 LocalIndex(NodeManager nodeManager) { | 44 LocalIndex(NodeManager nodeManager) { |
38 _store = new SplitIndexStore(nodeManager); | 45 _store = new SplitIndexStore(nodeManager); |
39 } | 46 } |
40 | 47 |
41 @override | 48 @override |
42 String get statistics => _store.statistics; | 49 String get statistics => _store.statistics; |
43 | 50 |
44 @override | 51 @override |
45 void clear() { | 52 void clear() { |
46 _store.clear(); | 53 _store.clear(); |
47 } | 54 } |
48 | 55 |
49 @override | |
50 void getRelationships(Element element, Relationship relationship, | |
51 RelationshipCallback callback) { | |
52 // TODO(scheglov) update Index API to use asynchronous interface | |
53 callback.hasRelationships(element, relationship, Location.EMPTY_ARRAY); | |
54 } | |
55 | |
56 /** | 56 /** |
57 * Returns a `Future<List<Location>>` that completes with the list of | 57 * Returns a `Future<List<Location>>` that completes with the list of |
58 * [Location]s of the given [relationship] with the given [element]. | 58 * [Location]s of the given [relationship] with the given [element]. |
59 * | 59 * |
60 * For example, if the [element] represents a function and the [relationship] | 60 * For example, if the [element] represents a function and the [relationship] |
61 * is the `is-invoked-by` relationship, then the locations will be all of the | 61 * is the `is-invoked-by` relationship, then the locations will be all of the |
62 * places where the function is invoked. | 62 * places where the function is invoked. |
63 */ | 63 */ |
64 Future<List<Location>> getRelationshipsAsync(Element element, | 64 @override |
| 65 Future<List<Location>> getRelationships(Element element, |
65 Relationship relationship) { | 66 Relationship relationship) { |
66 return _store.getRelationshipsAsync(element, relationship); | 67 return _store.getRelationships(element, relationship); |
67 } | 68 } |
68 | 69 |
69 @override | 70 @override |
70 void indexHtmlUnit(AnalysisContext context, HtmlUnit unit) { | 71 void indexHtmlUnit(AnalysisContext context, HtmlUnit unit) { |
71 if (unit == null) { | 72 contributors.indexHtmlUnit(_store, context, unit); |
72 return; | |
73 } | |
74 if (unit.element == null) { | |
75 return; | |
76 } | |
77 new IndexHtmlUnitOperation(_store, context, unit).performOperation(); | |
78 } | 73 } |
79 | 74 |
80 @override | 75 @override |
81 void indexUnit(AnalysisContext context, CompilationUnit unit) { | 76 void indexUnit(AnalysisContext context, CompilationUnit unit) { |
82 if (unit == null) { | 77 contributors.indexDartUnit(_store, context, unit); |
83 return; | |
84 } | |
85 if (unit.element == null) { | |
86 return; | |
87 } | |
88 new IndexUnitOperation(_store, context, unit).performOperation(); | |
89 } | 78 } |
90 | 79 |
91 @override | 80 @override |
92 void removeContext(AnalysisContext context) { | 81 void removeContext(AnalysisContext context) { |
93 _store.removeContext(context); | 82 _store.removeContext(context); |
94 } | 83 } |
95 | 84 |
96 @override | 85 @override |
97 void removeSource(AnalysisContext context, Source source) { | 86 void removeSource(AnalysisContext context, Source source) { |
98 _store.removeSource(context, source); | 87 _store.removeSource(context, source); |
99 } | 88 } |
100 | 89 |
101 @override | 90 @override |
102 void removeSources(AnalysisContext context, SourceContainer container) { | 91 void removeSources(AnalysisContext context, SourceContainer container) { |
103 _store.removeSources(context, container); | 92 _store.removeSources(context, container); |
104 } | 93 } |
105 | 94 |
106 @override | 95 @override |
107 void run() { | 96 void run() { |
108 // NO-OP if in the same isolate | 97 // NO-OP for the local index |
109 } | 98 } |
110 | 99 |
111 @override | 100 @override |
112 void stop() { | 101 void stop() { |
113 // NO-OP if in the same isolate | 102 // NO-OP for the local index |
114 } | 103 } |
115 } | 104 } |
OLD | NEW |