| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 Future<List<Location>> getUnresolvedMemberReferences(String name) async { | 263 Future<List<Location>> getUnresolvedMemberReferences(String name) async { |
| 264 return _mergeLocations((_PackageIndexRequester requester) { | 264 return _mergeLocations((_PackageIndexRequester requester) { |
| 265 return requester.getUnresolvedMemberReferences(context, name); | 265 return requester.getUnresolvedMemberReferences(context, name); |
| 266 }); | 266 }); |
| 267 } | 267 } |
| 268 | 268 |
| 269 /** | 269 /** |
| 270 * Index declarations in the given partially resolved [unit]. | 270 * Index declarations in the given partially resolved [unit]. |
| 271 */ | 271 */ |
| 272 void indexDeclarations(CompilationUnit unit) { | 272 void indexDeclarations(CompilationUnit unit) { |
| 273 PackageIndexAssembler assembler = new PackageIndexAssembler(); | 273 String key = _getUnitKeyForElement(unit.element); |
| 274 assembler.indexDeclarations(unit); | 274 if (!indexMap.containsKey(key)) { |
| 275 _putUnitIndexBuilder(unit, assembler); | 275 PackageIndexAssembler assembler = new PackageIndexAssembler(); |
| 276 assembler.indexDeclarations(unit); |
| 277 _putUnitIndexBuilder(key, assembler); |
| 278 } |
| 276 } | 279 } |
| 277 | 280 |
| 278 /** | 281 /** |
| 279 * Index the given fully resolved [unit]. | 282 * Index the given fully resolved [unit]. |
| 280 */ | 283 */ |
| 281 void indexUnit(CompilationUnit unit) { | 284 void indexUnit(CompilationUnit unit) { |
| 285 String key = _getUnitKeyForElement(unit.element); |
| 282 PackageIndexAssembler assembler = new PackageIndexAssembler(); | 286 PackageIndexAssembler assembler = new PackageIndexAssembler(); |
| 283 assembler.indexUnit(unit); | 287 assembler.indexUnit(unit); |
| 284 _putUnitIndexBuilder(unit, assembler); | 288 _putUnitIndexBuilder(key, assembler); |
| 285 } | 289 } |
| 286 | 290 |
| 287 /** | 291 /** |
| 288 * Remove index information about the unit. | 292 * Remove index information about the unit. |
| 289 */ | 293 */ |
| 290 void removeUnit(Source librarySource, Source unitSource) { | 294 void removeUnit(Source librarySource, Source unitSource) { |
| 291 String key = _getUnitKeyForSource(librarySource, unitSource); | 295 String key = _getUnitKeyForSource(librarySource, unitSource); |
| 292 indexMap.remove(key); | 296 indexMap.remove(key); |
| 293 } | 297 } |
| 294 | 298 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 308 List<Location> callback(_PackageIndexRequester requester)) async { | 312 List<Location> callback(_PackageIndexRequester requester)) async { |
| 309 List<Location> locations = <Location>[]; | 313 List<Location> locations = <Location>[]; |
| 310 for (PackageIndex index in indexMap.values) { | 314 for (PackageIndex index in indexMap.values) { |
| 311 _PackageIndexRequester requester = new _PackageIndexRequester(index); | 315 _PackageIndexRequester requester = new _PackageIndexRequester(index); |
| 312 List<Location> indexLocations = callback(requester); | 316 List<Location> indexLocations = callback(requester); |
| 313 locations.addAll(indexLocations); | 317 locations.addAll(indexLocations); |
| 314 } | 318 } |
| 315 return locations; | 319 return locations; |
| 316 } | 320 } |
| 317 | 321 |
| 318 void _putUnitIndexBuilder( | 322 void _putUnitIndexBuilder(String key, PackageIndexAssembler assembler) { |
| 319 CompilationUnit unit, PackageIndexAssembler assembler) { | |
| 320 PackageIndexBuilder indexBuilder = assembler.assemble(); | 323 PackageIndexBuilder indexBuilder = assembler.assemble(); |
| 321 // Put the index into the map. | 324 // Put the index into the map. |
| 322 List<int> indexBytes = indexBuilder.toBuffer(); | 325 List<int> indexBytes = indexBuilder.toBuffer(); |
| 323 PackageIndex index = new PackageIndex.fromBuffer(indexBytes); | 326 PackageIndex index = new PackageIndex.fromBuffer(indexBytes); |
| 324 String key = _getUnitKeyForElement(unit.element); | |
| 325 indexMap[key] = index; | 327 indexMap[key] = index; |
| 326 } | 328 } |
| 327 } | 329 } |
| 328 | 330 |
| 329 /** | 331 /** |
| 330 * Helper for requesting information from a single [PackageIndex]. | 332 * Helper for requesting information from a single [PackageIndex]. |
| 331 */ | 333 */ |
| 332 class _PackageIndexRequester { | 334 class _PackageIndexRequester { |
| 333 final PackageIndex index; | 335 final PackageIndex index; |
| 334 | 336 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 unitUnitUri, | 576 unitUnitUri, |
| 575 unitIndex.usedNameKinds[i], | 577 unitIndex.usedNameKinds[i], |
| 576 unitIndex.usedNameOffsets[i], | 578 unitIndex.usedNameOffsets[i], |
| 577 name.length, | 579 name.length, |
| 578 unitIndex.usedNameIsQualifiedFlags[i], | 580 unitIndex.usedNameIsQualifiedFlags[i], |
| 579 false)); | 581 false)); |
| 580 } | 582 } |
| 581 return locations; | 583 return locations; |
| 582 } | 584 } |
| 583 } | 585 } |
| OLD | NEW |