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

Side by Side Diff: pkg/analyzer_experimental/lib/src/generated/engine.dart

Issue 24481002: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 library engine; 3 library engine;
4 import 'java_core.dart'; 4 import 'java_core.dart';
5 import 'java_engine.dart'; 5 import 'java_engine.dart';
6 import 'utilities_collection.dart'; 6 import 'utilities_collection.dart';
7 import 'utilities_general.dart';
7 import 'instrumentation.dart'; 8 import 'instrumentation.dart';
8 import 'error.dart'; 9 import 'error.dart';
9 import 'source.dart'; 10 import 'source.dart';
10 import 'scanner.dart' show Token, CharBufferScanner, StringScanner; 11 import 'scanner.dart' show Token, CharBufferScanner, StringScanner;
11 import 'ast.dart'; 12 import 'ast.dart';
12 import 'parser.dart' show Parser; 13 import 'parser.dart' show Parser;
13 import 'sdk.dart' show DartSdk; 14 import 'sdk.dart' show DartSdk;
14 import 'element.dart'; 15 import 'element.dart';
15 import 'resolver.dart'; 16 import 'resolver.dart';
16 import 'html.dart' show XmlTagNode, XmlAttributeNode, RecursiveXmlVisitor, HtmlS canner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlUnit; 17 import 'html.dart' show XmlTagNode, XmlAttributeNode, RecursiveXmlVisitor, HtmlS canner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlUnit;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 String extension = FileNameUtilities.getExtension(fileName); 69 String extension = FileNameUtilities.getExtension(fileName);
69 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqual sIgnoreCase(extension, SUFFIX_HTM); 70 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqual sIgnoreCase(extension, SUFFIX_HTM);
70 } 71 }
71 72
72 /** 73 /**
73 * The logger that should receive information about errors within the analysis engine. 74 * The logger that should receive information about errors within the analysis engine.
74 */ 75 */
75 Logger _logger = Logger.NULL; 76 Logger _logger = Logger.NULL;
76 77
77 /** 78 /**
78 * A flag indicating whether the new analysis context should be created.
79 */
80 bool _useExperimentalContext = false;
81
82 /**
83 * Create a new context in which analysis can be performed. 79 * Create a new context in which analysis can be performed.
84 * 80 *
85 * @return the analysis context that was created 81 * @return the analysis context that was created
86 */ 82 */
87 AnalysisContext createAnalysisContext() { 83 AnalysisContext createAnalysisContext() {
88 if (Instrumentation.isNullLogger) { 84 if (Instrumentation.isNullLogger) {
89 if (_useExperimentalContext) {
90 return new DelegatingAnalysisContextImpl2();
91 }
92 return new DelegatingAnalysisContextImpl(); 85 return new DelegatingAnalysisContextImpl();
93 } 86 }
94 if (_useExperimentalContext) {
95 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisCont extImpl2());
96 }
97 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisContex tImpl()); 87 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisContex tImpl());
98 } 88 }
99 89
100 /** 90 /**
101 * Return the logger that should receive information about errors within the a nalysis engine. 91 * Return the logger that should receive information about errors within the a nalysis engine.
102 * 92 *
103 * @return the logger that should receive information about errors within the analysis engine 93 * @return the logger that should receive information about errors within the analysis engine
104 */ 94 */
105 Logger get logger => _logger; 95 Logger get logger => _logger;
106 96
107 /** 97 /**
108 * Return `true` if the new analysis context should be created.
109 *
110 * @return `true` if the new analysis context should be created
111 */
112 bool get useExperimentalContext => _useExperimentalContext;
113
114 /**
115 * Set the logger that should receive information about errors within the anal ysis engine to the 98 * Set the logger that should receive information about errors within the anal ysis engine to the
116 * given logger. 99 * given logger.
117 * 100 *
118 * @param logger the logger that should receive information about errors withi n the analysis 101 * @param logger the logger that should receive information about errors withi n the analysis
119 * engine 102 * engine
120 */ 103 */
121 void set logger(Logger logger2) { 104 void set logger(Logger logger2) {
122 this._logger = logger2 == null ? Logger.NULL : logger2; 105 this._logger = logger2 == null ? Logger.NULL : logger2;
123 } 106 }
124
125 /**
126 * Set whether the new analysis context should be created to the given flag.
127 *
128 * @param use `true` if the new analysis context should be created
129 */
130 void set useExperimentalContext(bool use) {
131 _useExperimentalContext = use;
132 }
133 } 107 }
134 /** 108 /**
135 * Container with statistics about the [AnalysisContext]. 109 * Container with statistics about the [AnalysisContext].
136 */ 110 */
137 abstract class AnalysisContentStatistics { 111 abstract class AnalysisContentStatistics {
138 112
139 /** 113 /**
140 * @return the statistics for each kind of cached data. 114 * Return the exceptions that caused some entries to have a state of [CacheSta te#ERROR].
115 *
116 * @return the exceptions that caused some entries to have a state of [CacheSt ate#ERROR]
117 */
118 List<AnalysisException> get exceptions;
119
120 /**
121 * Return the statistics for each kind of cached data.
122 *
123 * @return the statistics for each kind of cached data
141 */ 124 */
142 List<AnalysisContentStatistics_CacheRow> get cacheRows; 125 List<AnalysisContentStatistics_CacheRow> get cacheRows;
143 } 126 }
144 /** 127 /**
145 * Information about single item in the cache. 128 * Information about single item in the cache.
146 */ 129 */
147 abstract class AnalysisContentStatistics_CacheRow { 130 abstract class AnalysisContentStatistics_CacheRow {
148 int get errorCount; 131 int get errorCount;
149 int get flushedCount; 132 int get flushedCount;
150 int get inProcessCount; 133 int get inProcessCount;
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 */ 653 */
671 AnalysisException.con3(Exception cause) : super.withCause(cause); 654 AnalysisException.con3(Exception cause) : super.withCause(cause);
672 } 655 }
673 /** 656 /**
674 * The interface `AnalysisOptions` defines the behavior of objects that provide access to a 657 * The interface `AnalysisOptions` defines the behavior of objects that provide access to a
675 * set of analysis options used to control the behavior of an analysis context. 658 * set of analysis options used to control the behavior of an analysis context.
676 */ 659 */
677 abstract class AnalysisOptions { 660 abstract class AnalysisOptions {
678 661
679 /** 662 /**
663 * Return `true` if analysis is to generate dart2js related hint results.
664 *
665 * @return `true` if analysis is to generate dart2js related hint results
666 */
667 bool get dart2jsHint;
668
669 /**
680 * Return `true` if analysis is to generate hint results (e.g. type inference based 670 * Return `true` if analysis is to generate hint results (e.g. type inference based
681 * information and pub best practices). 671 * information and pub best practices).
682 * 672 *
683 * @return `true` if analysis is to generate hint results 673 * @return `true` if analysis is to generate hint results
684 */ 674 */
685 bool get hint; 675 bool get hint;
686 676
687 /** 677 /**
688 * Return `true` if analysis is to use strict mode. In strict mode, error repo rting is based 678 * Return `true` if analysis is to use strict mode. In strict mode, error repo rting is based
689 * exclusively on the static type information. 679 * exclusively on the static type information.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 /** 774 /**
785 * Record that the specified source container has been removed. 775 * Record that the specified source container has been removed.
786 * 776 *
787 * @param container the source container that was removed 777 * @param container the source container that was removed
788 */ 778 */
789 void removedContainer(SourceContainer container) { 779 void removedContainer(SourceContainer container) {
790 if (container != null) { 780 if (container != null) {
791 removedContainers.add(container); 781 removedContainers.add(container);
792 } 782 }
793 } 783 }
784 String toString() {
785 JavaStringBuilder builder = new JavaStringBuilder();
786 bool needsSeparator = appendSources(builder, added3, false, "added");
787 needsSeparator = appendSources(builder, changed3, needsSeparator, "changed") ;
788 appendSources(builder, removed3, needsSeparator, "removed");
789 int count = removedContainers.length;
790 if (count > 0) {
791 if (removed3.isEmpty) {
792 if (needsSeparator) {
793 builder.append("; ");
794 }
795 builder.append("removed: from ");
796 builder.append(count);
797 builder.append(" containers");
798 } else {
799 builder.append(", and more from ");
800 builder.append(count);
801 builder.append(" containers");
802 }
803 }
804 return builder.toString();
805 }
806
807 /**
808 * Append the given sources to the given builder, prefixed with the given labe l and possibly a
809 * separator.
810 *
811 * @param builder the builder to which the sources are to be appended
812 * @param sources the sources to be appended
813 * @param needsSeparator `true` if a separator is needed before the label
814 * @param label the label used to prefix the sources
815 * @return `true` if future lists of sources will need a separator
816 */
817 bool appendSources(JavaStringBuilder builder, List<Source> sources, bool needs Separator, String label) {
818 if (sources.isEmpty) {
819 return needsSeparator;
820 }
821 if (needsSeparator) {
822 builder.append("; ");
823 }
824 builder.append(label);
825 String prefix = " ";
826 for (Source source in sources) {
827 builder.append(prefix);
828 builder.append(source.fullName);
829 prefix = ", ";
830 }
831 return true;
832 }
794 } 833 }
795 /** 834 /**
796 * Instances of the class `AnalysisCache` implement an LRU cache of information related to 835 * Instances of the class `AnalysisCache` implement an LRU cache of information related to
797 * analysis. 836 * analysis.
798 */ 837 */
799 class AnalysisCache { 838 class AnalysisCache {
800 839
801 /** 840 /**
802 * A table mapping the sources known to the context to the information known a bout the source. 841 * A table mapping the sources known to the context to the information known a bout the source.
803 */ 842 */
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 _cacheRemovalCount--; 909 _cacheRemovalCount--;
871 } 910 }
872 if (_cacheRemovalCount == 0) { 911 if (_cacheRemovalCount == 0) {
873 while (_recentlyUsed.length > _maxCacheSize) { 912 while (_recentlyUsed.length > _maxCacheSize) {
874 flushAstFromCache(); 913 flushAstFromCache();
875 } 914 }
876 } 915 }
877 } 916 }
878 917
879 /** 918 /**
880 * Return a set containing all of the map entries mapping sources to cache ent ries. Clients should 919 * Return a collection containing all of the map entries mapping sources to ca che entries. Clients
881 * not modify the returned set. 920 * should not modify the returned collection.
882 * 921 *
883 * @return a set containing all of the map entries mapping sources to cache en tries 922 * @return a collection containing all of the map entries mapping sources to c ache entries
884 */ 923 */
885 Set<MapEntry<Source, SourceEntry>> entrySet() => getMapEntrySet(_sourceMap); 924 Iterable<MapEntry<Source, SourceEntry>> entrySet() => getMapEntrySet(_sourceMa p);
886 925
887 /** 926 /**
888 * Return the entry associated with the given source. 927 * Return the entry associated with the given source.
889 * 928 *
890 * @param source the source whose entry is to be returned 929 * @param source the source whose entry is to be returned
891 * @return the entry associated with the given source 930 * @return the entry associated with the given source
892 */ 931 */
893 SourceEntry get(Source source) => _sourceMap[source]; 932 SourceEntry get(Source source) => _sourceMap[source];
894 933
895 /** 934 /**
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 * The state of the cached launchable flag. 1317 * The state of the cached launchable flag.
1279 */ 1318 */
1280 CacheState _launchableState = CacheState.INVALID; 1319 CacheState _launchableState = CacheState.INVALID;
1281 1320
1282 /** 1321 /**
1283 * An integer holding bit masks such as [LAUNCHABLE] and [CLIENT_CODE]. 1322 * An integer holding bit masks such as [LAUNCHABLE] and [CLIENT_CODE].
1284 */ 1323 */
1285 int _bitmask = 0; 1324 int _bitmask = 0;
1286 1325
1287 /** 1326 /**
1288 * Mask indicating that this library is launchable: that the file has a main m ethod. 1327 * The index of the bit in the [bitmask] indicating that this library is launc hable: that
1328 * the file has a main method.
1289 */ 1329 */
1290 static int _LAUNCHABLE = 1 << 1; 1330 static int _LAUNCHABLE_INDEX = 1;
1291 1331
1292 /** 1332 /**
1293 * Mask indicating that the library is client code: that the library depends o n the html library. 1333 * The index of the bit in the [bitmask] indicating that the library is client code: that
1294 * If the library is not "client code", then it is referenced as "server code" . 1334 * the library depends on the html library. If the library is not "client code ", then it is
1335 * referred to as "server code".
1295 */ 1336 */
1296 static int _CLIENT_CODE = 1 << 2; 1337 static int _CLIENT_CODE_INDEX = 2;
1297 1338
1298 /** 1339 /**
1299 * Flush any AST structures being maintained by this entry. 1340 * Flush any AST structures being maintained by this entry.
1300 */ 1341 */
1301 void flushAstStructures() { 1342 void flushAstStructures() {
1302 if (identical(_parsedUnitState, CacheState.VALID)) { 1343 if (identical(_parsedUnitState, CacheState.VALID)) {
1303 _parsedUnitState = CacheState.FLUSHED; 1344 _parsedUnitState = CacheState.FLUSHED;
1304 _parsedUnitAccessed = false; 1345 _parsedUnitAccessed = false;
1305 _parsedUnit = null; 1346 _parsedUnit = null;
1306 } 1347 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 return _sourceKindState; 1438 return _sourceKindState;
1398 } else { 1439 } else {
1399 return super.getState(descriptor); 1440 return super.getState(descriptor);
1400 } 1441 }
1401 } 1442 }
1402 CacheState getState2(DataDescriptor descriptor, Source librarySource2) { 1443 CacheState getState2(DataDescriptor descriptor, Source librarySource2) {
1403 DartEntryImpl_ResolutionState state = _resolutionState; 1444 DartEntryImpl_ResolutionState state = _resolutionState;
1404 while (state != null) { 1445 while (state != null) {
1405 if (librarySource2 == state._librarySource) { 1446 if (librarySource2 == state._librarySource) {
1406 if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) { 1447 if (identical(descriptor, DartEntry.RESOLUTION_ERRORS)) {
1407 return _resolutionState._resolutionErrorsState; 1448 return state._resolutionErrorsState;
1408 } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) { 1449 } else if (identical(descriptor, DartEntry.RESOLVED_UNIT)) {
1409 return _resolutionState._resolvedUnitState; 1450 return state._resolvedUnitState;
1410 } else if (identical(descriptor, DartEntry.HINTS)) { 1451 } else if (identical(descriptor, DartEntry.HINTS)) {
1411 return _resolutionState._hintsState; 1452 return state._hintsState;
1412 } else { 1453 } else {
1413 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}" ); 1454 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}" );
1414 } 1455 }
1415 } 1456 }
1416 state = state._nextState; 1457 state = state._nextState;
1417 } 1458 }
1418 ; 1459 ;
1419 if (identical(descriptor, DartEntry.RESOLUTION_ERRORS) || identical(descript or, DartEntry.RESOLVED_UNIT) || identical(descriptor, DartEntry.HINTS)) { 1460 if (identical(descriptor, DartEntry.RESOLUTION_ERRORS) || identical(descript or, DartEntry.RESOLVED_UNIT) || identical(descriptor, DartEntry.HINTS)) {
1420 return CacheState.INVALID; 1461 return CacheState.INVALID;
1421 } else { 1462 } else {
1422 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 1463 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
1423 } 1464 }
1424 } 1465 }
1425 Object getValue(DataDescriptor descriptor) { 1466 Object getValue(DataDescriptor descriptor) {
1426 if (identical(descriptor, DartEntry.ELEMENT)) { 1467 if (identical(descriptor, DartEntry.ELEMENT)) {
1427 return _element as Object; 1468 return _element as Object;
1428 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { 1469 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) {
1429 return _exportedLibraries as Object; 1470 return _exportedLibraries as Object;
1430 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { 1471 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) {
1431 return _importedLibraries as Object; 1472 return _importedLibraries as Object;
1432 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { 1473 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) {
1433 return _includedParts as Object; 1474 return _includedParts as Object;
1434 } else if (identical(descriptor, DartEntry.IS_CLIENT)) { 1475 } else if (identical(descriptor, DartEntry.IS_CLIENT)) {
1435 return ((_bitmask & _CLIENT_CODE) != 0 ? true : false) as Object; 1476 return (BooleanArray.get2(_bitmask, _CLIENT_CODE_INDEX) as bool) as Object ;
1436 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) { 1477 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) {
1437 return ((_bitmask & _LAUNCHABLE) != 0 ? true : false) as Object; 1478 return (BooleanArray.get2(_bitmask, _LAUNCHABLE_INDEX) as bool) as Object;
1438 } else if (identical(descriptor, DartEntry.PARSE_ERRORS)) { 1479 } else if (identical(descriptor, DartEntry.PARSE_ERRORS)) {
1439 return _parseErrors as Object; 1480 return _parseErrors as Object;
1440 } else if (identical(descriptor, DartEntry.PARSED_UNIT)) { 1481 } else if (identical(descriptor, DartEntry.PARSED_UNIT)) {
1441 _parsedUnitAccessed = true; 1482 _parsedUnitAccessed = true;
1442 return _parsedUnit as Object; 1483 return _parsedUnit as Object;
1443 } else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) { 1484 } else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) {
1444 return _publicNamespace as Object; 1485 return _publicNamespace as Object;
1445 } else if (identical(descriptor, DartEntry.SOURCE_KIND)) { 1486 } else if (identical(descriptor, DartEntry.SOURCE_KIND)) {
1446 return _sourceKind as Object; 1487 return _sourceKind as Object;
1447 } 1488 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { 1729 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) {
1689 _exportedLibraries = updatedValue(state, _exportedLibraries, Source.EMPTY_ ARRAY); 1730 _exportedLibraries = updatedValue(state, _exportedLibraries, Source.EMPTY_ ARRAY);
1690 _exportedLibrariesState = state; 1731 _exportedLibrariesState = state;
1691 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { 1732 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) {
1692 _importedLibraries = updatedValue(state, _importedLibraries, Source.EMPTY_ ARRAY); 1733 _importedLibraries = updatedValue(state, _importedLibraries, Source.EMPTY_ ARRAY);
1693 _importedLibrariesState = state; 1734 _importedLibrariesState = state;
1694 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { 1735 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) {
1695 _includedParts = updatedValue(state, _includedParts, Source.EMPTY_ARRAY); 1736 _includedParts = updatedValue(state, _includedParts, Source.EMPTY_ARRAY);
1696 _includedPartsState = state; 1737 _includedPartsState = state;
1697 } else if (identical(descriptor, DartEntry.IS_CLIENT)) { 1738 } else if (identical(descriptor, DartEntry.IS_CLIENT)) {
1698 _bitmask = updatedValue2(state, _bitmask, _CLIENT_CODE); 1739 _bitmask = updatedValue2(state, _bitmask, _CLIENT_CODE_INDEX);
1699 _clientServerState = state; 1740 _clientServerState = state;
1700 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) { 1741 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) {
1701 _bitmask = updatedValue2(state, _bitmask, _LAUNCHABLE); 1742 _bitmask = updatedValue2(state, _bitmask, _LAUNCHABLE_INDEX);
1702 _launchableState = state; 1743 _launchableState = state;
1703 } else if (identical(descriptor, DartEntry.PARSE_ERRORS)) { 1744 } else if (identical(descriptor, DartEntry.PARSE_ERRORS)) {
1704 _parseErrors = updatedValue(state, _parseErrors, AnalysisError.NO_ERRORS); 1745 _parseErrors = updatedValue(state, _parseErrors, AnalysisError.NO_ERRORS);
1705 _parseErrorsState = state; 1746 _parseErrorsState = state;
1706 } else if (identical(descriptor, DartEntry.PARSED_UNIT)) { 1747 } else if (identical(descriptor, DartEntry.PARSED_UNIT)) {
1707 CompilationUnit newUnit = updatedValue(state, _parsedUnit, null); 1748 CompilationUnit newUnit = updatedValue(state, _parsedUnit, null);
1708 if (newUnit != _parsedUnit) { 1749 if (newUnit != _parsedUnit) {
1709 _parsedUnitAccessed = false; 1750 _parsedUnitAccessed = false;
1710 } 1751 }
1711 _parsedUnit = newUnit; 1752 _parsedUnit = newUnit;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { 1793 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) {
1753 _exportedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>); 1794 _exportedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>);
1754 _exportedLibrariesState = CacheState.VALID; 1795 _exportedLibrariesState = CacheState.VALID;
1755 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { 1796 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) {
1756 _importedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>); 1797 _importedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>);
1757 _importedLibrariesState = CacheState.VALID; 1798 _importedLibrariesState = CacheState.VALID;
1758 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { 1799 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) {
1759 _includedParts = value == null ? Source.EMPTY_ARRAY : (value as List<Sourc e>); 1800 _includedParts = value == null ? Source.EMPTY_ARRAY : (value as List<Sourc e>);
1760 _includedPartsState = CacheState.VALID; 1801 _includedPartsState = CacheState.VALID;
1761 } else if (identical(descriptor, DartEntry.IS_CLIENT)) { 1802 } else if (identical(descriptor, DartEntry.IS_CLIENT)) {
1762 if (((value as bool))) { 1803 _bitmask = BooleanArray.set2(_bitmask, _CLIENT_CODE_INDEX, value as bool);
1763 _bitmask |= _CLIENT_CODE;
1764 } else {
1765 _bitmask &= ~_CLIENT_CODE;
1766 }
1767 _clientServerState = CacheState.VALID; 1804 _clientServerState = CacheState.VALID;
1768 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) { 1805 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) {
1769 if (((value as bool))) { 1806 _bitmask = BooleanArray.set2(_bitmask, _LAUNCHABLE_INDEX, value as bool);
1770 _bitmask |= _LAUNCHABLE;
1771 } else {
1772 _bitmask &= ~_LAUNCHABLE;
1773 }
1774 _launchableState = CacheState.VALID; 1807 _launchableState = CacheState.VALID;
1775 } else if (identical(descriptor, DartEntry.PARSE_ERRORS)) { 1808 } else if (identical(descriptor, DartEntry.PARSE_ERRORS)) {
1776 _parseErrors = value == null ? AnalysisError.NO_ERRORS : (value as List<An alysisError>); 1809 _parseErrors = value == null ? AnalysisError.NO_ERRORS : (value as List<An alysisError>);
1777 _parseErrorsState = CacheState.VALID; 1810 _parseErrorsState = CacheState.VALID;
1778 } else if (identical(descriptor, DartEntry.PARSED_UNIT)) { 1811 } else if (identical(descriptor, DartEntry.PARSED_UNIT)) {
1779 _parsedUnit = value as CompilationUnit; 1812 _parsedUnit = value as CompilationUnit;
1780 _parsedUnitAccessed = false; 1813 _parsedUnitAccessed = false;
1781 _parsedUnitState = CacheState.VALID; 1814 _parsedUnitState = CacheState.VALID;
1782 } else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) { 1815 } else if (identical(descriptor, DartEntry.PUBLIC_NAMESPACE)) {
1783 _publicNamespace = value as Namespace; 1816 _publicNamespace = value as Namespace;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 1924
1892 /** 1925 /**
1893 * Given that one of the flags is being transitioned to the given state, retur n the value of the 1926 * Given that one of the flags is being transitioned to the given state, retur n the value of the
1894 * flags that should be kept in the cache. 1927 * flags that should be kept in the cache.
1895 * 1928 *
1896 * @param state the state to which the data is being transitioned 1929 * @param state the state to which the data is being transitioned
1897 * @param currentValue the value of the flags before the transition 1930 * @param currentValue the value of the flags before the transition
1898 * @param bitMask the mask used to access the bit whose state is being set 1931 * @param bitMask the mask used to access the bit whose state is being set
1899 * @return the value of the data that should be kept in the cache 1932 * @return the value of the data that should be kept in the cache
1900 */ 1933 */
1901 int updatedValue2(CacheState state, int currentValue, int bitMask) { 1934 int updatedValue2(CacheState state, int currentValue, int bitIndex) {
1902 if (identical(state, CacheState.VALID)) { 1935 if (identical(state, CacheState.VALID)) {
1903 throw new IllegalArgumentException("Use setValue() to set the state to VAL ID"); 1936 throw new IllegalArgumentException("Use setValue() to set the state to VAL ID");
1904 } else if (identical(state, CacheState.IN_PROCESS)) { 1937 } else if (identical(state, CacheState.IN_PROCESS)) {
1905 return currentValue; 1938 return currentValue;
1906 } 1939 }
1907 return currentValue &= ~bitMask; 1940 return BooleanArray.set2(currentValue, bitIndex, false);
1908 } 1941 }
1909 } 1942 }
1910 /** 1943 /**
1911 * Instances of the class `ResolutionState` represent the information produced b y resolving 1944 * Instances of the class `ResolutionState` represent the information produced b y resolving
1912 * a compilation unit as part of a specific library. 1945 * a compilation unit as part of a specific library.
1913 */ 1946 */
1914 class DartEntryImpl_ResolutionState { 1947 class DartEntryImpl_ResolutionState {
1915 1948
1916 /** 1949 /**
1917 * The next resolution state or `null` if none. 1950 * The next resolution state or `null` if none.
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 * @coverage dart.engine 2371 * @coverage dart.engine
2339 */ 2372 */
2340 abstract class SourceEntry { 2373 abstract class SourceEntry {
2341 2374
2342 /** 2375 /**
2343 * The data descriptor representing the line information. 2376 * The data descriptor representing the line information.
2344 */ 2377 */
2345 static final DataDescriptor<LineInfo> LINE_INFO = new DataDescriptor<LineInfo> ("SourceEntry.LINE_INFO"); 2378 static final DataDescriptor<LineInfo> LINE_INFO = new DataDescriptor<LineInfo> ("SourceEntry.LINE_INFO");
2346 2379
2347 /** 2380 /**
2381 * Return the exception that caused one or more values to have a state of [Cac heState#ERROR]
2382 * .
2383 *
2384 * @return the exception that caused one or more values to be uncomputable
2385 */
2386 AnalysisException get exception;
2387
2388 /**
2348 * Return the kind of the source, or `null` if the kind is not currently cache d. 2389 * Return the kind of the source, or `null` if the kind is not currently cache d.
2349 * 2390 *
2350 * @return the kind of the source 2391 * @return the kind of the source
2351 */ 2392 */
2352 SourceKind get kind; 2393 SourceKind get kind;
2353 2394
2354 /** 2395 /**
2355 * Return the most recent time at which the state of the source matched the st ate represented by 2396 * Return the most recent time at which the state of the source matched the st ate represented by
2356 * this entry. 2397 * this entry.
2357 * 2398 *
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 */ 2433 */
2393 abstract class SourceEntryImpl implements SourceEntry { 2434 abstract class SourceEntryImpl implements SourceEntry {
2394 2435
2395 /** 2436 /**
2396 * The most recent time at which the state of the source matched the state rep resented by this 2437 * The most recent time at which the state of the source matched the state rep resented by this
2397 * entry. 2438 * entry.
2398 */ 2439 */
2399 int _modificationTime = 0; 2440 int _modificationTime = 0;
2400 2441
2401 /** 2442 /**
2443 * The exception that caused one or more values to have a state of [CacheState #ERROR].
2444 */
2445 AnalysisException _exception;
2446
2447 /**
2402 * The state of the cached line information. 2448 * The state of the cached line information.
2403 */ 2449 */
2404 CacheState _lineInfoState = CacheState.INVALID; 2450 CacheState _lineInfoState = CacheState.INVALID;
2405 2451
2406 /** 2452 /**
2407 * The line information computed for the source, or `null` if the line informa tion is not 2453 * The line information computed for the source, or `null` if the line informa tion is not
2408 * currently cached. 2454 * currently cached.
2409 */ 2455 */
2410 LineInfo _lineInfo; 2456 LineInfo _lineInfo;
2457
2458 /**
2459 * Return the exception that caused one or more values to have a state of [Cac heState#ERROR]
2460 * .
2461 *
2462 * @return the exception that caused one or more values to be uncomputable
2463 */
2464 AnalysisException get exception => _exception;
2411 int get modificationTime => _modificationTime; 2465 int get modificationTime => _modificationTime;
2412 CacheState getState(DataDescriptor descriptor) { 2466 CacheState getState(DataDescriptor descriptor) {
2413 if (identical(descriptor, SourceEntry.LINE_INFO)) { 2467 if (identical(descriptor, SourceEntry.LINE_INFO)) {
2414 return _lineInfoState; 2468 return _lineInfoState;
2415 } else { 2469 } else {
2416 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 2470 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
2417 } 2471 }
2418 } 2472 }
2419 Object getValue(DataDescriptor descriptor) { 2473 Object getValue(DataDescriptor descriptor) {
2420 if (identical(descriptor, SourceEntry.LINE_INFO)) { 2474 if (identical(descriptor, SourceEntry.LINE_INFO)) {
2421 return _lineInfo as Object; 2475 return _lineInfo as Object;
2422 } else { 2476 } else {
2423 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 2477 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
2424 } 2478 }
2425 } 2479 }
2426 2480
2427 /** 2481 /**
2482 * Set the exception that caused one or more values to have a state of [CacheS tate#ERROR] to
2483 * the given exception.
2484 *
2485 * @param exception the exception that caused one or more values to be uncompu table
2486 */
2487 void set exception(AnalysisException exception2) {
2488 this._exception = exception2;
2489 }
2490
2491 /**
2428 * Set the most recent time at which the state of the source matched the state represented by this 2492 * Set the most recent time at which the state of the source matched the state represented by this
2429 * entry to the given time. 2493 * entry to the given time.
2430 * 2494 *
2431 * @param time the new modification time of this entry 2495 * @param time the new modification time of this entry
2432 */ 2496 */
2433 void set modificationTime(int time) { 2497 void set modificationTime(int time) {
2434 _modificationTime = time; 2498 _modificationTime = time;
2435 } 2499 }
2436 2500
2437 /** 2501 /**
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2509 builder.append(_modificationTime.toRadixString(16)); 2573 builder.append(_modificationTime.toRadixString(16));
2510 builder.append("; lineInfo = "); 2574 builder.append("; lineInfo = ");
2511 builder.append(_lineInfoState); 2575 builder.append(_lineInfoState);
2512 } 2576 }
2513 } 2577 }
2514 /** 2578 /**
2515 * Implementation of the [AnalysisContentStatistics]. 2579 * Implementation of the [AnalysisContentStatistics].
2516 */ 2580 */
2517 class AnalysisContentStatisticsImpl implements AnalysisContentStatistics { 2581 class AnalysisContentStatisticsImpl implements AnalysisContentStatistics {
2518 Map<String, AnalysisContentStatistics_CacheRow> _dataMap = new Map<String, Ana lysisContentStatistics_CacheRow>(); 2582 Map<String, AnalysisContentStatistics_CacheRow> _dataMap = new Map<String, Ana lysisContentStatistics_CacheRow>();
2583 Set<AnalysisException> _exceptions = new Set<AnalysisException>();
2519 List<AnalysisContentStatistics_CacheRow> get cacheRows { 2584 List<AnalysisContentStatistics_CacheRow> get cacheRows {
2520 Iterable<AnalysisContentStatistics_CacheRow> items = _dataMap.values; 2585 Iterable<AnalysisContentStatistics_CacheRow> items = _dataMap.values;
2521 return new List.from(items); 2586 return new List.from(items);
2522 } 2587 }
2588 List<AnalysisException> get exceptions => new List.from(_exceptions);
2523 void putCacheItem(DartEntry dartEntry, DataDescriptor descriptor) { 2589 void putCacheItem(DartEntry dartEntry, DataDescriptor descriptor) {
2524 putCacheItem3(descriptor, dartEntry.getState(descriptor)); 2590 putCacheItem3(dartEntry, descriptor, dartEntry.getState(descriptor));
2525 } 2591 }
2526 void putCacheItem2(DartEntry dartEntry, Source librarySource, DataDescriptor d escriptor) { 2592 void putCacheItem2(DartEntry dartEntry, Source librarySource, DataDescriptor d escriptor) {
2527 putCacheItem3(descriptor, dartEntry.getState2(descriptor, librarySource)); 2593 putCacheItem3(dartEntry, descriptor, dartEntry.getState2(descriptor, library Source));
2528 } 2594 }
2529 void putCacheItem3(DataDescriptor rowDesc, CacheState state) { 2595 void putCacheItem3(SourceEntry dartEntry, DataDescriptor rowDesc, CacheState s tate) {
2530 String rowName = rowDesc.toString(); 2596 String rowName = rowDesc.toString();
2531 AnalysisContentStatisticsImpl_CacheRowImpl row = _dataMap[rowName] as Analys isContentStatisticsImpl_CacheRowImpl; 2597 AnalysisContentStatisticsImpl_CacheRowImpl row = _dataMap[rowName] as Analys isContentStatisticsImpl_CacheRowImpl;
2532 if (row == null) { 2598 if (row == null) {
2533 row = new AnalysisContentStatisticsImpl_CacheRowImpl(rowName); 2599 row = new AnalysisContentStatisticsImpl_CacheRowImpl(rowName);
2534 _dataMap[rowName] = row; 2600 _dataMap[rowName] = row;
2535 } 2601 }
2536 row.incState(state); 2602 row.incState(state);
2603 if (identical(state, CacheState.ERROR)) {
2604 AnalysisException exception = dartEntry.exception;
2605 if (exception != null) {
2606 javaSetAdd(_exceptions, exception);
2607 }
2608 }
2537 } 2609 }
2538 } 2610 }
2539 class AnalysisContentStatisticsImpl_CacheRowImpl implements AnalysisContentStati stics_CacheRow { 2611 class AnalysisContentStatisticsImpl_CacheRowImpl implements AnalysisContentStati stics_CacheRow {
2540 String _name; 2612 String _name;
2541 int _errorCount = 0; 2613 int _errorCount = 0;
2542 int _flushedCount = 0; 2614 int _flushedCount = 0;
2543 int _inProcessCount = 0; 2615 int _inProcessCount = 0;
2544 int _invalidCount = 0; 2616 int _invalidCount = 0;
2545 int _validCount = 0; 2617 int _validCount = 0;
2546 AnalysisContentStatisticsImpl_CacheRowImpl(String name) { 2618 AnalysisContentStatisticsImpl_CacheRowImpl(String name) {
(...skipping 26 matching lines...) Expand all
2573 } 2645 }
2574 } 2646 }
2575 /** 2647 /**
2576 * Instances of the class `AnalysisContextImpl` implement an [AnalysisContext]. 2648 * Instances of the class `AnalysisContextImpl` implement an [AnalysisContext].
2577 * 2649 *
2578 * @coverage dart.engine 2650 * @coverage dart.engine
2579 */ 2651 */
2580 class AnalysisContextImpl implements InternalAnalysisContext { 2652 class AnalysisContextImpl implements InternalAnalysisContext {
2581 2653
2582 /** 2654 /**
2583 * Helper for [getStatistics], puts the library-specific state into the given statistics
2584 * object.
2585 */
2586 static void putStatCacheItem(AnalysisContentStatisticsImpl statistics, DartEnt ry dartEntry, Source librarySource, DataDescriptor key) {
2587 statistics.putCacheItem3(key, dartEntry.getState2(key, librarySource));
2588 }
2589
2590 /**
2591 * Helper for [getStatistics], puts the library independent state into the giv en
2592 * statistics object.
2593 */
2594 static void putStatCacheItem2(AnalysisContentStatisticsImpl statistics, Source Entry entry, DataDescriptor key) {
2595 statistics.putCacheItem3(key, entry.getState(key));
2596 }
2597
2598 /**
2599 * The set of analysis options controlling the behavior of this context. 2655 * The set of analysis options controlling the behavior of this context.
2600 */ 2656 */
2601 AnalysisOptions _options = new AnalysisOptionsImpl(); 2657 AnalysisOptions _options = new AnalysisOptionsImpl();
2602 2658
2603 /** 2659 /**
2604 * The source factory used to create the sources that can be analyzed in this context. 2660 * The source factory used to create the sources that can be analyzed in this context.
2605 */ 2661 */
2606 SourceFactory _sourceFactory; 2662 SourceFactory _sourceFactory;
2607 2663
2608 /** 2664 /**
2609 * A table mapping the sources known to the context to the information known a bout the source. 2665 * A table mapping the sources known to the context to the information known a bout the source.
2610 */ 2666 */
2611 Map<Source, SourceEntry> _sourceMap = new Map<Source, SourceEntry>(); 2667 AnalysisCache _cache = new AnalysisCache(_MAX_CACHE_SIZE);
2612
2613 /**
2614 * An array containing the order in which sources will be analyzed by the meth od
2615 * [performAnalysisTask].
2616 */
2617 List<Source> _priorityOrder = Source.EMPTY_ARRAY;
2618 2668
2619 /** 2669 /**
2620 * A table mapping sources to the change notices that are waiting to be return ed related to that 2670 * A table mapping sources to the change notices that are waiting to be return ed related to that
2621 * source. 2671 * source.
2622 */ 2672 */
2623 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm pl>(); 2673 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm pl>();
2624 2674
2625 /** 2675 /**
2626 * A list containing the most recently accessed sources with the most recently used at the end of 2676 * The object used to synchronize access to all of the caches. The rules relat ed to the use of
2627 * the list. When more sources are added than the maximum allowed then the lea st recently used 2677 * this lock object are
2628 * source will be removed and will have it's cached AST structure flushed. 2678 *
2629 */ 2679 * * no analysis work is done while holding the lock, and
2630 List<Source> _recentlyUsed = new List<Source>(); 2680 * * no analysis results can be recorded unless we have obtained the lock and validated that the
2631 2681 * results are for the same version (modification time) of the source as our c urrent cache
2632 /** 2682 * content.
2633 * The number of times that the flushing of information from the cache has bee n disabled without 2683 *
2634 * being re-enabled.
2635 */
2636 int _cacheRemovalCount = 0;
2637
2638 /**
2639 * The object used to synchronize access to all of the caches.
2640 */ 2684 */
2641 Object _cacheLock = new Object(); 2685 Object _cacheLock = new Object();
2642 2686
2643 /** 2687 /**
2688 * The object used to record the results of performing an analysis task.
2689 */
2690 AnalysisContextImpl_AnalysisTaskResultRecorder _resultRecorder;
2691
2692 /**
2644 * The maximum number of sources for which data should be kept in the cache. 2693 * The maximum number of sources for which data should be kept in the cache.
2645 */ 2694 */
2646 static int _MAX_CACHE_SIZE = 64; 2695 static int _MAX_CACHE_SIZE = 64;
2647 2696
2648 /** 2697 /**
2649 * The maximum number of sources that can be on the priority list. This <b>mus t</b> be less than 2698 * The maximum number of sources that can be on the priority list. This <b>mus t</b> be less than
2650 * the [MAX_CACHE_SIZE] in order to prevent an infinite loop in performAnalysi sTask(). 2699 * the [MAX_CACHE_SIZE] in order to prevent an infinite loop in performAnalysi sTask().
2651 * 2700 *
2652 * @see #setAnalysisPriorityOrder(List) 2701 * @see #setAnalysisPriorityOrder(List)
2653 */ 2702 */
2654 static int _MAX_PRIORITY_LIST_SIZE = _MAX_CACHE_SIZE - 4; 2703 static int _MAX_PRIORITY_LIST_SIZE = _MAX_CACHE_SIZE - 4;
2655 2704
2656 /** 2705 /**
2657 * The name of the 'src' attribute in a HTML tag.
2658 */
2659 static String _ATTRIBUTE_SRC = "src";
2660
2661 /**
2662 * The name of the 'type' attribute in a HTML tag.
2663 */
2664 static String _ATTRIBUTE_TYPE = "type";
2665
2666 /**
2667 * The name of the 'script' tag in an HTML file.
2668 */
2669 static String _TAG_SCRIPT = "script";
2670
2671 /**
2672 * The value of the 'type' attribute of a 'script' tag that indicates that the script is written
2673 * in Dart.
2674 */
2675 static String _TYPE_DART = "application/dart";
2676
2677 /**
2678 * Initialize a newly created analysis context. 2706 * Initialize a newly created analysis context.
2679 */ 2707 */
2680 AnalysisContextImpl() : super() { 2708 AnalysisContextImpl() : super() {
2681 if (AnalysisEngine.instance.useExperimentalContext) { 2709 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this);
2682 throw new RuntimeException("Should not be creating an instance of Analysis ContextImpl");
2683 }
2684 } 2710 }
2685 void addSourceInfo(Source source, SourceEntry info) { 2711 void addSourceInfo(Source source, SourceEntry info) {
2686 _sourceMap[source] = info; 2712 _cache.put(source, info);
2687 } 2713 }
2688 void applyChanges(ChangeSet changeSet) { 2714 void applyChanges(ChangeSet changeSet) {
2689 if (changeSet.isEmpty) { 2715 if (changeSet.isEmpty) {
2690 return; 2716 return;
2691 } 2717 }
2692 { 2718 {
2693 List<Source> removedSources = new List<Source>.from(changeSet.removed3); 2719 List<Source> removedSources = new List<Source>.from(changeSet.removed3);
2694 for (SourceContainer container in changeSet.removedContainers) { 2720 for (SourceContainer container in changeSet.removedContainers) {
2695 addSourcesInContainer(removedSources, container); 2721 addSourcesInContainer(removedSources, container);
2696 } 2722 }
2697 bool addedDartSource = false; 2723 bool addedDartSource = false;
2698 for (Source source in changeSet.added3) { 2724 for (Source source in changeSet.added3) {
2699 if (sourceAvailable(source)) { 2725 if (sourceAvailable(source)) {
2700 addedDartSource = true; 2726 addedDartSource = true;
2701 } 2727 }
2702 } 2728 }
2703 for (Source source in changeSet.changed3) { 2729 for (Source source in changeSet.changed3) {
2704 sourceChanged(source); 2730 sourceChanged(source);
2705 } 2731 }
2706 for (Source source in removedSources) { 2732 for (Source source in removedSources) {
2707 sourceRemoved(source); 2733 sourceRemoved(source);
2708 } 2734 }
2709 if (addedDartSource) { 2735 if (addedDartSource) {
2710 for (MapEntry<Source, SourceEntry> mapEntry in getMapEntrySet(_sourceMap )) { 2736 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
2711 if (!mapEntry.getKey().isInSystemLibrary && mapEntry.getValue() is Dar tEntry) { 2737 SourceEntry sourceEntry = mapEntry.getValue();
2712 DartEntryImpl dartCopy = ((mapEntry.getValue() as DartEntry)).writab leCopy; 2738 if (!mapEntry.getKey().isInSystemLibrary && sourceEntry is DartEntry) {
2739 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
2713 dartCopy.invalidateAllResolutionInformation(); 2740 dartCopy.invalidateAllResolutionInformation();
2714 mapEntry.setValue(dartCopy); 2741 mapEntry.setValue(dartCopy);
2715 } 2742 }
2716 } 2743 }
2717 } 2744 }
2718 } 2745 }
2719 } 2746 }
2720 String computeDocumentationComment(Element element) { 2747 String computeDocumentationComment(Element element) {
2721 if (element == null) { 2748 if (element == null) {
2722 return null; 2749 return null;
(...skipping 26 matching lines...) Expand all
2749 } 2776 }
2750 nameNode = nameNode.parent; 2777 nameNode = nameNode.parent;
2751 } 2778 }
2752 return null; 2779 return null;
2753 } 2780 }
2754 List<AnalysisError> computeErrors(Source source) { 2781 List<AnalysisError> computeErrors(Source source) {
2755 SourceEntry sourceEntry = getReadableSourceEntry(source); 2782 SourceEntry sourceEntry = getReadableSourceEntry(source);
2756 if (sourceEntry is DartEntry) { 2783 if (sourceEntry is DartEntry) {
2757 List<AnalysisError> errors = new List<AnalysisError>(); 2784 List<AnalysisError> errors = new List<AnalysisError>();
2758 DartEntry dartEntry = sourceEntry as DartEntry; 2785 DartEntry dartEntry = sourceEntry as DartEntry;
2759 ListUtilities.addAll(errors, internalGetDartParseData(source, dartEntry, D artEntry.PARSE_ERRORS)); 2786 ListUtilities.addAll(errors, getDartParseData(source, dartEntry, DartEntry .PARSE_ERRORS));
2787 dartEntry = getReadableDartEntry(source);
2760 if (identical(dartEntry.getValue(DartEntry.SOURCE_KIND), SourceKind.LIBRAR Y)) { 2788 if (identical(dartEntry.getValue(DartEntry.SOURCE_KIND), SourceKind.LIBRAR Y)) {
2761 ListUtilities.addAll(errors, internalGetDartResolutionData(source, sourc e, dartEntry, DartEntry.RESOLUTION_ERRORS)); 2789 ListUtilities.addAll(errors, getDartResolutionData(source, source, dartE ntry, DartEntry.RESOLUTION_ERRORS));
2790 ListUtilities.addAll(errors, getDartHintData(source, source, dartEntry, DartEntry.HINTS));
2762 } else { 2791 } else {
2763 List<Source> libraries = getLibrariesContaining(source); 2792 List<Source> libraries = getLibrariesContaining(source);
2764 for (Source librarySource in libraries) { 2793 for (Source librarySource in libraries) {
2765 ListUtilities.addAll(errors, internalGetDartResolutionData(source, lib rarySource, dartEntry, DartEntry.RESOLUTION_ERRORS)); 2794 ListUtilities.addAll(errors, getDartResolutionData(source, librarySour ce, dartEntry, DartEntry.RESOLUTION_ERRORS));
2795 ListUtilities.addAll(errors, getDartHintData(source, librarySource, da rtEntry, DartEntry.HINTS));
2766 } 2796 }
2767 } 2797 }
2768 if (errors.isEmpty) { 2798 if (errors.isEmpty) {
2769 return AnalysisError.NO_ERRORS; 2799 return AnalysisError.NO_ERRORS;
2770 } 2800 }
2771 return new List.from(errors); 2801 return new List.from(errors);
2772 } else if (sourceEntry is HtmlEntry) { 2802 } else if (sourceEntry is HtmlEntry) {
2773 HtmlEntry htmlEntry = sourceEntry as HtmlEntry; 2803 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
2774 return internalGetHtmlResolutionData(source, htmlEntry, HtmlEntry.RESOLUTI ON_ERRORS, AnalysisError.NO_ERRORS); 2804 return getHtmlResolutionData2(source, htmlEntry, HtmlEntry.RESOLUTION_ERRO RS);
2775 } 2805 }
2776 return AnalysisError.NO_ERRORS; 2806 return AnalysisError.NO_ERRORS;
2777 } 2807 }
2778 List<Source> computeExportedLibraries(Source source) => internalGetDartParseDa ta2(source, DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY); 2808 List<Source> computeExportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY);
2779 HtmlElement computeHtmlElement(Source source) { 2809 HtmlElement computeHtmlElement(Source source) => getHtmlResolutionData(source, HtmlEntry.ELEMENT, null);
2780 HtmlEntry htmlEntry = getReadableHtmlEntry(source); 2810 List<Source> computeImportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY);
2781 if (htmlEntry == null) {
2782 return null;
2783 }
2784 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
2785 if (elementState != CacheState.ERROR && elementState != CacheState.VALID) {
2786 htmlEntry = internalResolveHtml(source);
2787 }
2788 return htmlEntry.getValue(HtmlEntry.ELEMENT);
2789 }
2790 List<Source> computeImportedLibraries(Source source) => internalGetDartParseDa ta2(source, DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY);
2791 SourceKind computeKindOf(Source source) { 2811 SourceKind computeKindOf(Source source) {
2792 SourceEntry sourceEntry = getReadableSourceEntry(source); 2812 SourceEntry sourceEntry = getReadableSourceEntry(source);
2793 if (sourceEntry == null) { 2813 if (sourceEntry == null) {
2794 return SourceKind.UNKNOWN; 2814 return SourceKind.UNKNOWN;
2795 } else if (sourceEntry is DartEntry) { 2815 } else if (sourceEntry is DartEntry) {
2796 try { 2816 try {
2797 return internalGetDartParseData(source, sourceEntry as DartEntry, DartEn try.SOURCE_KIND); 2817 return getDartParseData(source, sourceEntry as DartEntry, DartEntry.SOUR CE_KIND);
2798 } on AnalysisException catch (exception) { 2818 } on AnalysisException catch (exception) {
2799 return SourceKind.UNKNOWN; 2819 return SourceKind.UNKNOWN;
2800 } 2820 }
2801 } 2821 }
2802 return sourceEntry.kind; 2822 return sourceEntry.kind;
2803 } 2823 }
2804 LibraryElement computeLibraryElement(Source source) { 2824 LibraryElement computeLibraryElement(Source source) => getDartResolutionData2( source, source, DartEntry.ELEMENT, null);
2805 {
2806 DartEntry dartEntry = getDartEntry(source);
2807 if (dartEntry == null) {
2808 return null;
2809 }
2810 LibraryElement element = dartEntry.getValue(DartEntry.ELEMENT);
2811 if (element == null) {
2812 LibraryResolver resolver = new LibraryResolver(this);
2813 try {
2814 element = resolver.resolveLibrary(source, true);
2815 recordResolutionResults(resolver);
2816 } on AnalysisException catch (exception) {
2817 DartEntryImpl dartCopy = getDartEntry(source).writableCopy;
2818 dartCopy.recordResolutionError();
2819 _sourceMap[source] = dartCopy;
2820 AnalysisEngine.instance.logger.logError2("Could not resolve the librar y ${source.fullName}", exception);
2821 }
2822 }
2823 return element;
2824 }
2825 }
2826 LineInfo computeLineInfo(Source source) { 2825 LineInfo computeLineInfo(Source source) {
2827 SourceEntry sourceEntry = getReadableSourceEntry(source); 2826 SourceEntry sourceEntry = getReadableSourceEntry(source);
2828 if (sourceEntry is HtmlEntry) { 2827 if (sourceEntry is HtmlEntry) {
2829 return internalGetHtmlParseData(source, SourceEntry.LINE_INFO, null); 2828 return getHtmlParseData(source, SourceEntry.LINE_INFO, null);
2830 } else if (sourceEntry is DartEntry) { 2829 } else if (sourceEntry is DartEntry) {
2831 return internalGetDartParseData2(source, SourceEntry.LINE_INFO, null); 2830 return getDartParseData2(source, SourceEntry.LINE_INFO, null);
2832 } 2831 }
2833 return null; 2832 return null;
2834 } 2833 }
2835 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) { 2834 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) {
2836 while (true) { 2835 while (true) {
2837 { 2836 {
2838 SourceEntry sourceEntry = getSourceEntry(source); 2837 DartEntry dartEntry = getReadableDartEntry(source);
2839 if (sourceEntry is! DartEntry) { 2838 if (dartEntry == null) {
2840 throw new AnalysisException.con1("computeResolvableCompilationUnit for non-Dart: ${source.fullName}"); 2839 throw new AnalysisException.con1("computeResolvableCompilationUnit for non-Dart: ${source.fullName}");
2841 } 2840 }
2842 DartEntry dartEntry = sourceEntry as DartEntry;
2843 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.ERRO R)) { 2841 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.ERRO R)) {
2844 throw new AnalysisException.con1("Internal error: computeResolvableCom pilationUnit could not parse ${source.fullName}"); 2842 throw new AnalysisException.con1("Internal error: computeResolvableCom pilationUnit could not parse ${source.fullName}");
2845 } 2843 }
2846 DartEntryImpl dartCopy = dartEntry.writableCopy; 2844 DartEntryImpl dartCopy = dartEntry.writableCopy;
2847 CompilationUnit unit = dartCopy.resolvableCompilationUnit; 2845 CompilationUnit unit = dartCopy.resolvableCompilationUnit;
2848 if (unit != null) { 2846 if (unit != null) {
2849 _sourceMap[source] = dartCopy; 2847 _cache.put(source, dartCopy);
2850 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit); 2848 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit);
2851 } 2849 }
2852 } 2850 }
2853 internalParseDart(source); 2851 cacheDartParseData(source, getReadableDartEntry(source), DartEntry.PARSED_ UNIT);
2854 } 2852 }
2855 } 2853 }
2856 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) { 2854 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) {
2857 HtmlEntry htmlEntry = getReadableHtmlEntry(source); 2855 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
2858 if (htmlEntry == null) { 2856 if (htmlEntry == null) {
2859 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}"); 2857 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}");
2860 } 2858 }
2861 htmlEntry = internalCacheHtmlParseData(source, htmlEntry, [HtmlEntry.PARSED_ UNIT]); 2859 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT);
2862 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT); 2860 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
2863 if (unit == null) { 2861 if (unit == null) {
2864 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}"); 2862 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}");
2865 } 2863 }
2866 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit); 2864 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
2867 } 2865 }
2868 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context); 2866 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context);
2869 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) { 2867 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
2870 List<Source> sourcesToRemove = new List<Source>(); 2868 List<Source> sourcesToRemove = new List<Source>();
2871 { 2869 {
2872 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 2870 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
2873 Source source = entry.getKey(); 2871 Source source = entry.getKey();
2874 if (container.contains(source)) { 2872 if (container.contains(source)) {
2875 sourcesToRemove.add(source); 2873 sourcesToRemove.add(source);
2876 newContext.addSourceInfo(source, entry.getValue().writableCopy); 2874 newContext.addSourceInfo(source, entry.getValue().writableCopy);
2877 } 2875 }
2878 } 2876 }
2879 } 2877 }
2880 return newContext; 2878 return newContext;
2881 } 2879 }
2882 AnalysisOptions get analysisOptions => _options; 2880 AnalysisOptions get analysisOptions => _options;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 SourceKind sourceKind = getKindOf(source); 2916 SourceKind sourceKind = getKindOf(source);
2919 if (sourceKind == null) { 2917 if (sourceKind == null) {
2920 return Source.EMPTY_ARRAY; 2918 return Source.EMPTY_ARRAY;
2921 } 2919 }
2922 { 2920 {
2923 List<Source> htmlSources = new List<Source>(); 2921 List<Source> htmlSources = new List<Source>();
2924 while (true) { 2922 while (true) {
2925 if (sourceKind == SourceKind.LIBRARY) { 2923 if (sourceKind == SourceKind.LIBRARY) {
2926 } else if (sourceKind == SourceKind.PART) { 2924 } else if (sourceKind == SourceKind.PART) {
2927 List<Source> librarySources = getLibrariesContaining(source); 2925 List<Source> librarySources = getLibrariesContaining(source);
2928 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap) ) { 2926 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
2929 SourceEntry sourceEntry = entry.getValue(); 2927 SourceEntry sourceEntry = entry.getValue();
2930 if (identical(sourceEntry.kind, SourceKind.HTML)) { 2928 if (identical(sourceEntry.kind, SourceKind.HTML)) {
2931 List<Source> referencedLibraries = ((sourceEntry as HtmlEntry)).ge tValue(HtmlEntry.REFERENCED_LIBRARIES); 2929 List<Source> referencedLibraries = ((sourceEntry as HtmlEntry)).ge tValue(HtmlEntry.REFERENCED_LIBRARIES);
2932 if (containsAny(referencedLibraries, librarySources)) { 2930 if (containsAny(referencedLibraries, librarySources)) {
2933 htmlSources.add(entry.getKey()); 2931 htmlSources.add(entry.getKey());
2934 } 2932 }
2935 } 2933 }
2936 } 2934 }
2937 } 2935 }
2938 break; 2936 break;
2939 } 2937 }
2940 if (htmlSources.isEmpty) { 2938 if (htmlSources.isEmpty) {
2941 return Source.EMPTY_ARRAY; 2939 return Source.EMPTY_ARRAY;
2942 } 2940 }
2943 return new List.from(htmlSources); 2941 return new List.from(htmlSources);
2944 } 2942 }
2945 } 2943 }
2946 List<Source> get htmlSources => getSources(SourceKind.HTML); 2944 List<Source> get htmlSources => getSources(SourceKind.HTML);
2947 SourceKind getKindOf(Source source) { 2945 SourceKind getKindOf(Source source) {
2948 SourceEntry sourceEntry = getReadableSourceEntry(source); 2946 SourceEntry sourceEntry = getReadableSourceEntry(source);
2949 if (sourceEntry == null) { 2947 if (sourceEntry == null) {
2950 return SourceKind.UNKNOWN; 2948 return SourceKind.UNKNOWN;
2951 } 2949 }
2952 return sourceEntry.kind; 2950 return sourceEntry.kind;
2953 } 2951 }
2954 List<Source> get launchableClientLibrarySources { 2952 List<Source> get launchableClientLibrarySources {
2955 List<Source> sources = new List<Source>(); 2953 List<Source> sources = new List<Source>();
2956 { 2954 {
2957 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 2955 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
2958 Source source = entry.getKey(); 2956 Source source = entry.getKey();
2959 SourceEntry sourceEntry = entry.getValue(); 2957 SourceEntry sourceEntry = entry.getValue();
2960 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) { 2958 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
2961 sources.add(source); 2959 sources.add(source);
2962 } 2960 }
2963 } 2961 }
2964 } 2962 }
2965 return new List.from(sources); 2963 return new List.from(sources);
2966 } 2964 }
2967 List<Source> get launchableServerLibrarySources { 2965 List<Source> get launchableServerLibrarySources {
2968 List<Source> sources = new List<Source>(); 2966 List<Source> sources = new List<Source>();
2969 { 2967 {
2970 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 2968 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
2971 Source source = entry.getKey(); 2969 Source source = entry.getKey();
2972 SourceEntry sourceEntry = entry.getValue(); 2970 SourceEntry sourceEntry = entry.getValue();
2973 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) { 2971 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
2974 sources.add(source); 2972 sources.add(source);
2975 } 2973 }
2976 } 2974 }
2977 } 2975 }
2978 return new List.from(sources); 2976 return new List.from(sources);
2979 } 2977 }
2980 List<Source> getLibrariesContaining(Source source) { 2978 List<Source> getLibrariesContaining(Source source) {
2981 { 2979 {
2982 SourceEntry sourceEntry = _sourceMap[source]; 2980 SourceEntry sourceEntry = _cache.get(source);
2983 if (sourceEntry != null && identical(sourceEntry.kind, SourceKind.LIBRARY) ) { 2981 if (sourceEntry == null || sourceEntry.kind != SourceKind.PART) {
2984 return <Source> [source]; 2982 return <Source> [source];
2985 } 2983 }
2986 List<Source> librarySources = new List<Source>(); 2984 List<Source> librarySources = new List<Source>();
2987 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 2985 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
2988 sourceEntry = entry.getValue(); 2986 sourceEntry = entry.getValue();
2989 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) { 2987 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) {
2990 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.INCLUDED_ PARTS), source)) { 2988 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.INCLUDED_ PARTS), source)) {
2991 librarySources.add(entry.getKey()); 2989 librarySources.add(entry.getKey());
2992 } 2990 }
2993 } 2991 }
2994 } 2992 }
2995 if (librarySources.isEmpty) { 2993 if (librarySources.isEmpty) {
2996 return Source.EMPTY_ARRAY; 2994 return Source.EMPTY_ARRAY;
2997 } 2995 }
2998 return new List.from(librarySources); 2996 return new List.from(librarySources);
2999 } 2997 }
3000 } 2998 }
3001 List<Source> getLibrariesDependingOn(Source librarySource) { 2999 List<Source> getLibrariesDependingOn(Source librarySource) {
3002 { 3000 {
3003 List<Source> dependentLibraries = new List<Source>(); 3001 List<Source> dependentLibraries = new List<Source>();
3004 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 3002 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3005 SourceEntry sourceEntry = entry.getValue(); 3003 SourceEntry sourceEntry = entry.getValue();
3006 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) { 3004 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) {
3007 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.EXPORTED_ LIBRARIES), librarySource)) { 3005 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.EXPORTED_ LIBRARIES), librarySource)) {
3008 dependentLibraries.add(entry.getKey()); 3006 dependentLibraries.add(entry.getKey());
3009 } 3007 }
3010 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.IMPORTED_ LIBRARIES), librarySource)) { 3008 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.IMPORTED_ LIBRARIES), librarySource)) {
3011 dependentLibraries.add(entry.getKey()); 3009 dependentLibraries.add(entry.getKey());
3012 } 3010 }
3013 } 3011 }
3014 } 3012 }
(...skipping 17 matching lines...) Expand all
3032 return sourceEntry.getValue(SourceEntry.LINE_INFO); 3030 return sourceEntry.getValue(SourceEntry.LINE_INFO);
3033 } 3031 }
3034 return null; 3032 return null;
3035 } 3033 }
3036 Namespace getPublicNamespace(LibraryElement library) { 3034 Namespace getPublicNamespace(LibraryElement library) {
3037 Source source = library.definingCompilationUnit.source; 3035 Source source = library.definingCompilationUnit.source;
3038 DartEntry dartEntry = getReadableDartEntry(source); 3036 DartEntry dartEntry = getReadableDartEntry(source);
3039 if (dartEntry == null) { 3037 if (dartEntry == null) {
3040 return null; 3038 return null;
3041 } 3039 }
3042 { 3040 Namespace namespace = null;
3043 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); 3041 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
3044 if (namespace == null) { 3042 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
3045 NamespaceBuilder builder = new NamespaceBuilder(); 3043 }
3046 namespace = builder.createPublicNamespace(library); 3044 if (namespace == null) {
3047 DartEntryImpl dartCopy = getDartEntry(source).writableCopy; 3045 NamespaceBuilder builder = new NamespaceBuilder();
3048 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); 3046 namespace = builder.createPublicNamespace(library);
3049 _sourceMap[source] = dartCopy; 3047 {
3048 dartEntry = getReadableDartEntry(source);
3049 if (dartEntry == null) {
3050 AnalysisEngine.instance.logger.logError3(new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}"));
3051 return null;
3052 }
3053 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
3054 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
3055 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
3056 _cache.put(source, dartCopy);
3057 }
3050 } 3058 }
3051 return namespace;
3052 } 3059 }
3060 return namespace;
3053 } 3061 }
3054 Namespace getPublicNamespace2(Source source) { 3062 Namespace getPublicNamespace2(Source source) {
3055 DartEntry dartEntry = getReadableDartEntry(source); 3063 DartEntry dartEntry = getReadableDartEntry(source);
3056 if (dartEntry == null) { 3064 if (dartEntry == null) {
3057 return null; 3065 return null;
3058 } 3066 }
3059 { 3067 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
3060 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); 3068 if (namespace == null) {
3061 if (namespace == null) { 3069 LibraryElement library = computeLibraryElement(source);
3062 LibraryElement library = computeLibraryElement(source); 3070 if (library == null) {
3063 if (library == null) { 3071 return null;
3064 return null; 3072 }
3073 NamespaceBuilder builder = new NamespaceBuilder();
3074 namespace = builder.createPublicNamespace(library);
3075 {
3076 dartEntry = getReadableDartEntry(source);
3077 if (dartEntry == null) {
3078 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
3065 } 3079 }
3066 NamespaceBuilder builder = new NamespaceBuilder(); 3080 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
3067 namespace = builder.createPublicNamespace(library); 3081 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
3068 DartEntryImpl dartCopy = getDartEntry(source).writableCopy; 3082 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
3069 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); 3083 _cache.put(source, dartCopy);
3070 _sourceMap[source] = dartCopy; 3084 }
3071 } 3085 }
3072 return namespace;
3073 } 3086 }
3087 return namespace;
3074 } 3088 }
3075 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) { 3089 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
3076 if (library == null) { 3090 if (library == null) {
3077 return null; 3091 return null;
3078 } 3092 }
3079 return getResolvedCompilationUnit2(unitSource, library.source); 3093 return getResolvedCompilationUnit2(unitSource, library.source);
3080 } 3094 }
3081 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) { 3095 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
3082 SourceEntry sourceEntry = getReadableSourceEntry(unitSource); 3096 SourceEntry sourceEntry = getReadableSourceEntry(unitSource);
3083 if (sourceEntry is DartEntry) { 3097 if (sourceEntry is DartEntry) {
3084 return ((sourceEntry as DartEntry)).getValue2(DartEntry.RESOLVED_UNIT, lib rarySource); 3098 return ((sourceEntry as DartEntry)).getValue2(DartEntry.RESOLVED_UNIT, lib rarySource);
3085 } 3099 }
3086 return null; 3100 return null;
3087 } 3101 }
3088 SourceFactory get sourceFactory => _sourceFactory; 3102 SourceFactory get sourceFactory => _sourceFactory;
3089 3103
3090 /** 3104 /**
3091 * Return a list of the sources that would be processed by [performAnalysisTas k]. This 3105 * Return a list of the sources that would be processed by [performAnalysisTas k]. This
3092 * method is intended to be used for testing purposes only. 3106 * method duplicates, and must therefore be kept in sync with, [getNextTaskAna lysisTask].
3107 * This method is intended to be used for testing purposes only.
3093 * 3108 *
3094 * @return a list of the sources that would be processed by [performAnalysisTa sk] 3109 * @return a list of the sources that would be processed by [performAnalysisTa sk]
3095 */ 3110 */
3096 List<Source> get sourcesNeedingProcessing { 3111 List<Source> get sourcesNeedingProcessing {
3097 List<Source> sources = new List<Source>(); 3112 Set<Source> sources = new Set<Source>();
3098 { 3113 {
3099 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 3114 for (Source source in _cache.priorityOrder) {
3100 SourceEntry sourceEntry = entry.getValue(); 3115 SourceEntry sourceEntry = _cache.get(source);
3101 if (sourceEntry is DartEntry) { 3116 if (sourceEntry is DartEntry) {
3102 DartEntry dartEntry = sourceEntry as DartEntry; 3117 DartEntry dartEntry = sourceEntry as DartEntry;
3103 CacheState parsedUnitState = dartEntry.getState(DartEntry.PARSED_UNIT) ; 3118 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERROR S);
3104 CacheState elementState = dartEntry.getState(DartEntry.ELEMENT); 3119 if (identical(parseErrorsState, CacheState.INVALID) || identical(parse ErrorsState, CacheState.FLUSHED)) {
3105 if (identical(parsedUnitState, CacheState.INVALID) || identical(elemen tState, CacheState.INVALID)) { 3120 javaSetAdd(sources, source);
3106 sources.add(entry.getKey()); 3121 }
3122 CompilationUnit parseUnit = dartEntry.anyParsedCompilationUnit;
3123 if (parseUnit == null) {
3124 javaSetAdd(sources, source);
3125 }
3126 for (Source librarySource in getLibrariesContaining(source)) {
3127 SourceEntry libraryEntry = _cache.get(librarySource);
3128 if (libraryEntry is DartEntry) {
3129 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT) ;
3130 if (identical(elementState, CacheState.INVALID) || identical(eleme ntState, CacheState.FLUSHED)) {
3131 javaSetAdd(sources, source);
3132 }
3133 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOL VED_UNIT, librarySource);
3134 if (identical(resolvedUnitState, CacheState.INVALID) || identical( resolvedUnitState, CacheState.FLUSHED)) {
3135 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
3136 if (libraryElement != null) {
3137 javaSetAdd(sources, source);
3138 }
3139 }
3140 CacheState hintsState = dartEntry.getState2(DartEntry.HINTS, libra rySource);
3141 if (identical(hintsState, CacheState.INVALID) || identical(hintsSt ate, CacheState.FLUSHED)) {
3142 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
3143 if (libraryElement != null) {
3144 javaSetAdd(sources, source);
3145 }
3146 }
3147 }
3107 } 3148 }
3108 } else if (sourceEntry is HtmlEntry) { 3149 } else if (sourceEntry is HtmlEntry) {
3109 HtmlEntry htmlEntry = sourceEntry as HtmlEntry; 3150 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
3110 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ; 3151 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ;
3152 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsed UnitState, CacheState.FLUSHED)) {
3153 javaSetAdd(sources, source);
3154 }
3111 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT); 3155 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
3112 if (identical(parsedUnitState, CacheState.INVALID) || identical(elemen tState, CacheState.INVALID)) { 3156 if (identical(elementState, CacheState.INVALID) || identical(elementSt ate, CacheState.FLUSHED)) {
3113 sources.add(entry.getKey()); 3157 javaSetAdd(sources, source);
3158 }
3159 }
3160 }
3161 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3162 SourceEntry sourceEntry = entry.getValue();
3163 if (sourceEntry is DartEntry) {
3164 DartEntry dartEntry = sourceEntry as DartEntry;
3165 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.IN VALID)) {
3166 javaSetAdd(sources, entry.getKey());
3167 }
3168 } else if (sourceEntry is HtmlEntry) {
3169 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
3170 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.IN VALID)) {
3171 javaSetAdd(sources, entry.getKey());
3172 }
3173 }
3174 }
3175 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3176 SourceEntry sourceEntry = entry.getValue();
3177 if (sourceEntry is DartEntry) {
3178 DartEntry dartEntry = sourceEntry as DartEntry;
3179 if (identical(dartEntry.kind, SourceKind.LIBRARY) && identical(dartEnt ry.getState(DartEntry.ELEMENT), CacheState.INVALID)) {
3180 javaSetAdd(sources, entry.getKey());
3181 } else if (identical(dartEntry.getState2(DartEntry.HINTS, entry.getKey ()), CacheState.INVALID)) {
3182 javaSetAdd(sources, entry.getKey());
3183 }
3184 } else if (sourceEntry is HtmlEntry) {
3185 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
3186 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALI D)) {
3187 javaSetAdd(sources, entry.getKey());
3114 } 3188 }
3115 } 3189 }
3116 } 3190 }
3117 } 3191 }
3118 return sources; 3192 return new List<Source>.from(sources);
3119 } 3193 }
3120 AnalysisContentStatistics get statistics { 3194 AnalysisContentStatistics get statistics {
3121 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl (); 3195 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl ();
3122 { 3196 {
3123 for (MapEntry<Source, SourceEntry> mapEntry in getMapEntrySet(_sourceMap)) { 3197 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
3124 SourceEntry entry = mapEntry.getValue(); 3198 SourceEntry entry = mapEntry.getValue();
3125 if (entry is DartEntry) { 3199 if (entry is DartEntry) {
3126 Source source = mapEntry.getKey(); 3200 Source source = mapEntry.getKey();
3127 DartEntry dartEntry = entry as DartEntry; 3201 DartEntry dartEntry = entry as DartEntry;
3128 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND); 3202 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND);
3129 putStatCacheItem2(statistics, dartEntry, DartEntry.PARSE_ERRORS); 3203 statistics.putCacheItem(dartEntry, DartEntry.PARSE_ERRORS);
3130 putStatCacheItem2(statistics, dartEntry, DartEntry.PARSED_UNIT); 3204 statistics.putCacheItem(dartEntry, DartEntry.PARSED_UNIT);
3131 putStatCacheItem2(statistics, dartEntry, DartEntry.SOURCE_KIND); 3205 statistics.putCacheItem(dartEntry, DartEntry.SOURCE_KIND);
3132 putStatCacheItem2(statistics, dartEntry, DartEntry.LINE_INFO); 3206 statistics.putCacheItem(dartEntry, DartEntry.LINE_INFO);
3133 if (identical(kind, SourceKind.LIBRARY)) { 3207 if (identical(kind, SourceKind.LIBRARY)) {
3134 putStatCacheItem2(statistics, dartEntry, DartEntry.ELEMENT); 3208 statistics.putCacheItem(dartEntry, DartEntry.ELEMENT);
3135 putStatCacheItem2(statistics, dartEntry, DartEntry.EXPORTED_LIBRARIE S); 3209 statistics.putCacheItem(dartEntry, DartEntry.EXPORTED_LIBRARIES);
3136 putStatCacheItem2(statistics, dartEntry, DartEntry.IMPORTED_LIBRARIE S); 3210 statistics.putCacheItem(dartEntry, DartEntry.IMPORTED_LIBRARIES);
3137 putStatCacheItem2(statistics, dartEntry, DartEntry.INCLUDED_PARTS); 3211 statistics.putCacheItem(dartEntry, DartEntry.INCLUDED_PARTS);
3138 putStatCacheItem2(statistics, dartEntry, DartEntry.IS_CLIENT); 3212 statistics.putCacheItem(dartEntry, DartEntry.IS_CLIENT);
3139 putStatCacheItem2(statistics, dartEntry, DartEntry.IS_LAUNCHABLE); 3213 statistics.putCacheItem(dartEntry, DartEntry.IS_LAUNCHABLE);
3140 } 3214 }
3141 List<Source> librarySources = getLibrariesContaining(source); 3215 List<Source> librarySources = getLibrariesContaining(source);
3142 for (Source librarySource in librarySources) { 3216 for (Source librarySource in librarySources) {
3143 putStatCacheItem(statistics, dartEntry, librarySource, DartEntry.RES OLUTION_ERRORS); 3217 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.HINTS);
3144 putStatCacheItem(statistics, dartEntry, librarySource, DartEntry.RES OLVED_UNIT); 3218 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLUT ION_ERRORS);
3219 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLVE D_UNIT);
3145 } 3220 }
3146 } 3221 }
3147 } 3222 }
3148 } 3223 }
3149 return statistics; 3224 return statistics;
3150 } 3225 }
3226 TimestampedData<CompilationUnit> internalResolveCompilationUnit(Source unitSou rce, LibraryElement libraryElement) {
3227 DartEntry dartEntry = getReadableDartEntry(unitSource);
3228 if (dartEntry == null) {
3229 throw new AnalysisException.con1("internalResolveCompilationUnit invoked f or non-Dart file: ${unitSource.fullName}");
3230 }
3231 Source librarySource = libraryElement.source;
3232 dartEntry = cacheDartResolutionData(unitSource, librarySource, dartEntry, Da rtEntry.RESOLVED_UNIT);
3233 return new TimestampedData<CompilationUnit>(dartEntry.modificationTime, dart Entry.getValue2(DartEntry.RESOLVED_UNIT, librarySource));
3234 }
3151 bool isClientLibrary(Source librarySource) { 3235 bool isClientLibrary(Source librarySource) {
3152 SourceEntry sourceEntry = getReadableSourceEntry(librarySource); 3236 SourceEntry sourceEntry = getReadableSourceEntry(librarySource);
3153 if (sourceEntry is DartEntry) { 3237 if (sourceEntry is DartEntry) {
3154 DartEntry dartEntry = sourceEntry as DartEntry; 3238 DartEntry dartEntry = sourceEntry as DartEntry;
3155 return dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(DartE ntry.IS_LAUNCHABLE); 3239 return dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(DartE ntry.IS_LAUNCHABLE);
3156 } 3240 }
3157 return false; 3241 return false;
3158 } 3242 }
3159 bool isServerLibrary(Source librarySource) { 3243 bool isServerLibrary(Source librarySource) {
3160 SourceEntry sourceEntry = getReadableSourceEntry(librarySource); 3244 SourceEntry sourceEntry = getReadableSourceEntry(librarySource);
3161 if (sourceEntry is DartEntry) { 3245 if (sourceEntry is DartEntry) {
3162 DartEntry dartEntry = sourceEntry as DartEntry; 3246 DartEntry dartEntry = sourceEntry as DartEntry;
3163 return !dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(Dart Entry.IS_LAUNCHABLE); 3247 return !dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(Dart Entry.IS_LAUNCHABLE);
3164 } 3248 }
3165 return false; 3249 return false;
3166 } 3250 }
3167 void mergeContext(AnalysisContext context) { 3251 void mergeContext(AnalysisContext context) {
3168 if (context is InstrumentedAnalysisContextImpl) { 3252 if (context is InstrumentedAnalysisContextImpl) {
3169 context = ((context as InstrumentedAnalysisContextImpl)).basis; 3253 context = ((context as InstrumentedAnalysisContextImpl)).basis;
3170 } 3254 }
3171 if (context is! AnalysisContextImpl) { 3255 if (context is! AnalysisContextImpl) {
3172 return; 3256 return;
3173 } 3257 }
3174 { 3258 {
3175 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(((context as An alysisContextImpl))._sourceMap)) { 3259 for (MapEntry<Source, SourceEntry> entry in ((context as AnalysisContextIm pl))._cache.entrySet()) {
3176 Source newSource = entry.getKey(); 3260 Source newSource = entry.getKey();
3177 SourceEntry existingEntry = getSourceEntry(newSource); 3261 SourceEntry existingEntry = getReadableSourceEntry(newSource);
3178 if (existingEntry == null) { 3262 if (existingEntry == null) {
3179 _sourceMap[newSource] = entry.getValue().writableCopy; 3263 _cache.put(newSource, entry.getValue().writableCopy);
3180 } else { 3264 } else {
3181 } 3265 }
3182 } 3266 }
3183 } 3267 }
3184 } 3268 }
3185 CompilationUnit parseCompilationUnit(Source source) { 3269 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null);
3186 DartEntry dartEntry = getReadableDartEntry(source); 3270 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA RSED_UNIT, null);
3187 if (dartEntry == null) { 3271 List<ChangeNotice> performAnalysisTask() {
3188 return null; 3272 AnalysisTask task = nextTaskAnalysisTask;
3273 if (task == null) {
3274 return getChangeNotices(true);
3189 } 3275 }
3190 CompilationUnit unit = dartEntry.anyParsedCompilationUnit; 3276 try {
3191 if (unit == null) { 3277 task.perform(_resultRecorder);
3192 CacheState state = dartEntry.getState(DartEntry.PARSED_UNIT); 3278 } on AnalysisException catch (exception) {
3193 while (state != CacheState.VALID && state != CacheState.ERROR) { 3279 if (exception.cause is! JavaIOException) {
3194 dartEntry = internalParseDart(source); 3280 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception);
3195 state = dartEntry.getState(DartEntry.PARSED_UNIT);
3196 } 3281 }
3197 unit = dartEntry.anyParsedCompilationUnit;
3198 } 3282 }
3199 return unit; 3283 return getChangeNotices(false);
3200 }
3201 HtmlUnit parseHtmlUnit(Source source) => internalGetHtmlParseData(source, Html Entry.PARSED_UNIT, null);
3202 List<ChangeNotice> performAnalysisTask() {
3203 {
3204 if (!performSingleAnalysisTask() && _pendingNotices.isEmpty) {
3205 return null;
3206 }
3207 if (_pendingNotices.isEmpty) {
3208 return ChangeNoticeImpl.EMPTY_ARRAY;
3209 }
3210 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
3211 _pendingNotices.clear();
3212 return notices;
3213 }
3214 } 3284 }
3215 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 3285 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
3216 { 3286 {
3217 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); 3287 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML);
3218 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) { 3288 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
3219 Source librarySource = entry.getKey(); 3289 Source librarySource = entry.getKey();
3220 LibraryElement library = entry.getValue(); 3290 LibraryElement library = entry.getValue();
3221 DartEntry dartEntry = getDartEntry(librarySource); 3291 DartEntry dartEntry = getReadableDartEntry(librarySource);
3222 if (dartEntry != null) { 3292 if (dartEntry != null) {
3223 DartEntryImpl dartCopy = dartEntry.writableCopy; 3293 DartEntryImpl dartCopy = dartEntry.writableCopy;
3224 recordElementData(dartCopy, library, htmlSource); 3294 recordElementData(dartCopy, library, htmlSource);
3225 _sourceMap[librarySource] = dartCopy; 3295 _cache.put(librarySource, dartCopy);
3226 } 3296 }
3227 } 3297 }
3228 } 3298 }
3229 } 3299 }
3230 CompilationUnit resolveCompilationUnit(Source source2, LibraryElement library) { 3300 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) {
3231 if (library == null) { 3301 if (library == null) {
3232 return null; 3302 return null;
3233 } 3303 }
3234 return resolveCompilationUnit2(source2, library.source); 3304 return resolveCompilationUnit2(unitSource, library.source);
3235 } 3305 }
3236 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) { 3306 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT, null);
3237 { 3307 HtmlUnit resolveHtmlUnit(Source htmlSource) => parseHtmlUnit(htmlSource);
3238 accessed(unitSource);
3239 DartEntry dartEntry = getDartEntry(unitSource);
3240 if (dartEntry == null) {
3241 return null;
3242 }
3243 CompilationUnit unit = dartEntry.getValue2(DartEntry.RESOLVED_UNIT, librar ySource);
3244 if (unit == null) {
3245 disableCacheRemoval();
3246 try {
3247 LibraryElement libraryElement = computeLibraryElement(librarySource);
3248 unit = dartEntry.getValue2(DartEntry.RESOLVED_UNIT, librarySource);
3249 if (unit == null && libraryElement != null) {
3250 Source coreLibrarySource = libraryElement.context.sourceFactory.forU ri(DartSdk.DART_CORE);
3251 LibraryElement coreElement = computeLibraryElement(coreLibrarySource );
3252 TypeProvider typeProvider = new TypeProviderImpl(coreElement);
3253 ResolvableCompilationUnit resolvableUnit = computeResolvableCompilat ionUnit(unitSource);
3254 CompilationUnit unitAST = resolvableUnit.compilationUnit;
3255 new DeclarationResolver().resolve(unitAST, find(libraryElement, unit Source));
3256 RecordingErrorListener errorListener = new RecordingErrorListener();
3257 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.co n2(libraryElement, unitSource, typeProvider, errorListener);
3258 unitAST.accept(typeResolverVisitor);
3259 InheritanceManager inheritanceManager = new InheritanceManager(libra ryElement);
3260 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(libraryEl ement, unitSource, typeProvider, inheritanceManager, errorListener);
3261 unitAST.accept(resolverVisitor);
3262 for (ProxyConditionalAnalysisError conditionalCode in resolverVisito r.proxyConditionalAnalysisErrors) {
3263 if (conditionalCode.shouldIncludeErrorCode()) {
3264 resolverVisitor.reportError(conditionalCode.analysisError);
3265 }
3266 }
3267 ErrorReporter errorReporter = new ErrorReporter(errorListener, unitS ource);
3268 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, libra ryElement, typeProvider, inheritanceManager);
3269 unitAST.accept(errorVerifier);
3270 ConstantVerifier constantVerifier = new ConstantVerifier(errorReport er, typeProvider);
3271 unitAST.accept(constantVerifier);
3272 unitAST.resolutionErrors = errorListener.errors;
3273 DartEntryImpl dartCopy = getDartEntry(unitSource).writableCopy;
3274 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unitAST);
3275 _sourceMap[unitSource] = dartCopy;
3276 unit = unitAST;
3277 }
3278 } finally {
3279 enableCacheRemoval();
3280 }
3281 }
3282 return unit;
3283 }
3284 }
3285 HtmlUnit resolveHtmlUnit(Source source) => parseHtmlUnit(source);
3286 void set analysisOptions(AnalysisOptions options2) { 3308 void set analysisOptions(AnalysisOptions options2) {
3287 { 3309 {
3288 this._options = options2; 3310 this._options = options2;
3289 invalidateAllResults(); 3311 invalidateAllResolutionInformation();
3290 } 3312 }
3291 } 3313 }
3292 void set analysisPriorityOrder(List<Source> sources) { 3314 void set analysisPriorityOrder(List<Source> sources) {
3293 { 3315 {
3294 if (sources == null || sources.isEmpty) { 3316 if (sources == null || sources.isEmpty) {
3295 _priorityOrder = Source.EMPTY_ARRAY; 3317 _cache.priorityOrder = Source.EMPTY_ARRAY;
3296 } else { 3318 } else {
3297 while (sources.remove(null)) { 3319 while (sources.remove(null)) {
3298 } 3320 }
3321 if (sources.isEmpty) {
3322 _cache.priorityOrder = Source.EMPTY_ARRAY;
3323 }
3299 int count = Math.min(sources.length, _MAX_PRIORITY_LIST_SIZE); 3324 int count = Math.min(sources.length, _MAX_PRIORITY_LIST_SIZE);
3300 _priorityOrder = new List<Source>(count); 3325 List<Source> priorityOrder = new List<Source>(count);
3301 for (int i = 0; i < count; i++) { 3326 for (int i = 0; i < count; i++) {
3302 _priorityOrder[i] = sources[i]; 3327 priorityOrder[i] = sources[i];
3303 } 3328 }
3329 _cache.priorityOrder = priorityOrder;
3304 } 3330 }
3305 } 3331 }
3306 } 3332 }
3307 void setContents(Source source, String contents) { 3333 void setContents(Source source, String contents) {
3308 { 3334 {
3309 if (_sourceFactory.setContents(source, contents)) { 3335 if (_sourceFactory.setContents(source, contents)) {
3310 sourceChanged(source); 3336 sourceChanged(source);
3311 } 3337 }
3312 } 3338 }
3313 } 3339 }
3314 void set sourceFactory(SourceFactory factory) { 3340 void set sourceFactory(SourceFactory factory) {
3315 { 3341 {
3316 if (identical(_sourceFactory, factory)) { 3342 if (identical(_sourceFactory, factory)) {
3317 return; 3343 return;
3318 } else if (factory.context != null) { 3344 } else if (factory.context != null) {
3319 throw new IllegalStateException("Source factories cannot be shared betwe en contexts"); 3345 throw new IllegalStateException("Source factories cannot be shared betwe en contexts");
3320 } 3346 }
3321 if (_sourceFactory != null) { 3347 if (_sourceFactory != null) {
3322 _sourceFactory.context = null; 3348 _sourceFactory.context = null;
3323 } 3349 }
3324 factory.context = this; 3350 factory.context = this;
3325 _sourceFactory = factory; 3351 _sourceFactory = factory;
3326 invalidateAllResults(); 3352 invalidateAllResolutionInformation();
3327 } 3353 }
3328 } 3354 }
3329 Iterable<Source> sourcesToResolve(List<Source> changedSources) { 3355 Iterable<Source> sourcesToResolve(List<Source> changedSources) {
3330 List<Source> librarySources = new List<Source>(); 3356 List<Source> librarySources = new List<Source>();
3331 for (Source source in changedSources) { 3357 for (Source source in changedSources) {
3332 if (identical(computeKindOf(source), SourceKind.LIBRARY)) { 3358 if (identical(computeKindOf(source), SourceKind.LIBRARY)) {
3333 librarySources.add(source); 3359 librarySources.add(source);
3334 } 3360 }
3335 } 3361 }
3336 return librarySources; 3362 return librarySources;
3337 } 3363 }
3338 3364
3339 /** 3365 /**
3340 * Record that the given source was just accessed for some unspecified purpose .
3341 *
3342 * Note: This method must only be invoked while we are synchronized on [cacheL ock].
3343 *
3344 * @param source the source that was accessed
3345 */
3346 void accessed(Source source) {
3347 if (_recentlyUsed.remove(source)) {
3348 _recentlyUsed.add(source);
3349 return;
3350 }
3351 if (_cacheRemovalCount == 0 && _recentlyUsed.length >= _MAX_CACHE_SIZE) {
3352 flushAstFromCache();
3353 }
3354 _recentlyUsed.add(source);
3355 }
3356
3357 /**
3358 * Add all of the sources contained in the given source container to the given list of sources. 3366 * Add all of the sources contained in the given source container to the given list of sources.
3359 * 3367 *
3360 * Note: This method must only be invoked while we are synchronized on [cacheL ock]. 3368 * Note: This method must only be invoked while we are synchronized on [cacheL ock].
3361 * 3369 *
3362 * @param sources the list to which sources are to be added 3370 * @param sources the list to which sources are to be added
3363 * @param container the source container containing the sources to be added to the list 3371 * @param container the source container containing the sources to be added to the list
3364 */ 3372 */
3365 void addSourcesInContainer(List<Source> sources, SourceContainer container) { 3373 void addSourcesInContainer(List<Source> sources, SourceContainer container) {
3366 for (Source source in _sourceMap.keys.toSet()) { 3374 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
3375 Source source = entry.getKey();
3367 if (container.contains(source)) { 3376 if (container.contains(source)) {
3368 sources.add(source); 3377 sources.add(source);
3369 } 3378 }
3370 } 3379 }
3371 } 3380 }
3372 3381
3373 /** 3382 /**
3383 * Return `true` if the modification times of the sources used by the given li brary resolver
3384 * to resolve one or more libraries are consistent with the modification times in the cache.
3385 *
3386 * @param resolver the library resolver used to resolve one or more libraries
3387 * @return `true` if we should record the results of the resolution
3388 * @throws AnalysisException if any of the modification times could not be det ermined (this should
3389 * not happen)
3390 */
3391 bool allModificationTimesMatch(LibraryResolver resolver) {
3392 bool allTimesMatch = true;
3393 for (Library library in resolver.resolvedLibraries) {
3394 for (Source source in library.compilationUnitSources) {
3395 DartEntry dartEntry = getReadableDartEntry(source);
3396 if (dartEntry == null) {
3397 throw new AnalysisException.con1("Internal error: attempting to reolve non-Dart file as a Dart file: ${source.fullName}");
3398 }
3399 int sourceTime = source.modificationStamp;
3400 int resultTime = library.getModificationTime(source);
3401 if (sourceTime != resultTime) {
3402 sourceChanged(source);
3403 allTimesMatch = false;
3404 }
3405 }
3406 }
3407 return allTimesMatch;
3408 }
3409
3410 /**
3411 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
3412 * the data represented by the given descriptor is available. This method assu mes that the data
3413 * can be produced by generating hints for the library if the data is not alre ady cached.
3414 *
3415 * @param unitSource the source representing the Dart file
3416 * @param librarySource the source representing the library containing the Dar t file
3417 * @param dartEntry the cache entry associated with the Dart file
3418 * @param descriptor the descriptor representing the data to be returned
3419 * @return a cache entry containing the required data
3420 * @throws AnalysisException if data could not be returned because the source could not be parsed
3421 */
3422 DartEntry cacheDartHintData(Source unitSource, Source librarySource, DartEntry dartEntry, DataDescriptor descriptor) {
3423 CacheState state = dartEntry.getState2(descriptor, librarySource);
3424 while (state != CacheState.ERROR && state != CacheState.VALID) {
3425 dartEntry = new GenerateDartHintsTask(this, getLibraryElement(librarySourc e)).perform(_resultRecorder) as DartEntry;
3426 state = dartEntry.getState2(descriptor, librarySource);
3427 }
3428 return dartEntry;
3429 }
3430
3431 /**
3432 * Given a source for a Dart file, return a cache entry in which the data repr esented by the given
3433 * descriptor is available. This method assumes that the data can be produced by parsing the
3434 * source if it is not already cached.
3435 *
3436 * @param source the source representing the Dart file
3437 * @param dartEntry the cache entry associated with the Dart file
3438 * @param descriptor the descriptor representing the data to be returned
3439 * @return a cache entry containing the required data
3440 * @throws AnalysisException if data could not be returned because the source could not be
3441 * resolved
3442 */
3443 DartEntry cacheDartParseData(Source source, DartEntry dartEntry, DataDescripto r descriptor) {
3444 if (identical(descriptor, DartEntry.PARSED_UNIT)) {
3445 CompilationUnit unit = dartEntry.anyParsedCompilationUnit;
3446 if (unit != null) {
3447 return dartEntry;
3448 }
3449 }
3450 CacheState state = dartEntry.getState(descriptor);
3451 while (state != CacheState.ERROR && state != CacheState.VALID) {
3452 dartEntry = new ParseDartTask(this, source).perform(_resultRecorder) as Da rtEntry;
3453 state = dartEntry.getState(descriptor);
3454 }
3455 return dartEntry;
3456 }
3457
3458 /**
3459 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
3460 * the data represented by the given descriptor is available. This method assu mes that the data
3461 * can be produced by resolving the source in the context of the library if it is not already
3462 * cached.
3463 *
3464 * @param unitSource the source representing the Dart file
3465 * @param librarySource the source representing the library containing the Dar t file
3466 * @param dartEntry the cache entry associated with the Dart file
3467 * @param descriptor the descriptor representing the data to be returned
3468 * @return a cache entry containing the required data
3469 * @throws AnalysisException if data could not be returned because the source could not be parsed
3470 */
3471 DartEntry cacheDartResolutionData(Source unitSource, Source librarySource, Dar tEntry dartEntry, DataDescriptor descriptor) {
3472 CacheState state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.ge tState(descriptor) : dartEntry.getState2(descriptor, librarySource);
3473 while (state != CacheState.ERROR && state != CacheState.VALID) {
3474 dartEntry = new ResolveDartLibraryTask(this, unitSource, librarySource).pe rform(_resultRecorder) as DartEntry;
3475 state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.getState(de scriptor) : dartEntry.getState2(descriptor, librarySource);
3476 }
3477 return dartEntry;
3478 }
3479
3480 /**
3481 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by
3482 * the given descriptors is available. This method assumes that the data can b e produced by
3483 * parsing the source if it is not already cached.
3484 *
3485 * @param source the source representing the HTML file
3486 * @param htmlEntry the cache entry associated with the HTML file
3487 * @param descriptor the descriptor representing the data to be returned
3488 * @return a cache entry containing the required data
3489 * @throws AnalysisException if data could not be returned because the source could not be
3490 * resolved
3491 */
3492 HtmlEntry cacheHtmlParseData(Source source, HtmlEntry htmlEntry, DataDescripto r descriptor) {
3493 CacheState state = htmlEntry.getState(descriptor);
3494 while (state != CacheState.ERROR && state != CacheState.VALID) {
3495 htmlEntry = new ParseHtmlTask(this, source).perform(_resultRecorder) as Ht mlEntry;
3496 state = htmlEntry.getState(descriptor);
3497 }
3498 return htmlEntry;
3499 }
3500
3501 /**
3502 * Given a source for an HTML file, return a cache entry in which the the data represented by the
3503 * given descriptor is available. This method assumes that the data can be pro duced by resolving
3504 * the source if it is not already cached.
3505 *
3506 * @param source the source representing the HTML file
3507 * @param dartEntry the cache entry associated with the HTML file
3508 * @param descriptor the descriptor representing the data to be returned
3509 * @return a cache entry containing the required data
3510 * @throws AnalysisException if data could not be returned because the source could not be
3511 * resolved
3512 */
3513 HtmlEntry cacheHtmlResolutionData(Source source, HtmlEntry htmlEntry, DataDesc riptor descriptor) {
3514 CacheState state = htmlEntry.getState(descriptor);
3515 while (state != CacheState.ERROR && state != CacheState.VALID) {
3516 htmlEntry = new ResolveHtmlTask(this, source).perform(_resultRecorder) as HtmlEntry;
3517 state = htmlEntry.getState(descriptor);
3518 }
3519 return htmlEntry;
3520 }
3521
3522 /**
3374 * Given the encoded form of a source, use the source factory to reconstitute the original source. 3523 * Given the encoded form of a source, use the source factory to reconstitute the original source.
3375 * 3524 *
3376 * @param encoding the encoded form of a source 3525 * @param encoding the encoded form of a source
3377 * @return the source represented by the encoding 3526 * @return the source represented by the encoding
3378 */ 3527 */
3379 Source computeSourceFromEncoding(String encoding) { 3528 Source computeSourceFromEncoding(String encoding) {
3380 { 3529 {
3381 return _sourceFactory.fromEncoding(encoding); 3530 return _sourceFactory.fromEncoding(encoding);
3382 } 3531 }
3383 } 3532 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 * object that was created, or `null` if the source should not be tracked by t his context. 3568 * object that was created, or `null` if the source should not be tracked by t his context.
3420 * 3569 *
3421 * @param source the source for which an information object is being created 3570 * @param source the source for which an information object is being created
3422 * @return the source information object that was created 3571 * @return the source information object that was created
3423 */ 3572 */
3424 SourceEntry createSourceEntry(Source source) { 3573 SourceEntry createSourceEntry(Source source) {
3425 String name = source.shortName; 3574 String name = source.shortName;
3426 if (AnalysisEngine.isHtmlFileName(name)) { 3575 if (AnalysisEngine.isHtmlFileName(name)) {
3427 HtmlEntryImpl htmlEntry = new HtmlEntryImpl(); 3576 HtmlEntryImpl htmlEntry = new HtmlEntryImpl();
3428 htmlEntry.modificationTime = source.modificationStamp; 3577 htmlEntry.modificationTime = source.modificationStamp;
3429 _sourceMap[source] = htmlEntry; 3578 _cache.put(source, htmlEntry);
3430 return htmlEntry; 3579 return htmlEntry;
3431 } else { 3580 } else {
3432 DartEntryImpl dartEntry = new DartEntryImpl(); 3581 DartEntryImpl dartEntry = new DartEntryImpl();
3433 dartEntry.modificationTime = source.modificationStamp; 3582 dartEntry.modificationTime = source.modificationStamp;
3434 _sourceMap[source] = dartEntry; 3583 _cache.put(source, dartEntry);
3435 return dartEntry; 3584 return dartEntry;
3436 } 3585 }
3437 } 3586 }
3438 3587
3439 /** 3588 /**
3440 * Disable flushing information from the cache until [enableCacheRemoval] has been 3589 * Return an array containing all of the change notices that are waiting to be returned. If there
3441 * called. 3590 * are no notices, then return either `null` or an empty array, depending on t he value of
3442 */ 3591 * the argument.
3443 void disableCacheRemoval() { 3592 *
3444 _cacheRemovalCount++; 3593 * @param nullIfEmpty `true` if `null` should be returned when there are no no tices
3445 } 3594 * @return the change notices that are waiting to be returned
3446 3595 */
3447 /** 3596 List<ChangeNotice> getChangeNotices(bool nullIfEmpty) {
3448 * Re-enable flushing information from the cache.
3449 */
3450 void enableCacheRemoval() {
3451 if (_cacheRemovalCount > 0) {
3452 _cacheRemovalCount--;
3453 }
3454 if (_cacheRemovalCount == 0) {
3455 while (_recentlyUsed.length >= _MAX_CACHE_SIZE) {
3456 flushAstFromCache();
3457 }
3458 }
3459 }
3460
3461 /**
3462 * Search the compilation units that are part of the given library and return the element
3463 * representing the compilation unit with the given source. Return `null` if t here is no
3464 * such compilation unit.
3465 *
3466 * @param libraryElement the element representing the library being searched t hrough
3467 * @param unitSource the source for the compilation unit whose element is to b e returned
3468 * @return the element representing the compilation unit
3469 */
3470 CompilationUnitElement find(LibraryElement libraryElement, Source unitSource) {
3471 CompilationUnitElement element = libraryElement.definingCompilationUnit;
3472 if (element.source == unitSource) {
3473 return element;
3474 }
3475 for (CompilationUnitElement partElement in libraryElement.parts) {
3476 if (partElement.source == unitSource) {
3477 return partElement;
3478 }
3479 }
3480 return null;
3481 }
3482
3483 /**
3484 * Flush one AST structure from the cache.
3485 *
3486 * Note: This method must only be invoked while we are synchronized on [cacheL ock].
3487 */
3488 void flushAstFromCache() {
3489 Source removedSource = removeAstToFlush();
3490 SourceEntry sourceEntry = _sourceMap[removedSource];
3491 if (sourceEntry is HtmlEntry) {
3492 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
3493 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED);
3494 _sourceMap[removedSource] = htmlCopy;
3495 } else if (sourceEntry is DartEntry) {
3496 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
3497 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
3498 for (Source librarySource in getLibrariesContaining(removedSource)) {
3499 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState.FL USHED);
3500 }
3501 _sourceMap[removedSource] = dartCopy;
3502 }
3503 }
3504
3505 /**
3506 * Return the compilation unit information associated with the given source, o r `null` if
3507 * the source is not known to this context. This method should be used to acce ss the compilation
3508 * unit information rather than accessing the compilation unit map directly be cause sources in the
3509 * SDK are implicitly part of every analysis context and are therefore only ad ded to the map when
3510 * first accessed.
3511 *
3512 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
3513 *
3514 * @param source the source for which information is being sought
3515 * @return the compilation unit information associated with the given source
3516 */
3517 DartEntry getDartEntry(Source source) {
3518 SourceEntry sourceEntry = getSourceEntry(source);
3519 if (sourceEntry == null) {
3520 sourceEntry = new DartEntryImpl();
3521 _sourceMap[source] = sourceEntry;
3522 return sourceEntry as DartEntry;
3523 } else if (sourceEntry is DartEntry) {
3524 return sourceEntry as DartEntry;
3525 }
3526 return null;
3527 }
3528
3529 /**
3530 * Return the sources of libraries that are referenced in the specified HTML f ile.
3531 *
3532 * @param htmlSource the source of the HTML file being analyzed
3533 * @param htmlUnit the AST for the HTML file being analyzed
3534 * @return the sources of libraries that are referenced in the HTML file
3535 */
3536 List<Source> getLibrarySources2(Source htmlSource, HtmlUnit htmlUnit) {
3537 List<Source> libraries = new List<Source>();
3538 htmlUnit.accept(new RecursiveXmlVisitor_6(this, htmlSource, libraries));
3539 if (libraries.isEmpty) {
3540 return Source.EMPTY_ARRAY;
3541 }
3542 return new List.from(libraries);
3543 }
3544
3545 /**
3546 * Look through the cache for a task that needs to be performed. Return the ta sk that was found,
3547 * or `null` if there is no more work to be done.
3548 *
3549 * @return the next task that needs to be performed
3550 */
3551 AnalysisContextImpl_AnalysisTask get nextTaskAnalysisTask {
3552 { 3597 {
3553 for (Source source in _priorityOrder) { 3598 if (_pendingNotices.isEmpty) {
3554 SourceEntry sourceEntry = _sourceMap[source]; 3599 if (nullIfEmpty) {
3555 if (sourceEntry is DartEntry) { 3600 return null;
3556 DartEntry dartEntry = sourceEntry as DartEntry;
3557 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERROR S);
3558 if (identical(parseErrorsState, CacheState.INVALID) || identical(parse ErrorsState, CacheState.FLUSHED)) {
3559 DartEntryImpl dartCopy = dartEntry.writableCopy;
3560 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
3561 _sourceMap[source] = dartCopy;
3562 return new AnalysisContextImpl_ParseDartTask(this, source);
3563 }
3564 CacheState parseUnitState = dartEntry.getState(DartEntry.PARSED_UNIT);
3565 if (identical(parseUnitState, CacheState.INVALID) || identical(parseUn itState, CacheState.FLUSHED)) {
3566 DartEntryImpl dartCopy = dartEntry.writableCopy;
3567 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS);
3568 _sourceMap[source] = dartCopy;
3569 return new AnalysisContextImpl_ParseDartTask(this, source);
3570 }
3571 for (Source librarySource in getLibrariesContaining(source)) {
3572 SourceEntry libraryEntry = _sourceMap[librarySource];
3573 if (libraryEntry is DartEntry) {
3574 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT) ;
3575 if (identical(elementState, CacheState.INVALID) || identical(eleme ntState, CacheState.FLUSHED)) {
3576 DartEntryImpl libraryCopy = ((libraryEntry as DartEntry)).writab leCopy;
3577 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
3578 _sourceMap[librarySource] = libraryCopy;
3579 return new AnalysisContextImpl_ResolveDartLibraryTask(this, libr arySource);
3580 }
3581 }
3582 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOLVE D_UNIT, librarySource);
3583 if (identical(resolvedUnitState, CacheState.INVALID) || identical(re solvedUnitState, CacheState.FLUSHED)) {
3584 DartEntryImpl dartCopy = dartEntry.writableCopy;
3585 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheSt ate.IN_PROCESS);
3586 _sourceMap[source] = dartCopy;
3587 return new AnalysisContextImpl_ResolveDartUnitTask(this, source, l ibrarySource);
3588 }
3589 }
3590 } else if (sourceEntry is HtmlEntry) {
3591 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
3592 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ;
3593 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsed UnitState, CacheState.FLUSHED)) {
3594 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
3595 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
3596 _sourceMap[source] = htmlCopy;
3597 return new AnalysisContextImpl_ParseHtmlTask(this, source);
3598 }
3599 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
3600 if (identical(elementState, CacheState.INVALID) || identical(elementSt ate, CacheState.FLUSHED)) {
3601 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
3602 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
3603 _sourceMap[source] = htmlCopy;
3604 return new AnalysisContextImpl_ResolveHtmlTask(this, source);
3605 }
3606 } 3601 }
3607 } 3602 return ChangeNoticeImpl.EMPTY_ARRAY;
3608 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 3603 }
3609 SourceEntry sourceEntry = entry.getValue(); 3604 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
3610 if (sourceEntry is DartEntry) { 3605 _pendingNotices.clear();
3611 DartEntry dartEntry = sourceEntry as DartEntry; 3606 return notices;
3612 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.IN VALID)) { 3607 }
3613 Source source = entry.getKey(); 3608 }
3614 DartEntryImpl dartCopy = dartEntry.writableCopy; 3609
3615 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS); 3610 /**
3616 _sourceMap[source] = dartCopy; 3611 * Given a source for a Dart file and the library that contains it, return the data represented by
3617 return new AnalysisContextImpl_ParseDartTask(this, source); 3612 * the given descriptor that is associated with that source. This method assum es that the data can
3618 } 3613 * be produced by generating hints for the library if it is not already cached .
3619 } else if (sourceEntry is HtmlEntry) {
3620 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
3621 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.IN VALID)) {
3622 Source source = entry.getKey();
3623 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
3624 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
3625 _sourceMap[source] = htmlCopy;
3626 return new AnalysisContextImpl_ParseHtmlTask(this, source);
3627 }
3628 }
3629 }
3630 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) {
3631 SourceEntry sourceEntry = entry.getValue();
3632 if (sourceEntry is DartEntry && identical(sourceEntry.kind, SourceKind.L IBRARY)) {
3633 DartEntry dartEntry = sourceEntry as DartEntry;
3634 if (identical(dartEntry.getState(DartEntry.ELEMENT), CacheState.INVALI D)) {
3635 Source source = entry.getKey();
3636 DartEntryImpl dartCopy = dartEntry.writableCopy;
3637 dartCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
3638 _sourceMap[source] = dartCopy;
3639 return new AnalysisContextImpl_ResolveDartLibraryTask(this, source);
3640 }
3641 } else if (sourceEntry is HtmlEntry) {
3642 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
3643 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALI D)) {
3644 Source source = entry.getKey();
3645 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
3646 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
3647 _sourceMap[source] = htmlCopy;
3648 return new AnalysisContextImpl_ResolveHtmlTask(this, source);
3649 }
3650 }
3651 }
3652 return null;
3653 }
3654 }
3655
3656 /**
3657 * Return a change notice for the given source, creating one if one does not a lready exist.
3658 *
3659 * @param source the source for which changes are being reported
3660 * @return a change notice for the given source
3661 */
3662 ChangeNoticeImpl getNotice(Source source) {
3663 ChangeNoticeImpl notice = _pendingNotices[source];
3664 if (notice == null) {
3665 notice = new ChangeNoticeImpl(source);
3666 _pendingNotices[source] = notice;
3667 }
3668 return notice;
3669 }
3670
3671 /**
3672 * Return the cache entry associated with the given source, or `null` if the s ource is not a
3673 * Dart file.
3674 *
3675 * @param source the source for which a cache entry is being sought
3676 * @return the source cache entry associated with the given source
3677 */
3678 DartEntry getReadableDartEntry(Source source) {
3679 {
3680 SourceEntry sourceEntry = _sourceMap[source];
3681 if (sourceEntry == null) {
3682 sourceEntry = createSourceEntry(source);
3683 }
3684 if (sourceEntry is DartEntry) {
3685 accessed(source);
3686 return sourceEntry as DartEntry;
3687 }
3688 return null;
3689 }
3690 }
3691
3692 /**
3693 * Return the cache entry associated with the given source, or `null` if the s ource is not
3694 * an HTML file.
3695 *
3696 * @param source the source for which a cache entry is being sought
3697 * @return the source cache entry associated with the given source
3698 */
3699 HtmlEntry getReadableHtmlEntry(Source source) {
3700 {
3701 SourceEntry sourceEntry = _sourceMap[source];
3702 if (sourceEntry == null) {
3703 sourceEntry = createSourceEntry(source);
3704 }
3705 if (sourceEntry is HtmlEntry) {
3706 accessed(source);
3707 return sourceEntry as HtmlEntry;
3708 }
3709 return null;
3710 }
3711 }
3712
3713 /**
3714 * Return the cache entry associated with the given source, or `null` if there is no entry
3715 * associated with the source.
3716 *
3717 * @param source the source for which a cache entry is being sought
3718 * @return the source cache entry associated with the given source
3719 */
3720 SourceEntry getReadableSourceEntry(Source source) {
3721 {
3722 SourceEntry sourceEntry = _sourceMap[source];
3723 if (sourceEntry == null) {
3724 sourceEntry = createSourceEntry(source);
3725 }
3726 if (sourceEntry != null) {
3727 accessed(source);
3728 }
3729 return sourceEntry;
3730 }
3731 }
3732
3733 /**
3734 * Return the source information associated with the given source, or `null` i f the source
3735 * is not known to this context. This method should be used to access the sour ce information
3736 * rather than accessing the source map directly because sources in the SDK ar e implicitly part of
3737 * every analysis context and are therefore only added to the map when first a ccessed.
3738 *
3739 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
3740 *
3741 * @param source the source for which information is being sought
3742 * @return the source information associated with the given source
3743 */
3744 SourceEntry getSourceEntry(Source source) {
3745 SourceEntry sourceEntry = _sourceMap[source];
3746 if (sourceEntry == null) {
3747 sourceEntry = createSourceEntry(source);
3748 }
3749 return sourceEntry;
3750 }
3751
3752 /**
3753 * Return an array containing all of the sources known to this context that ha ve the given kind.
3754 *
3755 * @param kind the kind of sources to be returned
3756 * @return all of the sources known to this context that have the given kind
3757 */
3758 List<Source> getSources(SourceKind kind2) {
3759 List<Source> sources = new List<Source>();
3760 {
3761 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) {
3762 if (identical(entry.getValue().kind, kind2)) {
3763 sources.add(entry.getKey());
3764 }
3765 }
3766 }
3767 return new List.from(sources);
3768 }
3769
3770 /**
3771 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by
3772 * the given descriptors is available. This method assumes that the data can b e produced by
3773 * parsing the source if it is not already cached.
3774 *
3775 * @param htmlEntry the cache entry associated with the HTML file
3776 * @param descriptor the descriptor representing the data to be returned
3777 * @return a cache entry containing the required data
3778 */
3779 bool hasHtmlParseDataCached(HtmlEntry htmlEntry, List<DataDescriptor> descript ors) {
3780 for (DataDescriptor descriptor in descriptors) {
3781 CacheState state = htmlEntry.getState(descriptor);
3782 if (state != CacheState.VALID && state != CacheState.ERROR) {
3783 return false;
3784 }
3785 }
3786 return true;
3787 }
3788
3789 /**
3790 * Given a source for a Dart file, return a cache entry in which the data repr esented by the given
3791 * descriptor is available. This method assumes that the data can be produced by parsing the
3792 * source if it is not already cached.
3793 *
3794 * @param source the source representing the Dart file
3795 * @param dartEntry the cache entry associated with the Dart file
3796 * @param descriptor the descriptor representing the data to be returned
3797 * @return a cache entry containing the required data
3798 * @throws AnalysisException if data could not be returned because the source could not be
3799 * resolved
3800 */
3801 DartEntry internalCacheDartParseData(Source source, DartEntry dartEntry, DataD escriptor descriptor) {
3802 CacheState state = dartEntry.getState(descriptor);
3803 while (state != CacheState.ERROR && state != CacheState.VALID) {
3804 dartEntry = internalParseDart(source);
3805 state = dartEntry.getState(descriptor);
3806 }
3807 return dartEntry;
3808 }
3809
3810 /**
3811 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
3812 * all of the data represented by the given descriptors is available. This met hod assumes that the
3813 * data can be produced by resolving the source in the context of the library if it is not already
3814 * cached.
3815 * 3614 *
3816 * @param unitSource the source representing the Dart file 3615 * @param unitSource the source representing the Dart file
3817 * @param librarySource the source representing the library containing the Dar t file 3616 * @param librarySource the source representing the library containing the Dar t file
3818 * @param dartEntry the cache entry associated with the Dart file 3617 * @param dartEntry the entry representing the Dart file
3819 * @param descriptor the descriptor representing the data to be returned 3618 * @param descriptor the descriptor representing the data to be returned
3820 * @return the requested data about the given source 3619 * @return the requested data about the given source
3821 * @throws AnalysisException if data could not be returned because the source could not be parsed 3620 * @throws AnalysisException if data could not be returned because the source could not be
3822 */ 3621 * resolved
3823 DartEntry internalCacheDartResolutionData(Source unitSource, Source librarySou rce, DartEntry dartEntry, DataDescriptor descriptor) { 3622 */
3824 CacheState state = dartEntry.getState2(descriptor, librarySource); 3623 Object getDartHintData(Source unitSource, Source librarySource, DartEntry dart Entry, DataDescriptor descriptor) {
3825 while (state != CacheState.ERROR && state != CacheState.VALID) { 3624 dartEntry = cacheDartHintData(unitSource, librarySource, dartEntry, descript or);
3826 dartEntry = internalResolveDart(unitSource, librarySource); 3625 if (identical(descriptor, DartEntry.ELEMENT)) {
3827 state = dartEntry.getState2(descriptor, librarySource); 3626 return dartEntry.getValue(descriptor);
3828 } 3627 }
3829 return dartEntry; 3628 return dartEntry.getValue2(descriptor, librarySource);
3830 }
3831
3832 /**
3833 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by
3834 * the given descriptors is available. This method assumes that the data can b e produced by
3835 * parsing the source if it is not already cached.
3836 *
3837 * @param source the source representing the HTML file
3838 * @param htmlEntry the cache entry associated with the HTML file
3839 * @param descriptor the descriptor representing the data to be returned
3840 * @return a cache entry containing the required data
3841 * @throws AnalysisException if data could not be returned because the source could not be
3842 * resolved
3843 */
3844 HtmlEntry internalCacheHtmlParseData(Source source, HtmlEntry htmlEntry, List< DataDescriptor> descriptors) {
3845 while (!hasHtmlParseDataCached(htmlEntry, descriptors)) {
3846 htmlEntry = internalParseHtml(source);
3847 }
3848 return htmlEntry;
3849 } 3629 }
3850 3630
3851 /** 3631 /**
3852 * Given a source for a Dart file, return the data represented by the given de scriptor that is 3632 * Given a source for a Dart file, return the data represented by the given de scriptor that is
3853 * associated with that source. This method assumes that the data can be produ ced by parsing the 3633 * associated with that source. This method assumes that the data can be produ ced by parsing the
3854 * source if it is not already cached. 3634 * source if it is not already cached.
3855 * 3635 *
3856 * @param source the source representing the Dart file 3636 * @param source the source representing the Dart file
3857 * @param dartEntry the cache entry associated with the Dart file 3637 * @param dartEntry the cache entry associated with the Dart file
3858 * @param descriptor the descriptor representing the data to be returned 3638 * @param descriptor the descriptor representing the data to be returned
3859 * @return the requested data about the given source 3639 * @return the requested data about the given source
3860 * @throws AnalysisException if data could not be returned because the source could not be parsed 3640 * @throws AnalysisException if data could not be returned because the source could not be parsed
3861 */ 3641 */
3862 Object internalGetDartParseData(Source source, DartEntry dartEntry, DataDescri ptor descriptor) { 3642 Object getDartParseData(Source source, DartEntry dartEntry, DataDescriptor des criptor) {
3863 dartEntry = internalCacheDartParseData(source, dartEntry, descriptor); 3643 dartEntry = cacheDartParseData(source, dartEntry, descriptor);
3644 if (identical(descriptor, DartEntry.PARSED_UNIT)) {
3645 return dartEntry.anyParsedCompilationUnit as Object;
3646 }
3864 return dartEntry.getValue(descriptor); 3647 return dartEntry.getValue(descriptor);
3865 } 3648 }
3866 3649
3867 /** 3650 /**
3868 * Given a source for a Dart file, return the data represented by the given de scriptor that is 3651 * Given a source for a Dart file, return the data represented by the given de scriptor that is
3869 * associated with that source, or the given default value if the source is no t a Dart file. This 3652 * associated with that source, or the given default value if the source is no t a Dart file. This
3870 * method assumes that the data can be produced by parsing the source if it is not already cached. 3653 * method assumes that the data can be produced by parsing the source if it is not already cached.
3871 * 3654 *
3872 * @param source the source representing the Dart file 3655 * @param source the source representing the Dart file
3873 * @param descriptor the descriptor representing the data to be returned 3656 * @param descriptor the descriptor representing the data to be returned
3874 * @param defaultValue the value to be returned if the source is not a Dart fi le 3657 * @param defaultValue the value to be returned if the source is not a Dart fi le
3875 * @return the requested data about the given source 3658 * @return the requested data about the given source
3876 * @throws AnalysisException if data could not be returned because the source could not be parsed 3659 * @throws AnalysisException if data could not be returned because the source could not be parsed
3877 */ 3660 */
3878 Object internalGetDartParseData2(Source source, DataDescriptor descriptor, Obj ect defaultValue) { 3661 Object getDartParseData2(Source source, DataDescriptor descriptor, Object defa ultValue) {
3879 DartEntry dartEntry = getReadableDartEntry(source); 3662 DartEntry dartEntry = getReadableDartEntry(source);
3880 if (dartEntry == null) { 3663 if (dartEntry == null) {
3881 return defaultValue; 3664 return defaultValue;
3882 } 3665 }
3883 return internalGetDartParseData(source, dartEntry, descriptor); 3666 return getDartParseData(source, dartEntry, descriptor);
3884 } 3667 }
3885 3668
3886 /** 3669 /**
3887 * Given a source for a Dart file and the library that contains it, return the data represented by 3670 * Given a source for a Dart file and the library that contains it, return the data represented by
3888 * the given descriptor that is associated with that source. This method assum es that the data can 3671 * the given descriptor that is associated with that source. This method assum es that the data can
3889 * be produced by resolving the source in the context of the library if it is not already cached. 3672 * be produced by resolving the source in the context of the library if it is not already cached.
3890 * 3673 *
3891 * @param unitSource the source representing the Dart file 3674 * @param unitSource the source representing the Dart file
3892 * @param librarySource the source representing the library containing the Dar t file 3675 * @param librarySource the source representing the library containing the Dar t file
3893 * @param dartEntry the entry representing the Dart file 3676 * @param dartEntry the entry representing the Dart file
3894 * @param descriptor the descriptor representing the data to be returned 3677 * @param descriptor the descriptor representing the data to be returned
3895 * @return the requested data about the given source 3678 * @return the requested data about the given source
3896 * @throws AnalysisException if data could not be returned because the source could not be parsed 3679 * @throws AnalysisException if data could not be returned because the source could not be
3680 * resolved
3897 */ 3681 */
3898 Object internalGetDartResolutionData(Source unitSource, Source librarySource, DartEntry dartEntry, DataDescriptor descriptor) { 3682 Object getDartResolutionData(Source unitSource, Source librarySource, DartEntr y dartEntry, DataDescriptor descriptor) {
3899 dartEntry = internalCacheDartResolutionData(unitSource, librarySource, dartE ntry, descriptor); 3683 dartEntry = cacheDartResolutionData(unitSource, librarySource, dartEntry, de scriptor);
3684 if (identical(descriptor, DartEntry.ELEMENT)) {
3685 return dartEntry.getValue(descriptor);
3686 }
3900 return dartEntry.getValue2(descriptor, librarySource); 3687 return dartEntry.getValue2(descriptor, librarySource);
3901 } 3688 }
3902 3689
3903 /** 3690 /**
3904 * Given a source for a Dart file and the library that contains it, return the data represented by 3691 * Given a source for a Dart file and the library that contains it, return the data represented by
3905 * the given descriptor that is associated with that source. This method assum es that the data can 3692 * the given descriptor that is associated with that source, or the given defa ult value if the
3906 * be produced by resolving the source in the context of the library if it is not already cached. 3693 * source is not a Dart file. This method assumes that the data can be produce d by resolving the
3694 * source in the context of the library if it is not already cached.
3907 * 3695 *
3908 * @param unitSource the source representing the Dart file 3696 * @param unitSource the source representing the Dart file
3909 * @param librarySource the source representing the library containing the Dar t file 3697 * @param librarySource the source representing the library containing the Dar t file
3910 * @param descriptor the descriptor representing the data to be returned 3698 * @param descriptor the descriptor representing the data to be returned
3911 * @param defaultValue the value to be returned if the file is not a Dart file 3699 * @param defaultValue the value to be returned if the source is not a Dart fi le
3912 * @return the requested data about the given source 3700 * @return the requested data about the given source
3913 * @throws AnalysisException if data could not be returned because the source could not be parsed 3701 * @throws AnalysisException if data could not be returned because the source could not be
3702 * resolved
3914 */ 3703 */
3915 Object internalGetDartResolutionData2(Source unitSource, Source librarySource, DataDescriptor descriptor, Object defaultValue) { 3704 Object getDartResolutionData2(Source unitSource, Source librarySource, DataDes criptor descriptor, Object defaultValue) {
3916 DartEntry dartEntry = getReadableDartEntry(unitSource); 3705 DartEntry dartEntry = getReadableDartEntry(unitSource);
3917 if (dartEntry == null) { 3706 if (dartEntry == null) {
3918 return defaultValue; 3707 return defaultValue;
3919 } 3708 }
3920 dartEntry = internalCacheDartResolutionData(unitSource, librarySource, dartE ntry, descriptor); 3709 return getDartResolutionData(unitSource, librarySource, dartEntry, descripto r);
3921 return dartEntry.getValue(descriptor);
3922 } 3710 }
3923 3711
3924 /** 3712 /**
3925 * Given a source for an HTML file, return the data represented by the given d escriptor that is 3713 * Given a source for an HTML file, return the data represented by the given d escriptor that is
3926 * associated with that source, or the given default value if the source is no t an HTML file. This 3714 * associated with that source, or the given default value if the source is no t an HTML file. This
3927 * method assumes that the data can be produced by parsing the source if it is not already cached. 3715 * method assumes that the data can be produced by parsing the source if it is not already cached.
3928 * 3716 *
3929 * @param source the source representing the Dart file 3717 * @param source the source representing the Dart file
3930 * @param descriptor the descriptor representing the data to be returned 3718 * @param descriptor the descriptor representing the data to be returned
3931 * @param defaultValue the value to be returned if the source is not a Dart fi le 3719 * @param defaultValue the value to be returned if the source is not an HTML f ile
3932 * @return the requested data about the given source 3720 * @return the requested data about the given source
3933 * @throws AnalysisException if data could not be returned because the source could not be parsed 3721 * @throws AnalysisException if data could not be returned because the source could not be parsed
3934 */ 3722 */
3935 Object internalGetHtmlParseData(Source source, DataDescriptor descriptor, Obje ct defaultValue) { 3723 Object getHtmlParseData(Source source, DataDescriptor descriptor, Object defau ltValue) {
3936 HtmlEntry htmlEntry = getReadableHtmlEntry(source); 3724 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
3937 if (htmlEntry == null) { 3725 if (htmlEntry == null) {
3938 return defaultValue; 3726 return defaultValue;
3939 } 3727 }
3940 htmlEntry = internalCacheHtmlParseData(source, htmlEntry, [descriptor]); 3728 htmlEntry = cacheHtmlParseData(source, htmlEntry, descriptor);
3941 return htmlEntry.getValue(descriptor); 3729 return htmlEntry.getValue(descriptor);
3942 } 3730 }
3943 3731
3944 /** 3732 /**
3945 * Given a source for an HTML file, return the data represented by the given d escriptor that is 3733 * Given a source for an HTML file, return the data represented by the given d escriptor that is
3946 * associated with that source, or the given default value if the source is no t an HTML file. This 3734 * associated with that source, or the given default value if the source is no t an HTML file. This
3947 * method assumes that the data can be produced by resolving the source if it is not already 3735 * method assumes that the data can be produced by resolving the source if it is not already
3948 * cached. 3736 * cached.
3949 * 3737 *
3950 * @param source the source representing the HTML file 3738 * @param source the source representing the HTML file
3951 * @param descriptor the descriptor representing the data to be returned 3739 * @param descriptor the descriptor representing the data to be returned
3952 * @param defaultValue the value to be returned if the source is not an HTML f ile 3740 * @param defaultValue the value to be returned if the source is not an HTML f ile
3953 * @return the requested data about the given source 3741 * @return the requested data about the given source
3954 * @throws AnalysisException if data could not be returned because the source could not be 3742 * @throws AnalysisException if data could not be returned because the source could not be
3955 * resolved 3743 * resolved
3956 */ 3744 */
3957 Object internalGetHtmlResolutionData(Source source, HtmlEntry htmlEntry, DataD escriptor descriptor, Object defaultValue) { 3745 Object getHtmlResolutionData(Source source, DataDescriptor descriptor, Object defaultValue) {
3746 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
3958 if (htmlEntry == null) { 3747 if (htmlEntry == null) {
3959 return defaultValue; 3748 return defaultValue;
3960 } 3749 }
3961 CacheState state = htmlEntry.getState(descriptor); 3750 return getHtmlResolutionData2(source, htmlEntry, descriptor);
3962 while (state != CacheState.ERROR && state != CacheState.VALID) { 3751 }
3963 htmlEntry = internalResolveHtml(source); 3752
3964 state = htmlEntry.getState(descriptor); 3753 /**
3965 } 3754 * Given a source for an HTML file, return the data represented by the given d escriptor that is
3755 * associated with that source. This method assumes that the data can be produ ced by resolving the
3756 * source if it is not already cached.
3757 *
3758 * @param source the source representing the HTML file
3759 * @param htmlEntry the entry representing the HTML file
3760 * @param descriptor the descriptor representing the data to be returned
3761 * @return the requested data about the given source
3762 * @throws AnalysisException if data could not be returned because the source could not be
3763 * resolved
3764 */
3765 Object getHtmlResolutionData2(Source source, HtmlEntry htmlEntry, DataDescript or descriptor) {
3766 htmlEntry = cacheHtmlResolutionData(source, htmlEntry, descriptor);
3966 return htmlEntry.getValue(descriptor); 3767 return htmlEntry.getValue(descriptor);
3967 } 3768 }
3968 CompilationUnit internalParseCompilationUnit(DartEntryImpl dartCopy, Source so urce) { 3769
3969 try { 3770 /**
3970 accessed(source); 3771 * Look through the cache for a task that needs to be performed. Return the ta sk that was found,
3971 RecordingErrorListener errorListener = new RecordingErrorListener(); 3772 * or `null` if there is no more work to be done.
3972 AnalysisContextImpl_ScanResult scanResult = internalScan(source, errorList ener); 3773 *
3973 Parser parser = new Parser(source, errorListener); 3774 * @return the next task that needs to be performed
3974 CompilationUnit unit = parser.parseCompilationUnit(scanResult._token); 3775 */
3975 LineInfo lineInfo = new LineInfo(scanResult._lineStarts); 3776 AnalysisTask get nextTaskAnalysisTask {
3976 List<AnalysisError> errors = errorListener.getErrors2(source); 3777 {
3977 bool hasPartOfDirective = false; 3778 bool enableHints = analysisOptions.hint;
3978 bool hasLibraryDirective = false; 3779 for (Source source in _cache.priorityOrder) {
3979 Set<Source> exportedSources = new Set<Source>(); 3780 SourceEntry sourceEntry = _cache.get(source);
3980 Set<Source> importedSources = new Set<Source>(); 3781 if (sourceEntry is DartEntry) {
3981 Set<Source> includedSources = new Set<Source>(); 3782 DartEntry dartEntry = sourceEntry as DartEntry;
3982 for (Directive directive in unit.directives) { 3783 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERROR S);
3983 if (directive is ExportDirective) { 3784 if (identical(parseErrorsState, CacheState.INVALID) || identical(parse ErrorsState, CacheState.FLUSHED)) {
3984 Source exportSource = resolveSource(source, directive as ExportDirecti ve); 3785 DartEntryImpl dartCopy = dartEntry.writableCopy;
3985 if (exportSource != null) { 3786 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
3986 javaSetAdd(exportedSources, exportSource); 3787 _cache.put(source, dartCopy);
3987 } 3788 return new ParseDartTask(this, source);
3988 } else if (directive is ImportDirective) { 3789 }
3989 Source importSource = resolveSource(source, directive as ImportDirecti ve); 3790 CompilationUnit parseUnit = dartEntry.anyParsedCompilationUnit;
3990 if (importSource != null) { 3791 if (parseUnit == null) {
3991 javaSetAdd(importedSources, importSource); 3792 DartEntryImpl dartCopy = dartEntry.writableCopy;
3992 } 3793 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS);
3993 } else if (directive is LibraryDirective) { 3794 _cache.put(source, dartCopy);
3994 hasLibraryDirective = true; 3795 return new ParseDartTask(this, source);
3995 } else if (directive is PartDirective) { 3796 }
3996 Source partSource = resolveSource(source, directive as PartDirective); 3797 for (Source librarySource in getLibrariesContaining(source)) {
3997 if (partSource != null) { 3798 SourceEntry libraryEntry = _cache.get(librarySource);
3998 javaSetAdd(includedSources, partSource); 3799 if (libraryEntry is DartEntry) {
3999 } 3800 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT) ;
4000 } else if (directive is PartOfDirective) { 3801 if (identical(elementState, CacheState.INVALID) || identical(eleme ntState, CacheState.FLUSHED)) {
4001 hasPartOfDirective = true; 3802 DartEntryImpl libraryCopy = ((libraryEntry as DartEntry)).writab leCopy;
4002 } 3803 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
4003 } 3804 _cache.put(librarySource, libraryCopy);
4004 unit.parsingErrors = errors; 3805 return new ResolveDartLibraryTask(this, source, librarySource);
4005 unit.lineInfo = lineInfo; 3806 }
4006 if (identical(dartCopy.getState(DartEntry.SOURCE_KIND), CacheState.INVALID )) { 3807 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOL VED_UNIT, librarySource);
4007 if (hasPartOfDirective && !hasLibraryDirective) { 3808 if (identical(resolvedUnitState, CacheState.INVALID) || identical( resolvedUnitState, CacheState.FLUSHED)) {
4008 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); 3809 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
4009 } else { 3810 if (libraryElement != null) {
4010 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); 3811 DartEntryImpl dartCopy = dartEntry.writableCopy;
4011 } 3812 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, Cac heState.IN_PROCESS);
4012 } 3813 _cache.put(source, dartCopy);
4013 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 3814 return new ResolveDartUnitTask(this, source, libraryElement);
4014 dartCopy.setValue(DartEntry.PARSED_UNIT, unit); 3815 }
4015 dartCopy.setValue(DartEntry.PARSE_ERRORS, errors); 3816 }
4016 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, toArray(exportedSources)); 3817 CacheState hintsState = dartEntry.getState2(DartEntry.HINTS, libra rySource);
4017 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, toArray(importedSources)); 3818 if (enableHints && (identical(hintsState, CacheState.INVALID) || i dentical(hintsState, CacheState.FLUSHED))) {
4018 dartCopy.setValue(DartEntry.INCLUDED_PARTS, toArray(includedSources)); 3819 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
4019 return dartCopy.getValue(DartEntry.PARSED_UNIT); 3820 if (libraryElement != null) {
4020 } on AnalysisException catch (exception) { 3821 DartEntryImpl dartCopy = dartEntry.writableCopy;
4021 dartCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR); 3822 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState. IN_PROCESS);
4022 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.ERROR); 3823 _cache.put(source, dartCopy);
4023 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.ERROR); 3824 return new GenerateDartHintsTask(this, libraryElement);
4024 dartCopy.setState(DartEntry.EXPORTED_LIBRARIES, CacheState.ERROR); 3825 }
4025 dartCopy.setState(DartEntry.IMPORTED_LIBRARIES, CacheState.ERROR); 3826 }
4026 dartCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.ERROR); 3827 }
4027 throw exception; 3828 }
4028 } 3829 } else if (sourceEntry is HtmlEntry) {
4029 } 3830 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
4030 3831 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ;
4031 /** 3832 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsed UnitState, CacheState.FLUSHED)) {
4032 * Scan and parse the given Dart file, updating the cache as appropriate, and return the updated 3833 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4033 * cache entry associated with the source. 3834 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
4034 * 3835 _cache.put(source, htmlCopy);
4035 * @param source the source representing the compilation unit to be parsed 3836 return new ParseHtmlTask(this, source);
4036 * @return the updated cache entry associated with the source 3837 }
4037 * @throws AnalysisException if the source does not represent a Dart compilati on unit or if the 3838 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
4038 * compilation unit cannot be parsed for some reason 3839 if (identical(elementState, CacheState.INVALID) || identical(elementSt ate, CacheState.FLUSHED)) {
4039 */ 3840 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4040 DartEntry internalParseDart(Source source) { 3841 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
4041 AnalysisContextImpl_ScanResult scanResult = null; 3842 _cache.put(source, htmlCopy);
4042 LineInfo lineInfo = null; 3843 return new ResolveHtmlTask(this, source);
4043 CompilationUnit unit = null; 3844 }
4044 List<AnalysisError> errors = null; 3845 }
4045 bool hasPartOfDirective = false; 3846 }
4046 bool hasLibraryDirective = false; 3847 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4047 Set<Source> exportedSources = new Set<Source>(); 3848 SourceEntry sourceEntry = entry.getValue();
4048 Set<Source> importedSources = new Set<Source>(); 3849 if (sourceEntry is DartEntry) {
4049 Set<Source> includedSources = new Set<Source>(); 3850 DartEntry dartEntry = sourceEntry as DartEntry;
4050 AnalysisException thrownException = null; 3851 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.IN VALID)) {
4051 try { 3852 Source source = entry.getKey();
4052 RecordingErrorListener errorListener = new RecordingErrorListener(); 3853 DartEntryImpl dartCopy = dartEntry.writableCopy;
4053 scanResult = internalScan(source, errorListener); 3854 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
4054 Parser parser = new Parser(source, errorListener); 3855 _cache.put(source, dartCopy);
4055 unit = parser.parseCompilationUnit(scanResult._token); 3856 return new ParseDartTask(this, source);
4056 lineInfo = new LineInfo(scanResult._lineStarts); 3857 }
4057 errors = errorListener.getErrors2(source); 3858 } else if (sourceEntry is HtmlEntry) {
4058 for (Directive directive in unit.directives) { 3859 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
4059 if (directive is ExportDirective) { 3860 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.IN VALID)) {
4060 Source exportSource = resolveSource(source, directive as ExportDirecti ve); 3861 Source source = entry.getKey();
4061 if (exportSource != null) { 3862 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4062 javaSetAdd(exportedSources, exportSource); 3863 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
4063 } 3864 _cache.put(source, htmlCopy);
4064 } else if (directive is ImportDirective) { 3865 return new ParseHtmlTask(this, source);
4065 Source importSource = resolveSource(source, directive as ImportDirecti ve); 3866 }
4066 if (importSource != null) { 3867 }
4067 javaSetAdd(importedSources, importSource); 3868 }
4068 } 3869 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4069 } else if (directive is LibraryDirective) { 3870 SourceEntry sourceEntry = entry.getValue();
4070 hasLibraryDirective = true; 3871 if (sourceEntry is DartEntry) {
4071 } else if (directive is PartDirective) { 3872 Source source = entry.getKey();
4072 Source partSource = resolveSource(source, directive as PartDirective); 3873 DartEntry dartEntry = sourceEntry as DartEntry;
4073 if (partSource != null) { 3874 if (identical(dartEntry.kind, SourceKind.LIBRARY) && identical(dartEnt ry.getState(DartEntry.ELEMENT), CacheState.INVALID)) {
4074 javaSetAdd(includedSources, partSource); 3875 DartEntryImpl dartCopy = dartEntry.writableCopy;
4075 } 3876 dartCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
4076 } else if (directive is PartOfDirective) { 3877 _cache.put(source, dartCopy);
4077 hasPartOfDirective = true; 3878 return new ResolveDartLibraryTask(this, source, source);
4078 } 3879 } else if (enableHints && identical(dartEntry.getState2(DartEntry.HINT S, source), CacheState.INVALID)) {
4079 } 3880 LibraryElement libraryElement = dartEntry.getValue(DartEntry.ELEMENT );
4080 unit.parsingErrors = errors; 3881 if (libraryElement != null) {
4081 unit.lineInfo = lineInfo; 3882 DartEntryImpl dartCopy = dartEntry.writableCopy;
4082 } on AnalysisException catch (exception) { 3883 dartCopy.setState2(DartEntry.HINTS, source, CacheState.IN_PROCESS) ;
4083 thrownException = exception; 3884 _cache.put(source, dartCopy);
4084 } 3885 return new GenerateDartHintsTask(this, libraryElement);
4085 DartEntry dartEntry = null; 3886 }
4086 { 3887 }
4087 SourceEntry sourceEntry = _sourceMap[source]; 3888 } else if (sourceEntry is HtmlEntry) {
4088 if (sourceEntry is! DartEntry) { 3889 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
4089 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}"); 3890 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALI D)) {
4090 } 3891 Source source = entry.getKey();
4091 dartEntry = sourceEntry as DartEntry; 3892 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4092 accessed(source); 3893 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
4093 int sourceTime = source.modificationStamp; 3894 _cache.put(source, htmlCopy);
4094 int resultTime = scanResult == null ? sourceTime : scanResult.modification Time; 3895 return new ResolveHtmlTask(this, source);
4095 if (sourceTime == resultTime) { 3896 }
4096 if (dartEntry.modificationTime != sourceTime) { 3897 }
4097 sourceChanged(source); 3898 }
4098 dartEntry = getReadableDartEntry(source); 3899 return null;
4099 } 3900 }
4100 DartEntryImpl dartCopy = dartEntry.writableCopy; 3901 }
4101 if (thrownException == null) { 3902
4102 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 3903 /**
4103 if (hasPartOfDirective && !hasLibraryDirective) { 3904 * Return a change notice for the given source, creating one if one does not a lready exist.
4104 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); 3905 *
4105 } else { 3906 * @param source the source for which changes are being reported
4106 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); 3907 * @return a change notice for the given source
4107 } 3908 */
4108 dartCopy.setValue(DartEntry.PARSED_UNIT, unit); 3909 ChangeNoticeImpl getNotice(Source source) {
4109 dartCopy.setValue(DartEntry.PARSE_ERRORS, errors); 3910 ChangeNoticeImpl notice = _pendingNotices[source];
4110 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, toArray(exportedSource s)); 3911 if (notice == null) {
4111 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, toArray(importedSource s)); 3912 notice = new ChangeNoticeImpl(source);
4112 dartCopy.setValue(DartEntry.INCLUDED_PARTS, toArray(includedSources)); 3913 _pendingNotices[source] = notice;
4113 } else { 3914 }
4114 dartCopy.recordParseError(); 3915 return notice;
4115 } 3916 }
4116 _sourceMap[source] = dartCopy; 3917
4117 dartEntry = dartCopy; 3918 /**
4118 } 3919 * Return the cache entry associated with the given source, or `null` if the s ource is not a
4119 } 3920 * Dart file.
4120 if (thrownException != null) { 3921 *
4121 if (thrownException.cause is! JavaIOException) { 3922 * @param source the source for which a cache entry is being sought
4122 AnalysisEngine.instance.logger.logError2("Could not parse ${source.fullN ame}", thrownException); 3923 * @return the source cache entry associated with the given source
4123 } 3924 */
4124 throw thrownException; 3925 DartEntry getReadableDartEntry(Source source) {
4125 } 3926 {
4126 return dartEntry; 3927 SourceEntry sourceEntry = _cache.get(source);
4127 } 3928 if (sourceEntry == null) {
4128 3929 sourceEntry = createSourceEntry(source);
4129 /** 3930 }
4130 * Scan and parse the given HTML file, updating the cache as appropriate, and return the updated 3931 if (sourceEntry is DartEntry) {
4131 * cache entry associated with the source. 3932 _cache.accessed(source);
4132 * 3933 return sourceEntry as DartEntry;
4133 * @param source the source representing the HTML file to be parsed 3934 }
4134 * @return the updated cache entry associated with the source 3935 return null;
4135 * @throws AnalysisException if the source does not represent an HTML file or if the file cannot 3936 }
4136 * be parsed for some reason 3937 }
4137 */ 3938
4138 HtmlEntry internalParseHtml(Source source) { 3939 /**
4139 HtmlParseResult result = null; 3940 * Return the cache entry associated with the given source, or `null` if the s ource is not
4140 LineInfo lineInfo = null; 3941 * an HTML file.
4141 AnalysisException thrownException = null; 3942 *
4142 try { 3943 * @param source the source for which a cache entry is being sought
4143 result = new HtmlParser(source).parse(scanHtml(source)); 3944 * @return the source cache entry associated with the given source
4144 lineInfo = new LineInfo(result.lineStarts); 3945 */
4145 } on AnalysisException catch (exception) { 3946 HtmlEntry getReadableHtmlEntry(Source source) {
4146 thrownException = exception; 3947 {
4147 } 3948 SourceEntry sourceEntry = _cache.get(source);
4148 HtmlEntry htmlEntry = null; 3949 if (sourceEntry == null) {
4149 { 3950 sourceEntry = createSourceEntry(source);
4150 SourceEntry sourceEntry = _sourceMap[source]; 3951 }
4151 if (sourceEntry is! HtmlEntry) { 3952 if (sourceEntry is HtmlEntry) {
4152 throw new AnalysisException.con1("Internal error: attempting to parse no n-HTML file as a HTML file: ${source.fullName}"); 3953 _cache.accessed(source);
4153 } 3954 return sourceEntry as HtmlEntry;
4154 htmlEntry = sourceEntry as HtmlEntry; 3955 }
4155 accessed(source); 3956 return null;
4156 int sourceTime = source.modificationStamp; 3957 }
4157 int resultTime = result == null ? sourceTime : result.modificationTime; 3958 }
4158 if (sourceTime == resultTime) { 3959
4159 if (htmlEntry.modificationTime != sourceTime) { 3960 /**
4160 sourceChanged(source); 3961 * Return the cache entry associated with the given source, or `null` if there is no entry
4161 htmlEntry = getReadableHtmlEntry(source); 3962 * associated with the source.
4162 } 3963 *
4163 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; 3964 * @param source the source for which a cache entry is being sought
4164 if (thrownException == null) { 3965 * @return the source cache entry associated with the given source
4165 HtmlUnit unit = result.htmlUnit; 3966 */
4166 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 3967 SourceEntry getReadableSourceEntry(Source source) {
4167 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit); 3968 {
4168 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, getLibrarySources2(s ource, unit)); 3969 SourceEntry sourceEntry = _cache.get(source);
4169 } else { 3970 if (sourceEntry == null) {
4170 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR); 3971 sourceEntry = createSourceEntry(source);
4171 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR); 3972 }
4172 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR); 3973 if (sourceEntry != null) {
4173 } 3974 _cache.accessed(source);
4174 _sourceMap[source] = htmlCopy; 3975 }
4175 htmlEntry = htmlCopy; 3976 return sourceEntry;
4176 } 3977 }
4177 } 3978 }
4178 if (thrownException != null) { 3979
4179 AnalysisEngine.instance.logger.logError2("Could not parse ${source.fullNam e}", thrownException); 3980 /**
4180 throw thrownException; 3981 * Return an array containing all of the sources known to this context that ha ve the given kind.
4181 } 3982 *
4182 ChangeNoticeImpl notice = getNotice(source); 3983 * @param kind the kind of sources to be returned
4183 notice.setErrors(htmlEntry.allErrors, lineInfo); 3984 * @return all of the sources known to this context that have the given kind
4184 return htmlEntry; 3985 */
4185 } 3986 List<Source> getSources(SourceKind kind2) {
4186 DartEntry internalResolveDart(Source unitSource, Source librarySource) { 3987 List<Source> sources = new List<Source>();
4187 DartEntry dartEntry = getReadableDartEntry(unitSource); 3988 {
4188 if (dartEntry == null) { 3989 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4189 throw new AnalysisException.con1("Internal error: attempting to parse non- Dart file as a Dart file: ${unitSource.fullName}"); 3990 if (identical(entry.getValue().kind, kind2)) {
4190 } 3991 sources.add(entry.getKey());
4191 LibraryResolver resolver = null; 3992 }
4192 AnalysisException thrownException = null; 3993 }
4193 try { 3994 }
4194 resolver = new LibraryResolver(this); 3995 return new List.from(sources);
4195 resolver.resolveLibrary(librarySource, true); 3996 }
4196 } on AnalysisException catch (exception) { 3997
4197 thrownException = exception; 3998 /**
4198 } 3999 * Invalidate all of the resolution results computed by this context.
4199 if (thrownException == null) {
4200 {
4201 accessed(unitSource);
4202 }
4203 recordResolutionResults(resolver);
4204 dartEntry = getReadableDartEntry(unitSource);
4205 } else {
4206 AnalysisEngine.instance.logger.logError2("Could not resolve ${unitSource.f ullName}", thrownException);
4207 bool unitIsLibrary = unitSource == librarySource;
4208 DartEntryImpl dartCopy = dartEntry.writableCopy;
4209 dartCopy.setState2(DartEntry.RESOLUTION_ERRORS, librarySource, CacheState. ERROR);
4210 if (unitIsLibrary) {
4211 dartCopy.setState(DartEntry.ELEMENT, CacheState.ERROR);
4212 }
4213 _sourceMap[unitSource] = dartCopy;
4214 if (!unitIsLibrary) {
4215 DartEntry libraryEntry = getReadableDartEntry(librarySource);
4216 if (libraryEntry != null) {
4217 DartEntryImpl libraryCopy = dartEntry.writableCopy;
4218 libraryCopy.setState2(DartEntry.RESOLUTION_ERRORS, librarySource, Cach eState.ERROR);
4219 libraryCopy.setState(DartEntry.ELEMENT, CacheState.ERROR);
4220 _sourceMap[librarySource] = libraryCopy;
4221 }
4222 }
4223 throw thrownException;
4224 }
4225 ChangeNoticeImpl notice = getNotice(unitSource);
4226 notice.setErrors(dartEntry.allErrors, dartEntry.getValue(SourceEntry.LINE_IN FO));
4227 return dartEntry;
4228 }
4229
4230 /**
4231 * Scan and parse the given HTML file, updating the cache as appropriate, and return the updated
4232 * cache entry associated with the source.
4233 *
4234 * @param source the source representing the HTML file to be parsed
4235 * @return the updated cache entry associated with the source
4236 * @throws AnalysisException if the source does not represent an HTML file or if the file cannot
4237 * be parsed for some reason
4238 */
4239 HtmlEntry internalResolveHtml(Source source) {
4240 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
4241 if (htmlEntry == null) {
4242 throw new AnalysisException.con1("Internal error: attempting to parse non- HTML file as a HTML file: ${source.fullName}");
4243 }
4244 int resultTime = 0;
4245 HtmlElement element = null;
4246 List<AnalysisError> resolutionErrors = null;
4247 AnalysisException thrownException = null;
4248 try {
4249 htmlEntry = internalCacheHtmlParseData(source, htmlEntry, [HtmlEntry.PARSE D_UNIT]);
4250 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
4251 if (unit == null) {
4252 throw new AnalysisException.con1("Internal error: internalCacheHtmlParse Data returned an entry without a parsed HTML unit");
4253 }
4254 resultTime = htmlEntry.modificationTime;
4255 HtmlUnitBuilder builder = new HtmlUnitBuilder(this);
4256 element = builder.buildHtmlElement2(source, resultTime, unit);
4257 resolutionErrors = builder.errorListener.getErrors2(source);
4258 } on AnalysisException catch (exception) {
4259 thrownException = exception;
4260 }
4261 {
4262 SourceEntry sourceEntry = _sourceMap[source];
4263 if (sourceEntry is! HtmlEntry) {
4264 throw new AnalysisException.con1("Internal error: attempting to resolve non-HTML file as a HTML file: ${source.fullName}");
4265 }
4266 htmlEntry = sourceEntry as HtmlEntry;
4267 accessed(source);
4268 int sourceTime = source.modificationStamp;
4269 if (sourceTime == resultTime) {
4270 if (htmlEntry.modificationTime != sourceTime) {
4271 sourceChanged(source);
4272 htmlEntry = getReadableHtmlEntry(source);
4273 }
4274 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4275 if (thrownException == null) {
4276 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, resolutionErrors);
4277 htmlCopy.setValue(HtmlEntry.ELEMENT, element);
4278 } else {
4279 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.ERROR);
4280 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.ERROR);
4281 }
4282 _sourceMap[source] = htmlCopy;
4283 htmlEntry = htmlCopy;
4284 }
4285 }
4286 if (thrownException != null) {
4287 AnalysisEngine.instance.logger.logError2("Could not resolve ${source.fullN ame}", thrownException);
4288 throw thrownException;
4289 }
4290 ChangeNoticeImpl notice = getNotice(source);
4291 notice.setErrors(htmlEntry.allErrors, htmlEntry.getValue(SourceEntry.LINE_IN FO));
4292 return htmlEntry;
4293 }
4294 AnalysisContextImpl_ScanResult internalScan(Source source, AnalysisErrorListen er errorListener) {
4295 AnalysisContextImpl_ScanResult result = new AnalysisContextImpl_ScanResult() ;
4296 Source_ContentReceiver receiver = new Source_ContentReceiver_7(source, error Listener, result);
4297 try {
4298 source.getContents(receiver);
4299 } catch (exception) {
4300 throw new AnalysisException.con3(exception);
4301 }
4302 return result;
4303 }
4304
4305 /**
4306 * Invalidate all of the results computed by this context.
4307 * 4000 *
4308 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4001 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4309 */ 4002 */
4310 void invalidateAllResults() { 4003 void invalidateAllResolutionInformation() {
4311 for (MapEntry<Source, SourceEntry> mapEntry in getMapEntrySet(_sourceMap)) { 4004 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
4312 SourceEntry sourceEntry = mapEntry.getValue(); 4005 SourceEntry sourceEntry = mapEntry.getValue();
4313 if (sourceEntry is HtmlEntry) { 4006 if (sourceEntry is HtmlEntry) {
4314 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; 4007 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
4315 htmlCopy.invalidateAllResolutionInformation(); 4008 htmlCopy.invalidateAllResolutionInformation();
4316 mapEntry.setValue(htmlCopy); 4009 mapEntry.setValue(htmlCopy);
4317 } else if (sourceEntry is DartEntry) { 4010 } else if (sourceEntry is DartEntry) {
4318 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy; 4011 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
4319 dartCopy.invalidateAllResolutionInformation(); 4012 dartCopy.invalidateAllResolutionInformation();
4320 mapEntry.setValue(dartCopy); 4013 mapEntry.setValue(dartCopy);
4321 } 4014 }
4322 } 4015 }
4323 } 4016 }
4324 4017
4325 /** 4018 /**
4326 * In response to a change to at least one of the compilation units in the giv en library, 4019 * In response to a change to at least one of the compilation units in the giv en library,
4327 * invalidate any results that are dependent on the result of resolving that l ibrary. 4020 * invalidate any results that are dependent on the result of resolving that l ibrary.
4328 * 4021 *
4022 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4023 *
4329 * @param librarySource the source of the library being invalidated 4024 * @param librarySource the source of the library being invalidated
4330 */ 4025 */
4331 void invalidateLibraryResolution(Source librarySource) { 4026 void invalidateLibraryResolution(Source librarySource) {
4332 DartEntry libraryEntry = getDartEntry(librarySource); 4027 DartEntry libraryEntry = getReadableDartEntry(librarySource);
4333 if (libraryEntry != null) { 4028 if (libraryEntry != null) {
4334 List<Source> includedParts = libraryEntry.getValue(DartEntry.INCLUDED_PART S); 4029 List<Source> includedParts = libraryEntry.getValue(DartEntry.INCLUDED_PART S);
4335 DartEntryImpl libraryCopy = libraryEntry.writableCopy; 4030 DartEntryImpl libraryCopy = libraryEntry.writableCopy;
4336 libraryCopy.invalidateAllResolutionInformation(); 4031 libraryCopy.invalidateAllResolutionInformation();
4337 libraryCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID); 4032 libraryCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID);
4338 _sourceMap[librarySource] = libraryCopy; 4033 _cache.put(librarySource, libraryCopy);
4339 for (Source unitSource in includedParts) { 4034 for (Source partSource in includedParts) {
4340 DartEntry partEntry = getDartEntry(unitSource); 4035 SourceEntry partEntry = _cache.get(partSource);
4341 if (partEntry != null) { 4036 if (partEntry is DartEntry) {
4342 DartEntryImpl dartCopy = partEntry.writableCopy; 4037 DartEntryImpl partCopy = ((partEntry as DartEntry)).writableCopy;
4343 dartCopy.invalidateAllResolutionInformation(); 4038 partCopy.invalidateAllResolutionInformation();
4344 _sourceMap[unitSource] = dartCopy; 4039 _cache.put(partSource, partCopy);
4345 } 4040 }
4346 } 4041 }
4347 } 4042 }
4348 } 4043 }
4349 4044
4350 /** 4045 /**
4351 * Return `true` if this library is, or depends on, dart:html. 4046 * Return `true` if this library is, or depends on, dart:html.
4352 * 4047 *
4353 * @param library the library being tested 4048 * @param library the library being tested
4354 * @param visitedLibraries a collection of the libraries that have been visite d, used to prevent 4049 * @param visitedLibraries a collection of the libraries that have been visite d, used to prevent
(...skipping 15 matching lines...) Expand all
4370 } 4065 }
4371 for (LibraryElement exported in library.exportedLibraries) { 4066 for (LibraryElement exported in library.exportedLibraries) {
4372 if (isClient(exported, htmlSource, visitedLibraries)) { 4067 if (isClient(exported, htmlSource, visitedLibraries)) {
4373 return true; 4068 return true;
4374 } 4069 }
4375 } 4070 }
4376 return false; 4071 return false;
4377 } 4072 }
4378 4073
4379 /** 4074 /**
4380 * Return `true` if the given source is in the array of priority sources.
4381 *
4382 * Note: This method must only be invoked while we are synchronized on [cacheL ock].
4383 */
4384 bool isPrioritySource(Source source) {
4385 for (Source prioritySource in _priorityOrder) {
4386 if (source == prioritySource) {
4387 return true;
4388 }
4389 }
4390 return false;
4391 }
4392
4393 /**
4394 * Perform a single analysis task.
4395 *
4396 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4397 *
4398 * @return `true` if work was done, implying that there might be more work to be done
4399 */
4400 bool performSingleAnalysisTask() {
4401 for (Source source in _priorityOrder) {
4402 SourceEntry sourceEntry = _sourceMap[source];
4403 if (sourceEntry is DartEntry) {
4404 DartEntry dartEntry = sourceEntry as DartEntry;
4405 CacheState parsedUnitState = dartEntry.getState(DartEntry.PARSED_UNIT);
4406 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsedUn itState, CacheState.FLUSHED)) {
4407 safelyParseCompilationUnit(source, dartEntry);
4408 return true;
4409 }
4410 for (Source librarySource in getLibrariesContaining(source)) {
4411 SourceEntry libraryEntry = _sourceMap[librarySource];
4412 if (libraryEntry is DartEntry) {
4413 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT);
4414 if (identical(elementState, CacheState.INVALID) || identical(element State, CacheState.FLUSHED)) {
4415 safelyResolveCompilationUnit(librarySource);
4416 return true;
4417 }
4418 }
4419 if (identical(dartEntry.getState2(DartEntry.RESOLVED_UNIT, librarySour ce), CacheState.FLUSHED)) {
4420 safelyResolveCompilationUnit2(source, librarySource);
4421 return true;
4422 }
4423 }
4424 } else if (sourceEntry is HtmlEntry) {
4425 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
4426 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT);
4427 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsedUn itState, CacheState.FLUSHED)) {
4428 safelyParseHtmlUnit(source);
4429 return true;
4430 }
4431 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
4432 if (identical(elementState, CacheState.INVALID) || identical(elementStat e, CacheState.FLUSHED)) {
4433 safelyResolveHtmlUnit(source);
4434 return true;
4435 }
4436 }
4437 }
4438 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) {
4439 SourceEntry sourceEntry = entry.getValue();
4440 if (sourceEntry is DartEntry) {
4441 DartEntry dartEntry = sourceEntry as DartEntry;
4442 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.INVA LID)) {
4443 safelyParseCompilationUnit(entry.getKey(), dartEntry);
4444 return true;
4445 }
4446 } else if (sourceEntry is HtmlEntry) {
4447 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
4448 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.INVA LID)) {
4449 safelyParseHtmlUnit(entry.getKey());
4450 return true;
4451 }
4452 }
4453 }
4454 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) {
4455 SourceEntry sourceEntry = entry.getValue();
4456 if (sourceEntry is DartEntry && identical(sourceEntry.kind, SourceKind.LIB RARY)) {
4457 DartEntry dartEntry = sourceEntry as DartEntry;
4458 if (identical(dartEntry.getState(DartEntry.ELEMENT), CacheState.INVALID) ) {
4459 safelyResolveCompilationUnit(entry.getKey());
4460 return true;
4461 }
4462 } else if (sourceEntry is HtmlEntry) {
4463 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
4464 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALID) ) {
4465 safelyResolveHtmlUnit(entry.getKey());
4466 return true;
4467 }
4468 }
4469 }
4470 return false;
4471 }
4472
4473 /**
4474 * Given a cache entry and a library element, record the library element and o ther information 4075 * Given a cache entry and a library element, record the library element and o ther information
4475 * gleaned from the element in the cache entry. 4076 * gleaned from the element in the cache entry.
4476 * 4077 *
4477 * @param dartCopy the cache entry in which data is to be recorded 4078 * @param dartCopy the cache entry in which data is to be recorded
4478 * @param library the library element used to record information 4079 * @param library the library element used to record information
4479 * @param htmlSource the source for the HTML library 4080 * @param htmlSource the source for the HTML library
4480 */ 4081 */
4481 void recordElementData(DartEntryImpl dartCopy, LibraryElement library, Source htmlSource) { 4082 void recordElementData(DartEntryImpl dartCopy, LibraryElement library, Source htmlSource) {
4482 dartCopy.setValue(DartEntry.ELEMENT, library); 4083 dartCopy.setValue(DartEntry.ELEMENT, library);
4483 dartCopy.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null); 4084 dartCopy.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null);
4484 dartCopy.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set <LibraryElement>())); 4085 dartCopy.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set <LibraryElement>()));
4485 List<Source> unitSources = new List<Source>(); 4086 List<Source> unitSources = new List<Source>();
4486 unitSources.add(library.definingCompilationUnit.source); 4087 unitSources.add(library.definingCompilationUnit.source);
4487 for (CompilationUnitElement part in library.parts) { 4088 for (CompilationUnitElement part in library.parts) {
4488 Source partSource = part.source; 4089 Source partSource = part.source;
4489 unitSources.add(partSource); 4090 unitSources.add(partSource);
4490 } 4091 }
4491 dartCopy.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources)); 4092 dartCopy.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources));
4492 } 4093 }
4493 4094
4494 /** 4095 /**
4495 * Record the result of using the given resolver to resolve one or more librar ies. 4096 * Record the results produced by performing a [GenerateDartHintsTask]. If the results were
4496 * 4097 * computed from data that is now out-of-date, then the results will not be re corded.
4497 * @param resolver the resolver that has the needed results 4098 *
4498 * @throws AnalysisException if the results cannot be retrieved for some reaso n 4099 * @param task the task that was performed
4499 */ 4100 * @return an entry containing the computed results
4500 void recordResolutionResults(LibraryResolver resolver) { 4101 * @throws AnalysisException if the results could not be recorded
4501 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); 4102 */
4502 RecordingErrorListener errorListener = resolver.errorListener; 4103 DartEntry recordGenerateDartHintsTask(GenerateDartHintsTask task) {
4503 for (Library library in resolver.resolvedLibraries) { 4104 Source librarySource = task.libraryElement.source;
4504 Source librarySource = library.librarySource; 4105 AnalysisException thrownException = task.exception;
4505 for (Source source in library.compilationUnitSources) { 4106 DartEntry libraryEntry = null;
4506 CompilationUnit unit = library.getAST(source); 4107 Map<Source, TimestampedData<List<AnalysisError>>> hintMap = task.hintMap;
4507 List<AnalysisError> errors = errorListener.getErrors2(source); 4108 if (hintMap == null) {
4508 unit.resolutionErrors = errors; 4109 {
4509 LineInfo lineInfo = unit.lineInfo; 4110 SourceEntry sourceEntry = _cache.get(librarySource);
4510 { 4111 if (sourceEntry is! DartEntry) {
4511 DartEntry dartEntry = getDartEntry(source); 4112 throw new AnalysisException.con1("Internal error: attempting to genera te hints for non-Dart file as a Dart file: ${librarySource.fullName}");
4512 if (dartEntry != null) { 4113 }
4513 int sourceTime = source.modificationStamp; 4114 if (thrownException == null) {
4514 int resultTime = dartEntry.modificationTime; 4115 thrownException = new AnalysisException.con1("GenerateDartHintsTask re turned a null hint map without throwing an exception: ${librarySource.fullName}" );
4515 if (sourceTime == resultTime) { 4116 }
4117 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
4118 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR);
4119 dartCopy.exception = thrownException;
4120 _cache.put(librarySource, dartCopy);
4121 }
4122 throw thrownException;
4123 }
4124 for (MapEntry<Source, TimestampedData<List<AnalysisError>>> entry in getMapE ntrySet(hintMap)) {
4125 Source unitSource = entry.getKey();
4126 TimestampedData<List<AnalysisError>> results = entry.getValue();
4127 {
4128 SourceEntry sourceEntry = _cache.get(unitSource);
4129 if (sourceEntry is! DartEntry) {
4130 throw new AnalysisException.con1("Internal error: attempting to parse non-Dart file as a Dart file: ${unitSource.fullName}");
4131 }
4132 DartEntry dartEntry = sourceEntry as DartEntry;
4133 if (unitSource == librarySource) {
4134 libraryEntry = dartEntry;
4135 }
4136 _cache.accessed(unitSource);
4137 int sourceTime = unitSource.modificationStamp;
4138 int resultTime = results.modificationTime;
4139 if (sourceTime == resultTime) {
4140 if (dartEntry.modificationTime != sourceTime) {
4141 sourceChanged(unitSource);
4142 dartEntry = getReadableDartEntry(unitSource);
4143 if (dartEntry == null) {
4144 throw new AnalysisException.con1("A Dart file became a non-Dart fi le: ${unitSource.fullName}");
4145 }
4146 }
4147 DartEntryImpl dartCopy = dartEntry.writableCopy;
4148 if (thrownException == null) {
4149 dartCopy.setValue2(DartEntry.HINTS, librarySource, results.data);
4150 ChangeNoticeImpl notice = getNotice(unitSource);
4151 notice.setErrors(dartCopy.allErrors, dartCopy.getValue(SourceEntry.L INE_INFO));
4152 } else {
4153 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERROR) ;
4154 }
4155 dartCopy.exception = thrownException;
4156 _cache.put(unitSource, dartCopy);
4157 dartEntry = dartCopy;
4158 } else {
4159 if (identical(dartEntry.getState2(DartEntry.HINTS, librarySource), Cac heState.IN_PROCESS)) {
4160 DartEntryImpl dartCopy = dartEntry.writableCopy;
4161 if (thrownException == null || resultTime >= 0) {
4162 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.INVA LID);
4163 } else {
4164 dartCopy.setState2(DartEntry.HINTS, librarySource, CacheState.ERRO R);
4165 }
4166 dartCopy.exception = thrownException;
4167 _cache.put(unitSource, dartCopy);
4168 dartEntry = dartCopy;
4169 }
4170 }
4171 }
4172 }
4173 if (thrownException != null) {
4174 throw thrownException;
4175 }
4176 return libraryEntry;
4177 }
4178
4179 /**
4180 * Record the results produced by performing a [ParseDartTask]. If the results were computed
4181 * from data that is now out-of-date, then the results will not be recorded.
4182 *
4183 * @param task the task that was performed
4184 * @return an entry containing the computed results
4185 * @throws AnalysisException if the results could not be recorded
4186 */
4187 DartEntry recordParseDartTaskResults(ParseDartTask task) {
4188 Source source = task.source;
4189 AnalysisException thrownException = task.exception;
4190 DartEntry dartEntry = null;
4191 {
4192 SourceEntry sourceEntry = _cache.get(source);
4193 if (sourceEntry is! DartEntry) {
4194 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}");
4195 }
4196 dartEntry = sourceEntry as DartEntry;
4197 _cache.accessed(source);
4198 int sourceTime = source.modificationStamp;
4199 int resultTime = task.modificationTime;
4200 if (sourceTime == resultTime) {
4201 if (dartEntry.modificationTime != sourceTime) {
4202 sourceChanged(source);
4203 dartEntry = getReadableDartEntry(source);
4204 if (dartEntry == null) {
4205 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
4206 }
4207 }
4208 DartEntryImpl dartCopy = dartEntry.writableCopy;
4209 if (thrownException == null) {
4210 LineInfo lineInfo = task.lineInfo;
4211 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
4212 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) {
4213 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
4214 } else {
4215 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
4216 }
4217 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit);
4218 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors);
4219 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
4220 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
4221 dartCopy.setValue(DartEntry.INCLUDED_PARTS, task.includedSources);
4222 } else {
4223 dartCopy.recordParseError();
4224 }
4225 dartCopy.exception = thrownException;
4226 _cache.put(source, dartCopy);
4227 dartEntry = dartCopy;
4228 } else {
4229 DartEntryImpl dartCopy = dartEntry.writableCopy;
4230 if (thrownException == null || resultTime >= 0) {
4231 dartCopy.recordParseNotInProcess();
4232 } else {
4233 dartCopy.recordParseError();
4234 }
4235 dartCopy.exception = thrownException;
4236 _cache.put(source, dartCopy);
4237 dartEntry = dartCopy;
4238 }
4239 }
4240 if (thrownException != null) {
4241 throw thrownException;
4242 }
4243 return dartEntry;
4244 }
4245
4246 /**
4247 * Record the results produced by performing a [ParseHtmlTask]. If the results were computed
4248 * from data that is now out-of-date, then the results will not be recorded.
4249 *
4250 * @param task the task that was performed
4251 * @return an entry containing the computed results
4252 * @throws AnalysisException if the results could not be recorded
4253 */
4254 HtmlEntry recordParseHtmlTaskResults(ParseHtmlTask task) {
4255 Source source = task.source;
4256 AnalysisException thrownException = task.exception;
4257 HtmlEntry htmlEntry = null;
4258 {
4259 SourceEntry sourceEntry = _cache.get(source);
4260 if (sourceEntry is! HtmlEntry) {
4261 throw new AnalysisException.con1("Internal error: attempting to parse no n-HTML file as a HTML file: ${source.fullName}");
4262 }
4263 htmlEntry = sourceEntry as HtmlEntry;
4264 _cache.accessed(source);
4265 int sourceTime = source.modificationStamp;
4266 int resultTime = task.modificationTime;
4267 if (sourceTime == resultTime) {
4268 if (htmlEntry.modificationTime != sourceTime) {
4269 sourceChanged(source);
4270 htmlEntry = getReadableHtmlEntry(source);
4271 if (htmlEntry == null) {
4272 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
4273 }
4274 }
4275 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
4276 if (thrownException == null) {
4277 LineInfo lineInfo = task.lineInfo;
4278 HtmlUnit unit = task.htmlUnit;
4279 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
4280 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit);
4281 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries);
4282 ChangeNoticeImpl notice = getNotice(source);
4283 notice.setErrors(htmlEntry.allErrors, lineInfo);
4284 } else {
4285 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR);
4286 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
4287 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
4288 }
4289 htmlCopy.exception = thrownException;
4290 _cache.put(source, htmlCopy);
4291 htmlEntry = htmlCopy;
4292 } else {
4293 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
4294 if (thrownException == null || resultTime >= 0) {
4295 if (identical(htmlCopy.getState(SourceEntry.LINE_INFO), CacheState.IN_ PROCESS)) {
4296 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID);
4297 }
4298 if (identical(htmlCopy.getState(HtmlEntry.PARSED_UNIT), CacheState.IN_ PROCESS)) {
4299 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID);
4300 }
4301 if (identical(htmlCopy.getState(HtmlEntry.REFERENCED_LIBRARIES), Cache State.IN_PROCESS)) {
4302 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID );
4303 }
4304 } else {
4305 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR);
4306 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
4307 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
4308 }
4309 htmlCopy.exception = thrownException;
4310 _cache.put(source, htmlCopy);
4311 htmlEntry = htmlCopy;
4312 }
4313 }
4314 if (thrownException != null) {
4315 throw thrownException;
4316 }
4317 return htmlEntry;
4318 }
4319
4320 /**
4321 * Record the results produced by performing a [ResolveDartLibraryTask]. If th e results were
4322 * computed from data that is now out-of-date, then the results will not be re corded.
4323 *
4324 * @param task the task that was performed
4325 * @return an entry containing the computed results
4326 * @throws AnalysisException if the results could not be recorded
4327 */
4328 DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibraryTask task) {
4329 LibraryResolver resolver = task.libraryResolver;
4330 AnalysisException thrownException = task.exception;
4331 DartEntry unitEntry = null;
4332 Source unitSource = task.unitSource;
4333 if (resolver != null) {
4334 {
4335 if (allModificationTimesMatch(resolver)) {
4336 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
4337 RecordingErrorListener errorListener = resolver.errorListener;
4338 for (Library library in resolver.resolvedLibraries) {
4339 Source librarySource = library.librarySource;
4340 for (Source source in library.compilationUnitSources) {
4341 CompilationUnit unit = library.getAST(source);
4342 List<AnalysisError> errors = errorListener.getErrors2(source);
4343 unit.resolutionErrors = errors;
4344 LineInfo lineInfo = unit.lineInfo;
4345 DartEntry dartEntry = _cache.get(source) as DartEntry;
4346 int sourceTime = source.modificationStamp;
4347 if (dartEntry.modificationTime != sourceTime) {
4348 sourceChanged(source);
4349 dartEntry = getReadableDartEntry(source);
4350 if (dartEntry == null) {
4351 throw new AnalysisException.con1("A Dart file became a non-Dar t file: ${source.fullName}");
4352 }
4353 }
4516 DartEntryImpl dartCopy = dartEntry.writableCopy; 4354 DartEntryImpl dartCopy = dartEntry.writableCopy;
4517 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 4355 if (thrownException == null) {
4518 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); 4356 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
4519 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit); 4357 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
4520 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, err ors); 4358 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit) ;
4521 if (identical(source, librarySource)) { 4359 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, e rrors);
4522 recordElementData(dartCopy, library.libraryElement, htmlSource); 4360 if (identical(source, librarySource)) {
4361 recordElementData(dartCopy, library.libraryElement, htmlSource );
4362 }
4363 } else {
4364 dartCopy.recordResolutionError();
4523 } 4365 }
4524 _sourceMap[source] = dartCopy; 4366 dartCopy.exception = thrownException;
4367 _cache.put(source, dartCopy);
4368 if (source == unitSource) {
4369 unitEntry = dartCopy;
4370 }
4525 ChangeNoticeImpl notice = getNotice(source); 4371 ChangeNoticeImpl notice = getNotice(source);
4526 notice.compilationUnit = unit; 4372 notice.compilationUnit = unit;
4527 notice.setErrors(dartCopy.allErrors, lineInfo); 4373 notice.setErrors(dartCopy.allErrors, lineInfo);
4528 } else {
4529 sourceChanged(source);
4530 } 4374 }
4531 } 4375 }
4532 } 4376 } else {
4533 } 4377 for (Library library in resolver.resolvedLibraries) {
4534 } 4378 for (Source source in library.compilationUnitSources) {
4535 } 4379 DartEntry dartEntry = getReadableDartEntry(source);
4536 4380 if (dartEntry != null) {
4537 /** 4381 int resultTime = library.getModificationTime(source);
4538 * Remove and return one source from the list of recently used sources whose A ST structure can be 4382 DartEntryImpl dartCopy = dartEntry.writableCopy;
4539 * flushed from the cache. The source that will be returned will be the source that has been 4383 if (thrownException == null || resultTime >= 0) {
4540 * unreferenced for the longest period of time but that is not a priority for analysis. 4384 dartCopy.recordResolutionNotInProcess();
4541 * 4385 } else {
4542 * @return the source that was removed 4386 dartCopy.recordResolutionError();
4543 * 4387 }
4544 * Note: This method must only be invoked while we are synchronized on [cacheLock]. 4388 dartCopy.exception = thrownException;
4545 */ 4389 _cache.put(source, dartCopy);
4546 Source removeAstToFlush() { 4390 if (source == unitSource) {
4547 for (int i = 0; i < _recentlyUsed.length; i++) { 4391 unitEntry = dartCopy;
4548 Source source = _recentlyUsed[i]; 4392 }
4549 if (!isPrioritySource(source)) { 4393 }
4550 return _recentlyUsed.removeAt(i); 4394 }
4551 } 4395 }
4552 } 4396 }
4553 AnalysisEngine.instance.logger.logError2("Internal error: The number of prio rity sources is greater than the maximum cache size", new JavaException()); 4397 }
4554 return _recentlyUsed.removeAt(0); 4398 }
4555 } 4399 if (thrownException != null) {
4556 4400 throw thrownException;
4557 /** 4401 }
4558 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 4402 if (unitEntry == null) {
4559 * given library, or `null` if the URI is not valid. 4403 unitEntry = getReadableDartEntry(unitSource);
4560 * 4404 if (unitEntry == null) {
4561 * @param librarySource the source representing the library containing the dir ective 4405 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${ unitSource.fullName}");
4562 * @param directive the directive which URI should be resolved 4406 }
4563 * @return the result of resolving the URI against the URI of the library 4407 }
4564 */ 4408 return unitEntry;
4565 Source resolveSource(Source librarySource, UriBasedDirective directive) { 4409 }
4566 StringLiteral uriLiteral = directive.uri; 4410
4567 if (uriLiteral is StringInterpolation) { 4411 /**
4568 return null; 4412 * Record the results produced by performing a [ResolveDartUnitTask]. If the r esults were
4569 } 4413 * computed from data that is now out-of-date, then the results will not be re corded.
4570 String uriContent = uriLiteral.stringValue.trim(); 4414 *
4571 if (uriContent == null || uriContent.isEmpty) { 4415 * @param task the task that was performed
4572 return null; 4416 * @return an entry containing the computed results
4573 } 4417 * @throws AnalysisException if the results could not be recorded
4574 uriContent = Uri.encodeFull(uriContent); 4418 */
4575 try { 4419 SourceEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) {
4576 parseUriWithException(uriContent); 4420 Source unitSource = task.source;
4577 return _sourceFactory.resolveUri(librarySource, uriContent); 4421 Source librarySource = task.librarySource;
4578 } on URISyntaxException catch (exception) { 4422 AnalysisException thrownException = task.exception;
4579 return null; 4423 DartEntry dartEntry = null;
4580 } 4424 {
4581 } 4425 SourceEntry sourceEntry = _cache.get(unitSource);
4582 4426 if (sourceEntry is! DartEntry) {
4583 /** 4427 throw new AnalysisException.con1("Internal error: attempting to reolve n on-Dart file as a Dart file: ${unitSource.fullName}");
4584 * Parse the given source and update the cache. 4428 }
4585 * 4429 dartEntry = sourceEntry as DartEntry;
4586 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4430 _cache.accessed(unitSource);
4587 * 4431 int sourceTime = unitSource.modificationStamp;
4588 * @param source the source to be parsed 4432 int resultTime = task.modificationTime;
4589 * @param dartEntry the cache entry associated with the source 4433 if (sourceTime == resultTime) {
4590 */ 4434 if (dartEntry.modificationTime != sourceTime) {
4591 void safelyParseCompilationUnit(Source source, DartEntry dartEntry) { 4435 sourceChanged(unitSource);
4592 DartEntryImpl dartCopy = dartEntry.writableCopy; 4436 dartEntry = getReadableDartEntry(unitSource);
4593 try { 4437 if (dartEntry == null) {
4594 internalParseCompilationUnit(dartCopy, source); 4438 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${unitSource.fullName}");
4595 } on AnalysisException catch (exception) { 4439 }
4596 if (exception.cause is! JavaIOException) { 4440 }
4597 AnalysisEngine.instance.logger.logError2("Could not parse ${source.fullN ame}", exception); 4441 DartEntryImpl dartCopy = dartEntry.writableCopy;
4598 } 4442 if (thrownException == null) {
4599 } 4443 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, task.resolv edUnit);
4600 _sourceMap[source] = dartCopy; 4444 } else {
4601 } 4445 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR);
4602 4446 }
4603 /** 4447 dartCopy.exception = thrownException;
4604 * Parse the given source and update the cache. 4448 _cache.put(unitSource, dartCopy);
4605 * 4449 dartEntry = dartCopy;
4606 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4450 } else {
4607 * 4451 DartEntryImpl dartCopy = dartEntry.writableCopy;
4608 * @param source the source to be parsed 4452 if (thrownException == null || resultTime >= 0) {
4609 */ 4453 if (identical(dartCopy.getState(DartEntry.RESOLVED_UNIT), CacheState.I N_PROCESS)) {
4610 void safelyParseHtmlUnit(Source source) { 4454 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheStat e.INVALID);
4611 try { 4455 }
4612 parseHtmlUnit(source); 4456 } else {
4613 } on AnalysisException catch (exception) { 4457 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, CacheState. ERROR);
4614 if (exception.cause is! JavaIOException) { 4458 }
4615 AnalysisEngine.instance.logger.logError2("Could not parse ${source.fullN ame}", exception); 4459 dartCopy.exception = thrownException;
4616 } 4460 _cache.put(unitSource, dartCopy);
4617 } 4461 dartEntry = dartCopy;
4618 } 4462 }
4619 4463 }
4620 /** 4464 if (thrownException != null) {
4621 * Resolve the given source and update the cache. 4465 throw thrownException;
4622 * 4466 }
4623 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4467 return dartEntry;
4624 * 4468 }
4625 * @param source the source to be resolved 4469
4626 */ 4470 /**
4627 void safelyResolveCompilationUnit(Source source) { 4471 * Record the results produced by performing a [ResolveHtmlTask]. If the resul ts were
4628 try { 4472 * computed from data that is now out-of-date, then the results will not be re corded.
4629 computeLibraryElement(source); 4473 *
4630 } on AnalysisException catch (exception) { 4474 * @param task the task that was performed
4631 } 4475 * @return an entry containing the computed results
4632 } 4476 * @throws AnalysisException if the results could not be recorded
4633 4477 */
4634 /** 4478 SourceEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) {
4635 * Resolve the given source within the given library and update the cache. 4479 Source source = task.source;
4636 * 4480 AnalysisException thrownException = task.exception;
4637 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4481 HtmlEntry htmlEntry = null;
4638 * 4482 {
4639 * @param unitSource the source to be resolved 4483 SourceEntry sourceEntry = _cache.get(source);
4640 * @param librarySource the source 4484 if (sourceEntry is! HtmlEntry) {
4641 */ 4485 throw new AnalysisException.con1("Internal error: attempting to reolve n on-HTML file as an HTML file: ${source.fullName}");
4642 void safelyResolveCompilationUnit2(Source unitSource, Source librarySource) { 4486 }
4643 try { 4487 htmlEntry = sourceEntry as HtmlEntry;
4644 resolveCompilationUnit2(unitSource, librarySource); 4488 _cache.accessed(source);
4645 } on AnalysisException catch (exception) { 4489 int sourceTime = source.modificationStamp;
4646 DartEntryImpl dartCopy = getReadableDartEntry(unitSource).writableCopy; 4490 int resultTime = task.modificationTime;
4647 dartCopy.recordResolutionError(); 4491 if (sourceTime == resultTime) {
4648 _sourceMap[unitSource] = dartCopy; 4492 if (htmlEntry.modificationTime != sourceTime) {
4649 AnalysisEngine.instance.logger.logError2("Could not resolve ${unitSource.f ullName} in ${librarySource.fullName}", exception); 4493 sourceChanged(source);
4650 } 4494 htmlEntry = getReadableHtmlEntry(source);
4651 } 4495 if (htmlEntry == null) {
4652 4496 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
4653 /** 4497 }
4654 * Resolve the given source and update the cache. 4498 }
4655 * 4499 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4656 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4500 if (thrownException == null) {
4657 * 4501 htmlCopy.setValue(HtmlEntry.ELEMENT, task.element);
4658 * @param source the source to be resolved 4502 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, task.resolutionErrors);
4659 */ 4503 } else {
4660 void safelyResolveHtmlUnit(Source source) { 4504 htmlCopy.recordResolutionError();
4661 try { 4505 }
4662 computeHtmlElement(source); 4506 htmlCopy.exception = thrownException;
4663 } on AnalysisException catch (exception) { 4507 _cache.put(source, htmlCopy);
4664 AnalysisEngine.instance.logger.logError2("Could not resolve ${source.fullN ame}", exception); 4508 htmlEntry = htmlCopy;
4665 } 4509 } else {
4666 } 4510 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4667 HtmlScanResult scanHtml(Source source) { 4511 if (thrownException == null || resultTime >= 0) {
4668 HtmlScanner scanner = new HtmlScanner(source); 4512 if (identical(htmlCopy.getState(HtmlEntry.ELEMENT), CacheState.IN_PROC ESS)) {
4669 try { 4513 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
4670 source.getContents(scanner); 4514 }
4671 } catch (exception) { 4515 if (identical(htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS), CacheSta te.IN_PROCESS)) {
4672 throw new AnalysisException.con3(exception); 4516 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.INVALID);
4673 } 4517 }
4674 return scanner.result; 4518 } else {
4675 } 4519 htmlCopy.recordResolutionError();
4676 4520 }
4677 /** 4521 htmlCopy.exception = thrownException;
4522 _cache.put(source, htmlCopy);
4523 htmlEntry = htmlCopy;
4524 }
4525 }
4526 if (thrownException != null) {
4527 throw thrownException;
4528 }
4529 return htmlEntry;
4530 }
4531
4532 /**
4678 * Create an entry for the newly added source. Return `true` if the new source is a Dart 4533 * Create an entry for the newly added source. Return `true` if the new source is a Dart
4679 * file. 4534 * file.
4680 * 4535 *
4681 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4536 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4682 * 4537 *
4683 * @param source the source that has been added 4538 * @param source the source that has been added
4684 * @return `true` if the new source is a Dart file 4539 * @return `true` if the new source is a Dart file
4685 */ 4540 */
4686 bool sourceAvailable(Source source) { 4541 bool sourceAvailable(Source source) {
4687 SourceEntry sourceEntry = _sourceMap[source]; 4542 SourceEntry sourceEntry = _cache.get(source);
4688 if (sourceEntry == null) { 4543 if (sourceEntry == null) {
4689 sourceEntry = createSourceEntry(source); 4544 sourceEntry = createSourceEntry(source);
4690 } else { 4545 } else {
4691 SourceEntryImpl sourceCopy = sourceEntry.writableCopy; 4546 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
4692 sourceCopy.modificationTime = source.modificationStamp; 4547 sourceCopy.modificationTime = source.modificationStamp;
4693 _sourceMap[source] = sourceCopy; 4548 _cache.put(source, sourceCopy);
4694 } 4549 }
4695 return sourceEntry is DartEntry; 4550 return sourceEntry is DartEntry;
4696 } 4551 }
4697 4552
4698 /** 4553 /**
4699 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4554 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4700 * 4555 *
4701 * @param source the source that has been changed 4556 * @param source the source that has been changed
4702 */ 4557 */
4703 void sourceChanged(Source source) { 4558 void sourceChanged(Source source) {
4704 SourceEntry sourceEntry = _sourceMap[source]; 4559 SourceEntry sourceEntry = _cache.get(source);
4705 if (sourceEntry is HtmlEntry) { 4560 if (sourceEntry is HtmlEntry) {
4706 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy; 4561 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
4707 htmlCopy.modificationTime = source.modificationStamp; 4562 htmlCopy.modificationTime = source.modificationStamp;
4708 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID); 4563 htmlCopy.invalidateAllInformation();
4709 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID); 4564 _cache.put(source, htmlCopy);
4710 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID);
4711 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID);
4712 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.INVALID);
4713 _sourceMap[source] = htmlCopy;
4714 } else if (sourceEntry is DartEntry) { 4565 } else if (sourceEntry is DartEntry) {
4715 List<Source> containingLibraries = getLibrariesContaining(source); 4566 List<Source> containingLibraries = getLibrariesContaining(source);
4716 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
4717 dartCopy.modificationTime = source.modificationStamp;
4718 dartCopy.setState(DartEntry.ELEMENT, CacheState.INVALID);
4719 dartCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID);
4720 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.INVALID);
4721 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.INVALID);
4722 dartCopy.setState(DartEntry.SOURCE_KIND, CacheState.INVALID);
4723 _sourceMap[source] = dartCopy;
4724 for (Source library in containingLibraries) { 4567 for (Source library in containingLibraries) {
4725 invalidateLibraryResolution(library); 4568 invalidateLibraryResolution(library);
4726 } 4569 }
4570 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
4571 dartCopy.modificationTime = source.modificationStamp;
4572 dartCopy.invalidateAllInformation();
4573 _cache.put(source, dartCopy);
4727 } 4574 }
4728 } 4575 }
4729 4576
4730 /** 4577 /**
4731 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4578 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
4732 * 4579 *
4733 * @param source the source that has been deleted 4580 * @param source the source that has been deleted
4734 */ 4581 */
4735 void sourceRemoved(Source source) { 4582 void sourceRemoved(Source source) {
4736 DartEntry dartEntry = getDartEntry(source); 4583 SourceEntry sourceEntry = _cache.get(source);
4737 if (dartEntry != null) { 4584 if (sourceEntry is DartEntry) {
4738 Set<Source> libraries = new Set<Source>(); 4585 Set<Source> libraries = new Set<Source>();
4739 for (Source librarySource in getLibrariesContaining(source)) { 4586 for (Source librarySource in getLibrariesContaining(source)) {
4740 javaSetAdd(libraries, librarySource); 4587 javaSetAdd(libraries, librarySource);
4741 for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) { 4588 for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) {
4742 javaSetAdd(libraries, dependentLibrary); 4589 javaSetAdd(libraries, dependentLibrary);
4743 } 4590 }
4744 } 4591 }
4745 for (Source librarySource in libraries) { 4592 for (Source librarySource in libraries) {
4746 invalidateLibraryResolution(librarySource); 4593 invalidateLibraryResolution(librarySource);
4747 } 4594 }
4748 } 4595 }
4749 _sourceMap.remove(source);
4750 }
4751
4752 /**
4753 * Efficiently convert the given set of sources to an array.
4754 *
4755 * @param sources the set to be converted
4756 * @return an array containing all of the sources in the given set
4757 */
4758 List<Source> toArray(Set<Source> sources) {
4759 int size = sources.length;
4760 if (size == 0) {
4761 return Source.EMPTY_ARRAY;
4762 }
4763 return new List.from(sources);
4764 }
4765 }
4766 /**
4767 * The interface `AnalysisTask` defines the behavior of objects used to perform an analysis
4768 * task.
4769 */
4770 abstract class AnalysisContextImpl_AnalysisTask {
4771
4772 /**
4773 * Perform a single analysis task. Implementors should assume that the cache i s not locked.
4774 */
4775 void perform();
4776 }
4777 /**
4778 * Instances of the class `ParseDartTask` parse a specific source as a Dart file .
4779 */
4780 class AnalysisContextImpl_ParseDartTask implements AnalysisContextImpl_AnalysisT ask {
4781 final AnalysisContextImpl AnalysisContextImpl_this;
4782
4783 /**
4784 * The source to be parsed.
4785 */
4786 Source _source;
4787
4788 /**
4789 * Initialize a newly created task to parse the given source as a Dart file.
4790 *
4791 * @param source the source to be resolved
4792 */
4793 AnalysisContextImpl_ParseDartTask(this.AnalysisContextImpl_this, Source source ) {
4794 this._source = source;
4795 }
4796 void perform() {
4797 try {
4798 AnalysisContextImpl_this.internalParseDart(_source);
4799 } on AnalysisException catch (exception) {
4800 AnalysisEngine.instance.logger.logError2("Could not parse ${_source.fullNa me}", exception);
4801 }
4802 }
4803 }
4804 /**
4805 * Instances of the class `ParseHtmlTask` parse a specific source as an HTML fil e.
4806 */
4807 class AnalysisContextImpl_ParseHtmlTask implements AnalysisContextImpl_AnalysisT ask {
4808 final AnalysisContextImpl AnalysisContextImpl_this;
4809
4810 /**
4811 * The source to be parsed.
4812 */
4813 Source _source;
4814
4815 /**
4816 * Initialize a newly created task to parse the given source as an HTML file.
4817 *
4818 * @param source the source to be resolved
4819 */
4820 AnalysisContextImpl_ParseHtmlTask(this.AnalysisContextImpl_this, Source source ) {
4821 this._source = source;
4822 }
4823 void perform() {
4824 try {
4825 AnalysisContextImpl_this.internalParseHtml(_source);
4826 } on AnalysisException catch (exception) {
4827 AnalysisEngine.instance.logger.logError2("Could not parse ${_source.fullNa me}", exception);
4828 }
4829 }
4830 }
4831 /**
4832 * Instances of the class `ResolveDartLibraryTask` resolve a specific source as a Dart
4833 * library.
4834 */
4835 class AnalysisContextImpl_ResolveDartLibraryTask implements AnalysisContextImpl_ AnalysisTask {
4836 final AnalysisContextImpl AnalysisContextImpl_this;
4837
4838 /**
4839 * The source to be resolved.
4840 */
4841 Source _source;
4842
4843 /**
4844 * Initialize a newly created task to resolve the given source as a Dart file.
4845 *
4846 * @param source the source to be resolved
4847 */
4848 AnalysisContextImpl_ResolveDartLibraryTask(this.AnalysisContextImpl_this, Sour ce source) {
4849 this._source = source;
4850 }
4851 void perform() {
4852 try {
4853 AnalysisContextImpl_this.computeLibraryElement(_source);
4854 } on AnalysisException catch (exception) {
4855 AnalysisEngine.instance.logger.logError2("Could not resolve ${_source.full Name}", exception);
4856 }
4857 }
4858 }
4859 /**
4860 * Instances of the class `ResolveDartUnitTask` resolve a specific source as a D art file
4861 * within a library.
4862 */
4863 class AnalysisContextImpl_ResolveDartUnitTask implements AnalysisContextImpl_Ana lysisTask {
4864 final AnalysisContextImpl AnalysisContextImpl_this;
4865
4866 /**
4867 * The source to be resolved.
4868 */
4869 Source _unitSource;
4870
4871 /**
4872 * The source of the library in which the source is to be resolved.
4873 */
4874 Source _librarySource;
4875
4876 /**
4877 * Initialize a newly created task to resolve the given source as a Dart file.
4878 *
4879 * @param unitSource the source to be resolved
4880 * @param librarySource the source of the library in which the source is to be resolved
4881 */
4882 AnalysisContextImpl_ResolveDartUnitTask(this.AnalysisContextImpl_this, Source unitSource, Source librarySource) {
4883 this._unitSource = unitSource;
4884 this._librarySource = librarySource;
4885 }
4886 void perform() {
4887 try {
4888 AnalysisContextImpl_this.resolveCompilationUnit2(_unitSource, _librarySour ce);
4889 } on AnalysisException catch (exception) {
4890 DartEntryImpl dartCopy = AnalysisContextImpl_this.getReadableDartEntry(_un itSource).writableCopy;
4891 dartCopy.recordResolutionError();
4892 AnalysisContextImpl_this._sourceMap[_unitSource] = dartCopy;
4893 AnalysisEngine.instance.logger.logError2("Could not resolve ${_unitSource. fullName} in ${_librarySource.fullName}", exception);
4894 }
4895 }
4896 }
4897 /**
4898 * Instances of the class `ResolveHtmlTask` resolve a specific source as an HTML file.
4899 */
4900 class AnalysisContextImpl_ResolveHtmlTask implements AnalysisContextImpl_Analysi sTask {
4901 final AnalysisContextImpl AnalysisContextImpl_this;
4902
4903 /**
4904 * The source to be resolved.
4905 */
4906 Source _source;
4907
4908 /**
4909 * Initialize a newly created task to resolve the given source as an HTML file .
4910 *
4911 * @param source the source to be resolved
4912 */
4913 AnalysisContextImpl_ResolveHtmlTask(this.AnalysisContextImpl_this, Source sour ce) {
4914 this._source = source;
4915 }
4916 void perform() {
4917 try {
4918 AnalysisContextImpl_this.computeHtmlElement(_source);
4919 } on AnalysisException catch (exception) {
4920 AnalysisEngine.instance.logger.logError2("Could not resolve ${_source.full Name}", exception);
4921 }
4922 }
4923 }
4924 /**
4925 * Instances of the class `ScanResult` represent the results of scanning a sourc e.
4926 */
4927 class AnalysisContextImpl_ScanResult {
4928
4929 /**
4930 * The time at which the contents of the source were last modified.
4931 */
4932 int modificationTime = 0;
4933
4934 /**
4935 * The first token in the token stream.
4936 */
4937 Token _token;
4938
4939 /**
4940 * The line start information that was produced.
4941 */
4942 List<int> _lineStarts;
4943 }
4944 class RecursiveXmlVisitor_6 extends RecursiveXmlVisitor<Object> {
4945 final AnalysisContextImpl AnalysisContextImpl_this;
4946 Source htmlSource;
4947 List<Source> libraries;
4948 RecursiveXmlVisitor_6(this.AnalysisContextImpl_this, this.htmlSource, this.lib raries) : super();
4949 Object visitXmlTagNode(XmlTagNode node) {
4950 if (javaStringEqualsIgnoreCase(node.tag.lexeme, AnalysisContextImpl._TAG_SCR IPT)) {
4951 bool isDartScript = false;
4952 XmlAttributeNode scriptAttribute = null;
4953 for (XmlAttributeNode attribute in node.attributes) {
4954 if (javaStringEqualsIgnoreCase(attribute.name.lexeme, AnalysisContextImp l._ATTRIBUTE_SRC)) {
4955 scriptAttribute = attribute;
4956 } else if (javaStringEqualsIgnoreCase(attribute.name.lexeme, AnalysisCon textImpl._ATTRIBUTE_TYPE)) {
4957 String text = attribute.text;
4958 if (text != null && javaStringEqualsIgnoreCase(text, AnalysisContextIm pl._TYPE_DART)) {
4959 isDartScript = true;
4960 }
4961 }
4962 }
4963 if (isDartScript && scriptAttribute != null) {
4964 String text = scriptAttribute.text;
4965 if (text != null) {
4966 try {
4967 Uri uri = new Uri(path: text);
4968 String fileName = uri.path;
4969 Source librarySource = AnalysisContextImpl_this._sourceFactory.resol veUri(htmlSource, fileName);
4970 if (librarySource != null && librarySource.exists()) {
4971 libraries.add(librarySource);
4972 }
4973 } catch (exception) {
4974 AnalysisEngine.instance.logger.logInformation2("Invalid URI ('${text }') in script tag in '${htmlSource.fullName}'", exception);
4975 }
4976 }
4977 }
4978 }
4979 return super.visitXmlTagNode(node);
4980 }
4981 }
4982 class Source_ContentReceiver_7 implements Source_ContentReceiver {
4983 Source source;
4984 AnalysisErrorListener errorListener;
4985 AnalysisContextImpl_ScanResult result;
4986 Source_ContentReceiver_7(this.source, this.errorListener, this.result);
4987 void accept(CharBuffer contents, int modificationTime2) {
4988 CharBufferScanner scanner = new CharBufferScanner(source, contents, errorLis tener);
4989 result.modificationTime = modificationTime2;
4990 result._token = scanner.tokenize();
4991 result._lineStarts = scanner.lineStarts;
4992 }
4993 void accept2(String contents, int modificationTime2) {
4994 StringScanner scanner = new StringScanner(source, contents, errorListener);
4995 result.modificationTime = modificationTime2;
4996 result._token = scanner.tokenize();
4997 result._lineStarts = scanner.lineStarts;
4998 }
4999 }
5000 /**
5001 * Instances of the class `AnalysisContextImpl` implement an [AnalysisContext].
5002 *
5003 * @coverage dart.engine
5004 */
5005 class AnalysisContextImpl2 implements InternalAnalysisContext {
5006
5007 /**
5008 * The set of analysis options controlling the behavior of this context.
5009 */
5010 AnalysisOptions _options = new AnalysisOptionsImpl();
5011
5012 /**
5013 * The source factory used to create the sources that can be analyzed in this context.
5014 */
5015 SourceFactory _sourceFactory;
5016
5017 /**
5018 * A table mapping the sources known to the context to the information known a bout the source.
5019 */
5020 AnalysisCache _cache = new AnalysisCache(_MAX_CACHE_SIZE);
5021
5022 /**
5023 * A table mapping sources to the change notices that are waiting to be return ed related to that
5024 * source.
5025 */
5026 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm pl>();
5027
5028 /**
5029 * The object used to synchronize access to all of the caches. The rules relat ed to the use of
5030 * this lock object are
5031 *
5032 * * no analysis work is done while holding the lock, and
5033 * * no analysis results can be recorded unless we have obtained the lock and validated that the
5034 * results are for the same version (modification time) of the source as our c urrent cache
5035 * content.
5036 *
5037 */
5038 Object _cacheLock = new Object();
5039
5040 /**
5041 * The object used to record the results of performing an analysis task.
5042 */
5043 AnalysisContextImpl2_AnalysisTaskResultRecorder _resultRecorder;
5044
5045 /**
5046 * The maximum number of sources for which data should be kept in the cache.
5047 */
5048 static int _MAX_CACHE_SIZE = 64;
5049
5050 /**
5051 * The maximum number of sources that can be on the priority list. This <b>mus t</b> be less than
5052 * the [MAX_CACHE_SIZE] in order to prevent an infinite loop in performAnalysi sTask().
5053 *
5054 * @see #setAnalysisPriorityOrder(List)
5055 */
5056 static int _MAX_PRIORITY_LIST_SIZE = _MAX_CACHE_SIZE - 4;
5057
5058 /**
5059 * Initialize a newly created analysis context.
5060 */
5061 AnalysisContextImpl2() : super() {
5062 _resultRecorder = new AnalysisContextImpl2_AnalysisTaskResultRecorder(this);
5063 }
5064 void addSourceInfo(Source source, SourceEntry info) {
5065 _cache.put(source, info);
5066 }
5067 void applyChanges(ChangeSet changeSet) {
5068 if (changeSet.isEmpty) {
5069 return;
5070 }
5071 {
5072 List<Source> removedSources = new List<Source>.from(changeSet.removed3);
5073 for (SourceContainer container in changeSet.removedContainers) {
5074 addSourcesInContainer(removedSources, container);
5075 }
5076 bool addedDartSource = false;
5077 for (Source source in changeSet.added3) {
5078 if (sourceAvailable(source)) {
5079 addedDartSource = true;
5080 }
5081 }
5082 for (Source source in changeSet.changed3) {
5083 sourceChanged(source);
5084 }
5085 for (Source source in removedSources) {
5086 sourceRemoved(source);
5087 }
5088 if (addedDartSource) {
5089 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
5090 if (!mapEntry.getKey().isInSystemLibrary && mapEntry.getValue() is Dar tEntry) {
5091 DartEntryImpl dartCopy = ((mapEntry.getValue() as DartEntry)).writab leCopy;
5092 dartCopy.invalidateAllResolutionInformation();
5093 mapEntry.setValue(dartCopy);
5094 }
5095 }
5096 }
5097 }
5098 }
5099 String computeDocumentationComment(Element element) {
5100 if (element == null) {
5101 return null;
5102 }
5103 Source source = element.source;
5104 if (source == null) {
5105 return null;
5106 }
5107 CompilationUnit unit = parseCompilationUnit(source);
5108 if (unit == null) {
5109 return null;
5110 }
5111 NodeLocator locator = new NodeLocator.con1(element.nameOffset);
5112 ASTNode nameNode = locator.searchWithin(unit);
5113 while (nameNode != null) {
5114 if (nameNode is AnnotatedNode) {
5115 Comment comment = ((nameNode as AnnotatedNode)).documentationComment;
5116 if (comment == null) {
5117 return null;
5118 }
5119 JavaStringBuilder builder = new JavaStringBuilder();
5120 List<Token> tokens = comment.tokens;
5121 for (int i = 0; i < tokens.length; i++) {
5122 if (i > 0) {
5123 builder.append('\n');
5124 }
5125 builder.append(tokens[i].lexeme);
5126 }
5127 return builder.toString();
5128 }
5129 nameNode = nameNode.parent;
5130 }
5131 return null;
5132 }
5133 List<AnalysisError> computeErrors(Source source) {
5134 SourceEntry sourceEntry = getReadableSourceEntry(source);
5135 if (sourceEntry is DartEntry) {
5136 List<AnalysisError> errors = new List<AnalysisError>();
5137 DartEntry dartEntry = sourceEntry as DartEntry;
5138 ListUtilities.addAll(errors, getDartParseData(source, dartEntry, DartEntry .PARSE_ERRORS));
5139 dartEntry = getReadableDartEntry(source);
5140 if (identical(dartEntry.getValue(DartEntry.SOURCE_KIND), SourceKind.LIBRAR Y)) {
5141 ListUtilities.addAll(errors, getDartResolutionData(source, source, dartE ntry, DartEntry.RESOLUTION_ERRORS));
5142 } else {
5143 List<Source> libraries = getLibrariesContaining(source);
5144 for (Source librarySource in libraries) {
5145 ListUtilities.addAll(errors, getDartResolutionData(source, librarySour ce, dartEntry, DartEntry.RESOLUTION_ERRORS));
5146 }
5147 }
5148 if (errors.isEmpty) {
5149 return AnalysisError.NO_ERRORS;
5150 }
5151 return new List.from(errors);
5152 } else if (sourceEntry is HtmlEntry) {
5153 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5154 return getHtmlResolutionData2(source, htmlEntry, HtmlEntry.RESOLUTION_ERRO RS);
5155 }
5156 return AnalysisError.NO_ERRORS;
5157 }
5158 List<Source> computeExportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY);
5159 HtmlElement computeHtmlElement(Source source) => getHtmlResolutionData(source, HtmlEntry.ELEMENT, null);
5160 List<Source> computeImportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY);
5161 SourceKind computeKindOf(Source source) {
5162 SourceEntry sourceEntry = getReadableSourceEntry(source);
5163 if (sourceEntry == null) {
5164 return SourceKind.UNKNOWN;
5165 } else if (sourceEntry is DartEntry) {
5166 try {
5167 return getDartParseData(source, sourceEntry as DartEntry, DartEntry.SOUR CE_KIND);
5168 } on AnalysisException catch (exception) {
5169 return SourceKind.UNKNOWN;
5170 }
5171 }
5172 return sourceEntry.kind;
5173 }
5174 LibraryElement computeLibraryElement(Source source) => getDartResolutionData2( source, source, DartEntry.ELEMENT, null);
5175 LineInfo computeLineInfo(Source source) {
5176 SourceEntry sourceEntry = getReadableSourceEntry(source);
5177 if (sourceEntry is HtmlEntry) {
5178 return getHtmlParseData(source, SourceEntry.LINE_INFO, null);
5179 } else if (sourceEntry is DartEntry) {
5180 return getDartParseData2(source, SourceEntry.LINE_INFO, null);
5181 }
5182 return null;
5183 }
5184 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) {
5185 while (true) {
5186 {
5187 DartEntry dartEntry = getReadableDartEntry(source);
5188 if (dartEntry == null) {
5189 throw new AnalysisException.con1("computeResolvableCompilationUnit for non-Dart: ${source.fullName}");
5190 }
5191 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.ERRO R)) {
5192 throw new AnalysisException.con1("Internal error: computeResolvableCom pilationUnit could not parse ${source.fullName}");
5193 }
5194 DartEntryImpl dartCopy = dartEntry.writableCopy;
5195 CompilationUnit unit = dartCopy.resolvableCompilationUnit;
5196 if (unit != null) {
5197 _cache.put(source, dartCopy);
5198 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit);
5199 }
5200 }
5201 cacheDartParseData(source, getReadableDartEntry(source), DartEntry.PARSED_ UNIT);
5202 }
5203 }
5204 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) {
5205 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
5206 if (htmlEntry == null) {
5207 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}");
5208 }
5209 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT);
5210 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
5211 if (unit == null) {
5212 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}");
5213 }
5214 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
5215 }
5216 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context);
5217 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
5218 List<Source> sourcesToRemove = new List<Source>();
5219 {
5220 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5221 Source source = entry.getKey();
5222 if (container.contains(source)) {
5223 sourcesToRemove.add(source);
5224 newContext.addSourceInfo(source, entry.getValue().writableCopy);
5225 }
5226 }
5227 }
5228 return newContext;
5229 }
5230 AnalysisOptions get analysisOptions => _options;
5231 Element getElement(ElementLocation location) {
5232 try {
5233 List<String> components = ((location as ElementLocationImpl)).components;
5234 Source librarySource = computeSourceFromEncoding(components[0]);
5235 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl;
5236 for (int i = 1; i < components.length; i++) {
5237 if (element == null) {
5238 return null;
5239 }
5240 element = element.getChild(components[i]);
5241 }
5242 return element;
5243 } on AnalysisException catch (exception) {
5244 return null;
5245 }
5246 }
5247 AnalysisErrorInfo getErrors(Source source) {
5248 SourceEntry sourceEntry = getReadableSourceEntry(source);
5249 if (sourceEntry is DartEntry) {
5250 DartEntry dartEntry = sourceEntry as DartEntry;
5251 return new AnalysisErrorInfoImpl(dartEntry.allErrors, dartEntry.getValue(S ourceEntry.LINE_INFO));
5252 } else if (sourceEntry is HtmlEntry) {
5253 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5254 return new AnalysisErrorInfoImpl(htmlEntry.allErrors, htmlEntry.getValue(S ourceEntry.LINE_INFO));
5255 }
5256 return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, null);
5257 }
5258 HtmlElement getHtmlElement(Source source) {
5259 SourceEntry sourceEntry = getReadableSourceEntry(source);
5260 if (sourceEntry is HtmlEntry) {
5261 return ((sourceEntry as HtmlEntry)).getValue(HtmlEntry.ELEMENT);
5262 }
5263 return null;
5264 }
5265 List<Source> getHtmlFilesReferencing(Source source) {
5266 SourceKind sourceKind = getKindOf(source);
5267 if (sourceKind == null) {
5268 return Source.EMPTY_ARRAY;
5269 }
5270 {
5271 List<Source> htmlSources = new List<Source>();
5272 while (true) {
5273 if (sourceKind == SourceKind.LIBRARY) {
5274 } else if (sourceKind == SourceKind.PART) {
5275 List<Source> librarySources = getLibrariesContaining(source);
5276 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5277 SourceEntry sourceEntry = entry.getValue();
5278 if (identical(sourceEntry.kind, SourceKind.HTML)) {
5279 List<Source> referencedLibraries = ((sourceEntry as HtmlEntry)).ge tValue(HtmlEntry.REFERENCED_LIBRARIES);
5280 if (containsAny(referencedLibraries, librarySources)) {
5281 htmlSources.add(entry.getKey());
5282 }
5283 }
5284 }
5285 }
5286 break;
5287 }
5288 if (htmlSources.isEmpty) {
5289 return Source.EMPTY_ARRAY;
5290 }
5291 return new List.from(htmlSources);
5292 }
5293 }
5294 List<Source> get htmlSources => getSources(SourceKind.HTML);
5295 SourceKind getKindOf(Source source) {
5296 SourceEntry sourceEntry = getReadableSourceEntry(source);
5297 if (sourceEntry == null) {
5298 return SourceKind.UNKNOWN;
5299 }
5300 return sourceEntry.kind;
5301 }
5302 List<Source> get launchableClientLibrarySources {
5303 List<Source> sources = new List<Source>();
5304 {
5305 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5306 Source source = entry.getKey();
5307 SourceEntry sourceEntry = entry.getValue();
5308 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
5309 sources.add(source);
5310 }
5311 }
5312 }
5313 return new List.from(sources);
5314 }
5315 List<Source> get launchableServerLibrarySources {
5316 List<Source> sources = new List<Source>();
5317 {
5318 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5319 Source source = entry.getKey();
5320 SourceEntry sourceEntry = entry.getValue();
5321 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
5322 sources.add(source);
5323 }
5324 }
5325 }
5326 return new List.from(sources);
5327 }
5328 List<Source> getLibrariesContaining(Source source) {
5329 {
5330 SourceEntry sourceEntry = _cache.get(source);
5331 if (sourceEntry == null || sourceEntry.kind != SourceKind.PART) {
5332 return <Source> [source];
5333 }
5334 List<Source> librarySources = new List<Source>();
5335 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5336 sourceEntry = entry.getValue();
5337 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) {
5338 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.INCLUDED_ PARTS), source)) {
5339 librarySources.add(entry.getKey());
5340 }
5341 }
5342 }
5343 if (librarySources.isEmpty) {
5344 return Source.EMPTY_ARRAY;
5345 }
5346 return new List.from(librarySources);
5347 }
5348 }
5349 List<Source> getLibrariesDependingOn(Source librarySource) {
5350 {
5351 List<Source> dependentLibraries = new List<Source>();
5352 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5353 SourceEntry sourceEntry = entry.getValue();
5354 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) {
5355 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.EXPORTED_ LIBRARIES), librarySource)) {
5356 dependentLibraries.add(entry.getKey());
5357 }
5358 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.IMPORTED_ LIBRARIES), librarySource)) {
5359 dependentLibraries.add(entry.getKey());
5360 }
5361 }
5362 }
5363 if (dependentLibraries.isEmpty) {
5364 return Source.EMPTY_ARRAY;
5365 }
5366 return new List.from(dependentLibraries);
5367 }
5368 }
5369 LibraryElement getLibraryElement(Source source) {
5370 SourceEntry sourceEntry = getReadableSourceEntry(source);
5371 if (sourceEntry is DartEntry) {
5372 return ((sourceEntry as DartEntry)).getValue(DartEntry.ELEMENT);
5373 }
5374 return null;
5375 }
5376 List<Source> get librarySources => getSources(SourceKind.LIBRARY);
5377 LineInfo getLineInfo(Source source) {
5378 SourceEntry sourceEntry = getReadableSourceEntry(source);
5379 if (sourceEntry != null) {
5380 return sourceEntry.getValue(SourceEntry.LINE_INFO);
5381 }
5382 return null;
5383 }
5384 Namespace getPublicNamespace(LibraryElement library) {
5385 Source source = library.definingCompilationUnit.source;
5386 DartEntry dartEntry = getReadableDartEntry(source);
5387 if (dartEntry == null) {
5388 return null;
5389 }
5390 Namespace namespace = null;
5391 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
5392 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
5393 }
5394 if (namespace == null) {
5395 NamespaceBuilder builder = new NamespaceBuilder();
5396 namespace = builder.createPublicNamespace(library);
5397 {
5398 dartEntry = getReadableDartEntry(source);
5399 if (dartEntry == null) {
5400 AnalysisEngine.instance.logger.logError3(new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}"));
5401 return null;
5402 }
5403 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
5404 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
5405 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
5406 _cache.put(source, dartCopy);
5407 }
5408 }
5409 }
5410 return namespace;
5411 }
5412 Namespace getPublicNamespace2(Source source) {
5413 DartEntry dartEntry = getReadableDartEntry(source);
5414 if (dartEntry == null) {
5415 return null;
5416 }
5417 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
5418 if (namespace == null) {
5419 LibraryElement library = computeLibraryElement(source);
5420 if (library == null) {
5421 return null;
5422 }
5423 NamespaceBuilder builder = new NamespaceBuilder();
5424 namespace = builder.createPublicNamespace(library);
5425 {
5426 dartEntry = getReadableDartEntry(source);
5427 if (dartEntry == null) {
5428 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
5429 }
5430 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
5431 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
5432 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
5433 _cache.put(source, dartCopy);
5434 }
5435 }
5436 }
5437 return namespace;
5438 }
5439 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
5440 if (library == null) {
5441 return null;
5442 }
5443 return getResolvedCompilationUnit2(unitSource, library.source);
5444 }
5445 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
5446 SourceEntry sourceEntry = getReadableSourceEntry(unitSource);
5447 if (sourceEntry is DartEntry) {
5448 return ((sourceEntry as DartEntry)).getValue2(DartEntry.RESOLVED_UNIT, lib rarySource);
5449 }
5450 return null;
5451 }
5452 SourceFactory get sourceFactory => _sourceFactory;
5453
5454 /**
5455 * Return a list of the sources that would be processed by [performAnalysisTas k]. This
5456 * method duplicates, and must therefore be kept in sync with, [getNextTaskAna lysisTask].
5457 * This method is intended to be used for testing purposes only.
5458 *
5459 * @return a list of the sources that would be processed by [performAnalysisTa sk]
5460 */
5461 List<Source> get sourcesNeedingProcessing {
5462 Set<Source> sources = new Set<Source>();
5463 {
5464 for (Source source in _cache.priorityOrder) {
5465 SourceEntry sourceEntry = _cache.get(source);
5466 if (sourceEntry is DartEntry) {
5467 DartEntry dartEntry = sourceEntry as DartEntry;
5468 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERROR S);
5469 if (identical(parseErrorsState, CacheState.INVALID) || identical(parse ErrorsState, CacheState.FLUSHED)) {
5470 javaSetAdd(sources, source);
5471 }
5472 CacheState parseUnitState = dartEntry.getState(DartEntry.PARSED_UNIT);
5473 if (identical(parseUnitState, CacheState.INVALID) || identical(parseUn itState, CacheState.FLUSHED)) {
5474 javaSetAdd(sources, source);
5475 }
5476 for (Source librarySource in getLibrariesContaining(source)) {
5477 SourceEntry libraryEntry = _cache.get(librarySource);
5478 if (libraryEntry is DartEntry) {
5479 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT) ;
5480 if (identical(elementState, CacheState.INVALID) || identical(eleme ntState, CacheState.FLUSHED)) {
5481 javaSetAdd(sources, source);
5482 }
5483 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOL VED_UNIT, librarySource);
5484 if (identical(resolvedUnitState, CacheState.INVALID) || identical( resolvedUnitState, CacheState.FLUSHED)) {
5485 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
5486 if (libraryElement != null) {
5487 javaSetAdd(sources, source);
5488 }
5489 }
5490 }
5491 }
5492 } else if (sourceEntry is HtmlEntry) {
5493 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5494 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ;
5495 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsed UnitState, CacheState.FLUSHED)) {
5496 javaSetAdd(sources, source);
5497 }
5498 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
5499 if (identical(elementState, CacheState.INVALID) || identical(elementSt ate, CacheState.FLUSHED)) {
5500 javaSetAdd(sources, source);
5501 }
5502 }
5503 }
5504 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5505 SourceEntry sourceEntry = entry.getValue();
5506 if (sourceEntry is DartEntry) {
5507 DartEntry dartEntry = sourceEntry as DartEntry;
5508 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.IN VALID)) {
5509 javaSetAdd(sources, entry.getKey());
5510 }
5511 } else if (sourceEntry is HtmlEntry) {
5512 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5513 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.IN VALID)) {
5514 javaSetAdd(sources, entry.getKey());
5515 }
5516 }
5517 }
5518 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5519 SourceEntry sourceEntry = entry.getValue();
5520 if (sourceEntry is DartEntry && identical(sourceEntry.kind, SourceKind.L IBRARY)) {
5521 DartEntry dartEntry = sourceEntry as DartEntry;
5522 if (identical(dartEntry.getState(DartEntry.ELEMENT), CacheState.INVALI D)) {
5523 javaSetAdd(sources, entry.getKey());
5524 }
5525 } else if (sourceEntry is HtmlEntry) {
5526 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5527 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALI D)) {
5528 javaSetAdd(sources, entry.getKey());
5529 }
5530 }
5531 }
5532 }
5533 return new List<Source>.from(sources);
5534 }
5535 AnalysisContentStatistics get statistics {
5536 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl ();
5537 {
5538 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
5539 SourceEntry entry = mapEntry.getValue();
5540 if (entry is DartEntry) {
5541 Source source = mapEntry.getKey();
5542 DartEntry dartEntry = entry as DartEntry;
5543 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND);
5544 statistics.putCacheItem(dartEntry, DartEntry.PARSE_ERRORS);
5545 statistics.putCacheItem(dartEntry, DartEntry.PARSED_UNIT);
5546 statistics.putCacheItem(dartEntry, DartEntry.SOURCE_KIND);
5547 statistics.putCacheItem(dartEntry, DartEntry.LINE_INFO);
5548 if (identical(kind, SourceKind.LIBRARY)) {
5549 statistics.putCacheItem(dartEntry, DartEntry.ELEMENT);
5550 statistics.putCacheItem(dartEntry, DartEntry.EXPORTED_LIBRARIES);
5551 statistics.putCacheItem(dartEntry, DartEntry.IMPORTED_LIBRARIES);
5552 statistics.putCacheItem(dartEntry, DartEntry.INCLUDED_PARTS);
5553 statistics.putCacheItem(dartEntry, DartEntry.IS_CLIENT);
5554 statistics.putCacheItem(dartEntry, DartEntry.IS_LAUNCHABLE);
5555 }
5556 List<Source> librarySources = getLibrariesContaining(source);
5557 for (Source librarySource in librarySources) {
5558 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLUT ION_ERRORS);
5559 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLVE D_UNIT);
5560 }
5561 }
5562 }
5563 }
5564 return statistics;
5565 }
5566 bool isClientLibrary(Source librarySource) {
5567 SourceEntry sourceEntry = getReadableSourceEntry(librarySource);
5568 if (sourceEntry is DartEntry) {
5569 DartEntry dartEntry = sourceEntry as DartEntry;
5570 return dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(DartE ntry.IS_LAUNCHABLE);
5571 }
5572 return false;
5573 }
5574 bool isServerLibrary(Source librarySource) {
5575 SourceEntry sourceEntry = getReadableSourceEntry(librarySource);
5576 if (sourceEntry is DartEntry) {
5577 DartEntry dartEntry = sourceEntry as DartEntry;
5578 return !dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(Dart Entry.IS_LAUNCHABLE);
5579 }
5580 return false;
5581 }
5582 void mergeContext(AnalysisContext context) {
5583 if (context is InstrumentedAnalysisContextImpl) {
5584 context = ((context as InstrumentedAnalysisContextImpl)).basis;
5585 }
5586 if (context is! AnalysisContextImpl2) {
5587 return;
5588 }
5589 {
5590 for (MapEntry<Source, SourceEntry> entry in ((context as AnalysisContextIm pl2))._cache.entrySet()) {
5591 Source newSource = entry.getKey();
5592 SourceEntry existingEntry = getReadableSourceEntry(newSource);
5593 if (existingEntry == null) {
5594 _cache.put(newSource, entry.getValue().writableCopy);
5595 } else {
5596 }
5597 }
5598 }
5599 }
5600 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null);
5601 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA RSED_UNIT, null);
5602 List<ChangeNotice> performAnalysisTask() {
5603 AnalysisTask task = nextTaskAnalysisTask;
5604 if (task == null) {
5605 return getChangeNotices(true);
5606 }
5607 try {
5608 task.perform(_resultRecorder);
5609 } on AnalysisException catch (exception) {
5610 if (exception.cause is! JavaIOException) {
5611 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception);
5612 }
5613 }
5614 return getChangeNotices(false);
5615 }
5616 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
5617 {
5618 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML);
5619 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
5620 Source librarySource = entry.getKey();
5621 LibraryElement library = entry.getValue();
5622 DartEntry dartEntry = getReadableDartEntry(librarySource);
5623 if (dartEntry != null) {
5624 DartEntryImpl dartCopy = dartEntry.writableCopy;
5625 recordElementData(dartCopy, library, htmlSource);
5626 _cache.put(librarySource, dartCopy);
5627 }
5628 }
5629 }
5630 }
5631 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) {
5632 if (library == null) {
5633 return null;
5634 }
5635 return resolveCompilationUnit2(unitSource, library.source);
5636 }
5637 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT, null);
5638 HtmlUnit resolveHtmlUnit(Source htmlSource) => parseHtmlUnit(htmlSource);
5639 void set analysisOptions(AnalysisOptions options2) {
5640 {
5641 this._options = options2;
5642 invalidateAllResolutionInformation();
5643 }
5644 }
5645 void set analysisPriorityOrder(List<Source> sources) {
5646 {
5647 if (sources == null || sources.isEmpty) {
5648 _cache.priorityOrder = Source.EMPTY_ARRAY;
5649 } else {
5650 while (sources.remove(null)) {
5651 }
5652 if (sources.isEmpty) {
5653 _cache.priorityOrder = Source.EMPTY_ARRAY;
5654 }
5655 int count = Math.min(sources.length, _MAX_PRIORITY_LIST_SIZE);
5656 List<Source> priorityOrder = new List<Source>(count);
5657 for (int i = 0; i < count; i++) {
5658 priorityOrder[i] = sources[i];
5659 }
5660 _cache.priorityOrder = priorityOrder;
5661 }
5662 }
5663 }
5664 void setContents(Source source, String contents) {
5665 {
5666 if (_sourceFactory.setContents(source, contents)) {
5667 sourceChanged(source);
5668 }
5669 }
5670 }
5671 void set sourceFactory(SourceFactory factory) {
5672 {
5673 if (identical(_sourceFactory, factory)) {
5674 return;
5675 } else if (factory.context != null) {
5676 throw new IllegalStateException("Source factories cannot be shared betwe en contexts");
5677 }
5678 if (_sourceFactory != null) {
5679 _sourceFactory.context = null;
5680 }
5681 factory.context = this;
5682 _sourceFactory = factory;
5683 invalidateAllResolutionInformation();
5684 }
5685 }
5686 Iterable<Source> sourcesToResolve(List<Source> changedSources) {
5687 List<Source> librarySources = new List<Source>();
5688 for (Source source in changedSources) {
5689 if (identical(computeKindOf(source), SourceKind.LIBRARY)) {
5690 librarySources.add(source);
5691 }
5692 }
5693 return librarySources;
5694 }
5695
5696 /**
5697 * Add all of the sources contained in the given source container to the given list of sources.
5698 *
5699 * Note: This method must only be invoked while we are synchronized on [cacheL ock].
5700 *
5701 * @param sources the list to which sources are to be added
5702 * @param container the source container containing the sources to be added to the list
5703 */
5704 void addSourcesInContainer(List<Source> sources, SourceContainer container) {
5705 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5706 Source source = entry.getKey();
5707 if (container.contains(source)) {
5708 sources.add(source);
5709 }
5710 }
5711 }
5712
5713 /**
5714 * Return `true` if the modification times of the sources used by the given li brary resolver
5715 * to resolve one or more libraries are consistent with the modification times in the cache.
5716 *
5717 * @param resolver the library resolver used to resolve one or more libraries
5718 * @return `true` if we should record the results of the resolution
5719 * @throws AnalysisException if any of the modification times could not be det ermined (this should
5720 * not happen)
5721 */
5722 bool allModificationTimesMatch(LibraryResolver resolver) {
5723 bool allTimesMatch = true;
5724 for (Library library in resolver.resolvedLibraries) {
5725 for (Source source in library.compilationUnitSources) {
5726 DartEntry dartEntry = getReadableDartEntry(source);
5727 if (dartEntry == null) {
5728 throw new AnalysisException.con1("Internal error: attempting to reolve non-Dart file as a Dart file: ${source.fullName}");
5729 }
5730 int sourceTime = source.modificationStamp;
5731 int resultTime = library.getModificationTime(source);
5732 if (sourceTime != resultTime) {
5733 sourceChanged(source);
5734 allTimesMatch = false;
5735 }
5736 }
5737 }
5738 return allTimesMatch;
5739 }
5740
5741 /**
5742 * Given a source for a Dart file, return a cache entry in which the data repr esented by the given
5743 * descriptor is available. This method assumes that the data can be produced by parsing the
5744 * source if it is not already cached.
5745 *
5746 * @param source the source representing the Dart file
5747 * @param dartEntry the cache entry associated with the Dart file
5748 * @param descriptor the descriptor representing the data to be returned
5749 * @return a cache entry containing the required data
5750 * @throws AnalysisException if data could not be returned because the source could not be
5751 * resolved
5752 */
5753 DartEntry cacheDartParseData(Source source, DartEntry dartEntry, DataDescripto r descriptor) {
5754 if (identical(descriptor, DartEntry.PARSED_UNIT)) {
5755 CompilationUnit unit = dartEntry.anyParsedCompilationUnit;
5756 if (unit != null) {
5757 return dartEntry;
5758 }
5759 }
5760 CacheState state = dartEntry.getState(descriptor);
5761 while (state != CacheState.ERROR && state != CacheState.VALID) {
5762 dartEntry = new ParseDartTask(this, source).perform(_resultRecorder) as Da rtEntry;
5763 state = dartEntry.getState(descriptor);
5764 }
5765 return dartEntry;
5766 }
5767
5768 /**
5769 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
5770 * the data represented by the given descriptor is available. This method assu mes that the data
5771 * can be produced by resolving the source in the context of the library if it is not already
5772 * cached.
5773 *
5774 * @param unitSource the source representing the Dart file
5775 * @param librarySource the source representing the library containing the Dar t file
5776 * @param dartEntry the cache entry associated with the Dart file
5777 * @param descriptor the descriptor representing the data to be returned
5778 * @return a cache entry containing the required data
5779 * @throws AnalysisException if data could not be returned because the source could not be parsed
5780 */
5781 DartEntry cacheDartResolutionData(Source unitSource, Source librarySource, Dar tEntry dartEntry, DataDescriptor descriptor) {
5782 CacheState state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.ge tState(descriptor) : dartEntry.getState2(descriptor, librarySource);
5783 while (state != CacheState.ERROR && state != CacheState.VALID) {
5784 dartEntry = new ResolveDartLibraryTask(this, unitSource, librarySource).pe rform(_resultRecorder) as DartEntry;
5785 state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.getState(de scriptor) : dartEntry.getState2(descriptor, librarySource);
5786 }
5787 return dartEntry;
5788 }
5789
5790 /**
5791 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by
5792 * the given descriptors is available. This method assumes that the data can b e produced by
5793 * parsing the source if it is not already cached.
5794 *
5795 * @param source the source representing the HTML file
5796 * @param htmlEntry the cache entry associated with the HTML file
5797 * @param descriptor the descriptor representing the data to be returned
5798 * @return a cache entry containing the required data
5799 * @throws AnalysisException if data could not be returned because the source could not be
5800 * resolved
5801 */
5802 HtmlEntry cacheHtmlParseData(Source source, HtmlEntry htmlEntry, DataDescripto r descriptor) {
5803 CacheState state = htmlEntry.getState(descriptor);
5804 while (state != CacheState.ERROR && state != CacheState.VALID) {
5805 htmlEntry = new ParseHtmlTask(this, source).perform(_resultRecorder) as Ht mlEntry;
5806 state = htmlEntry.getState(descriptor);
5807 }
5808 return htmlEntry;
5809 }
5810
5811 /**
5812 * Given a source for an HTML file, return a cache entry in which the the data represented by the
5813 * given descriptor is available. This method assumes that the data can be pro duced by resolving
5814 * the source if it is not already cached.
5815 *
5816 * @param source the source representing the HTML file
5817 * @param dartEntry the cache entry associated with the HTML file
5818 * @param descriptor the descriptor representing the data to be returned
5819 * @return a cache entry containing the required data
5820 * @throws AnalysisException if data could not be returned because the source could not be
5821 * resolved
5822 */
5823 HtmlEntry cacheHtmlResolutionData(Source source, HtmlEntry htmlEntry, DataDesc riptor descriptor) {
5824 CacheState state = htmlEntry.getState(descriptor);
5825 while (state != CacheState.ERROR && state != CacheState.VALID) {
5826 htmlEntry = new ResolveHtmlTask(this, source).perform(_resultRecorder) as HtmlEntry;
5827 state = htmlEntry.getState(descriptor);
5828 }
5829 return htmlEntry;
5830 }
5831
5832 /**
5833 * Given the encoded form of a source, use the source factory to reconstitute the original source.
5834 *
5835 * @param encoding the encoded form of a source
5836 * @return the source represented by the encoding
5837 */
5838 Source computeSourceFromEncoding(String encoding) {
5839 {
5840 return _sourceFactory.fromEncoding(encoding);
5841 }
5842 }
5843
5844 /**
5845 * Return `true` if the given array of sources contains the given source.
5846 *
5847 * @param sources the sources being searched
5848 * @param targetSource the source being searched for
5849 * @return `true` if the given source is in the array
5850 */
5851 bool contains(List<Source> sources, Source targetSource) {
5852 for (Source source in sources) {
5853 if (source == targetSource) {
5854 return true;
5855 }
5856 }
5857 return false;
5858 }
5859
5860 /**
5861 * Return `true` if the given array of sources contains any of the given targe t sources.
5862 *
5863 * @param sources the sources being searched
5864 * @param targetSources the sources being searched for
5865 * @return `true` if any of the given target sources are in the array
5866 */
5867 bool containsAny(List<Source> sources, List<Source> targetSources) {
5868 for (Source targetSource in targetSources) {
5869 if (contains(sources, targetSource)) {
5870 return true;
5871 }
5872 }
5873 return false;
5874 }
5875
5876 /**
5877 * Create a source information object suitable for the given source. Return th e source information
5878 * object that was created, or `null` if the source should not be tracked by t his context.
5879 *
5880 * @param source the source for which an information object is being created
5881 * @return the source information object that was created
5882 */
5883 SourceEntry createSourceEntry(Source source) {
5884 String name = source.shortName;
5885 if (AnalysisEngine.isHtmlFileName(name)) {
5886 HtmlEntryImpl htmlEntry = new HtmlEntryImpl();
5887 htmlEntry.modificationTime = source.modificationStamp;
5888 _cache.put(source, htmlEntry);
5889 return htmlEntry;
5890 } else {
5891 DartEntryImpl dartEntry = new DartEntryImpl();
5892 dartEntry.modificationTime = source.modificationStamp;
5893 _cache.put(source, dartEntry);
5894 return dartEntry;
5895 }
5896 }
5897
5898 /**
5899 * Return an array containing all of the change notices that are waiting to be returned. If there
5900 * are no notices, then return either `null` or an empty array, depending on t he value of
5901 * the argument.
5902 *
5903 * @param nullIfEmpty `true` if `null` should be returned when there are no no tices
5904 * @return the change notices that are waiting to be returned
5905 */
5906 List<ChangeNotice> getChangeNotices(bool nullIfEmpty) {
5907 {
5908 if (_pendingNotices.isEmpty) {
5909 if (nullIfEmpty) {
5910 return null;
5911 }
5912 return ChangeNoticeImpl.EMPTY_ARRAY;
5913 }
5914 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
5915 _pendingNotices.clear();
5916 return notices;
5917 }
5918 }
5919
5920 /**
5921 * Given a source for a Dart file, return the data represented by the given de scriptor that is
5922 * associated with that source. This method assumes that the data can be produ ced by parsing the
5923 * source if it is not already cached.
5924 *
5925 * @param source the source representing the Dart file
5926 * @param dartEntry the cache entry associated with the Dart file
5927 * @param descriptor the descriptor representing the data to be returned
5928 * @return the requested data about the given source
5929 * @throws AnalysisException if data could not be returned because the source could not be parsed
5930 */
5931 Object getDartParseData(Source source, DartEntry dartEntry, DataDescriptor des criptor) {
5932 dartEntry = cacheDartParseData(source, dartEntry, descriptor);
5933 if (identical(descriptor, DartEntry.PARSED_UNIT)) {
5934 return dartEntry.anyParsedCompilationUnit as Object;
5935 }
5936 return dartEntry.getValue(descriptor);
5937 }
5938
5939 /**
5940 * Given a source for a Dart file, return the data represented by the given de scriptor that is
5941 * associated with that source, or the given default value if the source is no t a Dart file. This
5942 * method assumes that the data can be produced by parsing the source if it is not already cached.
5943 *
5944 * @param source the source representing the Dart file
5945 * @param descriptor the descriptor representing the data to be returned
5946 * @param defaultValue the value to be returned if the source is not a Dart fi le
5947 * @return the requested data about the given source
5948 * @throws AnalysisException if data could not be returned because the source could not be parsed
5949 */
5950 Object getDartParseData2(Source source, DataDescriptor descriptor, Object defa ultValue) {
5951 DartEntry dartEntry = getReadableDartEntry(source);
5952 if (dartEntry == null) {
5953 return defaultValue;
5954 }
5955 return getDartParseData(source, dartEntry, descriptor);
5956 }
5957
5958 /**
5959 * Given a source for a Dart file and the library that contains it, return the data represented by
5960 * the given descriptor that is associated with that source. This method assum es that the data can
5961 * be produced by resolving the source in the context of the library if it is not already cached.
5962 *
5963 * @param unitSource the source representing the Dart file
5964 * @param librarySource the source representing the library containing the Dar t file
5965 * @param dartEntry the entry representing the Dart file
5966 * @param descriptor the descriptor representing the data to be returned
5967 * @return the requested data about the given source
5968 * @throws AnalysisException if data could not be returned because the source could not be
5969 * resolved
5970 */
5971 Object getDartResolutionData(Source unitSource, Source librarySource, DartEntr y dartEntry, DataDescriptor descriptor) {
5972 dartEntry = cacheDartResolutionData(unitSource, librarySource, dartEntry, de scriptor);
5973 if (identical(descriptor, DartEntry.ELEMENT)) {
5974 return dartEntry.getValue(descriptor);
5975 }
5976 return dartEntry.getValue2(descriptor, librarySource);
5977 }
5978
5979 /**
5980 * Given a source for a Dart file and the library that contains it, return the data represented by
5981 * the given descriptor that is associated with that source, or the given defa ult value if the
5982 * source is not a Dart file. This method assumes that the data can be produce d by resolving the
5983 * source in the context of the library if it is not already cached.
5984 *
5985 * @param unitSource the source representing the Dart file
5986 * @param librarySource the source representing the library containing the Dar t file
5987 * @param descriptor the descriptor representing the data to be returned
5988 * @param defaultValue the value to be returned if the source is not a Dart fi le
5989 * @return the requested data about the given source
5990 * @throws AnalysisException if data could not be returned because the source could not be
5991 * resolved
5992 */
5993 Object getDartResolutionData2(Source unitSource, Source librarySource, DataDes criptor descriptor, Object defaultValue) {
5994 DartEntry dartEntry = getReadableDartEntry(unitSource);
5995 if (dartEntry == null) {
5996 return defaultValue;
5997 }
5998 return getDartResolutionData(unitSource, librarySource, dartEntry, descripto r);
5999 }
6000
6001 /**
6002 * Given a source for an HTML file, return the data represented by the given d escriptor that is
6003 * associated with that source, or the given default value if the source is no t an HTML file. This
6004 * method assumes that the data can be produced by parsing the source if it is not already cached.
6005 *
6006 * @param source the source representing the Dart file
6007 * @param descriptor the descriptor representing the data to be returned
6008 * @param defaultValue the value to be returned if the source is not an HTML f ile
6009 * @return the requested data about the given source
6010 * @throws AnalysisException if data could not be returned because the source could not be parsed
6011 */
6012 Object getHtmlParseData(Source source, DataDescriptor descriptor, Object defau ltValue) {
6013 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
6014 if (htmlEntry == null) {
6015 return defaultValue;
6016 }
6017 htmlEntry = cacheHtmlParseData(source, htmlEntry, descriptor);
6018 return htmlEntry.getValue(descriptor);
6019 }
6020
6021 /**
6022 * Given a source for an HTML file, return the data represented by the given d escriptor that is
6023 * associated with that source, or the given default value if the source is no t an HTML file. This
6024 * method assumes that the data can be produced by resolving the source if it is not already
6025 * cached.
6026 *
6027 * @param source the source representing the HTML file
6028 * @param descriptor the descriptor representing the data to be returned
6029 * @param defaultValue the value to be returned if the source is not an HTML f ile
6030 * @return the requested data about the given source
6031 * @throws AnalysisException if data could not be returned because the source could not be
6032 * resolved
6033 */
6034 Object getHtmlResolutionData(Source source, DataDescriptor descriptor, Object defaultValue) {
6035 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
6036 if (htmlEntry == null) {
6037 return defaultValue;
6038 }
6039 return getHtmlResolutionData2(source, htmlEntry, descriptor);
6040 }
6041
6042 /**
6043 * Given a source for an HTML file, return the data represented by the given d escriptor that is
6044 * associated with that source. This method assumes that the data can be produ ced by resolving the
6045 * source if it is not already cached.
6046 *
6047 * @param source the source representing the HTML file
6048 * @param htmlEntry the entry representing the HTML file
6049 * @param descriptor the descriptor representing the data to be returned
6050 * @return the requested data about the given source
6051 * @throws AnalysisException if data could not be returned because the source could not be
6052 * resolved
6053 */
6054 Object getHtmlResolutionData2(Source source, HtmlEntry htmlEntry, DataDescript or descriptor) {
6055 htmlEntry = cacheHtmlResolutionData(source, htmlEntry, descriptor);
6056 return htmlEntry.getValue(descriptor);
6057 }
6058
6059 /**
6060 * Look through the cache for a task that needs to be performed. Return the ta sk that was found,
6061 * or `null` if there is no more work to be done.
6062 *
6063 * @return the next task that needs to be performed
6064 */
6065 AnalysisTask get nextTaskAnalysisTask {
6066 {
6067 for (Source source in _cache.priorityOrder) {
6068 SourceEntry sourceEntry = _cache.get(source);
6069 if (sourceEntry is DartEntry) {
6070 DartEntry dartEntry = sourceEntry as DartEntry;
6071 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERROR S);
6072 if (identical(parseErrorsState, CacheState.INVALID) || identical(parse ErrorsState, CacheState.FLUSHED)) {
6073 DartEntryImpl dartCopy = dartEntry.writableCopy;
6074 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
6075 _cache.put(source, dartCopy);
6076 return new ParseDartTask(this, source);
6077 }
6078 CacheState parseUnitState = dartEntry.getState(DartEntry.PARSED_UNIT);
6079 if (identical(parseUnitState, CacheState.INVALID) || identical(parseUn itState, CacheState.FLUSHED)) {
6080 DartEntryImpl dartCopy = dartEntry.writableCopy;
6081 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS);
6082 _cache.put(source, dartCopy);
6083 return new ParseDartTask(this, source);
6084 }
6085 for (Source librarySource in getLibrariesContaining(source)) {
6086 SourceEntry libraryEntry = _cache.get(librarySource);
6087 if (libraryEntry is DartEntry) {
6088 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT) ;
6089 if (identical(elementState, CacheState.INVALID) || identical(eleme ntState, CacheState.FLUSHED)) {
6090 DartEntryImpl libraryCopy = ((libraryEntry as DartEntry)).writab leCopy;
6091 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
6092 _cache.put(librarySource, libraryCopy);
6093 return new ResolveDartLibraryTask(this, source, librarySource);
6094 }
6095 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOL VED_UNIT, librarySource);
6096 if (identical(resolvedUnitState, CacheState.INVALID) || identical( resolvedUnitState, CacheState.FLUSHED)) {
6097 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
6098 if (libraryElement != null) {
6099 DartEntryImpl dartCopy = dartEntry.writableCopy;
6100 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, Cac heState.IN_PROCESS);
6101 _cache.put(source, dartCopy);
6102 return new ResolveDartUnitTask(this, source, libraryElement);
6103 }
6104 }
6105 }
6106 }
6107 } else if (sourceEntry is HtmlEntry) {
6108 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
6109 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ;
6110 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsed UnitState, CacheState.FLUSHED)) {
6111 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6112 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
6113 _cache.put(source, htmlCopy);
6114 return new ParseHtmlTask(this, source);
6115 }
6116 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
6117 if (identical(elementState, CacheState.INVALID) || identical(elementSt ate, CacheState.FLUSHED)) {
6118 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6119 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
6120 _cache.put(source, htmlCopy);
6121 return new ResolveHtmlTask(this, source);
6122 }
6123 }
6124 }
6125 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
6126 SourceEntry sourceEntry = entry.getValue();
6127 if (sourceEntry is DartEntry) {
6128 DartEntry dartEntry = sourceEntry as DartEntry;
6129 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.IN VALID)) {
6130 Source source = entry.getKey();
6131 DartEntryImpl dartCopy = dartEntry.writableCopy;
6132 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
6133 _cache.put(source, dartCopy);
6134 return new ParseDartTask(this, source);
6135 }
6136 } else if (sourceEntry is HtmlEntry) {
6137 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
6138 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.IN VALID)) {
6139 Source source = entry.getKey();
6140 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6141 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
6142 _cache.put(source, htmlCopy);
6143 return new ParseHtmlTask(this, source);
6144 }
6145 }
6146 }
6147 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
6148 SourceEntry sourceEntry = entry.getValue();
6149 if (sourceEntry is DartEntry && identical(sourceEntry.kind, SourceKind.L IBRARY)) {
6150 DartEntry dartEntry = sourceEntry as DartEntry;
6151 if (identical(dartEntry.getState(DartEntry.ELEMENT), CacheState.INVALI D)) {
6152 Source source = entry.getKey();
6153 DartEntryImpl dartCopy = dartEntry.writableCopy;
6154 dartCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
6155 _cache.put(source, dartCopy);
6156 return new ResolveDartLibraryTask(this, source, source);
6157 }
6158 } else if (sourceEntry is HtmlEntry) {
6159 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
6160 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALI D)) {
6161 Source source = entry.getKey();
6162 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6163 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
6164 _cache.put(source, htmlCopy);
6165 return new ResolveHtmlTask(this, source);
6166 }
6167 }
6168 }
6169 return null;
6170 }
6171 }
6172
6173 /**
6174 * Return a change notice for the given source, creating one if one does not a lready exist.
6175 *
6176 * @param source the source for which changes are being reported
6177 * @return a change notice for the given source
6178 */
6179 ChangeNoticeImpl getNotice(Source source) {
6180 ChangeNoticeImpl notice = _pendingNotices[source];
6181 if (notice == null) {
6182 notice = new ChangeNoticeImpl(source);
6183 _pendingNotices[source] = notice;
6184 }
6185 return notice;
6186 }
6187
6188 /**
6189 * Return the cache entry associated with the given source, or `null` if the s ource is not a
6190 * Dart file.
6191 *
6192 * @param source the source for which a cache entry is being sought
6193 * @return the source cache entry associated with the given source
6194 */
6195 DartEntry getReadableDartEntry(Source source) {
6196 {
6197 SourceEntry sourceEntry = _cache.get(source);
6198 if (sourceEntry == null) {
6199 sourceEntry = createSourceEntry(source);
6200 }
6201 if (sourceEntry is DartEntry) {
6202 _cache.accessed(source);
6203 return sourceEntry as DartEntry;
6204 }
6205 return null;
6206 }
6207 }
6208
6209 /**
6210 * Return the cache entry associated with the given source, or `null` if the s ource is not
6211 * an HTML file.
6212 *
6213 * @param source the source for which a cache entry is being sought
6214 * @return the source cache entry associated with the given source
6215 */
6216 HtmlEntry getReadableHtmlEntry(Source source) {
6217 {
6218 SourceEntry sourceEntry = _cache.get(source);
6219 if (sourceEntry == null) {
6220 sourceEntry = createSourceEntry(source);
6221 }
6222 if (sourceEntry is HtmlEntry) {
6223 _cache.accessed(source);
6224 return sourceEntry as HtmlEntry;
6225 }
6226 return null;
6227 }
6228 }
6229
6230 /**
6231 * Return the cache entry associated with the given source, or `null` if there is no entry
6232 * associated with the source.
6233 *
6234 * @param source the source for which a cache entry is being sought
6235 * @return the source cache entry associated with the given source
6236 */
6237 SourceEntry getReadableSourceEntry(Source source) {
6238 {
6239 SourceEntry sourceEntry = _cache.get(source);
6240 if (sourceEntry == null) {
6241 sourceEntry = createSourceEntry(source);
6242 }
6243 if (sourceEntry != null) {
6244 _cache.accessed(source);
6245 }
6246 return sourceEntry;
6247 }
6248 }
6249
6250 /**
6251 * Return an array containing all of the sources known to this context that ha ve the given kind.
6252 *
6253 * @param kind the kind of sources to be returned
6254 * @return all of the sources known to this context that have the given kind
6255 */
6256 List<Source> getSources(SourceKind kind2) {
6257 List<Source> sources = new List<Source>();
6258 {
6259 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
6260 if (identical(entry.getValue().kind, kind2)) {
6261 sources.add(entry.getKey());
6262 }
6263 }
6264 }
6265 return new List.from(sources);
6266 }
6267
6268 /**
6269 * Invalidate all of the resolution results computed by this context.
6270 *
6271 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6272 */
6273 void invalidateAllResolutionInformation() {
6274 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
6275 SourceEntry sourceEntry = mapEntry.getValue();
6276 if (sourceEntry is HtmlEntry) {
6277 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6278 htmlCopy.invalidateAllResolutionInformation();
6279 mapEntry.setValue(htmlCopy);
6280 } else if (sourceEntry is DartEntry) {
6281 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
6282 dartCopy.invalidateAllResolutionInformation();
6283 mapEntry.setValue(dartCopy);
6284 }
6285 }
6286 }
6287
6288 /**
6289 * In response to a change to at least one of the compilation units in the giv en library,
6290 * invalidate any results that are dependent on the result of resolving that l ibrary.
6291 *
6292 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6293 *
6294 * @param librarySource the source of the library being invalidated
6295 */
6296 void invalidateLibraryResolution(Source librarySource) {
6297 DartEntry libraryEntry = getReadableDartEntry(librarySource);
6298 if (libraryEntry != null) {
6299 List<Source> includedParts = libraryEntry.getValue(DartEntry.INCLUDED_PART S);
6300 DartEntryImpl libraryCopy = libraryEntry.writableCopy;
6301 libraryCopy.invalidateAllResolutionInformation();
6302 libraryCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID);
6303 _cache.put(librarySource, libraryCopy);
6304 for (Source partSource in includedParts) {
6305 DartEntry partEntry = getReadableDartEntry(partSource);
6306 if (partEntry != null) {
6307 DartEntryImpl partCopy = partEntry.writableCopy;
6308 partCopy.invalidateAllResolutionInformation();
6309 _cache.put(partSource, partCopy);
6310 }
6311 }
6312 }
6313 }
6314
6315 /**
6316 * Return `true` if this library is, or depends on, dart:html.
6317 *
6318 * @param library the library being tested
6319 * @param visitedLibraries a collection of the libraries that have been visite d, used to prevent
6320 * infinite recursion
6321 * @return `true` if this library is, or depends on, dart:html
6322 */
6323 bool isClient(LibraryElement library, Source htmlSource, Set<LibraryElement> v isitedLibraries) {
6324 if (visitedLibraries.contains(library)) {
6325 return false;
6326 }
6327 if (library.source == htmlSource) {
6328 return true;
6329 }
6330 javaSetAdd(visitedLibraries, library);
6331 for (LibraryElement imported in library.importedLibraries) {
6332 if (isClient(imported, htmlSource, visitedLibraries)) {
6333 return true;
6334 }
6335 }
6336 for (LibraryElement exported in library.exportedLibraries) {
6337 if (isClient(exported, htmlSource, visitedLibraries)) {
6338 return true;
6339 }
6340 }
6341 return false;
6342 }
6343
6344 /**
6345 * Given a cache entry and a library element, record the library element and o ther information
6346 * gleaned from the element in the cache entry.
6347 *
6348 * @param dartCopy the cache entry in which data is to be recorded
6349 * @param library the library element used to record information
6350 * @param htmlSource the source for the HTML library
6351 */
6352 void recordElementData(DartEntryImpl dartCopy, LibraryElement library, Source htmlSource) {
6353 dartCopy.setValue(DartEntry.ELEMENT, library);
6354 dartCopy.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null);
6355 dartCopy.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set <LibraryElement>()));
6356 List<Source> unitSources = new List<Source>();
6357 unitSources.add(library.definingCompilationUnit.source);
6358 for (CompilationUnitElement part in library.parts) {
6359 Source partSource = part.source;
6360 unitSources.add(partSource);
6361 }
6362 dartCopy.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources));
6363 }
6364
6365 /**
6366 * Record the results produced by performing a [ParseDartTask]. If the results were computed
6367 * from data that is now out-of-date, then the results will not be recorded.
6368 *
6369 * @param task the task that was performed
6370 * @return an entry containing the computed results
6371 * @throws AnalysisException if the results could not be recorded
6372 */
6373 DartEntry recordParseDartTaskResults(ParseDartTask task) {
6374 Source source = task.source;
6375 AnalysisException thrownException = task.exception;
6376 DartEntry dartEntry = null;
6377 {
6378 SourceEntry sourceEntry = _cache.get(source);
6379 if (sourceEntry is! DartEntry) {
6380 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}");
6381 }
6382 dartEntry = sourceEntry as DartEntry;
6383 _cache.accessed(source);
6384 int sourceTime = source.modificationStamp;
6385 int resultTime = task.modificationTime;
6386 if (sourceTime == resultTime) {
6387 if (dartEntry.modificationTime != sourceTime) {
6388 sourceChanged(source);
6389 dartEntry = getReadableDartEntry(source);
6390 if (dartEntry == null) {
6391 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
6392 }
6393 }
6394 DartEntryImpl dartCopy = dartEntry.writableCopy;
6395 if (thrownException == null) {
6396 LineInfo lineInfo = task.lineInfo;
6397 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6398 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) {
6399 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
6400 } else {
6401 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
6402 }
6403 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit);
6404 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors);
6405 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
6406 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
6407 dartCopy.setValue(DartEntry.INCLUDED_PARTS, task.includedSources);
6408 } else {
6409 dartCopy.recordParseError();
6410 }
6411 _cache.put(source, dartCopy);
6412 dartEntry = dartCopy;
6413 } else {
6414 DartEntryImpl dartCopy = dartEntry.writableCopy;
6415 dartCopy.recordParseNotInProcess();
6416 _cache.put(source, dartCopy);
6417 dartEntry = dartCopy;
6418 }
6419 }
6420 if (thrownException != null) {
6421 throw thrownException;
6422 }
6423 return dartEntry;
6424 }
6425
6426 /**
6427 * Record the results produced by performing a [ParseHtmlTask]. If the results were computed
6428 * from data that is now out-of-date, then the results will not be recorded.
6429 *
6430 * @param task the task that was performed
6431 * @return an entry containing the computed results
6432 * @throws AnalysisException if the results could not be recorded
6433 */
6434 HtmlEntry recordParseHtmlTaskResults(ParseHtmlTask task) {
6435 Source source = task.source;
6436 AnalysisException thrownException = task.exception;
6437 HtmlEntry htmlEntry = null;
6438 {
6439 SourceEntry sourceEntry = _cache.get(source);
6440 if (sourceEntry is! HtmlEntry) {
6441 throw new AnalysisException.con1("Internal error: attempting to parse no n-HTML file as a HTML file: ${source.fullName}");
6442 }
6443 htmlEntry = sourceEntry as HtmlEntry;
6444 _cache.accessed(source);
6445 int sourceTime = source.modificationStamp;
6446 int resultTime = task.modificationTime;
6447 if (sourceTime == resultTime) {
6448 if (htmlEntry.modificationTime != sourceTime) {
6449 sourceChanged(source);
6450 htmlEntry = getReadableHtmlEntry(source);
6451 if (htmlEntry == null) {
6452 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
6453 }
6454 }
6455 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6456 if (thrownException == null) {
6457 LineInfo lineInfo = task.lineInfo;
6458 HtmlUnit unit = task.htmlUnit;
6459 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6460 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit);
6461 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries);
6462 ChangeNoticeImpl notice = getNotice(source);
6463 notice.setErrors(htmlEntry.allErrors, lineInfo);
6464 } else {
6465 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR);
6466 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
6467 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
6468 }
6469 _cache.put(source, htmlCopy);
6470 htmlEntry = htmlCopy;
6471 } else {
6472 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6473 if (identical(htmlCopy.getState(SourceEntry.LINE_INFO), CacheState.IN_PR OCESS)) {
6474 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID);
6475 }
6476 if (identical(htmlCopy.getState(HtmlEntry.PARSED_UNIT), CacheState.IN_PR OCESS)) {
6477 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID);
6478 }
6479 if (identical(htmlCopy.getState(HtmlEntry.REFERENCED_LIBRARIES), CacheSt ate.IN_PROCESS)) {
6480 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID);
6481 }
6482 _cache.put(source, htmlCopy);
6483 htmlEntry = htmlCopy;
6484 }
6485 }
6486 if (thrownException != null) {
6487 throw thrownException;
6488 }
6489 return htmlEntry;
6490 }
6491
6492 /**
6493 * Record the results produced by performing a [ResolveDartLibraryTask]. If th e results were
6494 * computed from data that is now out-of-date, then the results will not be re corded.
6495 *
6496 * @param task the task that was performed
6497 * @return an entry containing the computed results
6498 * @throws AnalysisException if the results could not be recorded
6499 */
6500 DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibraryTask task) {
6501 LibraryResolver resolver = task.libraryResolver;
6502 AnalysisException thrownException = task.exception;
6503 DartEntry unitEntry = null;
6504 {
6505 if (allModificationTimesMatch(resolver)) {
6506 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
6507 Source unitSource = task.unitSource;
6508 RecordingErrorListener errorListener = resolver.errorListener;
6509 for (Library library in resolver.resolvedLibraries) {
6510 Source librarySource = library.librarySource;
6511 for (Source source in library.compilationUnitSources) {
6512 CompilationUnit unit = library.getAST(source);
6513 List<AnalysisError> errors = errorListener.getErrors2(source);
6514 unit.resolutionErrors = errors;
6515 LineInfo lineInfo = unit.lineInfo;
6516 DartEntry dartEntry = _cache.get(source) as DartEntry;
6517 int sourceTime = source.modificationStamp;
6518 if (dartEntry.modificationTime != sourceTime) {
6519 sourceChanged(source);
6520 dartEntry = getReadableDartEntry(source);
6521 if (dartEntry == null) {
6522 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
6523 }
6524 }
6525 DartEntryImpl dartCopy = dartEntry.writableCopy;
6526 if (thrownException == null) {
6527 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6528 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
6529 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit);
6530 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, err ors);
6531 if (identical(source, librarySource)) {
6532 recordElementData(dartCopy, library.libraryElement, htmlSource);
6533 }
6534 } else {
6535 dartCopy.recordResolutionError();
6536 }
6537 _cache.put(source, dartCopy);
6538 if (source == unitSource) {
6539 unitEntry = dartCopy;
6540 }
6541 ChangeNoticeImpl notice = getNotice(source);
6542 notice.compilationUnit = unit;
6543 notice.setErrors(dartCopy.allErrors, lineInfo);
6544 }
6545 }
6546 } else {
6547 for (Library library in resolver.resolvedLibraries) {
6548 for (Source source in library.compilationUnitSources) {
6549 DartEntry dartEntry = getReadableDartEntry(source);
6550 if (dartEntry != null) {
6551 DartEntryImpl dartCopy = dartEntry.writableCopy;
6552 dartCopy.recordResolutionNotInProcess();
6553 _cache.put(source, dartCopy);
6554 }
6555 }
6556 }
6557 }
6558 }
6559 if (thrownException != null) {
6560 throw thrownException;
6561 }
6562 return unitEntry;
6563 }
6564
6565 /**
6566 * Record the results produced by performing a [ResolveDartUnitTask]. If the r esults were
6567 * computed from data that is now out-of-date, then the results will not be re corded.
6568 *
6569 * @param task the task that was performed
6570 * @return an entry containing the computed results
6571 * @throws AnalysisException if the results could not be recorded
6572 */
6573 SourceEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) {
6574 Source source = task.source;
6575 AnalysisException thrownException = task.exception;
6576 DartEntry dartEntry = null;
6577 {
6578 SourceEntry sourceEntry = _cache.get(source);
6579 if (sourceEntry is! DartEntry) {
6580 throw new AnalysisException.con1("Internal error: attempting to reolve n on-Dart file as a Dart file: ${source.fullName}");
6581 }
6582 dartEntry = sourceEntry as DartEntry;
6583 _cache.accessed(source);
6584 int sourceTime = source.modificationStamp;
6585 int resultTime = task.modificationTime;
6586 if (sourceTime == resultTime) {
6587 if (dartEntry.modificationTime != sourceTime) {
6588 sourceChanged(source);
6589 dartEntry = getReadableDartEntry(source);
6590 if (dartEntry == null) {
6591 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
6592 }
6593 }
6594 DartEntryImpl dartCopy = dartEntry.writableCopy;
6595 if (thrownException == null) {
6596 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, task.librarySource, task.r esolvedUnit);
6597 } else {
6598 dartCopy.setState(DartEntry.RESOLVED_UNIT, CacheState.ERROR);
6599 }
6600 _cache.put(source, dartCopy);
6601 dartEntry = dartCopy;
6602 } else {
6603 DartEntryImpl dartCopy = dartEntry.writableCopy;
6604 if (identical(dartCopy.getState(DartEntry.RESOLVED_UNIT), CacheState.IN_ PROCESS)) {
6605 dartCopy.setState(DartEntry.RESOLVED_UNIT, CacheState.INVALID);
6606 }
6607 _cache.put(source, dartCopy);
6608 dartEntry = dartCopy;
6609 }
6610 }
6611 if (thrownException != null) {
6612 throw thrownException;
6613 }
6614 return dartEntry;
6615 }
6616
6617 /**
6618 * Record the results produced by performing a [ResolveHtmlTask]. If the resul ts were
6619 * computed from data that is now out-of-date, then the results will not be re corded.
6620 *
6621 * @param task the task that was performed
6622 * @return an entry containing the computed results
6623 * @throws AnalysisException if the results could not be recorded
6624 */
6625 SourceEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) {
6626 Source source = task.source;
6627 AnalysisException thrownException = task.exception;
6628 HtmlEntry htmlEntry = null;
6629 {
6630 SourceEntry sourceEntry = _cache.get(source);
6631 if (sourceEntry is! HtmlEntry) {
6632 throw new AnalysisException.con1("Internal error: attempting to reolve n on-HTML file as an HTML file: ${source.fullName}");
6633 }
6634 htmlEntry = sourceEntry as HtmlEntry;
6635 _cache.accessed(source);
6636 int sourceTime = source.modificationStamp;
6637 int resultTime = task.modificationTime;
6638 if (sourceTime == resultTime) {
6639 if (htmlEntry.modificationTime != sourceTime) {
6640 sourceChanged(source);
6641 htmlEntry = getReadableHtmlEntry(source);
6642 if (htmlEntry == null) {
6643 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
6644 }
6645 }
6646 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6647 if (thrownException == null) {
6648 htmlCopy.setValue(HtmlEntry.ELEMENT, task.element);
6649 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, task.resolutionErrors);
6650 } else {
6651 htmlCopy.recordResolutionError();
6652 }
6653 _cache.put(source, htmlCopy);
6654 htmlEntry = htmlCopy;
6655 } else {
6656 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6657 if (identical(htmlCopy.getState(HtmlEntry.ELEMENT), CacheState.IN_PROCES S)) {
6658 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
6659 }
6660 if (identical(htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS), CacheState .IN_PROCESS)) {
6661 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.INVALID);
6662 }
6663 _cache.put(source, htmlCopy);
6664 htmlEntry = htmlCopy;
6665 }
6666 }
6667 if (thrownException != null) {
6668 throw thrownException;
6669 }
6670 return htmlEntry;
6671 }
6672
6673 /**
6674 * Create an entry for the newly added source. Return `true` if the new source is a Dart
6675 * file.
6676 *
6677 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6678 *
6679 * @param source the source that has been added
6680 * @return `true` if the new source is a Dart file
6681 */
6682 bool sourceAvailable(Source source) {
6683 SourceEntry sourceEntry = _cache.get(source);
6684 if (sourceEntry == null) {
6685 sourceEntry = createSourceEntry(source);
6686 } else {
6687 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
6688 sourceCopy.modificationTime = source.modificationStamp;
6689 _cache.put(source, sourceCopy);
6690 }
6691 return sourceEntry is DartEntry;
6692 }
6693
6694 /**
6695 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6696 *
6697 * @param source the source that has been changed
6698 */
6699 void sourceChanged(Source source) {
6700 SourceEntry sourceEntry = _cache.get(source);
6701 if (sourceEntry is HtmlEntry) {
6702 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6703 htmlCopy.modificationTime = source.modificationStamp;
6704 htmlCopy.invalidateAllInformation();
6705 _cache.put(source, htmlCopy);
6706 } else if (sourceEntry is DartEntry) {
6707 List<Source> containingLibraries = getLibrariesContaining(source);
6708 for (Source library in containingLibraries) {
6709 invalidateLibraryResolution(library);
6710 }
6711 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
6712 dartCopy.modificationTime = source.modificationStamp;
6713 dartCopy.invalidateAllInformation();
6714 _cache.put(source, dartCopy);
6715 }
6716 }
6717
6718 /**
6719 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6720 *
6721 * @param source the source that has been deleted
6722 */
6723 void sourceRemoved(Source source) {
6724 SourceEntry sourceEntry = _cache.get(source);
6725 if (sourceEntry is DartEntry) {
6726 Set<Source> libraries = new Set<Source>();
6727 for (Source librarySource in getLibrariesContaining(source)) {
6728 javaSetAdd(libraries, librarySource);
6729 for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) {
6730 javaSetAdd(libraries, dependentLibrary);
6731 }
6732 }
6733 for (Source librarySource in libraries) {
6734 invalidateLibraryResolution(librarySource);
6735 }
6736 }
6737 _cache.remove(source); 4596 _cache.remove(source);
6738 } 4597 }
6739 } 4598 }
6740 /** 4599 /**
6741 * Instances of the class `AnalysisTaskResultRecorder` are used by an analysis c ontext to 4600 * Instances of the class `AnalysisTaskResultRecorder` are used by an analysis c ontext to
6742 * record the results of a task. 4601 * record the results of a task.
6743 */ 4602 */
6744 class AnalysisContextImpl2_AnalysisTaskResultRecorder implements AnalysisTaskVis itor<SourceEntry> { 4603 class AnalysisContextImpl_AnalysisTaskResultRecorder implements AnalysisTaskVisi tor<SourceEntry> {
6745 final AnalysisContextImpl2 AnalysisContextImpl2_this; 4604 final AnalysisContextImpl AnalysisContextImpl_this;
6746 AnalysisContextImpl2_AnalysisTaskResultRecorder(this.AnalysisContextImpl2_this ); 4605 AnalysisContextImpl_AnalysisTaskResultRecorder(this.AnalysisContextImpl_this);
6747 DartEntry visitParseDartTask(ParseDartTask task) => AnalysisContextImpl2_this. recordParseDartTaskResults(task); 4606 SourceEntry visitGenerateDartHintsTask(GenerateDartHintsTask task) => Analysis ContextImpl_this.recordGenerateDartHintsTask(task);
6748 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => AnalysisContextImpl2_this. recordParseHtmlTaskResults(task); 4607 DartEntry visitParseDartTask(ParseDartTask task) => AnalysisContextImpl_this.r ecordParseDartTaskResults(task);
6749 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => Analysis ContextImpl2_this.recordResolveDartLibraryTaskResults(task); 4608 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => AnalysisContextImpl_this.r ecordParseHtmlTaskResults(task);
6750 SourceEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => AnalysisCont extImpl2_this.recordResolveDartUnitTaskResults(task); 4609 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => Analysis ContextImpl_this.recordResolveDartLibraryTaskResults(task);
6751 SourceEntry visitResolveHtmlTask(ResolveHtmlTask task) => AnalysisContextImpl2 _this.recordResolveHtmlTaskResults(task); 4610 SourceEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => AnalysisCont extImpl_this.recordResolveDartUnitTaskResults(task);
4611 SourceEntry visitResolveHtmlTask(ResolveHtmlTask task) => AnalysisContextImpl_ this.recordResolveHtmlTaskResults(task);
6752 } 4612 }
6753 /** 4613 /**
6754 * Instances of the class `AnalysisErrorInfoImpl` represent the analysis errors and line info 4614 * Instances of the class `AnalysisErrorInfoImpl` represent the analysis errors and line info
6755 * associated with a source. 4615 * associated with a source.
6756 */ 4616 */
6757 class AnalysisErrorInfoImpl implements AnalysisErrorInfo { 4617 class AnalysisErrorInfoImpl implements AnalysisErrorInfo {
6758 4618
6759 /** 4619 /**
6760 * The analysis errors associated with a source, or `null` if there are no err ors. 4620 * The analysis errors associated with a source, or `null` if there are no err ors.
6761 */ 4621 */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6802 * A flag indicating whether analysis is to use strict mode. In strict mode, e rror reporting is 4662 * A flag indicating whether analysis is to use strict mode. In strict mode, e rror reporting is
6803 * based exclusively on the static type information. 4663 * based exclusively on the static type information.
6804 */ 4664 */
6805 bool _strictMode = true; 4665 bool _strictMode = true;
6806 4666
6807 /** 4667 /**
6808 * A flag indicating whether analysis is to generate hint results (e.g. type i nference based 4668 * A flag indicating whether analysis is to generate hint results (e.g. type i nference based
6809 * information and pub best practices). 4669 * information and pub best practices).
6810 */ 4670 */
6811 bool _hint = true; 4671 bool _hint = true;
4672
4673 /**
4674 * A flag indicating whether analysis is to generate dart2js related hint resu lts.
4675 */
4676 bool _dart2jsHint = true;
4677 bool get dart2jsHint => _dart2jsHint;
6812 bool get hint => _hint; 4678 bool get hint => _hint;
6813 4679
6814 /** 4680 /**
6815 * Return `true` if analysis is to use strict mode. In strict mode, error repo rting is based 4681 * Return `true` if analysis is to use strict mode. In strict mode, error repo rting is based
6816 * exclusively on the static type information. 4682 * exclusively on the static type information.
6817 * 4683 *
6818 * @return `true` if analysis is to use strict mode 4684 * @return `true` if analysis is to use strict mode
6819 */ 4685 */
6820 bool get strictMode => _strictMode; 4686 bool get strictMode => _strictMode;
6821 4687
6822 /** 4688 /**
4689 * Set whether analysis is to generate dart2js related hint results.
4690 *
4691 * @param hint `true` if analysis is to generate dart2js related hint results
4692 */
4693 void set dart2jsHint(bool dart2jsHints) {
4694 this._dart2jsHint = dart2jsHints;
4695 }
4696
4697 /**
6823 * Set whether analysis is to generate hint results (e.g. type inference based information and pub 4698 * Set whether analysis is to generate hint results (e.g. type inference based information and pub
6824 * best practices). 4699 * best practices).
6825 * 4700 *
6826 * @param hint `true` if analysis is to generate hint results 4701 * @param hint `true` if analysis is to generate hint results
6827 */ 4702 */
6828 void set hint(bool hint2) { 4703 void set hint(bool hint2) {
6829 this._hint = hint2; 4704 this._hint = hint2;
6830 } 4705 }
6831 4706
6832 /** 4707 /**
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
6929 * 4804 *
6930 * @param errors the errors that changed as a result of the analysis 4805 * @param errors the errors that changed as a result of the analysis
6931 * @param lineInfo the line information associated with the source 4806 * @param lineInfo the line information associated with the source
6932 */ 4807 */
6933 void setErrors(List<AnalysisError> errors2, LineInfo lineInfo2) { 4808 void setErrors(List<AnalysisError> errors2, LineInfo lineInfo2) {
6934 this._errors = errors2; 4809 this._errors = errors2;
6935 this._lineInfo = lineInfo2; 4810 this._lineInfo = lineInfo2;
6936 } 4811 }
6937 } 4812 }
6938 /** 4813 /**
6939 * Instances of the class `DelegatingAnalysisContextImpl` extend [AnalysisContex tImpl
6940 ] to delegate sources to the appropriate analysis context. For instance, if the
6941 * source is in a system library then the analysis context from the [DartSdk] is used.
6942 *
6943 * @coverage dart.engine
6944 */
6945 class DelegatingAnalysisContextImpl extends AnalysisContextImpl {
6946
6947 /**
6948 * This references the [InternalAnalysisContext] held onto by the [DartSdk] wh ich is
6949 * used (instead of this [AnalysisContext]) for SDK sources. This field is set when
6950 * #setSourceFactory(SourceFactory) is called, and references the analysis con text in the
6951 * [DartUriResolver] in the [SourceFactory], this analysis context assumes tha t there
6952 * will be such a resolver.
6953 */
6954 InternalAnalysisContext _sdkAnalysisContext;
6955 void addSourceInfo(Source source, SourceEntry info) {
6956 if (source.isInSystemLibrary) {
6957 _sdkAnalysisContext.addSourceInfo(source, info);
6958 } else {
6959 super.addSourceInfo(source, info);
6960 }
6961 }
6962 List<AnalysisError> computeErrors(Source source) {
6963 if (source.isInSystemLibrary) {
6964 return _sdkAnalysisContext.computeErrors(source);
6965 } else {
6966 return super.computeErrors(source);
6967 }
6968 }
6969 List<Source> computeExportedLibraries(Source source) {
6970 if (source.isInSystemLibrary) {
6971 return _sdkAnalysisContext.computeExportedLibraries(source);
6972 } else {
6973 return super.computeExportedLibraries(source);
6974 }
6975 }
6976 HtmlElement computeHtmlElement(Source source) {
6977 if (source.isInSystemLibrary) {
6978 return _sdkAnalysisContext.computeHtmlElement(source);
6979 } else {
6980 return super.computeHtmlElement(source);
6981 }
6982 }
6983 List<Source> computeImportedLibraries(Source source) {
6984 if (source.isInSystemLibrary) {
6985 return _sdkAnalysisContext.computeImportedLibraries(source);
6986 } else {
6987 return super.computeImportedLibraries(source);
6988 }
6989 }
6990 SourceKind computeKindOf(Source source) {
6991 if (source.isInSystemLibrary) {
6992 return _sdkAnalysisContext.computeKindOf(source);
6993 } else {
6994 return super.computeKindOf(source);
6995 }
6996 }
6997 LibraryElement computeLibraryElement(Source source) {
6998 if (source.isInSystemLibrary) {
6999 return _sdkAnalysisContext.computeLibraryElement(source);
7000 } else {
7001 return super.computeLibraryElement(source);
7002 }
7003 }
7004 LineInfo computeLineInfo(Source source) {
7005 if (source.isInSystemLibrary) {
7006 return _sdkAnalysisContext.computeLineInfo(source);
7007 } else {
7008 return super.computeLineInfo(source);
7009 }
7010 }
7011 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) {
7012 if (source.isInSystemLibrary) {
7013 return _sdkAnalysisContext.computeResolvableCompilationUnit(source);
7014 } else {
7015 return super.computeResolvableCompilationUnit(source);
7016 }
7017 }
7018 AnalysisErrorInfo getErrors(Source source) {
7019 if (source.isInSystemLibrary) {
7020 return _sdkAnalysisContext.getErrors(source);
7021 } else {
7022 return super.getErrors(source);
7023 }
7024 }
7025 HtmlElement getHtmlElement(Source source) {
7026 if (source.isInSystemLibrary) {
7027 return _sdkAnalysisContext.getHtmlElement(source);
7028 } else {
7029 return super.getHtmlElement(source);
7030 }
7031 }
7032 List<Source> getHtmlFilesReferencing(Source source) {
7033 if (source.isInSystemLibrary) {
7034 return _sdkAnalysisContext.getHtmlFilesReferencing(source);
7035 } else {
7036 return super.getHtmlFilesReferencing(source);
7037 }
7038 }
7039 SourceKind getKindOf(Source source) {
7040 if (source.isInSystemLibrary) {
7041 return _sdkAnalysisContext.getKindOf(source);
7042 } else {
7043 return super.getKindOf(source);
7044 }
7045 }
7046 List<Source> getLibrariesContaining(Source source) {
7047 if (source.isInSystemLibrary) {
7048 return _sdkAnalysisContext.getLibrariesContaining(source);
7049 } else {
7050 return super.getLibrariesContaining(source);
7051 }
7052 }
7053 List<Source> getLibrariesDependingOn(Source librarySource) {
7054 if (librarySource.isInSystemLibrary) {
7055 return _sdkAnalysisContext.getLibrariesDependingOn(librarySource);
7056 } else {
7057 return super.getLibrariesDependingOn(librarySource);
7058 }
7059 }
7060 LibraryElement getLibraryElement(Source source) {
7061 if (source.isInSystemLibrary) {
7062 return _sdkAnalysisContext.getLibraryElement(source);
7063 } else {
7064 return super.getLibraryElement(source);
7065 }
7066 }
7067 List<Source> get librarySources => ArrayUtils.addAll(super.librarySources, _sd kAnalysisContext.librarySources);
7068 LineInfo getLineInfo(Source source) {
7069 if (source.isInSystemLibrary) {
7070 return _sdkAnalysisContext.getLineInfo(source);
7071 } else {
7072 return super.getLineInfo(source);
7073 }
7074 }
7075 Namespace getPublicNamespace(LibraryElement library) {
7076 Source source = library.source;
7077 if (source.isInSystemLibrary) {
7078 return _sdkAnalysisContext.getPublicNamespace(library);
7079 } else {
7080 return super.getPublicNamespace(library);
7081 }
7082 }
7083 Namespace getPublicNamespace2(Source source) {
7084 if (source.isInSystemLibrary) {
7085 return _sdkAnalysisContext.getPublicNamespace2(source);
7086 } else {
7087 return super.getPublicNamespace2(source);
7088 }
7089 }
7090 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
7091 if (unitSource.isInSystemLibrary) {
7092 return _sdkAnalysisContext.getResolvedCompilationUnit(unitSource, library) ;
7093 } else {
7094 return super.getResolvedCompilationUnit(unitSource, library);
7095 }
7096 }
7097 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
7098 if (unitSource.isInSystemLibrary) {
7099 return _sdkAnalysisContext.getResolvedCompilationUnit2(unitSource, library Source);
7100 } else {
7101 return super.getResolvedCompilationUnit2(unitSource, librarySource);
7102 }
7103 }
7104 bool isClientLibrary(Source librarySource) {
7105 if (librarySource.isInSystemLibrary) {
7106 return _sdkAnalysisContext.isClientLibrary(librarySource);
7107 } else {
7108 return super.isClientLibrary(librarySource);
7109 }
7110 }
7111 bool isServerLibrary(Source librarySource) {
7112 if (librarySource.isInSystemLibrary) {
7113 return _sdkAnalysisContext.isServerLibrary(librarySource);
7114 } else {
7115 return super.isServerLibrary(librarySource);
7116 }
7117 }
7118 CompilationUnit parseCompilationUnit(Source source) {
7119 if (source.isInSystemLibrary) {
7120 return _sdkAnalysisContext.parseCompilationUnit(source);
7121 } else {
7122 return super.parseCompilationUnit(source);
7123 }
7124 }
7125 HtmlUnit parseHtmlUnit(Source source) {
7126 if (source.isInSystemLibrary) {
7127 return _sdkAnalysisContext.parseHtmlUnit(source);
7128 } else {
7129 return super.parseHtmlUnit(source);
7130 }
7131 }
7132 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
7133 if (elementMap.isEmpty) {
7134 return;
7135 }
7136 Source source = new JavaIterator(elementMap.keys.toSet()).next();
7137 if (source.isInSystemLibrary) {
7138 _sdkAnalysisContext.recordLibraryElements(elementMap);
7139 } else {
7140 super.recordLibraryElements(elementMap);
7141 }
7142 }
7143 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) {
7144 if (source.isInSystemLibrary) {
7145 return _sdkAnalysisContext.resolveCompilationUnit(source, library);
7146 } else {
7147 return super.resolveCompilationUnit(source, library);
7148 }
7149 }
7150 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
7151 if (unitSource.isInSystemLibrary) {
7152 return _sdkAnalysisContext.resolveCompilationUnit2(unitSource, librarySour ce);
7153 } else {
7154 return super.resolveCompilationUnit2(unitSource, librarySource);
7155 }
7156 }
7157 HtmlUnit resolveHtmlUnit(Source unitSource) {
7158 if (unitSource.isInSystemLibrary) {
7159 return _sdkAnalysisContext.resolveHtmlUnit(unitSource);
7160 } else {
7161 return super.resolveHtmlUnit(unitSource);
7162 }
7163 }
7164 void setContents(Source source, String contents) {
7165 if (source.isInSystemLibrary) {
7166 _sdkAnalysisContext.setContents(source, contents);
7167 } else {
7168 super.setContents(source, contents);
7169 }
7170 }
7171 void set sourceFactory(SourceFactory factory) {
7172 super.sourceFactory = factory;
7173 DartSdk sdk = factory.dartSdk;
7174 if (sdk != null) {
7175 _sdkAnalysisContext = sdk.context as InternalAnalysisContext;
7176 if (_sdkAnalysisContext is DelegatingAnalysisContextImpl) {
7177 _sdkAnalysisContext = null;
7178 throw new IllegalStateException("The context provided by an SDK cannot i tself be a delegating analysis context");
7179 }
7180 } else {
7181 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. ");
7182 }
7183 }
7184 }
7185 /**
7186 * Instances of the class `DelegatingAnalysisContextImpl` extend [AnalysisContex tImpl 4814 * Instances of the class `DelegatingAnalysisContextImpl` extend [AnalysisContex tImpl
7187 ] to delegate sources to the appropriate analysis context. For instance, if the 4815 ] to delegate sources to the appropriate analysis context. For instance, if the
7188 * source is in a system library then the analysis context from the [DartSdk] is used. 4816 * source is in a system library then the analysis context from the [DartSdk] is used.
7189 * 4817 *
7190 * @coverage dart.engine 4818 * @coverage dart.engine
7191 */ 4819 */
7192 class DelegatingAnalysisContextImpl2 extends AnalysisContextImpl2 { 4820 class DelegatingAnalysisContextImpl extends AnalysisContextImpl {
7193 4821
7194 /** 4822 /**
7195 * This references the [InternalAnalysisContext] held onto by the [DartSdk] wh ich is 4823 * This references the [InternalAnalysisContext] held onto by the [DartSdk] wh ich is
7196 * used (instead of this [AnalysisContext]) for SDK sources. This field is set when 4824 * used (instead of this [AnalysisContext]) for SDK sources. This field is set when
7197 * #setSourceFactory(SourceFactory) is called, and references the analysis con text in the 4825 * #setSourceFactory(SourceFactory) is called, and references the analysis con text in the
7198 * [DartUriResolver] in the [SourceFactory], this analysis context assumes tha t there 4826 * [DartUriResolver] in the [SourceFactory], this analysis context assumes tha t there
7199 * will be such a resolver. 4827 * will be such a resolver.
7200 */ 4828 */
7201 InternalAnalysisContext _sdkAnalysisContext; 4829 InternalAnalysisContext _sdkAnalysisContext;
7202 void addSourceInfo(Source source, SourceEntry info) { 4830 void addSourceInfo(Source source, SourceEntry info) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
7413 _sdkAnalysisContext.setContents(source, contents); 5041 _sdkAnalysisContext.setContents(source, contents);
7414 } else { 5042 } else {
7415 super.setContents(source, contents); 5043 super.setContents(source, contents);
7416 } 5044 }
7417 } 5045 }
7418 void set sourceFactory(SourceFactory factory) { 5046 void set sourceFactory(SourceFactory factory) {
7419 super.sourceFactory = factory; 5047 super.sourceFactory = factory;
7420 DartSdk sdk = factory.dartSdk; 5048 DartSdk sdk = factory.dartSdk;
7421 if (sdk != null) { 5049 if (sdk != null) {
7422 _sdkAnalysisContext = sdk.context as InternalAnalysisContext; 5050 _sdkAnalysisContext = sdk.context as InternalAnalysisContext;
7423 if (_sdkAnalysisContext is DelegatingAnalysisContextImpl2) { 5051 if (_sdkAnalysisContext is DelegatingAnalysisContextImpl) {
7424 _sdkAnalysisContext = null; 5052 _sdkAnalysisContext = null;
7425 throw new IllegalStateException("The context provided by an SDK cannot i tself be a delegating analysis context"); 5053 throw new IllegalStateException("The context provided by an SDK cannot i tself be a delegating analysis context");
7426 } 5054 }
7427 } else { 5055 } else {
7428 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. "); 5056 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. ");
7429 } 5057 }
7430 } 5058 }
7431 } 5059 }
7432 /** 5060 /**
7433 * Instances of the class `InstrumentedAnalysisContextImpl` implement an 5061 * Instances of the class `InstrumentedAnalysisContextImpl` implement an
(...skipping 21 matching lines...) Expand all
7455 5083
7456 /** 5084 /**
7457 * The analysis context to which all of the non-instrumentation work is delega ted. 5085 * The analysis context to which all of the non-instrumentation work is delega ted.
7458 */ 5086 */
7459 InternalAnalysisContext basis; 5087 InternalAnalysisContext basis;
7460 5088
7461 /** 5089 /**
7462 * Create a new [InstrumentedAnalysisContextImpl] which wraps a new 5090 * Create a new [InstrumentedAnalysisContextImpl] which wraps a new
7463 * [AnalysisContextImpl] as the basis context. 5091 * [AnalysisContextImpl] as the basis context.
7464 */ 5092 */
7465 InstrumentedAnalysisContextImpl() : this.con1(AnalysisEngine.instance.useExper imentalContext ? new DelegatingAnalysisContextImpl2() : new DelegatingAnalysisCo ntextImpl()); 5093 InstrumentedAnalysisContextImpl() : this.con1(new DelegatingAnalysisContextImp l());
7466 5094
7467 /** 5095 /**
7468 * Create a new [InstrumentedAnalysisContextImpl] with a specified basis conte xt, aka the 5096 * Create a new [InstrumentedAnalysisContextImpl] with a specified basis conte xt, aka the
7469 * context to wrap and instrument. 5097 * context to wrap and instrument.
7470 * 5098 *
7471 * @param context some [InstrumentedAnalysisContext] to wrap and instrument 5099 * @param context some [InstrumentedAnalysisContext] to wrap and instrument
7472 */ 5100 */
7473 InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) { 5101 InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) {
7474 basis = context; 5102 basis = context;
7475 } 5103 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
7763 SourceFactory get sourceFactory { 5391 SourceFactory get sourceFactory {
7764 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getSourceFactory"); 5392 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getSourceFactory");
7765 try { 5393 try {
7766 instrumentation.metric3("contextId", _contextId); 5394 instrumentation.metric3("contextId", _contextId);
7767 return basis.sourceFactory; 5395 return basis.sourceFactory;
7768 } finally { 5396 } finally {
7769 instrumentation.log2(2); 5397 instrumentation.log2(2);
7770 } 5398 }
7771 } 5399 }
7772 AnalysisContentStatistics get statistics => basis.statistics; 5400 AnalysisContentStatistics get statistics => basis.statistics;
5401 TimestampedData<CompilationUnit> internalResolveCompilationUnit(Source unitSou rce, LibraryElement libraryElement) => basis.internalResolveCompilationUnit(unit Source, libraryElement);
7773 bool isClientLibrary(Source librarySource) { 5402 bool isClientLibrary(Source librarySource) {
7774 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- isClientLibrary"); 5403 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- isClientLibrary");
7775 try { 5404 try {
7776 instrumentation.metric3("contextId", _contextId); 5405 instrumentation.metric3("contextId", _contextId);
7777 return basis.isClientLibrary(librarySource); 5406 return basis.isClientLibrary(librarySource);
7778 } finally { 5407 } finally {
7779 instrumentation.log(); 5408 instrumentation.log();
7780 } 5409 }
7781 } 5410 }
7782 bool isServerLibrary(Source librarySource) { 5411 bool isServerLibrary(Source librarySource) {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
8008 * @throws AnalysisException if the public namespace could not be computed 5637 * @throws AnalysisException if the public namespace could not be computed
8009 */ 5638 */
8010 Namespace getPublicNamespace2(Source source); 5639 Namespace getPublicNamespace2(Source source);
8011 5640
8012 /** 5641 /**
8013 * Returns a statistics about this context. 5642 * Returns a statistics about this context.
8014 */ 5643 */
8015 AnalysisContentStatistics get statistics; 5644 AnalysisContentStatistics get statistics;
8016 5645
8017 /** 5646 /**
5647 * Return a time-stamped fully-resolved compilation unit for the given source in the given
5648 * library.
5649 *
5650 * @param unitSource the source of the compilation unit for which a resolved A ST structure is to
5651 * be returned
5652 * @param libraryElement the element representing the library in which the com pilation unit is to
5653 * be resolved
5654 * @return a time-stamped fully-resolved compilation unit for the source
5655 * @throws AnalysisException if the resolved compilation unit could not be com puted
5656 */
5657 TimestampedData<CompilationUnit> internalResolveCompilationUnit(Source unitSou rce, LibraryElement libraryElement);
5658
5659 /**
8018 * Given a table mapping the source for the libraries represented by the corre sponding elements to 5660 * Given a table mapping the source for the libraries represented by the corre sponding elements to
8019 * the elements representing the libraries, record those mappings. 5661 * the elements representing the libraries, record those mappings.
8020 * 5662 *
8021 * @param elementMap a table mapping the source for the libraries represented by the elements to 5663 * @param elementMap a table mapping the source for the libraries represented by the elements to
8022 * the elements representing the libraries 5664 * the elements representing the libraries
8023 */ 5665 */
8024 void recordLibraryElements(Map<Source, LibraryElement> elementMap); 5666 void recordLibraryElements(Map<Source, LibraryElement> elementMap);
8025 } 5667 }
8026 /** 5668 /**
5669 * Container with global [AnalysisContext] performance statistics.
5670 */
5671 class PerformanceStatistics {
5672
5673 /**
5674 * The [TimeCounter] for time spent in scanning.
5675 */
5676 static TimeCounter scan = new TimeCounter();
5677
5678 /**
5679 * The [TimeCounter] for time spent in parsing.
5680 */
5681 static TimeCounter parse = new TimeCounter();
5682
5683 /**
5684 * The [TimeCounter] for time spent in resolving.
5685 */
5686 static TimeCounter resolve = new TimeCounter();
5687
5688 /**
5689 * The [TimeCounter] for time spent in error verifier.
5690 */
5691 static TimeCounter errors = new TimeCounter();
5692
5693 /**
5694 * The [TimeCounter] for time spent in hints generator.
5695 */
5696 static TimeCounter hints = new TimeCounter();
5697 }
5698 /**
8027 * Instances of the class `RecordingErrorListener` implement an error listener t hat will 5699 * Instances of the class `RecordingErrorListener` implement an error listener t hat will
8028 * record the errors that are reported to it in a way that is appropriate for ca ching those errors 5700 * record the errors that are reported to it in a way that is appropriate for ca ching those errors
8029 * within an analysis context. 5701 * within an analysis context.
8030 * 5702 *
8031 * @coverage dart.engine 5703 * @coverage dart.engine
8032 */ 5704 */
8033 class RecordingErrorListener implements AnalysisErrorListener { 5705 class RecordingErrorListener implements AnalysisErrorListener {
8034 5706
8035 /** 5707 /**
8036 * A HashMap of lists containing the errors that were collected, keyed by each [Source]. 5708 * A HashMap of lists containing the errors that were collected, keyed by each [Source].
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
8109 Object visitCompilationUnit(CompilationUnit node) { 5781 Object visitCompilationUnit(CompilationUnit node) {
8110 node.element = null; 5782 node.element = null;
8111 return super.visitCompilationUnit(node); 5783 return super.visitCompilationUnit(node);
8112 } 5784 }
8113 Object visitConstructorDeclaration(ConstructorDeclaration node) { 5785 Object visitConstructorDeclaration(ConstructorDeclaration node) {
8114 node.element = null; 5786 node.element = null;
8115 return super.visitConstructorDeclaration(node); 5787 return super.visitConstructorDeclaration(node);
8116 } 5788 }
8117 Object visitConstructorName(ConstructorName node) { 5789 Object visitConstructorName(ConstructorName node) {
8118 node.staticElement = null; 5790 node.staticElement = null;
8119 node.element = null;
8120 return super.visitConstructorName(node); 5791 return super.visitConstructorName(node);
8121 } 5792 }
8122 Object visitDirective(Directive node) { 5793 Object visitDirective(Directive node) {
8123 node.element = null; 5794 node.element = null;
8124 return super.visitDirective(node); 5795 return super.visitDirective(node);
8125 } 5796 }
8126 Object visitExpression(Expression node) { 5797 Object visitExpression(Expression node) {
8127 node.staticType = null; 5798 node.staticType = null;
8128 node.propagatedType = null; 5799 node.propagatedType = null;
8129 return super.visitExpression(node); 5800 return super.visitExpression(node);
8130 } 5801 }
8131 Object visitFunctionExpression(FunctionExpression node) { 5802 Object visitFunctionExpression(FunctionExpression node) {
8132 node.element = null; 5803 node.element = null;
8133 return super.visitFunctionExpression(node); 5804 return super.visitFunctionExpression(node);
8134 } 5805 }
8135 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 5806 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
8136 node.staticElement = null; 5807 node.staticElement = null;
8137 node.propagatedElement = null; 5808 node.propagatedElement = null;
8138 return super.visitFunctionExpressionInvocation(node); 5809 return super.visitFunctionExpressionInvocation(node);
8139 } 5810 }
8140 Object visitIndexExpression(IndexExpression node) { 5811 Object visitIndexExpression(IndexExpression node) {
8141 node.staticElement = null; 5812 node.staticElement = null;
8142 node.propagatedElement = null; 5813 node.propagatedElement = null;
8143 return super.visitIndexExpression(node); 5814 return super.visitIndexExpression(node);
8144 } 5815 }
8145 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 5816 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
8146 node.staticElement = null; 5817 node.staticElement = null;
8147 node.element = null;
8148 return super.visitInstanceCreationExpression(node); 5818 return super.visitInstanceCreationExpression(node);
8149 } 5819 }
8150 Object visitPostfixExpression(PostfixExpression node) { 5820 Object visitPostfixExpression(PostfixExpression node) {
8151 node.staticElement = null; 5821 node.staticElement = null;
8152 node.propagatedElement = null; 5822 node.propagatedElement = null;
8153 return super.visitPostfixExpression(node); 5823 return super.visitPostfixExpression(node);
8154 } 5824 }
8155 Object visitPrefixExpression(PrefixExpression node) { 5825 Object visitPrefixExpression(PrefixExpression node) {
8156 node.staticElement = null; 5826 node.staticElement = null;
8157 node.propagatedElement = null; 5827 node.propagatedElement = null;
8158 return super.visitPrefixExpression(node); 5828 return super.visitPrefixExpression(node);
8159 } 5829 }
8160 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 5830 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
8161 node.staticElement = null; 5831 node.staticElement = null;
8162 node.element = null;
8163 return super.visitRedirectingConstructorInvocation(node); 5832 return super.visitRedirectingConstructorInvocation(node);
8164 } 5833 }
8165 Object visitSimpleIdentifier(SimpleIdentifier node) { 5834 Object visitSimpleIdentifier(SimpleIdentifier node) {
8166 node.staticElement = null; 5835 node.staticElement = null;
8167 node.propagatedElement = null; 5836 node.propagatedElement = null;
8168 return super.visitSimpleIdentifier(node); 5837 return super.visitSimpleIdentifier(node);
8169 } 5838 }
8170 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { 5839 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) {
8171 node.staticElement = null; 5840 node.staticElement = null;
8172 node.element = null;
8173 return super.visitSuperConstructorInvocation(node); 5841 return super.visitSuperConstructorInvocation(node);
8174 } 5842 }
8175 } 5843 }
8176 /** 5844 /**
8177 * Instances of the class `ResolvableCompilationUnit` represent a compilation un it that is not 5845 * Instances of the class `ResolvableCompilationUnit` represent a compilation un it that is not
8178 * referenced by any other objects and for which we have modification stamp info rmation. It is used 5846 * referenced by any other objects and for which we have modification stamp info rmation. It is used
8179 * by the [LibraryResolver] to resolve a library. 5847 * by the [LibraryResolver] to resolve a library.
8180 */ 5848 */
8181 class ResolvableCompilationUnit { 5849 class ResolvableCompilationUnit extends TimestampedData<CompilationUnit> {
8182
8183 /**
8184 * The modification time of the source from which the AST was created.
8185 */
8186 int modificationTime = 0;
8187
8188 /**
8189 * The AST that was created from the source.
8190 */
8191 CompilationUnit compilationUnit;
8192 5850
8193 /** 5851 /**
8194 * Initialize a newly created holder to hold the given values. 5852 * Initialize a newly created holder to hold the given values.
5853 *
5854 * @param modificationTime the modification time of the source from which the AST was created
5855 * @param unit the AST that was created from the source
5856 */
5857 ResolvableCompilationUnit(int modificationTime, CompilationUnit unit) : super( modificationTime, unit);
5858
5859 /**
5860 * Return the AST that was created from the source.
5861 *
5862 * @return the AST that was created from the source
5863 */
5864 CompilationUnit get compilationUnit => data;
5865 }
5866 /**
5867 * Instances of the class `ResolvableHtmlUnit` represent an HTML unit that is no t referenced
5868 * by any other objects and for which we have modification stamp information. It is used by the
5869 * [ResolveHtmlTask] to resolve an HTML source.
5870 */
5871 class ResolvableHtmlUnit extends TimestampedData<HtmlUnit> {
5872
5873 /**
5874 * Initialize a newly created holder to hold the given values.
8195 * 5875 *
8196 * @param modificationTime the modification time of the source from which the AST was created 5876 * @param modificationTime the modification time of the source from which the AST was created
8197 * @param unit the AST that was created from the source 5877 * @param unit the AST that was created from the source
8198 */ 5878 */
8199 ResolvableCompilationUnit(int modificationTime, CompilationUnit unit) { 5879 ResolvableHtmlUnit(int modificationTime, HtmlUnit unit) : super(modificationTi me, unit);
8200 this.modificationTime = modificationTime; 5880
8201 this.compilationUnit = unit; 5881 /**
8202 } 5882 * Return the AST that was created from the source.
5883 *
5884 * @return the AST that was created from the source
5885 */
5886 HtmlUnit get compilationUnit => data;
8203 } 5887 }
8204 /** 5888 /**
8205 * Instances of the class `ResolvableHtmlUnit` represent an HTML unit that is no t referenced 5889 * Instances of the class `TimestampedData` represent analysis data for which we have a
8206 * by any other objects and for which we have modification stamp information. It is used by the 5890 * modification time.
8207 * [ResolveHtmlTask] to resolve an HTML source.
8208 */ 5891 */
8209 class ResolvableHtmlUnit { 5892 class TimestampedData<E> {
8210 5893
8211 /** 5894 /**
8212 * The modification time of the source from which the AST was created. 5895 * The modification time of the source from which the data was created.
8213 */ 5896 */
8214 int modificationTime = 0; 5897 int modificationTime = 0;
8215 5898
8216 /** 5899 /**
8217 * The AST that was created from the source. 5900 * The data that was created from the source.
8218 */ 5901 */
8219 HtmlUnit compilationUnit; 5902 E data;
8220 5903
8221 /** 5904 /**
8222 * Initialize a newly created holder to hold the given values. 5905 * Initialize a newly created holder to hold the given values.
8223 * 5906 *
8224 * @param modificationTime the modification time of the source from which the AST was created 5907 * @param modificationTime the modification time of the source from which the data was created
8225 * @param unit the AST that was created from the source 5908 * @param unit the data that was created from the source
8226 */ 5909 */
8227 ResolvableHtmlUnit(int modificationTime, HtmlUnit unit) { 5910 TimestampedData(int modificationTime, E data) {
8228 this.modificationTime = modificationTime; 5911 this.modificationTime = modificationTime;
8229 this.compilationUnit = unit; 5912 this.data = data;
8230 } 5913 }
8231 } 5914 }
8232 /** 5915 /**
8233 * The abstract class `AnalysisTask` defines the behavior of objects used to per form an 5916 * The abstract class `AnalysisTask` defines the behavior of objects used to per form an
8234 * analysis task. 5917 * analysis task.
8235 */ 5918 */
8236 abstract class AnalysisTask { 5919 abstract class AnalysisTask {
8237 5920
8238 /** 5921 /**
8239 * The context in which the task is to be performed. 5922 * The context in which the task is to be performed.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
8313 } 5996 }
8314 } 5997 }
8315 /** 5998 /**
8316 * The interface `AnalysisTaskVisitor` defines the behavior of objects that can visit tasks. 5999 * The interface `AnalysisTaskVisitor` defines the behavior of objects that can visit tasks.
8317 * While tasks are not structured in any interesting way, this class provides th e ability to 6000 * While tasks are not structured in any interesting way, this class provides th e ability to
8318 * dispatch to an appropriate method. 6001 * dispatch to an appropriate method.
8319 */ 6002 */
8320 abstract class AnalysisTaskVisitor<E> { 6003 abstract class AnalysisTaskVisitor<E> {
8321 6004
8322 /** 6005 /**
6006 * Visit a [GenerateDartHintsTask].
6007 *
6008 * @param task the task to be visited
6009 * @return the result of visiting the task
6010 * @throws AnalysisException if the visitor throws an exception for some reaso n
6011 */
6012 E visitGenerateDartHintsTask(GenerateDartHintsTask task);
6013
6014 /**
8323 * Visit a [ParseDartTask]. 6015 * Visit a [ParseDartTask].
8324 * 6016 *
8325 * @param task the task to be visited 6017 * @param task the task to be visited
8326 * @return the result of visiting the task 6018 * @return the result of visiting the task
8327 * @throws AnalysisException if the visitor throws an exception for some reaso n 6019 * @throws AnalysisException if the visitor throws an exception for some reaso n
8328 */ 6020 */
8329 E visitParseDartTask(ParseDartTask task); 6021 E visitParseDartTask(ParseDartTask task);
8330 6022
8331 /** 6023 /**
8332 * Visit a [ParseHtmlTask]. 6024 * Visit a [ParseHtmlTask].
(...skipping 25 matching lines...) Expand all
8358 /** 6050 /**
8359 * Visit a [ResolveHtmlTask]. 6051 * Visit a [ResolveHtmlTask].
8360 * 6052 *
8361 * @param task the task to be visited 6053 * @param task the task to be visited
8362 * @return the result of visiting the task 6054 * @return the result of visiting the task
8363 * @throws AnalysisException if the visitor throws an exception for some reaso n 6055 * @throws AnalysisException if the visitor throws an exception for some reaso n
8364 */ 6056 */
8365 E visitResolveHtmlTask(ResolveHtmlTask task); 6057 E visitResolveHtmlTask(ResolveHtmlTask task);
8366 } 6058 }
8367 /** 6059 /**
6060 * Instances of the class `GenerateDartHintsTask` generate hints for a single Da rt library.
6061 */
6062 class GenerateDartHintsTask extends AnalysisTask {
6063
6064 /**
6065 * The element model for the library being analyzed.
6066 */
6067 LibraryElement libraryElement;
6068
6069 /**
6070 * A table mapping the sources that were analyzed to the hints that were gener ated for the
6071 * sources.
6072 */
6073 Map<Source, TimestampedData<List<AnalysisError>>> hintMap;
6074
6075 /**
6076 * Initialize a newly created task to perform analysis within the given contex t.
6077 *
6078 * @param context the context in which the task is to be performed
6079 * @param libraryElement the element model for the library being analyzed
6080 */
6081 GenerateDartHintsTask(InternalAnalysisContext context, LibraryElement libraryE lement) : super(context) {
6082 this.libraryElement = libraryElement;
6083 }
6084 accept(AnalysisTaskVisitor visitor) => visitor.visitGenerateDartHintsTask(this );
6085 String get taskDescription {
6086 Source librarySource = libraryElement.source;
6087 if (librarySource == null) {
6088 return "generate Dart hints for library without source";
6089 }
6090 return "generate Dart hints for ${librarySource.fullName}";
6091 }
6092 void internalPerform() {
6093 RecordingErrorListener errorListener = new RecordingErrorListener();
6094 List<CompilationUnitElement> parts = libraryElement.parts;
6095 int partCount = parts.length;
6096 List<CompilationUnit> compilationUnits = new List<CompilationUnit>(partCount + 1);
6097 Map<Source, TimestampedData<CompilationUnit>> timestampMap = new Map<Source, TimestampedData<CompilationUnit>>();
6098 Source unitSource = libraryElement.definingCompilationUnit.source;
6099 TimestampedData<CompilationUnit> resolvedUnit = getCompilationUnit(unitSourc e);
6100 timestampMap[unitSource] = resolvedUnit;
6101 compilationUnits[0] = resolvedUnit.data;
6102 for (int i = 0; i < partCount; i++) {
6103 unitSource = parts[i].source;
6104 resolvedUnit = getCompilationUnit(unitSource);
6105 timestampMap[unitSource] = resolvedUnit;
6106 compilationUnits[i + 1] = resolvedUnit.data;
6107 }
6108 HintGenerator hintGenerator = new HintGenerator(compilationUnits, context, e rrorListener);
6109 hintGenerator.generateForLibrary();
6110 hintMap = new Map<Source, TimestampedData<List<AnalysisError>>>();
6111 for (MapEntry<Source, TimestampedData<CompilationUnit>> entry in getMapEntry Set(timestampMap)) {
6112 Source source = entry.getKey();
6113 TimestampedData<CompilationUnit> unitData = entry.getValue();
6114 List<AnalysisError> errors = errorListener.getErrors2(source);
6115 hintMap[source] = new TimestampedData<List<AnalysisError>>(unitData.modifi cationTime, errors);
6116 unitData.data.hints = errors;
6117 }
6118 }
6119
6120 /**
6121 * Return the resolved compilation unit associated with the given source.
6122 *
6123 * @param unitSource the source for the compilation unit whose resolved AST is to be returned
6124 * @return the resolved compilation unit associated with the given source
6125 * @throws AnalysisException if the resolved compilation unit could not be com puted
6126 */
6127 TimestampedData<CompilationUnit> getCompilationUnit(Source unitSource) => cont ext.internalResolveCompilationUnit(unitSource, libraryElement);
6128 }
6129 /**
8368 * Instances of the class `ParseDartTask` parse a specific source as a Dart file . 6130 * Instances of the class `ParseDartTask` parse a specific source as a Dart file .
8369 */ 6131 */
8370 class ParseDartTask extends AnalysisTask { 6132 class ParseDartTask extends AnalysisTask {
8371 6133
8372 /** 6134 /**
8373 * The source to be parsed. 6135 * The source to be parsed.
8374 */ 6136 */
8375 Source source; 6137 Source source;
8376 6138
8377 /** 6139 /**
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
8462 */ 6224 */
8463 bool hasLibraryDirective() => _hasLibraryDirective2; 6225 bool hasLibraryDirective() => _hasLibraryDirective2;
8464 6226
8465 /** 6227 /**
8466 * Return `true` if the source contains a 'part of' directive, or `false` if t he task 6228 * Return `true` if the source contains a 'part of' directive, or `false` if t he task
8467 * has not yet been performed or if an exception occurred. 6229 * has not yet been performed or if an exception occurred.
8468 * 6230 *
8469 * @return `true` if the source contains a 'part of' directive 6231 * @return `true` if the source contains a 'part of' directive
8470 */ 6232 */
8471 bool hasPartOfDirective() => _hasPartOfDirective2; 6233 bool hasPartOfDirective() => _hasPartOfDirective2;
8472 String get taskDescription => "parse as dart ${source.fullName}"; 6234 String get taskDescription {
6235 if (source == null) {
6236 return "parse as dart null source";
6237 }
6238 return "parse as dart ${source.fullName}";
6239 }
8473 void internalPerform() { 6240 void internalPerform() {
8474 RecordingErrorListener errorListener = new RecordingErrorListener(); 6241 RecordingErrorListener errorListener = new RecordingErrorListener();
8475 List<Token> token = [null]; 6242 List<Token> token = [null];
8476 Source_ContentReceiver receiver = new Source_ContentReceiver_10(this, errorL istener, token); 6243 TimeCounter_TimeCounterHandle timeCounterScan = PerformanceStatistics.scan.s tart();
6244 Source_ContentReceiver receiver = new Source_ContentReceiver_9(this, errorLi stener, token);
8477 try { 6245 try {
8478 source.getContents(receiver); 6246 source.getContents(receiver);
8479 } catch (exception) { 6247 } catch (exception) {
8480 modificationTime = source.modificationStamp; 6248 modificationTime = source.modificationStamp;
8481 throw new AnalysisException.con3(exception); 6249 throw new AnalysisException.con3(exception);
8482 } 6250 }
6251 timeCounterScan.stop();
6252 TimeCounter_TimeCounterHandle timeCounterParse = PerformanceStatistics.parse .start();
8483 Parser parser = new Parser(source, errorListener); 6253 Parser parser = new Parser(source, errorListener);
8484 compilationUnit = parser.parseCompilationUnit(token[0]); 6254 compilationUnit = parser.parseCompilationUnit(token[0]);
8485 errors = errorListener.getErrors2(source); 6255 errors = errorListener.getErrors2(source);
8486 for (Directive directive in compilationUnit.directives) { 6256 for (Directive directive in compilationUnit.directives) {
8487 if (directive is ExportDirective) { 6257 if (directive is ExportDirective) {
8488 Source exportSource = resolveSource(source, directive as ExportDirective ); 6258 Source exportSource = resolveSource(source, directive as ExportDirective );
8489 if (exportSource != null) { 6259 if (exportSource != null) {
8490 javaSetAdd(_exportedSources, exportSource); 6260 javaSetAdd(_exportedSources, exportSource);
8491 } 6261 }
8492 } else if (directive is ImportDirective) { 6262 } else if (directive is ImportDirective) {
8493 Source importSource = resolveSource(source, directive as ImportDirective ); 6263 Source importSource = resolveSource(source, directive as ImportDirective );
8494 if (importSource != null) { 6264 if (importSource != null) {
8495 javaSetAdd(_importedSources, importSource); 6265 javaSetAdd(_importedSources, importSource);
8496 } 6266 }
8497 } else if (directive is LibraryDirective) { 6267 } else if (directive is LibraryDirective) {
8498 _hasLibraryDirective2 = true; 6268 _hasLibraryDirective2 = true;
8499 } else if (directive is PartDirective) { 6269 } else if (directive is PartDirective) {
8500 Source partSource = resolveSource(source, directive as PartDirective); 6270 Source partSource = resolveSource(source, directive as PartDirective);
8501 if (partSource != null) { 6271 if (partSource != null) {
8502 javaSetAdd(_includedSources, partSource); 6272 javaSetAdd(_includedSources, partSource);
8503 } 6273 }
8504 } else if (directive is PartOfDirective) { 6274 } else if (directive is PartOfDirective) {
8505 _hasPartOfDirective2 = true; 6275 _hasPartOfDirective2 = true;
8506 } 6276 }
8507 } 6277 }
8508 compilationUnit.parsingErrors = errors; 6278 compilationUnit.parsingErrors = errors;
8509 compilationUnit.lineInfo = lineInfo; 6279 compilationUnit.lineInfo = lineInfo;
6280 timeCounterParse.stop();
8510 } 6281 }
8511 6282
8512 /** 6283 /**
8513 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 6284 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
8514 * given library, or `null` if the URI is not valid. 6285 * given library, or `null` if the URI is not valid.
8515 * 6286 *
8516 * @param librarySource the source representing the library containing the dir ective 6287 * @param librarySource the source representing the library containing the dir ective
8517 * @param directive the directive which URI should be resolved 6288 * @param directive the directive which URI should be resolved
8518 * @return the result of resolving the URI against the URI of the library 6289 * @return the result of resolving the URI against the URI of the library
8519 */ 6290 */
(...skipping 22 matching lines...) Expand all
8542 * @return an array containing all of the sources in the given set 6313 * @return an array containing all of the sources in the given set
8543 */ 6314 */
8544 List<Source> toArray(Set<Source> sources) { 6315 List<Source> toArray(Set<Source> sources) {
8545 int size = sources.length; 6316 int size = sources.length;
8546 if (size == 0) { 6317 if (size == 0) {
8547 return Source.EMPTY_ARRAY; 6318 return Source.EMPTY_ARRAY;
8548 } 6319 }
8549 return new List.from(sources); 6320 return new List.from(sources);
8550 } 6321 }
8551 } 6322 }
8552 class Source_ContentReceiver_10 implements Source_ContentReceiver { 6323 class Source_ContentReceiver_9 implements Source_ContentReceiver {
8553 final ParseDartTask ParseDartTask_this; 6324 final ParseDartTask ParseDartTask_this;
8554 RecordingErrorListener errorListener; 6325 RecordingErrorListener errorListener;
8555 List<Token> token; 6326 List<Token> token;
8556 Source_ContentReceiver_10(this.ParseDartTask_this, this.errorListener, this.to ken); 6327 Source_ContentReceiver_9(this.ParseDartTask_this, this.errorListener, this.tok en);
8557 void accept(CharBuffer contents, int modificationTime2) { 6328 void accept(CharBuffer contents, int modificationTime2) {
8558 ParseDartTask_this.modificationTime = modificationTime2; 6329 ParseDartTask_this.modificationTime = modificationTime2;
8559 CharBufferScanner scanner = new CharBufferScanner(ParseDartTask_this.source, contents, errorListener); 6330 CharBufferScanner scanner = new CharBufferScanner(ParseDartTask_this.source, contents, errorListener);
8560 token[0] = scanner.tokenize(); 6331 token[0] = scanner.tokenize();
8561 ParseDartTask_this.lineInfo = new LineInfo(scanner.lineStarts); 6332 ParseDartTask_this.lineInfo = new LineInfo(scanner.lineStarts);
8562 } 6333 }
8563 void accept2(String contents, int modificationTime2) { 6334 void accept2(String contents, int modificationTime2) {
8564 ParseDartTask_this.modificationTime = modificationTime2; 6335 ParseDartTask_this.modificationTime = modificationTime2;
8565 StringScanner scanner = new StringScanner(ParseDartTask_this.source, content s, errorListener); 6336 StringScanner scanner = new StringScanner(ParseDartTask_this.source, content s, errorListener);
8566 token[0] = scanner.tokenize(); 6337 token[0] = scanner.tokenize();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
8621 /** 6392 /**
8622 * Initialize a newly created task to perform analysis within the given contex t. 6393 * Initialize a newly created task to perform analysis within the given contex t.
8623 * 6394 *
8624 * @param context the context in which the task is to be performed 6395 * @param context the context in which the task is to be performed
8625 * @param source the source to be parsed 6396 * @param source the source to be parsed
8626 */ 6397 */
8627 ParseHtmlTask(InternalAnalysisContext context, Source source) : super(context) { 6398 ParseHtmlTask(InternalAnalysisContext context, Source source) : super(context) {
8628 this.source = source; 6399 this.source = source;
8629 } 6400 }
8630 accept(AnalysisTaskVisitor visitor) => visitor.visitParseHtmlTask(this); 6401 accept(AnalysisTaskVisitor visitor) => visitor.visitParseHtmlTask(this);
8631 String get taskDescription => "parse as html ${source.fullName}"; 6402 String get taskDescription {
6403 if (source == null) {
6404 return "parse as html null source";
6405 }
6406 return "parse as html ${source.fullName}";
6407 }
8632 void internalPerform() { 6408 void internalPerform() {
8633 HtmlScanner scanner = new HtmlScanner(source); 6409 HtmlScanner scanner = new HtmlScanner(source);
8634 try { 6410 try {
8635 source.getContents(scanner); 6411 source.getContents(scanner);
8636 } catch (exception) { 6412 } catch (exception) {
8637 throw new AnalysisException.con3(exception); 6413 throw new AnalysisException.con3(exception);
8638 } 6414 }
8639 HtmlScanResult scannerResult = scanner.result; 6415 HtmlScanResult scannerResult = scanner.result;
8640 modificationTime = scannerResult.modificationTime; 6416 modificationTime = scannerResult.modificationTime;
8641 lineInfo = new LineInfo(scannerResult.lineStarts); 6417 lineInfo = new LineInfo(scannerResult.lineStarts);
8642 HtmlParseResult result = new HtmlParser(source).parse(scannerResult); 6418 HtmlParseResult result = new HtmlParser(source).parse(scannerResult);
8643 htmlUnit = result.htmlUnit; 6419 htmlUnit = result.htmlUnit;
8644 referencedLibraries = librarySources; 6420 referencedLibraries = librarySources;
8645 } 6421 }
8646 6422
8647 /** 6423 /**
8648 * Return the sources of libraries that are referenced in the specified HTML f ile. 6424 * Return the sources of libraries that are referenced in the specified HTML f ile.
8649 * 6425 *
8650 * @return the sources of libraries that are referenced in the HTML file 6426 * @return the sources of libraries that are referenced in the HTML file
8651 */ 6427 */
8652 List<Source> get librarySources { 6428 List<Source> get librarySources {
8653 List<Source> libraries = new List<Source>(); 6429 List<Source> libraries = new List<Source>();
8654 htmlUnit.accept(new RecursiveXmlVisitor_11(this, libraries)); 6430 htmlUnit.accept(new RecursiveXmlVisitor_10(this, libraries));
8655 if (libraries.isEmpty) { 6431 if (libraries.isEmpty) {
8656 return Source.EMPTY_ARRAY; 6432 return Source.EMPTY_ARRAY;
8657 } 6433 }
8658 return new List.from(libraries); 6434 return new List.from(libraries);
8659 } 6435 }
8660 } 6436 }
8661 class RecursiveXmlVisitor_11 extends RecursiveXmlVisitor<Object> { 6437 class RecursiveXmlVisitor_10 extends RecursiveXmlVisitor<Object> {
8662 final ParseHtmlTask ParseHtmlTask_this; 6438 final ParseHtmlTask ParseHtmlTask_this;
8663 List<Source> libraries; 6439 List<Source> libraries;
8664 RecursiveXmlVisitor_11(this.ParseHtmlTask_this, this.libraries) : super(); 6440 RecursiveXmlVisitor_10(this.ParseHtmlTask_this, this.libraries) : super();
8665 Object visitXmlTagNode(XmlTagNode node) { 6441 Object visitXmlTagNode(XmlTagNode node) {
8666 if (javaStringEqualsIgnoreCase(node.tag.lexeme, ParseHtmlTask._TAG_SCRIPT)) { 6442 if (javaStringEqualsIgnoreCase(node.tag.lexeme, ParseHtmlTask._TAG_SCRIPT)) {
8667 bool isDartScript = false; 6443 bool isDartScript = false;
8668 XmlAttributeNode scriptAttribute = null; 6444 XmlAttributeNode scriptAttribute = null;
8669 for (XmlAttributeNode attribute in node.attributes) { 6445 for (XmlAttributeNode attribute in node.attributes) {
8670 if (javaStringEqualsIgnoreCase(attribute.name.lexeme, ParseHtmlTask._ATT RIBUTE_SRC)) { 6446 if (javaStringEqualsIgnoreCase(attribute.name.lexeme, ParseHtmlTask._ATT RIBUTE_SRC)) {
8671 scriptAttribute = attribute; 6447 scriptAttribute = attribute;
8672 } else if (javaStringEqualsIgnoreCase(attribute.name.lexeme, ParseHtmlTa sk._ATTRIBUTE_TYPE)) { 6448 } else if (javaStringEqualsIgnoreCase(attribute.name.lexeme, ParseHtmlTa sk._ATTRIBUTE_TYPE)) {
8673 if (javaStringEqualsIgnoreCase(attribute.text, ParseHtmlTask._TYPE_DAR T)) { 6449 if (javaStringEqualsIgnoreCase(attribute.text, ParseHtmlTask._TYPE_DAR T)) {
8674 isDartScript = true; 6450 isDartScript = true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
8716 * 6492 *
8717 * @param context the context in which the task is to be performed 6493 * @param context the context in which the task is to be performed
8718 * @param unitSource the source representing the file whose compilation unit i s to be returned 6494 * @param unitSource the source representing the file whose compilation unit i s to be returned
8719 * @param librarySource the source representing the library to be resolved 6495 * @param librarySource the source representing the library to be resolved
8720 */ 6496 */
8721 ResolveDartLibraryTask(InternalAnalysisContext context, Source unitSource, Sou rce librarySource) : super(context) { 6497 ResolveDartLibraryTask(InternalAnalysisContext context, Source unitSource, Sou rce librarySource) : super(context) {
8722 this.unitSource = unitSource; 6498 this.unitSource = unitSource;
8723 this.librarySource = librarySource; 6499 this.librarySource = librarySource;
8724 } 6500 }
8725 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveDartLibraryTask(thi s); 6501 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveDartLibraryTask(thi s);
8726 String get taskDescription => "resolve library ${librarySource.fullName}"; 6502 String get taskDescription {
6503 if (librarySource == null) {
6504 return "resolve library null source";
6505 }
6506 return "resolve library ${librarySource.fullName}";
6507 }
8727 void internalPerform() { 6508 void internalPerform() {
8728 libraryResolver = new LibraryResolver(context); 6509 libraryResolver = new LibraryResolver(context);
8729 libraryResolver.resolveLibrary(librarySource, true); 6510 libraryResolver.resolveLibrary(librarySource, true);
8730 } 6511 }
8731 } 6512 }
8732 /** 6513 /**
8733 * Instances of the class `ResolveDartUnitTask` resolve a single Dart file based on a existing 6514 * Instances of the class `ResolveDartUnitTask` resolve a single Dart file based on a existing
8734 * element model. 6515 * element model.
8735 */ 6516 */
8736 class ResolveDartUnitTask extends AnalysisTask { 6517 class ResolveDartUnitTask extends AnalysisTask {
(...skipping 30 matching lines...) Expand all
8767 this._libraryElement = libraryElement; 6548 this._libraryElement = libraryElement;
8768 } 6549 }
8769 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveDartUnitTask(this); 6550 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveDartUnitTask(this);
8770 6551
8771 /** 6552 /**
8772 * Return the source for the library containing the source that is to be resol ved. 6553 * Return the source for the library containing the source that is to be resol ved.
8773 * 6554 *
8774 * @return the source for the library containing the source that is to be reso lved 6555 * @return the source for the library containing the source that is to be reso lved
8775 */ 6556 */
8776 Source get librarySource => _libraryElement.source; 6557 Source get librarySource => _libraryElement.source;
8777 String get taskDescription => "resolve unit ${_libraryElement.source.fullName} "; 6558 String get taskDescription {
6559 Source librarySource = _libraryElement.source;
6560 if (librarySource == null) {
6561 return "resolve unit null source";
6562 }
6563 return "resolve unit ${librarySource.fullName}";
6564 }
8778 void internalPerform() { 6565 void internalPerform() {
8779 Source coreLibrarySource = _libraryElement.context.sourceFactory.forUri(Dart Sdk.DART_CORE); 6566 Source coreLibrarySource = _libraryElement.context.sourceFactory.forUri(Dart Sdk.DART_CORE);
8780 LibraryElement coreElement = context.computeLibraryElement(coreLibrarySource ); 6567 LibraryElement coreElement = context.computeLibraryElement(coreLibrarySource );
8781 TypeProvider typeProvider = new TypeProviderImpl(coreElement); 6568 TypeProvider typeProvider = new TypeProviderImpl(coreElement);
8782 ResolvableCompilationUnit resolvableUnit = context.computeResolvableCompilat ionUnit(source); 6569 ResolvableCompilationUnit resolvableUnit = context.computeResolvableCompilat ionUnit(source);
8783 modificationTime = resolvableUnit.modificationTime; 6570 modificationTime = resolvableUnit.modificationTime;
8784 CompilationUnit unit = resolvableUnit.compilationUnit; 6571 CompilationUnit unit = resolvableUnit.compilationUnit;
8785 if (unit == null) { 6572 if (unit == null) {
8786 throw new AnalysisException.con1("Internal error: computeResolvableCompila tionUnit returned a value without a parsed Dart unit"); 6573 throw new AnalysisException.con1("Internal error: computeResolvableCompila tionUnit returned a value without a parsed Dart unit");
8787 } 6574 }
8788 new DeclarationResolver().resolve(unit, find(_libraryElement, source)); 6575 new DeclarationResolver().resolve(unit, find(_libraryElement, source));
8789 RecordingErrorListener errorListener = new RecordingErrorListener(); 6576 RecordingErrorListener errorListener = new RecordingErrorListener();
8790 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(_libr aryElement, source, typeProvider, errorListener); 6577 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(_libr aryElement, source, typeProvider, errorListener);
8791 unit.accept(typeResolverVisitor); 6578 unit.accept(typeResolverVisitor);
8792 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt); 6579 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt);
8793 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(_libraryElement, source, typeProvider, inheritanceManager, errorListener); 6580 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(_libraryElement, source, typeProvider, inheritanceManager, errorListener);
8794 unit.accept(resolverVisitor); 6581 unit.accept(resolverVisitor);
8795 for (ProxyConditionalAnalysisError conditionalCode in resolverVisitor.proxyC onditionalAnalysisErrors) { 6582 for (ProxyConditionalAnalysisError conditionalCode in resolverVisitor.proxyC onditionalAnalysisErrors) {
8796 if (conditionalCode.shouldIncludeErrorCode()) { 6583 if (conditionalCode.shouldIncludeErrorCode()) {
8797 resolverVisitor.reportError(conditionalCode.analysisError); 6584 resolverVisitor.reportError(conditionalCode.analysisError);
8798 } 6585 }
8799 } 6586 }
6587 TimeCounter_TimeCounterHandle counterHandleErrors = PerformanceStatistics.er rors.start();
8800 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); 6588 ErrorReporter errorReporter = new ErrorReporter(errorListener, source);
8801 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEleme nt, typeProvider, inheritanceManager); 6589 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEleme nt, typeProvider, inheritanceManager);
8802 unit.accept(errorVerifier); 6590 unit.accept(errorVerifier);
8803 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, type Provider); 6591 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, type Provider);
8804 unit.accept(constantVerifier); 6592 unit.accept(constantVerifier);
6593 counterHandleErrors.stop();
8805 unit.resolutionErrors = errorListener.errors; 6594 unit.resolutionErrors = errorListener.errors;
8806 resolvedUnit = unit; 6595 resolvedUnit = unit;
8807 } 6596 }
8808 6597
8809 /** 6598 /**
8810 * Search the compilation units that are part of the given library and return the element 6599 * Search the compilation units that are part of the given library and return the element
8811 * representing the compilation unit with the given source. Return `null` if t here is no 6600 * representing the compilation unit with the given source. Return `null` if t here is no
8812 * such compilation unit. 6601 * such compilation unit.
8813 * 6602 *
8814 * @param libraryElement the element representing the library being searched t hrough 6603 * @param libraryElement the element representing the library being searched t hrough
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
8856 /** 6645 /**
8857 * Initialize a newly created task to perform analysis within the given contex t. 6646 * Initialize a newly created task to perform analysis within the given contex t.
8858 * 6647 *
8859 * @param context the context in which the task is to be performed 6648 * @param context the context in which the task is to be performed
8860 * @param source the source to be resolved 6649 * @param source the source to be resolved
8861 */ 6650 */
8862 ResolveHtmlTask(InternalAnalysisContext context, Source source) : super(contex t) { 6651 ResolveHtmlTask(InternalAnalysisContext context, Source source) : super(contex t) {
8863 this.source = source; 6652 this.source = source;
8864 } 6653 }
8865 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveHtmlTask(this); 6654 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveHtmlTask(this);
8866 String get taskDescription => "resolve as html ${source.fullName}"; 6655 String get taskDescription {
6656 if (source == null) {
6657 return "resolve as html null source";
6658 }
6659 return "resolve as html ${source.fullName}";
6660 }
8867 void internalPerform() { 6661 void internalPerform() {
8868 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(so urce); 6662 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(so urce);
8869 HtmlUnit unit = resolvableHtmlUnit.compilationUnit; 6663 HtmlUnit unit = resolvableHtmlUnit.compilationUnit;
8870 if (unit == null) { 6664 if (unit == null) {
8871 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit"); 6665 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit");
8872 } 6666 }
8873 modificationTime = resolvableHtmlUnit.modificationTime; 6667 modificationTime = resolvableHtmlUnit.modificationTime;
8874 HtmlUnitBuilder builder = new HtmlUnitBuilder(context); 6668 HtmlUnitBuilder builder = new HtmlUnitBuilder(context);
8875 element = builder.buildHtmlElement2(source, modificationTime, unit); 6669 element = builder.buildHtmlElement2(source, modificationTime, unit);
8876 resolutionErrors = builder.errorListener.getErrors2(source); 6670 resolutionErrors = builder.errorListener.getErrors2(source);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
8933 } 6727 }
8934 void logError2(String message, Exception exception) { 6728 void logError2(String message, Exception exception) {
8935 } 6729 }
8936 void logError3(Exception exception) { 6730 void logError3(Exception exception) {
8937 } 6731 }
8938 void logInformation(String message) { 6732 void logInformation(String message) {
8939 } 6733 }
8940 void logInformation2(String message, Exception exception) { 6734 void logInformation2(String message, Exception exception) {
8941 } 6735 }
8942 } 6736 }
OLDNEW
« no previous file with comments | « pkg/analyzer_experimental/lib/src/generated/element.dart ('k') | pkg/analyzer_experimental/lib/src/generated/error.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698