| 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.store.codec; | 5 library services.src.index.store.codec; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/index/index_core.dart'; | 9 import 'package:analysis_server/plugin/index/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:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | |
| 13 | 12 |
| 14 /** | 13 /** |
| 15 * A helper that encodes/decodes [AnalysisContext]s from/to integers. | 14 * A helper that encodes/decodes [AnalysisContext]s from/to integers. |
| 16 */ | 15 */ |
| 17 class ContextCodec { | 16 class ContextCodec { |
| 18 /** | 17 /** |
| 19 * A table mapping contexts to their unique indices. | 18 * A table mapping contexts to their unique indices. |
| 20 */ | 19 */ |
| 21 Map<AnalysisContext, int> _contextToIndex = | 20 Map<AnalysisContext, int> _contextToIndex = |
| 22 new HashMap<AnalysisContext, int>(); | 21 new HashMap<AnalysisContext, int>(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 String filePath = _stringCodec.decode(fileId); | 85 String filePath = _stringCodec.decode(fileId); |
| 87 return kind.decode(context, filePath, offset); | 86 return kind.decode(context, filePath, offset); |
| 88 } | 87 } |
| 89 | 88 |
| 90 /** | 89 /** |
| 91 * Returns the first component of the [indexable] id. | 90 * Returns the first component of the [indexable] id. |
| 92 * In the most cases it is an encoding of the [indexable]'s file path. | 91 * In the most cases it is an encoding of the [indexable]'s file path. |
| 93 * If the given [indexable] is not defined in a file, returns `-1`. | 92 * If the given [indexable] is not defined in a file, returns `-1`. |
| 94 */ | 93 */ |
| 95 int encode1(IndexableObject indexable) { | 94 int encode1(IndexableObject indexable) { |
| 96 Source source = indexable.source; | 95 String file = indexable.file; |
| 97 if (source == null) { | 96 if (file == null) { |
| 98 return -1; | 97 return -1; |
| 99 } | 98 } |
| 100 String filePath = source.fullName; | 99 return _stringCodec.encode(file); |
| 101 return _stringCodec.encode(filePath); | |
| 102 } | 100 } |
| 103 | 101 |
| 104 /** | 102 /** |
| 105 * Returns the second component of the [indexable] id. | 103 * Returns the second component of the [indexable] id. |
| 106 * In the most cases it is the [indexable]'s name offset. | 104 * In the most cases it is the [indexable]'s name offset. |
| 107 */ | 105 */ |
| 108 int encode2(IndexableObject indexable) { | 106 int encode2(IndexableObject indexable) { |
| 109 if (indexable is IndexableName) { | 107 if (indexable is IndexableName) { |
| 110 String name = indexable.name; | 108 String name = indexable.name; |
| 111 return _stringCodec.encode(name); | 109 return _stringCodec.encode(name); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 int encode(String name) { | 171 int encode(String name) { |
| 174 int index = nameToIndex[name]; | 172 int index = nameToIndex[name]; |
| 175 if (index == null) { | 173 if (index == null) { |
| 176 index = _indexToName.length; | 174 index = _indexToName.length; |
| 177 nameToIndex[name] = index; | 175 nameToIndex[name] = index; |
| 178 _indexToName.add(name); | 176 _indexToName.add(name); |
| 179 } | 177 } |
| 180 return index; | 178 return index; |
| 181 } | 179 } |
| 182 } | 180 } |
| OLD | NEW |