| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.context.context; | 5 library analyzer.src.context.context; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/instrumentation/instrumentation.dart'; | 10 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 } | 559 } |
| 560 nameNode = nameNode.parent; | 560 nameNode = nameNode.parent; |
| 561 } | 561 } |
| 562 return null; | 562 return null; |
| 563 } | 563 } |
| 564 | 564 |
| 565 @override | 565 @override |
| 566 List<AnalysisError> computeErrors(Source source) { | 566 List<AnalysisError> computeErrors(Source source) { |
| 567 String name = source.shortName; | 567 String name = source.shortName; |
| 568 if (AnalysisEngine.isDartFileName(name)) { | 568 if (AnalysisEngine.isDartFileName(name)) { |
| 569 return _computeResult(source, DART_ERRORS); | 569 return computeResult(source, DART_ERRORS); |
| 570 } else if (AnalysisEngine.isHtmlFileName(name)) { | 570 } else if (AnalysisEngine.isHtmlFileName(name)) { |
| 571 return _computeResult(source, HTML_ERRORS); | 571 return computeResult(source, HTML_ERRORS); |
| 572 } | 572 } |
| 573 return AnalysisError.NO_ERRORS; | 573 return AnalysisError.NO_ERRORS; |
| 574 } | 574 } |
| 575 | 575 |
| 576 @override | 576 @override |
| 577 List<Source> computeExportedLibraries(Source source) => | 577 List<Source> computeExportedLibraries(Source source) => |
| 578 _computeResult(source, EXPORTED_LIBRARIES); | 578 computeResult(source, EXPORTED_LIBRARIES); |
| 579 | 579 |
| 580 @override | 580 @override |
| 581 @deprecated | 581 @deprecated |
| 582 HtmlElement computeHtmlElement(Source source) { | 582 HtmlElement computeHtmlElement(Source source) { |
| 583 // TODO(brianwilkerson) Remove this method after switching to the new task | 583 // TODO(brianwilkerson) Remove this method after switching to the new task |
| 584 // model. | 584 // model. |
| 585 throw new UnimplementedError('Not supported in the new task model'); | 585 throw new UnimplementedError('Not supported in the new task model'); |
| 586 } | 586 } |
| 587 | 587 |
| 588 @override | 588 @override |
| 589 List<Source> computeImportedLibraries(Source source) => | 589 List<Source> computeImportedLibraries(Source source) => |
| 590 _computeResult(source, EXPLICITLY_IMPORTED_LIBRARIES); | 590 computeResult(source, EXPLICITLY_IMPORTED_LIBRARIES); |
| 591 | 591 |
| 592 @override | 592 @override |
| 593 SourceKind computeKindOf(Source source) { | 593 SourceKind computeKindOf(Source source) { |
| 594 String name = source.shortName; | 594 String name = source.shortName; |
| 595 if (AnalysisEngine.isDartFileName(name)) { | 595 if (AnalysisEngine.isDartFileName(name)) { |
| 596 return _computeResult(source, SOURCE_KIND); | 596 return computeResult(source, SOURCE_KIND); |
| 597 } else if (AnalysisEngine.isHtmlFileName(name)) { | 597 } else if (AnalysisEngine.isHtmlFileName(name)) { |
| 598 return SourceKind.HTML; | 598 return SourceKind.HTML; |
| 599 } | 599 } |
| 600 return SourceKind.UNKNOWN; | 600 return SourceKind.UNKNOWN; |
| 601 } | 601 } |
| 602 | 602 |
| 603 @override | 603 @override |
| 604 LibraryElement computeLibraryElement(Source source) { | 604 LibraryElement computeLibraryElement(Source source) { |
| 605 //_computeResult(source, HtmlEntry.ELEMENT); | 605 //_computeResult(source, HtmlEntry.ELEMENT); |
| 606 return _computeResult(source, LIBRARY_ELEMENT); | 606 return computeResult(source, LIBRARY_ELEMENT); |
| 607 } | 607 } |
| 608 | 608 |
| 609 @override | 609 @override |
| 610 LineInfo computeLineInfo(Source source) => _computeResult(source, LINE_INFO); | 610 LineInfo computeLineInfo(Source source) => computeResult(source, LINE_INFO); |
| 611 | 611 |
| 612 @override | 612 @override |
| 613 @deprecated | 613 @deprecated |
| 614 CompilationUnit computeResolvableCompilationUnit(Source source) { | 614 CompilationUnit computeResolvableCompilationUnit(Source source) { |
| 615 return null; | 615 return null; |
| 616 } | 616 } |
| 617 | 617 |
| 618 @override | 618 @override |
| 619 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( | 619 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( |
| 620 Source unitSource, Source librarySource) { | 620 Source unitSource, Source librarySource) { |
| 621 if (!AnalysisEngine.isDartFileName(unitSource.shortName) || | 621 if (!AnalysisEngine.isDartFileName(unitSource.shortName) || |
| 622 !AnalysisEngine.isDartFileName(librarySource.shortName)) { | 622 !AnalysisEngine.isDartFileName(librarySource.shortName)) { |
| 623 return new CancelableFuture.error(new AnalysisNotScheduledError()); | 623 return new CancelableFuture.error(new AnalysisNotScheduledError()); |
| 624 } | 624 } |
| 625 var unitTarget = new LibrarySpecificUnit(librarySource, unitSource); | 625 var unitTarget = new LibrarySpecificUnit(librarySource, unitSource); |
| 626 return new _AnalysisFutureHelper<CompilationUnit>(this).computeAsync( | 626 return new _AnalysisFutureHelper<CompilationUnit>(this).computeAsync( |
| 627 unitTarget, (CacheEntry entry) { | 627 unitTarget, (CacheEntry entry) { |
| 628 CacheState state = entry.getState(RESOLVED_UNIT); | 628 CacheState state = entry.getState(RESOLVED_UNIT); |
| 629 if (state == CacheState.ERROR) { | 629 if (state == CacheState.ERROR) { |
| 630 throw entry.exception; | 630 throw entry.exception; |
| 631 } else if (state == CacheState.INVALID) { | 631 } else if (state == CacheState.INVALID) { |
| 632 return null; | 632 return null; |
| 633 } | 633 } |
| 634 return entry.getValue(RESOLVED_UNIT); | 634 return entry.getValue(RESOLVED_UNIT); |
| 635 }, () { | 635 }, () { |
| 636 dartWorkManager.addPriorityResult(unitTarget, RESOLVED_UNIT); | 636 dartWorkManager.addPriorityResult(unitTarget, RESOLVED_UNIT); |
| 637 }); | 637 }); |
| 638 } | 638 } |
| 639 | 639 |
| 640 Object /*V*/ computeResult( |
| 641 AnalysisTarget target, ResultDescriptor /*<V>*/ descriptor) { |
| 642 CacheEntry entry = getCacheEntry(target); |
| 643 CacheState state = entry.getState(descriptor); |
| 644 if (state == CacheState.FLUSHED || state == CacheState.INVALID) { |
| 645 driver.computeResult(target, descriptor); |
| 646 } |
| 647 state = entry.getState(descriptor); |
| 648 if (state == CacheState.ERROR) { |
| 649 throw new AnalysisException( |
| 650 'Cannot compute $descriptor for $target', entry.exception); |
| 651 } |
| 652 return entry.getValue(descriptor); |
| 653 } |
| 654 |
| 640 /** | 655 /** |
| 641 * Create an analysis cache based on the given source [factory]. | 656 * Create an analysis cache based on the given source [factory]. |
| 642 */ | 657 */ |
| 643 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 658 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
| 644 if (factory == null) { | 659 if (factory == null) { |
| 645 return new AnalysisCache(<CachePartition>[_privatePartition]); | 660 return new AnalysisCache(<CachePartition>[_privatePartition]); |
| 646 } | 661 } |
| 647 DartSdk sdk = factory.dartSdk; | 662 DartSdk sdk = factory.dartSdk; |
| 648 if (sdk == null) { | 663 if (sdk == null) { |
| 649 return new AnalysisCache(<CachePartition>[_privatePartition]); | 664 return new AnalysisCache(<CachePartition>[_privatePartition]); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 CompilationUnit parseCompilationUnit(Source source) { | 1021 CompilationUnit parseCompilationUnit(Source source) { |
| 1007 if (!AnalysisEngine.isDartFileName(source.shortName)) { | 1022 if (!AnalysisEngine.isDartFileName(source.shortName)) { |
| 1008 return null; | 1023 return null; |
| 1009 } | 1024 } |
| 1010 try { | 1025 try { |
| 1011 getContents(source); | 1026 getContents(source); |
| 1012 } catch (exception, stackTrace) { | 1027 } catch (exception, stackTrace) { |
| 1013 throw new AnalysisException('Could not get contents of $source', | 1028 throw new AnalysisException('Could not get contents of $source', |
| 1014 new CaughtException(exception, stackTrace)); | 1029 new CaughtException(exception, stackTrace)); |
| 1015 } | 1030 } |
| 1016 return _computeResult(source, PARSED_UNIT); | 1031 return computeResult(source, PARSED_UNIT); |
| 1017 } | 1032 } |
| 1018 | 1033 |
| 1019 @override | 1034 @override |
| 1020 Document parseHtmlDocument(Source source) { | 1035 Document parseHtmlDocument(Source source) { |
| 1021 if (!AnalysisEngine.isHtmlFileName(source.shortName)) { | 1036 if (!AnalysisEngine.isHtmlFileName(source.shortName)) { |
| 1022 return null; | 1037 return null; |
| 1023 } | 1038 } |
| 1024 return _computeResult(source, HTML_DOCUMENT); | 1039 return computeResult(source, HTML_DOCUMENT); |
| 1025 } | 1040 } |
| 1026 | 1041 |
| 1027 @override | 1042 @override |
| 1028 @deprecated // use parseHtmlDocument(source) | 1043 @deprecated // use parseHtmlDocument(source) |
| 1029 ht.HtmlUnit parseHtmlUnit(Source source) { | 1044 ht.HtmlUnit parseHtmlUnit(Source source) { |
| 1030 // TODO(brianwilkerson) Remove this method after switching to the new task | 1045 // TODO(brianwilkerson) Remove this method after switching to the new task |
| 1031 // model. | 1046 // model. |
| 1032 throw new UnimplementedError('Not supported in the new task model'); | 1047 throw new UnimplementedError('Not supported in the new task model'); |
| 1033 } | 1048 } |
| 1034 | 1049 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 return resolveCompilationUnit2(unitSource, library.source); | 1139 return resolveCompilationUnit2(unitSource, library.source); |
| 1125 } | 1140 } |
| 1126 | 1141 |
| 1127 @override | 1142 @override |
| 1128 CompilationUnit resolveCompilationUnit2( | 1143 CompilationUnit resolveCompilationUnit2( |
| 1129 Source unitSource, Source librarySource) { | 1144 Source unitSource, Source librarySource) { |
| 1130 if (!AnalysisEngine.isDartFileName(unitSource.shortName) || | 1145 if (!AnalysisEngine.isDartFileName(unitSource.shortName) || |
| 1131 !AnalysisEngine.isDartFileName(librarySource.shortName)) { | 1146 !AnalysisEngine.isDartFileName(librarySource.shortName)) { |
| 1132 return null; | 1147 return null; |
| 1133 } | 1148 } |
| 1134 return _computeResult( | 1149 return computeResult( |
| 1135 new LibrarySpecificUnit(librarySource, unitSource), RESOLVED_UNIT); | 1150 new LibrarySpecificUnit(librarySource, unitSource), RESOLVED_UNIT); |
| 1136 } | 1151 } |
| 1137 | 1152 |
| 1138 @override | 1153 @override |
| 1139 @deprecated | 1154 @deprecated |
| 1140 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { | 1155 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { |
| 1141 // TODO(brianwilkerson) Remove this method after switching to the new task | 1156 // TODO(brianwilkerson) Remove this method after switching to the new task |
| 1142 // model. | 1157 // model. |
| 1143 throw new UnimplementedError('Not supported in the new task model'); | 1158 throw new UnimplementedError('Not supported in the new task model'); |
| 1144 } | 1159 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 List<PendingFuture> pendingFutures = | 1339 List<PendingFuture> pendingFutures = |
| 1325 _pendingFutureTargets[pendingFuture.target]; | 1340 _pendingFutureTargets[pendingFuture.target]; |
| 1326 if (pendingFutures != null) { | 1341 if (pendingFutures != null) { |
| 1327 pendingFutures.remove(pendingFuture); | 1342 pendingFutures.remove(pendingFuture); |
| 1328 if (pendingFutures.isEmpty) { | 1343 if (pendingFutures.isEmpty) { |
| 1329 _pendingFutureTargets.remove(pendingFuture.target); | 1344 _pendingFutureTargets.remove(pendingFuture.target); |
| 1330 } | 1345 } |
| 1331 } | 1346 } |
| 1332 } | 1347 } |
| 1333 | 1348 |
| 1334 Object /*V*/ _computeResult( | |
| 1335 AnalysisTarget target, ResultDescriptor /*<V>*/ descriptor) { | |
| 1336 CacheEntry entry = getCacheEntry(target); | |
| 1337 CacheState state = entry.getState(descriptor); | |
| 1338 if (state == CacheState.FLUSHED || state == CacheState.INVALID) { | |
| 1339 driver.computeResult(target, descriptor); | |
| 1340 } | |
| 1341 state = entry.getState(descriptor); | |
| 1342 if (state == CacheState.ERROR) { | |
| 1343 throw new AnalysisException( | |
| 1344 'Cannot compute $descriptor for $target', entry.exception); | |
| 1345 } | |
| 1346 return entry.getValue(descriptor); | |
| 1347 } | |
| 1348 | |
| 1349 /** | 1349 /** |
| 1350 * Given the encoded form of a source ([encoding]), use the source factory to | 1350 * Given the encoded form of a source ([encoding]), use the source factory to |
| 1351 * reconstitute the original source. | 1351 * reconstitute the original source. |
| 1352 */ | 1352 */ |
| 1353 Source _computeSourceFromEncoding(String encoding) => | 1353 Source _computeSourceFromEncoding(String encoding) => |
| 1354 _sourceFactory.fromEncoding(encoding); | 1354 _sourceFactory.fromEncoding(encoding); |
| 1355 | 1355 |
| 1356 /** | 1356 /** |
| 1357 * Return `true` if the given list of [sources] contains the given | 1357 * Return `true` if the given list of [sources] contains the given |
| 1358 * [targetSource]. | 1358 * [targetSource]. |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 new PendingFuture<T>(_context, target, computeValue); | 2033 new PendingFuture<T>(_context, target, computeValue); |
| 2034 if (!pendingFuture.evaluate(entry)) { | 2034 if (!pendingFuture.evaluate(entry)) { |
| 2035 _context._pendingFutureTargets | 2035 _context._pendingFutureTargets |
| 2036 .putIfAbsent(target, () => <PendingFuture>[]) | 2036 .putIfAbsent(target, () => <PendingFuture>[]) |
| 2037 .add(pendingFuture); | 2037 .add(pendingFuture); |
| 2038 scheduleComputation(); | 2038 scheduleComputation(); |
| 2039 } | 2039 } |
| 2040 return pendingFuture.future; | 2040 return pendingFuture.future; |
| 2041 } | 2041 } |
| 2042 } | 2042 } |
| OLD | NEW |