Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: pkg/analysis_server/lib/src/services/index/index.dart

Issue 1829463002: Issue 26063. Index declarations in even partically analyzed units. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 * Complete with a list of locations where a class members with the given 70 * Complete with a list of locations where a class members with the given
71 * [name] is referenced with a qualifier, but is not resolved. 71 * [name] is referenced with a qualifier, but is not resolved.
72 */ 72 */
73 Future<List<Location>> getUnresolvedMemberReferences(String name) { 73 Future<List<Location>> getUnresolvedMemberReferences(String name) {
74 return _mergeLocations((_ContextIndex index) { 74 return _mergeLocations((_ContextIndex index) {
75 return index.getUnresolvedMemberReferences(name); 75 return index.getUnresolvedMemberReferences(name);
76 }); 76 });
77 } 77 }
78 78
79 /** 79 /**
80 * Index declarations in the given partially resolved [unit].
81 */
82 void indexDeclarations(CompilationUnit unit) {
83 if (unit?.element?.library == null) {
84 return;
85 }
86 AnalysisContext context = unit.element.context;
87 _getContextIndex(context).indexDeclarations(unit);
88 }
89
90 /**
80 * Index the given fully resolved [unit]. 91 * Index the given fully resolved [unit].
81 */ 92 */
82 void indexUnit(CompilationUnit unit) { 93 void indexUnit(CompilationUnit unit) {
83 if (unit == null || unit.element == null) { 94 if (unit?.element?.library == null) {
84 return; 95 return;
85 } 96 }
86 AnalysisContext context = unit.element.context; 97 AnalysisContext context = unit.element.context;
87 _getContextIndex(context).indexUnit(unit); 98 _getContextIndex(context).indexUnit(unit);
88 } 99 }
89 100
90 /** 101 /**
91 * Remove all index information for the given [context]. 102 * Remove all index information for the given [context].
92 */ 103 */
93 void removeContext(AnalysisContext context) { 104 void removeContext(AnalysisContext context) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 * Complete with a list of locations where a class members with the given 260 * Complete with a list of locations where a class members with the given
250 * [name] is referenced with a qualifier, but is not resolved. 261 * [name] is referenced with a qualifier, but is not resolved.
251 */ 262 */
252 Future<List<Location>> getUnresolvedMemberReferences(String name) async { 263 Future<List<Location>> getUnresolvedMemberReferences(String name) async {
253 return _mergeLocations((_PackageIndexRequester requester) { 264 return _mergeLocations((_PackageIndexRequester requester) {
254 return requester.getUnresolvedMemberReferences(context, name); 265 return requester.getUnresolvedMemberReferences(context, name);
255 }); 266 });
256 } 267 }
257 268
258 /** 269 /**
270 * Index declarations in the given partially resolved [unit].
271 */
272 void indexDeclarations(CompilationUnit unit) {
273 PackageIndexAssembler assembler = new PackageIndexAssembler();
274 assembler.indexDeclarations(unit);
275 _putUnitIndexBuilder(unit, assembler);
276 }
277
278 /**
259 * Index the given fully resolved [unit]. 279 * Index the given fully resolved [unit].
260 */ 280 */
261 void indexUnit(CompilationUnit unit) { 281 void indexUnit(CompilationUnit unit) {
262 // Index the unit.
263 PackageIndexAssembler assembler = new PackageIndexAssembler(); 282 PackageIndexAssembler assembler = new PackageIndexAssembler();
264 assembler.index(unit); 283 assembler.indexUnit(unit);
265 PackageIndexBuilder indexBuilder = assembler.assemble(); 284 _putUnitIndexBuilder(unit, assembler);
266 // Put the index into the map.
267 List<int> indexBytes = indexBuilder.toBuffer();
268 PackageIndex index = new PackageIndex.fromBuffer(indexBytes);
269 String key = _getUnitKeyForElement(unit.element);
270 indexMap[key] = index;
271 } 285 }
272 286
273 /** 287 /**
274 * Remove index information about the unit. 288 * Remove index information about the unit.
275 */ 289 */
276 void removeUnit(Source librarySource, Source unitSource) { 290 void removeUnit(Source librarySource, Source unitSource) {
277 String key = _getUnitKeyForSource(librarySource, unitSource); 291 String key = _getUnitKeyForSource(librarySource, unitSource);
278 indexMap.remove(key); 292 indexMap.remove(key);
279 } 293 }
280 294
(...skipping 12 matching lines...) Expand all
293 Future<List<Location>> _mergeLocations( 307 Future<List<Location>> _mergeLocations(
294 List<Location> callback(_PackageIndexRequester requester)) async { 308 List<Location> callback(_PackageIndexRequester requester)) async {
295 List<Location> locations = <Location>[]; 309 List<Location> locations = <Location>[];
296 for (PackageIndex index in indexMap.values) { 310 for (PackageIndex index in indexMap.values) {
297 _PackageIndexRequester requester = new _PackageIndexRequester(index); 311 _PackageIndexRequester requester = new _PackageIndexRequester(index);
298 List<Location> indexLocations = callback(requester); 312 List<Location> indexLocations = callback(requester);
299 locations.addAll(indexLocations); 313 locations.addAll(indexLocations);
300 } 314 }
301 return locations; 315 return locations;
302 } 316 }
317
318 void _putUnitIndexBuilder(
319 CompilationUnit unit, PackageIndexAssembler assembler) {
320 PackageIndexBuilder indexBuilder = assembler.assemble();
321 // Put the index into the map.
322 List<int> indexBytes = indexBuilder.toBuffer();
323 PackageIndex index = new PackageIndex.fromBuffer(indexBytes);
324 String key = _getUnitKeyForElement(unit.element);
325 indexMap[key] = index;
326 }
303 } 327 }
304 328
305 /** 329 /**
306 * Helper for requesting information from a single [PackageIndex]. 330 * Helper for requesting information from a single [PackageIndex].
307 */ 331 */
308 class _PackageIndexRequester { 332 class _PackageIndexRequester {
309 final PackageIndex index; 333 final PackageIndex index;
310 334
311 _PackageIndexRequester(this.index); 335 _PackageIndexRequester(this.index);
312 336
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 unitUnitUri, 574 unitUnitUri,
551 unitIndex.usedNameKinds[i], 575 unitIndex.usedNameKinds[i],
552 unitIndex.usedNameOffsets[i], 576 unitIndex.usedNameOffsets[i],
553 name.length, 577 name.length,
554 unitIndex.usedNameIsQualifiedFlags[i], 578 unitIndex.usedNameIsQualifiedFlags[i],
555 false)); 579 false));
556 } 580 }
557 return locations; 581 return locations;
558 } 582 }
559 } 583 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/test/services/index/index_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698