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

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

Issue 1787803003: Improve used name relations and fields indexing. (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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 * The URI of the source of the library containing this location. 144 * The URI of the source of the library containing this location.
145 */ 145 */
146 final String libraryUri; 146 final String libraryUri;
147 147
148 /** 148 /**
149 * The URI of the source of the unit containing this location. 149 * The URI of the source of the unit containing this location.
150 */ 150 */
151 final String unitUri; 151 final String unitUri;
152 152
153 /** 153 /**
154 * The kind of usage at this location.
155 */
156 final IndexRelationKind kind;
157
158 /**
154 * The offset of this location within the [unitUri]. 159 * The offset of this location within the [unitUri].
155 */ 160 */
156 final int offset; 161 final int offset;
157 162
158 /** 163 /**
159 * The length of this location. 164 * The length of this location.
160 */ 165 */
161 final int length; 166 final int length;
162 167
163 /** 168 /**
164 * Is `true` if this location is qualified. 169 * Is `true` if this location is qualified.
165 */ 170 */
166 final bool isQualified; 171 final bool isQualified;
167 172
168 Location(this.context, this.libraryUri, this.unitUri, this.offset, 173 /**
169 this.length, this.isQualified); 174 * Is `true` if this location is resolved.
175 */
176 final bool isResolved;
177
178 Location(this.context, this.libraryUri, this.unitUri, this.kind, this.offset,
179 this.length, this.isQualified, this.isResolved);
170 180
171 @override 181 @override
172 String toString() => 'Location{librarySourceUri: $libraryUri, ' 182 String toString() => 'Location{librarySourceUri: $libraryUri, '
173 'unitSourceUri: $unitUri, offset: $offset, length: $length, ' 183 'unitSourceUri: $unitUri, offset: $offset, length: $length, '
174 'isQualified: $isQualified}'; 184 'isQualified: $isQualified}, isResolved: $isResolved}';
175 } 185 }
176 186
177 /** 187 /**
178 * Opaque identifier of a [PackageIndex]. 188 * Opaque identifier of a [PackageIndex].
179 */ 189 */
180 abstract class PackageIndexId {} 190 abstract class PackageIndexId {}
181 191
182 /** 192 /**
183 * Storage of [PackageIndex] objects. 193 * Storage of [PackageIndex] objects.
184 */ 194 */
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 List<Location> locations = <Location>[]; 463 List<Location> locations = <Location>[];
454 String unitLibraryUri = null; 464 String unitLibraryUri = null;
455 String unitUnitUri = null; 465 String unitUnitUri = null;
456 for (int i = 0; i < unitIndex.definedNames.length; i++) { 466 for (int i = 0; i < unitIndex.definedNames.length; i++) {
457 if (unitIndex.definedNameKinds[i] == kind) { 467 if (unitIndex.definedNameKinds[i] == kind) {
458 int nameIndex = unitIndex.definedNames[i]; 468 int nameIndex = unitIndex.definedNames[i];
459 String name = packageRequester.index.strings[nameIndex]; 469 String name = packageRequester.index.strings[nameIndex];
460 if (regExp.matchAsPrefix(name) != null) { 470 if (regExp.matchAsPrefix(name) != null) {
461 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit); 471 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit);
462 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit); 472 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit);
463 locations.add(new Location(context, unitLibraryUri, unitUnitUri, 473 locations.add(new Location(context, unitLibraryUri, unitUnitUri, null,
464 unitIndex.definedNameOffsets[i], name.length, false)); 474 unitIndex.definedNameOffsets[i], name.length, false, true));
465 } 475 }
466 } 476 }
467 } 477 }
468 return locations; 478 return locations;
469 } 479 }
470 480
471 /** 481 /**
472 * Return a list of locations where an element with the given [elementId] has 482 * Return a list of locations where an element with the given [elementId] has
473 * relation of the given [kind]. 483 * relation of the given [kind].
474 */ 484 */
(...skipping 12 matching lines...) Expand all
487 i < unitIndex.usedElements.length && 497 i < unitIndex.usedElements.length &&
488 unitIndex.usedElements[i] == elementId; 498 unitIndex.usedElements[i] == elementId;
489 i++) { 499 i++) {
490 if (unitIndex.usedElementKinds[i] == kind) { 500 if (unitIndex.usedElementKinds[i] == kind) {
491 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit); 501 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit);
492 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit); 502 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit);
493 locations.add(new Location( 503 locations.add(new Location(
494 context, 504 context,
495 unitLibraryUri, 505 unitLibraryUri,
496 unitUnitUri, 506 unitUnitUri,
507 kind,
497 unitIndex.usedElementOffsets[i], 508 unitIndex.usedElementOffsets[i],
498 unitIndex.usedElementLengths[i], 509 unitIndex.usedElementLengths[i],
499 unitIndex.usedElementIsQualifiedFlags[i])); 510 unitIndex.usedElementIsQualifiedFlags[i],
511 true));
500 } 512 }
501 } 513 }
502 return locations; 514 return locations;
503 } 515 }
504 516
505 /** 517 /**
506 * Complete with a list of locations where a class members with the given 518 * Complete with a list of locations where a class members with the given
507 * [name] is referenced with a qualifier, but is not resolved. 519 * [name] is referenced with a qualifier, but is not resolved.
508 */ 520 */
509 List<Location> getUnresolvedMemberReferences( 521 List<Location> getUnresolvedMemberReferences(
(...skipping 10 matching lines...) Expand all
520 } 532 }
521 // Create locations for every usage of the name. 533 // Create locations for every usage of the name.
522 List<Location> locations = <Location>[]; 534 List<Location> locations = <Location>[];
523 String unitLibraryUri = null; 535 String unitLibraryUri = null;
524 String unitUnitUri = null; 536 String unitUnitUri = null;
525 for (; 537 for (;
526 i < unitIndex.usedNames.length && unitIndex.usedNames[i] == nameId; 538 i < unitIndex.usedNames.length && unitIndex.usedNames[i] == nameId;
527 i++) { 539 i++) {
528 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit); 540 unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit);
529 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit); 541 unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit);
530 locations.add(new Location(context, unitLibraryUri, unitUnitUri, 542 locations.add(new Location(
531 unitIndex.usedNameOffsets[i], name.length, true)); 543 context,
544 unitLibraryUri,
545 unitUnitUri,
546 unitIndex.usedNameKinds[i],
547 unitIndex.usedNameOffsets[i],
548 name.length,
549 true,
550 false));
532 } 551 }
533 return locations; 552 return locations;
534 } 553 }
535 } 554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698