| 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/analysis/index/index_core.dart'; | 9 import 'package:analysis_server/analysis/index/index_core.dart'; |
| 10 import 'package:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 /** | 77 /** |
| 78 * Returns an [IndexableObject] that corresponds to the given identifiers. | 78 * Returns an [IndexableObject] that corresponds to the given identifiers. |
| 79 */ | 79 */ |
| 80 IndexableObject decode( | 80 IndexableObject decode( |
| 81 AnalysisContext context, int fileId, int offset, int kindId) { | 81 AnalysisContext context, int fileId, int offset, int kindId) { |
| 82 String filePath = _stringCodec.decode(fileId); | 82 String filePath = _stringCodec.decode(fileId); |
| 83 IndexableObjectKind kind = IndexableObjectKind.getKind(kindId); | 83 IndexableObjectKind kind = IndexableObjectKind.getKind(kindId); |
| 84 if (kind == null) { | 84 if (kind == null) { |
| 85 return null; | 85 return null; |
| 86 } else if (kind is IndexableNameKind) { | 86 } else if (kind is IndexableNameKind) { |
| 87 return new IndexableElement(new NameElement(_stringCodec.decode(offset))); | 87 String name = _stringCodec.decode(offset); |
| 88 return new IndexableName(name); |
| 88 } | 89 } |
| 89 return kind.decode(context, filePath, offset); | 90 return kind.decode(context, filePath, offset); |
| 90 } | 91 } |
| 91 | 92 |
| 92 /** | 93 /** |
| 93 * Returns the first component of the [element] id. | 94 * Returns the first component of the [indexable] id. |
| 94 * In the most cases it is an encoding of the [element]'s file path. | 95 * In the most cases it is an encoding of the [indexable]'s file path. |
| 95 * If the given [element] is not defined in a file, returns `-1`. | 96 * If the given [indexable] is not defined in a file, returns `-1`. |
| 96 */ | 97 */ |
| 97 int encode1(IndexableObject indexable) { | 98 int encode1(IndexableObject indexable) { |
| 98 Source source = indexable.source; | 99 Source source = indexable.source; |
| 99 if (source == null) { | 100 if (source == null) { |
| 100 return -1; | 101 return -1; |
| 101 } | 102 } |
| 102 String filePath = source.fullName; | 103 String filePath = source.fullName; |
| 103 return _stringCodec.encode(filePath); | 104 return _stringCodec.encode(filePath); |
| 104 } | 105 } |
| 105 | 106 |
| 106 /** | 107 /** |
| 107 * Returns the second component of the [element] id. | 108 * Returns the second component of the [indexable] id. |
| 108 * In the most cases it is the [element]'s name offset. | 109 * In the most cases it is the [indexable]'s name offset. |
| 109 */ | 110 */ |
| 110 int encode2(IndexableObject indexable) { | 111 int encode2(IndexableObject indexable) { |
| 111 if (indexable is IndexableName) { | 112 if (indexable is IndexableName) { |
| 112 String name = indexable.name; | 113 String name = indexable.name; |
| 113 return _stringCodec.encode(name); | 114 return _stringCodec.encode(name); |
| 114 } | 115 } |
| 115 int offset = indexable.offset; | 116 int offset = indexable.offset; |
| 116 if (offset < 0) { | 117 if (offset < 0) { |
| 117 return _stringCodec.encode(indexable.name); | 118 return _stringCodec.encode(indexable.name); |
| 118 } | 119 } |
| 119 return offset; | 120 return offset; |
| 120 } | 121 } |
| 121 | 122 |
| 122 /** | 123 /** |
| 123 * Returns the third component of the [element] id. | 124 * Returns the third component of the [indexable] id. |
| 124 * In the most cases it is the [element]'s kind. | 125 * In the most cases it is the [indexable]'s kind. |
| 125 */ | 126 */ |
| 126 int encode3(IndexableObject indexable) { | 127 int encode3(IndexableObject indexable) { |
| 127 return indexable.kind.index; | 128 return indexable.kind.index; |
| 128 } | 129 } |
| 129 | 130 |
| 130 /** | 131 /** |
| 131 * Returns an integer that corresponds to the name of [element]. | 132 * Returns an integer that corresponds to the name of [indexable]. |
| 132 */ | 133 */ |
| 133 int encodeHash(IndexableObject indexable) { | 134 int encodeHash(IndexableObject indexable) { |
| 134 // TODO(brianwilkerson) Consider moving this to IndexableObjectKind so that | 135 // TODO(brianwilkerson) Consider moving this to IndexableObjectKind so that |
| 135 // we don't have to break encapsulation. | 136 // we don't have to break encapsulation. |
| 136 String elementName = indexable.name; // was: indexable.displayName; | 137 String elementName = indexable.name; // was: indexable.displayName; |
| 137 int elementNameId = _stringCodec.encode(elementName); | 138 int elementNameId = _stringCodec.encode(elementName); |
| 138 if (indexable is IndexableElement) { | 139 if (indexable is IndexableElement) { |
| 139 LibraryElement libraryElement = indexable.element.library; | 140 LibraryElement libraryElement = indexable.element.library; |
| 140 if (libraryElement != null) { | 141 if (libraryElement != null) { |
| 141 String libraryPath = libraryElement.source.fullName; | 142 String libraryPath = libraryElement.source.fullName; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 int encode(String name) { | 192 int encode(String name) { |
| 192 int index = nameToIndex[name]; | 193 int index = nameToIndex[name]; |
| 193 if (index == null) { | 194 if (index == null) { |
| 194 index = _indexToName.length; | 195 index = _indexToName.length; |
| 195 nameToIndex[name] = index; | 196 nameToIndex[name] = index; |
| 196 _indexToName.add(name); | 197 _indexToName.add(name); |
| 197 } | 198 } |
| 198 return index; | 199 return index; |
| 199 } | 200 } |
| 200 } | 201 } |
| OLD | NEW |