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

Side by Side Diff: pkg/analyzer/lib/src/summary/index_unit.dart

Issue 1751453002: Add ElementInfo.id check fr null to debug flakiness on bots. (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/token.dart'; 6 import 'package:analyzer/dart/ast/token.dart';
7 import 'package:analyzer/dart/ast/visitor.dart'; 7 import 'package:analyzer/dart/ast/visitor.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/generated/utilities_dart.dart'; 9 import 'package:analyzer/src/generated/utilities_dart.dart';
10 import 'package:analyzer/src/summary/format.dart'; 10 import 'package:analyzer/src/summary/format.dart';
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 */ 95 */
96 _ElementInfo _getElementInfo(Element element) { 96 _ElementInfo _getElementInfo(Element element) {
97 return _elementMap.putIfAbsent(element, () { 97 return _elementMap.putIfAbsent(element, () {
98 CompilationUnitElement unitElement = getUnitElement(element); 98 CompilationUnitElement unitElement = getUnitElement(element);
99 int unitId = _getUnitElementId(unitElement); 99 int unitId = _getUnitElementId(unitElement);
100 int offset = element.nameOffset; 100 int offset = element.nameOffset;
101 if (element is LibraryElement || element is CompilationUnitElement) { 101 if (element is LibraryElement || element is CompilationUnitElement) {
102 offset = 0; 102 offset = 0;
103 } 103 }
104 IndexSyntheticElementKind kind = getIndexElementKind(element); 104 IndexSyntheticElementKind kind = getIndexElementKind(element);
105 return new _ElementInfo(unitId, offset, kind); 105 return new _ElementInfo(element, unitId, offset, kind);
106 }); 106 });
107 } 107 }
108 108
109 /** 109 /**
110 * Add information about [str] to [_strings] if necessary, and return the 110 * Add information about [str] to [_strings] if necessary, and return the
111 * location in this array representing [str]. 111 * location in this array representing [str].
112 */ 112 */
113 int _getStringId(String str) { 113 int _getStringId(String str) {
114 return _stringMap.putIfAbsent(str, () { 114 return _stringMap.putIfAbsent(str, () {
115 int id = _strings.length; 115 int id = _strings.length;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 final int offset; 186 final int offset;
187 187
188 _DefinedNameInfo(this.nameId, this.kind, this.offset); 188 _DefinedNameInfo(this.nameId, this.kind, this.offset);
189 } 189 }
190 190
191 /** 191 /**
192 * Information about an element referenced in index. 192 * Information about an element referenced in index.
193 */ 193 */
194 class _ElementInfo { 194 class _ElementInfo {
195 /** 195 /**
196 * TODO(scheglov) remove after fixing build flakiness on bots
197 */
198 final Element element;
199
200 /**
196 * The identifier of the [CompilationUnitElement] containing this element. 201 * The identifier of the [CompilationUnitElement] containing this element.
197 */ 202 */
198 final int unitId; 203 final int unitId;
199 204
200 /** 205 /**
201 * The name offset of the element. 206 * The name offset of the element.
202 */ 207 */
203 final int offset; 208 final int offset;
204 209
205 /** 210 /**
206 * The kind of the element. 211 * The kind of the element.
207 */ 212 */
208 final IndexSyntheticElementKind kind; 213 final IndexSyntheticElementKind kind;
209 214
210 /** 215 /**
211 * The unique id of the element. It is set after indexing of the whole 216 * The unique id of the element. It is set after indexing of the whole
212 * package is done and we are assembling the full package index. 217 * package is done and we are assembling the full package index.
213 */ 218 */
214 int id; 219 int id;
215 220
216 _ElementInfo(this.unitId, this.offset, this.kind); 221 _ElementInfo(this.element, this.unitId, this.offset, this.kind);
217 } 222 }
218 223
219 /** 224 /**
220 * Visits a resolved AST and adds relationships into [_UnitIndexAssembler]. 225 * Visits a resolved AST and adds relationships into [_UnitIndexAssembler].
221 */ 226 */
222 class _IndexContributor extends GeneralizingAstVisitor { 227 class _IndexContributor extends GeneralizingAstVisitor {
223 final _UnitIndexAssembler assembler; 228 final _UnitIndexAssembler assembler;
224 229
225 _IndexContributor(this.assembler); 230 _IndexContributor(this.assembler);
226 231
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 relations.add(new _RelationInfo(elementInfo, kind, offset, length)); 585 relations.add(new _RelationInfo(elementInfo, kind, offset, length));
581 } on StateError {} 586 } on StateError {}
582 } 587 }
583 588
584 /** 589 /**
585 * Assemble a new [UnitIndexBuilder] using the information gathered 590 * Assemble a new [UnitIndexBuilder] using the information gathered
586 * by [addRelation] and [defineName]. 591 * by [addRelation] and [defineName].
587 */ 592 */
588 UnitIndexBuilder assemble() { 593 UnitIndexBuilder assemble() {
589 relations.sort((a, b) { 594 relations.sort((a, b) {
595 if (a.elementInfo.id == null) {
596 throw new StateError('No id for ${a.elementInfo.element}, '
597 'location= ${a.elementInfo.element?.location}');
598 }
590 return a.elementInfo.id - b.elementInfo.id; 599 return a.elementInfo.id - b.elementInfo.id;
591 }); 600 });
592 definedNames.sort((a, b) { 601 definedNames.sort((a, b) {
593 return a.nameId - b.nameId; 602 return a.nameId - b.nameId;
594 }); 603 });
595 return new UnitIndexBuilder( 604 return new UnitIndexBuilder(
596 definedNames: definedNames.map((n) => n.nameId).toList(), 605 definedNames: definedNames.map((n) => n.nameId).toList(),
597 definedNameKinds: definedNames.map((n) => n.kind).toList(), 606 definedNameKinds: definedNames.map((n) => n.kind).toList(),
598 definedNameOffsets: definedNames.map((n) => n.offset).toList(), 607 definedNameOffsets: definedNames.map((n) => n.offset).toList(),
599 elements: relations.map((r) => r.elementInfo.id).toList(), 608 elements: relations.map((r) => r.elementInfo.id).toList(),
600 kinds: relations.map((r) => r.kind).toList(), 609 kinds: relations.map((r) => r.kind).toList(),
601 locationOffsets: relations.map((r) => r.offset).toList(), 610 locationOffsets: relations.map((r) => r.offset).toList(),
602 locationLengths: relations.map((r) => r.length).toList(), 611 locationLengths: relations.map((r) => r.length).toList(),
603 libraryUri: pkg._getUriId(unitElement.library.source.uri), 612 libraryUri: pkg._getUriId(unitElement.library.source.uri),
604 unitUri: pkg._getUriId(unitElement.source.uri)); 613 unitUri: pkg._getUriId(unitElement.source.uri));
605 } 614 }
606 615
607 void defineName(String name, IndexNameKind kind, int offset) { 616 void defineName(String name, IndexNameKind kind, int offset) {
608 int nameId = pkg._getStringId(name); 617 int nameId = pkg._getStringId(name);
609 definedNames.add(new _DefinedNameInfo(nameId, kind, offset)); 618 definedNames.add(new _DefinedNameInfo(nameId, kind, offset));
610 } 619 }
611 } 620 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698