Chromium Code Reviews| 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/src/services/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 115 } |
| 116 return element; | 116 return element; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 return null; | 120 return null; |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Returns the first component of the [element] id. | 124 * Returns the first component of the [element] id. |
| 125 * In the most cases it is an encoding of the [element]'s file path. | |
|
Brian Wilkerson
2015/04/09 16:01:25
This should say when it isn't (an encoding of the
| |
| 125 */ | 126 */ |
| 126 int encode1(Element element) { | 127 int encode1(Element element) { |
| 127 Source source = element.source; | 128 Source source = element.source; |
| 128 if (source == null) { | 129 if (source == null) { |
| 129 return NAMED_FILE_ID; | 130 return NAMED_FILE_ID; |
| 130 } | 131 } |
| 131 String filePath = source.fullName; | 132 String filePath = source.fullName; |
| 132 return _stringCodec.encode(filePath); | 133 return _stringCodec.encode(filePath); |
| 133 } | 134 } |
| 134 | 135 |
| 135 /** | 136 /** |
| 136 * Returns the second component of the [element] id. | 137 * Returns the second component of the [element] id. |
| 138 * In the most cases it is the [element]'s name offset. | |
| 137 */ | 139 */ |
| 138 int encode2(Element element) { | 140 int encode2(Element element) { |
| 139 if (element is NameElement) { | 141 if (element is NameElement) { |
| 140 String name = element.name; | 142 String name = element.name; |
| 141 return _stringCodec.encode(name); | 143 return _stringCodec.encode(name); |
| 142 } | 144 } |
| 143 if (element is ConstructorElement) { | 145 if (element is ConstructorElement) { |
| 144 return element.enclosingElement.nameOffset; | 146 return element.enclosingElement.nameOffset; |
| 145 } | 147 } |
| 146 return element.nameOffset; | 148 return element.nameOffset; |
| 147 } | 149 } |
| 148 | 150 |
| 149 /** | 151 /** |
| 150 * Returns the third component of the [element] id. | 152 * Returns the third component of the [element] id. |
| 153 * In the most cases it is the [element]'s kind. | |
| 151 */ | 154 */ |
| 152 int encode3(Element element) { | 155 int encode3(Element element) { |
| 153 if (element is NameElement) { | 156 if (element is NameElement) { |
| 154 return NAMED_KIND_ID; | 157 return NAMED_KIND_ID; |
| 155 } | 158 } |
| 156 if (element is ConstructorElement) { | 159 if (element is ConstructorElement) { |
| 157 ClassElement classElement = element.enclosingElement; | 160 ClassElement classElement = element.enclosingElement; |
| 158 int constructorIndex = classElement.constructors.indexOf(element); | 161 int constructorIndex = classElement.constructors.indexOf(element); |
| 159 return _CONSTRUCTOR_KIND_BASE - constructorIndex; | 162 return _CONSTRUCTOR_KIND_BASE - constructorIndex; |
| 160 } | 163 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 int encode(String name) { | 225 int encode(String name) { |
| 223 int index = nameToIndex[name]; | 226 int index = nameToIndex[name]; |
| 224 if (index == null) { | 227 if (index == null) { |
| 225 index = _indexToName.length; | 228 index = _indexToName.length; |
| 226 nameToIndex[name] = index; | 229 nameToIndex[name] = index; |
| 227 _indexToName.add(name); | 230 _indexToName.add(name); |
| 228 } | 231 } |
| 229 return index; | 232 return index; |
| 230 } | 233 } |
| 231 } | 234 } |
| OLD | NEW |