| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; | 9 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 /** | 298 /** |
| 299 * Return the [element]'s identifier in the [index] or `-1` if the | 299 * Return the [element]'s identifier in the [index] or `-1` if the |
| 300 * [element] is not referenced in the [index]. | 300 * [element] is not referenced in the [index]. |
| 301 */ | 301 */ |
| 302 int findElementId(Element element) { | 302 int findElementId(Element element) { |
| 303 // Find the id of the element's unit. | 303 // Find the id of the element's unit. |
| 304 int unitId = getUnitId(element); | 304 int unitId = getUnitId(element); |
| 305 if (unitId == -1) { | 305 if (unitId == -1) { |
| 306 return -1; | 306 return -1; |
| 307 } | 307 } |
| 308 // Prepare the offset of the element. | 308 // Prepare information about the element. |
| 309 int offset = element.nameOffset; | 309 ElementInfo info = PackageIndexAssembler.newElementInfo(unitId, element); |
| 310 if (element is LibraryElement || element is CompilationUnitElement) { | |
| 311 offset = 0; | |
| 312 } | |
| 313 // Find the first occurrence of an element with the same offset. | 310 // Find the first occurrence of an element with the same offset. |
| 314 int elementId = _findFirstOccurrence(index.elementOffsets, offset); | 311 int elementId = _findFirstOccurrence(index.elementOffsets, info.offset); |
| 315 if (elementId == -1) { | 312 if (elementId == -1) { |
| 316 return -1; | 313 return -1; |
| 317 } | 314 } |
| 318 // Try to find the element id using offset, unit and kind. | 315 // Try to find the element id using offset, unit and kind. |
| 319 IndexSyntheticElementKind kind = | |
| 320 PackageIndexAssembler.getIndexElementKind(element); | |
| 321 for (; | 316 for (; |
| 322 elementId < index.elementOffsets.length && | 317 elementId < index.elementOffsets.length && |
| 323 index.elementOffsets[elementId] == offset; | 318 index.elementOffsets[elementId] == info.offset; |
| 324 elementId++) { | 319 elementId++) { |
| 325 if (index.elementUnits[elementId] == unitId && | 320 if (index.elementUnits[elementId] == unitId && |
| 326 index.elementKinds[elementId] == kind) { | 321 index.elementKinds[elementId] == info.kind) { |
| 327 return elementId; | 322 return elementId; |
| 328 } | 323 } |
| 329 } | 324 } |
| 330 return -1; | 325 return -1; |
| 331 } | 326 } |
| 332 | 327 |
| 333 /** | 328 /** |
| 334 * Complete with a list of locations where elements of the given [kind] with | 329 * Complete with a list of locations where elements of the given [kind] with |
| 335 * names satisfying the given [regExp] are defined. | 330 * names satisfying the given [regExp] are defined. |
| 336 */ | 331 */ |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 i < unitIndex.usedNames.length && unitIndex.usedNames[i] == nameId; | 526 i < unitIndex.usedNames.length && unitIndex.usedNames[i] == nameId; |
| 532 i++) { | 527 i++) { |
| 533 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit); | 528 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit); |
| 534 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit); | 529 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit); |
| 535 locations.add(new Location(context, unitLibraryUri, unitUnitUri, | 530 locations.add(new Location(context, unitLibraryUri, unitUnitUri, |
| 536 unitIndex.usedNameOffsets[i], name.length, true)); | 531 unitIndex.usedNameOffsets[i], name.length, true)); |
| 537 } | 532 } |
| 538 return locations; | 533 return locations; |
| 539 } | 534 } |
| 540 } | 535 } |
| OLD | NEW |