| 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 test.index.store_memory_node_manager; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:collection'; |
| 9 |
| 10 import 'package:analysis_server/src/index/store/codec.dart'; |
| 11 import 'package:analysis_server/src/index/store/split_store.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 |
| 14 |
| 15 class MemoryNodeManager implements NodeManager { |
| 16 ContextCodec _contextCodec = new ContextCodec(); |
| 17 ElementCodec _elementCodec; |
| 18 int _locationCount = 0; |
| 19 final Map<String, int> _nodeLocationCounts = new HashMap<String, int>(); |
| 20 final Map<String, IndexNode> _nodes = new HashMap<String, IndexNode>(); |
| 21 RelationshipCodec _relationshipCodec; |
| 22 StringCodec _stringCodec = new StringCodec(); |
| 23 |
| 24 MemoryNodeManager() { |
| 25 _elementCodec = new ElementCodec(_stringCodec); |
| 26 _relationshipCodec = new RelationshipCodec(_stringCodec); |
| 27 } |
| 28 |
| 29 @override |
| 30 ContextCodec get contextCodec { |
| 31 return _contextCodec; |
| 32 } |
| 33 |
| 34 @override |
| 35 ElementCodec get elementCodec { |
| 36 return _elementCodec; |
| 37 } |
| 38 |
| 39 @override |
| 40 int get locationCount { |
| 41 return _locationCount; |
| 42 } |
| 43 |
| 44 @override |
| 45 StringCodec get stringCodec { |
| 46 return _stringCodec; |
| 47 } |
| 48 |
| 49 @override |
| 50 void clear() { |
| 51 _nodes.clear(); |
| 52 } |
| 53 |
| 54 int getLocationCount(String name) { |
| 55 int locationCount = _nodeLocationCounts[name]; |
| 56 return locationCount != null ? locationCount : 0; |
| 57 } |
| 58 |
| 59 @override |
| 60 Future<IndexNode> getNode(String name) { |
| 61 return new Future.value(_nodes[name]); |
| 62 } |
| 63 |
| 64 bool isEmpty() { |
| 65 for (IndexNode node in _nodes.values) { |
| 66 Map<RelationKeyData, List<LocationData>> relations = node.relations; |
| 67 if (!relations.isEmpty) { |
| 68 return false; |
| 69 } |
| 70 } |
| 71 return true; |
| 72 } |
| 73 |
| 74 @override |
| 75 IndexNode newNode(AnalysisContext context) { |
| 76 return new IndexNode(context, elementCodec, _relationshipCodec); |
| 77 } |
| 78 |
| 79 @override |
| 80 void putNode(String name, IndexNode node) { |
| 81 // update location count |
| 82 { |
| 83 _locationCount -= getLocationCount(name); |
| 84 int nodeLocationCount = node.locationCount; |
| 85 _nodeLocationCounts[name] = nodeLocationCount; |
| 86 _locationCount += nodeLocationCount; |
| 87 } |
| 88 // remember the node |
| 89 _nodes[name] = node; |
| 90 } |
| 91 |
| 92 @override |
| 93 void removeNode(String name) { |
| 94 _nodes.remove(name); |
| 95 } |
| 96 } |
| OLD | NEW |