@@ -158,6 +158,10 @@ class LibraryAnalyzer {
158
158
}
159
159
160
160
void _computeHints (FileState file, CompilationUnit unit) {
161
+ if (file.source == null ) {
162
+ return ;
163
+ }
164
+
161
165
AnalysisErrorListener errorListener = _getErrorListener (file);
162
166
ErrorReporter errorReporter = _getErrorReporter (file);
163
167
@@ -209,6 +213,10 @@ class LibraryAnalyzer {
209
213
}
210
214
211
215
void _computeLints (FileState file, CompilationUnit unit) {
216
+ if (file.source == null ) {
217
+ return ;
218
+ }
219
+
212
220
ErrorReporter errorReporter = _getErrorReporter (file);
213
221
214
222
List <AstVisitor > visitors = < AstVisitor > [];
@@ -239,6 +247,10 @@ class LibraryAnalyzer {
239
247
}
240
248
241
249
void _computeVerifyErrors (FileState file, CompilationUnit unit) {
250
+ if (file.source == null ) {
251
+ return ;
252
+ }
253
+
242
254
RecordingErrorListener errorListener = _getErrorListener (file);
243
255
244
256
if (_analysisOptions.strongMode) {
@@ -377,24 +389,14 @@ class LibraryAnalyzer {
377
389
378
390
void _resolveDirectives (Map <FileState , CompilationUnit > units) {
379
391
CompilationUnit definingCompilationUnit = units[_library];
380
-
381
- var uriToElement = < Uri , CompilationUnitElement > {};
382
- for (CompilationUnitElement partElement in _libraryElement.units) {
383
- uriToElement[partElement.source.uri] = partElement;
384
- }
385
-
386
- var sourceToUnit = < Source , CompilationUnit > {};
387
- units.forEach ((file, unit) {
388
- Source source = file.source;
389
- unit.element = uriToElement[source.uri];
390
- sourceToUnit[source] = unit;
391
- });
392
+ definingCompilationUnit.element = _libraryElement.definingCompilationUnit;
392
393
393
394
ErrorReporter libraryErrorReporter = _getErrorReporter (_library);
394
395
LibraryIdentifier libraryNameNode = null ;
395
396
bool hasPartDirective = false ;
396
397
var seenPartSources = new Set <Source >();
397
398
var directivesToResolve = < Directive > [];
399
+ int partIndex = 0 ;
398
400
for (Directive directive in definingCompilationUnit.directives) {
399
401
if (directive is LibraryDirective ) {
400
402
libraryNameNode = directive.name;
@@ -403,7 +405,8 @@ class LibraryAnalyzer {
403
405
for (ImportElement importElement in _libraryElement.imports) {
404
406
if (importElement.nameOffset == directive.offset) {
405
407
directive.element = importElement;
406
- if (! _isLibrarySource (importElement.importedLibrary.source)) {
408
+ Source source = importElement.importedLibrary? .source;
409
+ if (source != null && ! _isLibrarySource (source)) {
407
410
ErrorCode errorCode = importElement.isDeferred
408
411
? StaticWarningCode .IMPORT_OF_NON_LIBRARY
409
412
: CompileTimeErrorCode .IMPORT_OF_NON_LIBRARY ;
@@ -416,7 +419,8 @@ class LibraryAnalyzer {
416
419
for (ExportElement exportElement in _libraryElement.exports) {
417
420
if (exportElement.nameOffset == directive.offset) {
418
421
directive.element = exportElement;
419
- if (! _isLibrarySource (exportElement.exportedLibrary.source)) {
422
+ Source source = exportElement.exportedLibrary? .source;
423
+ if (source != null && ! _isLibrarySource (source)) {
420
424
libraryErrorReporter.reportErrorForNode (
421
425
CompileTimeErrorCode .EXPORT_OF_NON_LIBRARY ,
422
426
directive.uri,
@@ -427,46 +431,55 @@ class LibraryAnalyzer {
427
431
} else if (directive is PartDirective ) {
428
432
hasPartDirective = true ;
429
433
StringLiteral partUri = directive.uri;
434
+
435
+ FileState partFile = _library.partedFiles[partIndex];
436
+ CompilationUnit partUnit = units[partFile];
437
+ CompilationUnitElement partElement = _libraryElement.parts[partIndex];
438
+ partUnit.element = partElement;
439
+ directive.element = partElement;
440
+ partIndex++ ;
441
+
430
442
Source partSource = directive.uriSource;
431
- CompilationUnit partUnit = sourceToUnit[partSource];
432
- if (partUnit != null ) {
433
- directive.element = partUnit.element;
434
- //
435
- // Validate that the part source is unique in the library.
436
- //
437
- if (! seenPartSources.add (partSource)) {
443
+ if (partSource == null ) {
444
+ continue ;
445
+ }
446
+
447
+ //
448
+ // Validate that the part source is unique in the library.
449
+ //
450
+ if (! seenPartSources.add (partSource)) {
451
+ libraryErrorReporter.reportErrorForNode (
452
+ CompileTimeErrorCode .DUPLICATE_PART , partUri, [partSource.uri]);
453
+ }
454
+
455
+ //
456
+ // Validate that the part contains a part-of directive with the same
457
+ // name or uri as the library.
458
+ //
459
+ if (_context.exists (partSource)) {
460
+ _NameOrSource nameOrSource = _getPartLibraryNameOrUri (
461
+ partSource, partUnit, directivesToResolve);
462
+ if (nameOrSource == null ) {
438
463
libraryErrorReporter.reportErrorForNode (
439
- CompileTimeErrorCode .DUPLICATE_PART , partUri, [partSource.uri]);
440
- }
441
- //
442
- // Validate that the part contains a part-of directive with the same
443
- // name as the library.
444
- //
445
- if (_context.exists (partSource)) {
446
- _NameOrSource nameOrSource = _getPartLibraryNameOrUri (
447
- partSource, partUnit, directivesToResolve);
448
- if (nameOrSource == null ) {
449
- libraryErrorReporter.reportErrorForNode (
450
- CompileTimeErrorCode .PART_OF_NON_PART ,
451
- partUri,
452
- [partUri.toSource ()]);
464
+ CompileTimeErrorCode .PART_OF_NON_PART ,
465
+ partUri,
466
+ [partUri.toSource ()]);
467
+ } else {
468
+ String name = nameOrSource.name;
469
+ if (name != null ) {
470
+ if (libraryNameNode != null && libraryNameNode.name != name) {
471
+ libraryErrorReporter.reportErrorForNode (
472
+ StaticWarningCode .PART_OF_DIFFERENT_LIBRARY ,
473
+ partUri,
474
+ [libraryNameNode.name, name]);
475
+ }
453
476
} else {
454
- String name = nameOrSource.name;
455
- if (name != null ) {
456
- if (libraryNameNode != null && libraryNameNode.name != name) {
457
- libraryErrorReporter.reportErrorForNode (
458
- StaticWarningCode .PART_OF_DIFFERENT_LIBRARY ,
459
- partUri,
460
- [libraryNameNode.name, name]);
461
- }
462
- } else {
463
- Source source = nameOrSource.source;
464
- if (source != _library.source) {
465
- libraryErrorReporter.reportErrorForNode (
466
- StaticWarningCode .PART_OF_DIFFERENT_LIBRARY ,
467
- partUri,
468
- [_library.uriStr, source.uri]);
469
- }
477
+ Source source = nameOrSource.source;
478
+ if (source != _library.source) {
479
+ libraryErrorReporter.reportErrorForNode (
480
+ StaticWarningCode .PART_OF_DIFFERENT_LIBRARY ,
481
+ partUri,
482
+ [_library.uriStr, source.uri]);
470
483
}
471
484
}
472
485
}
@@ -492,10 +505,14 @@ class LibraryAnalyzer {
492
505
}
493
506
494
507
void _resolveFile (FileState file, CompilationUnit unit) {
508
+ Source source = file.source;
509
+ if (source == null ) {
510
+ return ;
511
+ }
512
+
495
513
RecordingErrorListener errorListener = _getErrorListener (file);
496
514
497
515
CompilationUnitElement unitElement = unit.element;
498
- Source source = file.source;
499
516
500
517
// TODO(scheglov) Hack: set types for top-level variables
501
518
// Otherwise TypeResolverVisitor will set declared types, and because we
0 commit comments