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

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

Issue 23461019: New analyzer_experimental snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 'instrumentation.dart'; 7 import 'instrumentation.dart';
8 import 'error.dart'; 8 import 'error.dart';
9 import 'source.dart'; 9 import 'source.dart';
10 import 'scanner.dart' show Token, CharBufferScanner, StringScanner; 10 import 'scanner.dart' show Token, CharBufferScanner, StringScanner;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 String extension = FileNameUtilities.getExtension(fileName); 75 String extension = FileNameUtilities.getExtension(fileName);
76 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqual sIgnoreCase(extension, SUFFIX_HTM); 76 return javaStringEqualsIgnoreCase(extension, SUFFIX_HTML) || javaStringEqual sIgnoreCase(extension, SUFFIX_HTM);
77 } 77 }
78 78
79 /** 79 /**
80 * The logger that should receive information about errors within the analysis engine. 80 * The logger that should receive information about errors within the analysis engine.
81 */ 81 */
82 Logger _logger = Logger.NULL; 82 Logger _logger = Logger.NULL;
83 83
84 /** 84 /**
85 * A flag indicating whether the new analysis context should be created.
86 */
87 bool _useExperimentalContext = false;
88
89 /**
85 * Create a new context in which analysis can be performed. 90 * Create a new context in which analysis can be performed.
86 * 91 *
87 * @return the analysis context that was created 92 * @return the analysis context that was created
88 */ 93 */
89 AnalysisContext createAnalysisContext() { 94 AnalysisContext createAnalysisContext() {
90 if (Instrumentation.isNullLogger) { 95 if (Instrumentation.isNullLogger) {
96 if (_useExperimentalContext) {
97 return new DelegatingAnalysisContextImpl2();
98 }
91 return new DelegatingAnalysisContextImpl(); 99 return new DelegatingAnalysisContextImpl();
92 } else {
93 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisCont extImpl());
94 } 100 }
101 if (_useExperimentalContext) {
102 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisCont extImpl2());
103 }
104 return new InstrumentedAnalysisContextImpl.con1(new DelegatingAnalysisContex tImpl());
95 } 105 }
96 106
97 /** 107 /**
98 * Return the logger that should receive information about errors within the a nalysis engine. 108 * Return the logger that should receive information about errors within the a nalysis engine.
99 * 109 *
100 * @return the logger that should receive information about errors within the analysis engine 110 * @return the logger that should receive information about errors within the analysis engine
101 */ 111 */
102 Logger get logger => _logger; 112 Logger get logger => _logger;
103 113
104 /** 114 /**
115 * Return `true` if the new analysis context should be created.
116 *
117 * @return `true` if the new analysis context should be created
118 */
119 bool get useExperimentalContext => _useExperimentalContext;
120
121 /**
105 * Set the logger that should receive information about errors within the anal ysis engine to the 122 * Set the logger that should receive information about errors within the anal ysis engine to the
106 * given logger. 123 * given logger.
107 * 124 *
108 * @param logger the logger that should receive information about errors withi n the analysis 125 * @param logger the logger that should receive information about errors withi n the analysis
109 * engine 126 * engine
110 */ 127 */
111 void set logger(Logger logger2) { 128 void set logger(Logger logger2) {
112 this._logger = logger2 == null ? Logger.NULL : logger2; 129 this._logger = logger2 == null ? Logger.NULL : logger2;
113 } 130 }
131
132 /**
133 * Set whether the new analysis context should be created to the given flag.
134 *
135 * @param use `true` if the new analysis context should be created
136 */
137 void set useExperimentalContext(bool use) {
138 _useExperimentalContext = use;
139 }
114 } 140 }
115 /** 141 /**
116 * Container with statistics about the [AnalysisContext]. 142 * Container with statistics about the [AnalysisContext].
117 */ 143 */
118 abstract class AnalysisContentStatistics { 144 abstract class AnalysisContentStatistics {
119 145
120 /** 146 /**
121 * @return the statistics for each kind of cached data. 147 * @return the statistics for each kind of cached data.
122 */ 148 */
123 List<AnalysisContentStatistics_CacheRow> get cacheRows; 149 List<AnalysisContentStatistics_CacheRow> get cacheRows;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 * @param library the library containing the source to be resolved 542 * @param library the library containing the source to be resolved
517 * @return the result of resolving the AST structure representing the content of the source in the 543 * @return the result of resolving the AST structure representing the content of the source in the
518 * context of the given library 544 * context of the given library
519 * @throws AnalysisException if the analysis could not be performed 545 * @throws AnalysisException if the analysis could not be performed
520 * @see #getResolvedCompilationUnit(Source, LibraryElement) 546 * @see #getResolvedCompilationUnit(Source, LibraryElement)
521 */ 547 */
522 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry); 548 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry);
523 549
524 /** 550 /**
525 * Parse and resolve a single source within the given context to produce a ful ly resolved AST. 551 * Parse and resolve a single source within the given context to produce a ful ly resolved AST.
552 * Return the resolved AST structure, or `null` if the source could not be eit her parsed or
553 * resolved.
526 * 554 *
527 * @param unitSource the source to be parsed and resolved 555 * @param unitSource the source to be parsed and resolved
528 * @param librarySource the source of the defining compilation unit of the lib rary containing the 556 * @param librarySource the source of the defining compilation unit of the lib rary containing the
529 * source to be resolved 557 * source to be resolved
530 * @return the result of resolving the AST structure representing the content of the source in the 558 * @return the result of resolving the AST structure representing the content of the source in the
531 * context of the given library 559 * context of the given library
532 * @throws AnalysisException if the analysis could not be performed 560 * @throws AnalysisException if the analysis could not be performed
533 * @see #getResolvedCompilationUnit(Source, Source) 561 * @see #getResolvedCompilationUnit(Source, Source)
534 */ 562 */
535 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e); 563 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e);
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 * Associate the given entry with the given source. 938 * Associate the given entry with the given source.
911 * 939 *
912 * @param source the source with which the entry is to be associated 940 * @param source the source with which the entry is to be associated
913 * @param entry the entry to be associated with the source 941 * @param entry the entry to be associated with the source
914 */ 942 */
915 void put(Source source, SourceEntry entry) { 943 void put(Source source, SourceEntry entry) {
916 _sourceMap[source] = entry; 944 _sourceMap[source] = entry;
917 } 945 }
918 946
919 /** 947 /**
948 * Remove all information related to the given source from this cache.
949 *
950 * @param source the source to be removed
951 */
952 void remove(Source source) {
953 _sourceMap.remove(source);
954 }
955
956 /**
920 * Set the sources for which data should not be flushed to the given array. 957 * Set the sources for which data should not be flushed to the given array.
921 * 958 *
922 * @param sources the sources for which data should not be flushed 959 * @param sources the sources for which data should not be flushed
923 */ 960 */
924 void set priorityOrder(List<Source> sources) { 961 void set priorityOrder(List<Source> sources) {
925 _priorityOrder = sources; 962 _priorityOrder = sources;
926 } 963 }
927 964
928 /** 965 /**
929 * Flush one AST structure from the cache. 966 * Flush one AST structure from the cache.
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 } 1531 }
1495 if (_importedLibrariesState != CacheState.VALID) { 1532 if (_importedLibrariesState != CacheState.VALID) {
1496 _importedLibrariesState = CacheState.IN_PROCESS; 1533 _importedLibrariesState = CacheState.IN_PROCESS;
1497 } 1534 }
1498 if (_includedPartsState != CacheState.VALID) { 1535 if (_includedPartsState != CacheState.VALID) {
1499 _includedPartsState = CacheState.IN_PROCESS; 1536 _includedPartsState = CacheState.IN_PROCESS;
1500 } 1537 }
1501 } 1538 }
1502 1539
1503 /** 1540 /**
1541 * Record that an in-process parse has stopped without recording results becau se the results were
1542 * invalidated before they could be recorded.
1543 */
1544 void recordParseNotInProcess() {
1545 if (identical(getState(SourceEntry.LINE_INFO), CacheState.IN_PROCESS)) {
1546 setState(SourceEntry.LINE_INFO, CacheState.INVALID);
1547 }
1548 if (identical(_sourceKindState, CacheState.IN_PROCESS)) {
1549 _sourceKindState = CacheState.INVALID;
1550 }
1551 if (identical(_parseErrorsState, CacheState.IN_PROCESS)) {
1552 _parseErrorsState = CacheState.INVALID;
1553 }
1554 if (identical(_parsedUnitState, CacheState.IN_PROCESS)) {
1555 _parsedUnitState = CacheState.INVALID;
1556 }
1557 if (identical(_exportedLibrariesState, CacheState.IN_PROCESS)) {
1558 _exportedLibrariesState = CacheState.INVALID;
1559 }
1560 if (identical(_importedLibrariesState, CacheState.IN_PROCESS)) {
1561 _importedLibrariesState = CacheState.INVALID;
1562 }
1563 if (identical(_includedPartsState, CacheState.IN_PROCESS)) {
1564 _includedPartsState = CacheState.INVALID;
1565 }
1566 }
1567
1568 /**
1504 * Record that an error occurred while attempting to scan or parse the entry r epresented by this 1569 * Record that an error occurred while attempting to scan or parse the entry r epresented by this
1505 * entry. This will set the state of all resolution-based information as being in error, but will 1570 * entry. This will set the state of all resolution-based information as being in error, but will
1506 * not change the state of any parse results. 1571 * not change the state of any parse results.
1507 */ 1572 */
1508 void recordResolutionError() { 1573 void recordResolutionError() {
1509 _element = null; 1574 _element = null;
1510 _elementState = CacheState.ERROR; 1575 _elementState = CacheState.ERROR;
1511 _bitmask = 0; 1576 _bitmask = 0;
1512 _clientServerState = CacheState.ERROR; 1577 _clientServerState = CacheState.ERROR;
1513 _launchableState = CacheState.ERROR; 1578 _launchableState = CacheState.ERROR;
1514 _publicNamespace = null; 1579 _publicNamespace = null;
1515 _publicNamespaceState = CacheState.ERROR; 1580 _publicNamespaceState = CacheState.ERROR;
1516 _resolutionState.recordResolutionError(); 1581 _resolutionState.recordResolutionError();
1517 } 1582 }
1518 1583
1519 /** 1584 /**
1585 * Record that an in-process parse has stopped without recording results becau se the results were
1586 * invalidated before they could be recorded.
1587 */
1588 void recordResolutionNotInProcess() {
1589 if (identical(_elementState, CacheState.IN_PROCESS)) {
1590 _elementState = CacheState.INVALID;
1591 }
1592 if (identical(_clientServerState, CacheState.IN_PROCESS)) {
1593 _clientServerState = CacheState.INVALID;
1594 }
1595 if (identical(_launchableState, CacheState.IN_PROCESS)) {
1596 _launchableState = CacheState.INVALID;
1597 }
1598 if (identical(_publicNamespaceState, CacheState.IN_PROCESS)) {
1599 _publicNamespaceState = CacheState.INVALID;
1600 }
1601 _resolutionState.recordResolutionNotInProcess();
1602 }
1603
1604 /**
1520 * Remove any resolution information associated with this compilation unit bei ng part of the given 1605 * Remove any resolution information associated with this compilation unit bei ng part of the given
1521 * library, presumably because it is no longer part of the library. 1606 * library, presumably because it is no longer part of the library.
1522 * 1607 *
1523 * @param librarySource the source of the defining compilation unit of the lib rary that used to 1608 * @param librarySource the source of the defining compilation unit of the lib rary that used to
1524 * contain this part but no longer does 1609 * contain this part but no longer does
1525 */ 1610 */
1526 void removeResolution(Source librarySource2) { 1611 void removeResolution(Source librarySource2) {
1527 if (librarySource2 != null) { 1612 if (librarySource2 != null) {
1528 if (librarySource2 == _resolutionState._librarySource) { 1613 if (librarySource2 == _resolutionState._librarySource) {
1529 if (_resolutionState._nextState == null) { 1614 if (_resolutionState._nextState == null) {
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 _librarySource = null; 1988 _librarySource = null;
1904 _resolvedUnitState = CacheState.ERROR; 1989 _resolvedUnitState = CacheState.ERROR;
1905 _resolvedUnit = null; 1990 _resolvedUnit = null;
1906 _resolutionErrorsState = CacheState.ERROR; 1991 _resolutionErrorsState = CacheState.ERROR;
1907 _resolutionErrors = AnalysisError.NO_ERRORS; 1992 _resolutionErrors = AnalysisError.NO_ERRORS;
1908 _hintsState = CacheState.ERROR; 1993 _hintsState = CacheState.ERROR;
1909 _hints = AnalysisError.NO_ERRORS; 1994 _hints = AnalysisError.NO_ERRORS;
1910 } 1995 }
1911 1996
1912 /** 1997 /**
1998 * Record that an in-process parse has stopped without recording results becau se the results
1999 * were invalidated before they could be recorded.
2000 */
2001 void recordResolutionNotInProcess() {
2002 if (identical(_resolvedUnitState, CacheState.IN_PROCESS)) {
2003 _resolvedUnitState = CacheState.INVALID;
2004 }
2005 if (identical(_resolutionErrorsState, CacheState.IN_PROCESS)) {
2006 _resolutionErrorsState = CacheState.INVALID;
2007 }
2008 if (identical(_hintsState, CacheState.IN_PROCESS)) {
2009 _hintsState = CacheState.INVALID;
2010 }
2011 if (_nextState != null) {
2012 _nextState.recordResolutionNotInProcess();
2013 }
2014 }
2015
2016 /**
1913 * Write a textual representation of this state to the given builder. The resu lt will only be 2017 * Write a textual representation of this state to the given builder. The resu lt will only be
1914 * used for debugging purposes. 2018 * used for debugging purposes.
1915 * 2019 *
1916 * @param builder the builder to which the text should be written 2020 * @param builder the builder to which the text should be written
1917 */ 2021 */
1918 void writeOn(JavaStringBuilder builder) { 2022 void writeOn(JavaStringBuilder builder) {
1919 if (_librarySource != null) { 2023 if (_librarySource != null) {
1920 builder.append("; resolvedUnit = "); 2024 builder.append("; resolvedUnit = ");
1921 builder.append(_resolvedUnitState); 2025 builder.append(_resolvedUnitState);
1922 builder.append("; resolutionErrors = "); 2026 builder.append("; resolutionErrors = ");
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 } 2196 }
2093 return super.getValue(descriptor); 2197 return super.getValue(descriptor);
2094 } 2198 }
2095 HtmlEntryImpl get writableCopy { 2199 HtmlEntryImpl get writableCopy {
2096 HtmlEntryImpl copy = new HtmlEntryImpl(); 2200 HtmlEntryImpl copy = new HtmlEntryImpl();
2097 copy.copyFrom(this); 2201 copy.copyFrom(this);
2098 return copy; 2202 return copy;
2099 } 2203 }
2100 2204
2101 /** 2205 /**
2102 * Invalidate all of the resolution information associated with the compilatio n unit. 2206 * Invalidate all of the information associated with the HTML file.
2207 */
2208 void invalidateAllInformation() {
2209 setState(SourceEntry.LINE_INFO, CacheState.INVALID);
2210 _parsedUnit = null;
2211 _parsedUnitState = CacheState.INVALID;
2212 _referencedLibraries = Source.EMPTY_ARRAY;
2213 _referencedLibrariesState = CacheState.INVALID;
2214 invalidateAllResolutionInformation();
2215 }
2216
2217 /**
2218 * Invalidate all of the resolution information associated with the HTML file.
2103 */ 2219 */
2104 void invalidateAllResolutionInformation() { 2220 void invalidateAllResolutionInformation() {
2105 _element = null; 2221 _element = null;
2106 _elementState = CacheState.INVALID; 2222 _elementState = CacheState.INVALID;
2107 _resolutionErrors = AnalysisError.NO_ERRORS; 2223 _resolutionErrors = AnalysisError.NO_ERRORS;
2108 _resolutionErrorsState = CacheState.INVALID; 2224 _resolutionErrorsState = CacheState.INVALID;
2109 _hints = AnalysisError.NO_ERRORS; 2225 _hints = AnalysisError.NO_ERRORS;
2110 _hintsState = CacheState.INVALID; 2226 _hintsState = CacheState.INVALID;
2111 } 2227 }
2228
2229 /**
2230 * Record that an error was encountered while attempting to resolve the source associated with
2231 * this entry.
2232 */
2233 void recordResolutionError() {
2234 setState(HtmlEntry.ELEMENT, CacheState.ERROR);
2235 setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.ERROR);
2236 }
2112 void setState(DataDescriptor descriptor, CacheState state) { 2237 void setState(DataDescriptor descriptor, CacheState state) {
2113 if (identical(descriptor, HtmlEntry.ELEMENT)) { 2238 if (identical(descriptor, HtmlEntry.ELEMENT)) {
2114 _element = updatedValue(state, _element, null); 2239 _element = updatedValue(state, _element, null);
2115 _elementState = state; 2240 _elementState = state;
2116 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { 2241 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) {
2117 _parsedUnit = updatedValue(state, _parsedUnit, null); 2242 _parsedUnit = updatedValue(state, _parsedUnit, null);
2118 _parsedUnitState = state; 2243 _parsedUnitState = state;
2119 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) { 2244 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) {
2120 _referencedLibraries = updatedValue(state, _referencedLibraries, Source.EM PTY_ARRAY); 2245 _referencedLibraries = updatedValue(state, _referencedLibraries, Source.EM PTY_ARRAY);
2121 _referencedLibrariesState = state; 2246 _referencedLibrariesState = state;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 } 2486 }
2362 /** 2487 /**
2363 * Implementation of the [AnalysisContentStatistics]. 2488 * Implementation of the [AnalysisContentStatistics].
2364 */ 2489 */
2365 class AnalysisContentStatisticsImpl implements AnalysisContentStatistics { 2490 class AnalysisContentStatisticsImpl implements AnalysisContentStatistics {
2366 Map<String, AnalysisContentStatistics_CacheRow> _dataMap = new Map<String, Ana lysisContentStatistics_CacheRow>(); 2491 Map<String, AnalysisContentStatistics_CacheRow> _dataMap = new Map<String, Ana lysisContentStatistics_CacheRow>();
2367 List<AnalysisContentStatistics_CacheRow> get cacheRows { 2492 List<AnalysisContentStatistics_CacheRow> get cacheRows {
2368 Iterable<AnalysisContentStatistics_CacheRow> items = _dataMap.values; 2493 Iterable<AnalysisContentStatistics_CacheRow> items = _dataMap.values;
2369 return new List.from(items); 2494 return new List.from(items);
2370 } 2495 }
2371 void putCacheItem(DataDescriptor rowDesc, CacheState state) { 2496 void putCacheItem(DartEntry dartEntry, DataDescriptor descriptor) {
2497 putCacheItem3(descriptor, dartEntry.getState(descriptor));
2498 }
2499 void putCacheItem2(DartEntry dartEntry, Source librarySource, DataDescriptor d escriptor) {
2500 putCacheItem3(descriptor, dartEntry.getState2(descriptor, librarySource));
2501 }
2502 void putCacheItem3(DataDescriptor rowDesc, CacheState state) {
2372 String rowName = rowDesc.toString(); 2503 String rowName = rowDesc.toString();
2373 AnalysisContentStatisticsImpl_CacheRowImpl row = _dataMap[rowName] as Analys isContentStatisticsImpl_CacheRowImpl; 2504 AnalysisContentStatisticsImpl_CacheRowImpl row = _dataMap[rowName] as Analys isContentStatisticsImpl_CacheRowImpl;
2374 if (row == null) { 2505 if (row == null) {
2375 row = new AnalysisContentStatisticsImpl_CacheRowImpl(rowName); 2506 row = new AnalysisContentStatisticsImpl_CacheRowImpl(rowName);
2376 _dataMap[rowName] = row; 2507 _dataMap[rowName] = row;
2377 } 2508 }
2378 row.incState(state); 2509 row.incState(state);
2379 } 2510 }
2380 } 2511 }
2381 class AnalysisContentStatisticsImpl_CacheRowImpl implements AnalysisContentStati stics_CacheRow { 2512 class AnalysisContentStatisticsImpl_CacheRowImpl implements AnalysisContentStati stics_CacheRow {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 * 2550 *
2420 * @coverage dart.engine 2551 * @coverage dart.engine
2421 */ 2552 */
2422 class AnalysisContextImpl implements InternalAnalysisContext { 2553 class AnalysisContextImpl implements InternalAnalysisContext {
2423 2554
2424 /** 2555 /**
2425 * Helper for [getStatistics], puts the library-specific state into the given statistics 2556 * Helper for [getStatistics], puts the library-specific state into the given statistics
2426 * object. 2557 * object.
2427 */ 2558 */
2428 static void putStatCacheItem(AnalysisContentStatisticsImpl statistics, DartEnt ry dartEntry, Source librarySource, DataDescriptor key) { 2559 static void putStatCacheItem(AnalysisContentStatisticsImpl statistics, DartEnt ry dartEntry, Source librarySource, DataDescriptor key) {
2429 statistics.putCacheItem(key, dartEntry.getState2(key, librarySource)); 2560 statistics.putCacheItem3(key, dartEntry.getState2(key, librarySource));
2430 } 2561 }
2431 2562
2432 /** 2563 /**
2433 * Helper for [getStatistics], puts the library independent state into the giv en 2564 * Helper for [getStatistics], puts the library independent state into the giv en
2434 * statistics object. 2565 * statistics object.
2435 */ 2566 */
2436 static void putStatCacheItem2(AnalysisContentStatisticsImpl statistics, Source Entry entry, DataDescriptor key) { 2567 static void putStatCacheItem2(AnalysisContentStatisticsImpl statistics, Source Entry entry, DataDescriptor key) {
2437 statistics.putCacheItem(key, entry.getState(key)); 2568 statistics.putCacheItem3(key, entry.getState(key));
2438 } 2569 }
2439 2570
2440 /** 2571 /**
2441 * The set of analysis options controlling the behavior of this context. 2572 * The set of analysis options controlling the behavior of this context.
2442 */ 2573 */
2443 AnalysisOptions _options = new AnalysisOptionsImpl(); 2574 AnalysisOptions _options = new AnalysisOptionsImpl();
2444 2575
2445 /** 2576 /**
2446 * The source factory used to create the sources that can be analyzed in this context. 2577 * The source factory used to create the sources that can be analyzed in this context.
2447 */ 2578 */
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 /** 2639 /**
2509 * The name of the 'script' tag in an HTML file. 2640 * The name of the 'script' tag in an HTML file.
2510 */ 2641 */
2511 static String _TAG_SCRIPT = "script"; 2642 static String _TAG_SCRIPT = "script";
2512 2643
2513 /** 2644 /**
2514 * The value of the 'type' attribute of a 'script' tag that indicates that the script is written 2645 * The value of the 'type' attribute of a 'script' tag that indicates that the script is written
2515 * in Dart. 2646 * in Dart.
2516 */ 2647 */
2517 static String _TYPE_DART = "application/dart"; 2648 static String _TYPE_DART = "application/dart";
2649
2650 /**
2651 * Initialize a newly created analysis context.
2652 */
2653 AnalysisContextImpl() : super() {
2654 if (AnalysisEngine.instance.useExperimentalContext) {
2655 throw new RuntimeException("Should not be creating an instance of Analysis ContextImpl");
2656 }
2657 }
2518 void addSourceInfo(Source source, SourceEntry info) { 2658 void addSourceInfo(Source source, SourceEntry info) {
2519 _sourceMap[source] = info; 2659 _sourceMap[source] = info;
2520 } 2660 }
2521 void applyChanges(ChangeSet changeSet) { 2661 void applyChanges(ChangeSet changeSet) {
2522 if (changeSet.isEmpty) { 2662 if (changeSet.isEmpty) {
2523 return; 2663 return;
2524 } 2664 }
2525 { 2665 {
2526 List<Source> removedSources = new List<Source>.from(changeSet.removed); 2666 List<Source> removedSources = new List<Source>.from(changeSet.removed);
2527 for (SourceContainer container in changeSet.removedContainers) { 2667 for (SourceContainer container in changeSet.removedContainers) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2679 DartEntryImpl dartCopy = dartEntry.writableCopy; 2819 DartEntryImpl dartCopy = dartEntry.writableCopy;
2680 CompilationUnit unit = dartCopy.resolvableCompilationUnit; 2820 CompilationUnit unit = dartCopy.resolvableCompilationUnit;
2681 if (unit != null) { 2821 if (unit != null) {
2682 _sourceMap[source] = dartCopy; 2822 _sourceMap[source] = dartCopy;
2683 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit); 2823 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit);
2684 } 2824 }
2685 } 2825 }
2686 internalParseDart(source); 2826 internalParseDart(source);
2687 } 2827 }
2688 } 2828 }
2829 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) {
2830 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
2831 if (htmlEntry == null) {
2832 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}");
2833 }
2834 htmlEntry = internalCacheHtmlParseData(source, htmlEntry, [HtmlEntry.PARSED_ UNIT]);
2835 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
2836 if (unit == null) {
2837 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}");
2838 }
2839 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
2840 }
2689 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context); 2841 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context);
2690 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) { 2842 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
2691 List<Source> sourcesToRemove = new List<Source>(); 2843 List<Source> sourcesToRemove = new List<Source>();
2692 { 2844 {
2693 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) { 2845 for (MapEntry<Source, SourceEntry> entry in getMapEntrySet(_sourceMap)) {
2694 Source source = entry.getKey(); 2846 Source source = entry.getKey();
2695 if (container.contains(source)) { 2847 if (container.contains(source)) {
2696 sourcesToRemove.add(source); 2848 sourcesToRemove.add(source);
2697 newContext.addSourceInfo(source, entry.getValue().writableCopy); 2849 newContext.addSourceInfo(source, entry.getValue().writableCopy);
2698 } 2850 }
(...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after
4819 result._lineStarts = scanner.lineStarts; 4971 result._lineStarts = scanner.lineStarts;
4820 } 4972 }
4821 void accept2(String contents, int modificationTime2) { 4973 void accept2(String contents, int modificationTime2) {
4822 StringScanner scanner = new StringScanner(source, contents, errorListener); 4974 StringScanner scanner = new StringScanner(source, contents, errorListener);
4823 result._modificationTime = modificationTime2; 4975 result._modificationTime = modificationTime2;
4824 result._token = scanner.tokenize(); 4976 result._token = scanner.tokenize();
4825 result._lineStarts = scanner.lineStarts; 4977 result._lineStarts = scanner.lineStarts;
4826 } 4978 }
4827 } 4979 }
4828 /** 4980 /**
4981 * Instances of the class `AnalysisContextImpl` implement an [AnalysisContext].
4982 *
4983 * @coverage dart.engine
4984 */
4985 class AnalysisContextImpl2 implements InternalAnalysisContext {
4986
4987 /**
4988 * The set of analysis options controlling the behavior of this context.
4989 */
4990 AnalysisOptions _options = new AnalysisOptionsImpl();
4991
4992 /**
4993 * The source factory used to create the sources that can be analyzed in this context.
4994 */
4995 SourceFactory _sourceFactory;
4996
4997 /**
4998 * A table mapping the sources known to the context to the information known a bout the source.
4999 */
5000 AnalysisCache _cache = new AnalysisCache(_MAX_CACHE_SIZE);
5001
5002 /**
5003 * A table mapping sources to the change notices that are waiting to be return ed related to that
5004 * source.
5005 */
5006 Map<Source, ChangeNoticeImpl> _pendingNotices = new Map<Source, ChangeNoticeIm pl>();
5007
5008 /**
5009 * The object used to synchronize access to all of the caches. The rules relat ed to the use of
5010 * this lock object are
5011 *
5012 * * no analysis work is done while holding the lock, and
5013 * * no analysis results can be recorded unless we have obtained the lock and validated that the
5014 * results are for the same version (modification time) of the source as our c urrent cache
5015 * content.
5016 *
5017 */
5018 Object _cacheLock = new Object();
5019
5020 /**
5021 * The object used to record the results of performing an analysis task.
5022 */
5023 AnalysisContextImpl2_AnalysisTaskResultRecorder _resultRecorder;
5024
5025 /**
5026 * The maximum number of sources for which data should be kept in the cache.
5027 */
5028 static int _MAX_CACHE_SIZE = 64;
5029
5030 /**
5031 * The maximum number of sources that can be on the priority list. This <b>mus t</b> be less than
5032 * the [MAX_CACHE_SIZE] in order to prevent an infinite loop in performAnalysi sTask().
5033 *
5034 * @see #setAnalysisPriorityOrder(List)
5035 */
5036 static int _MAX_PRIORITY_LIST_SIZE = _MAX_CACHE_SIZE - 4;
5037
5038 /**
5039 * Initialize a newly created analysis context.
5040 */
5041 AnalysisContextImpl2() : super() {
5042 _resultRecorder = new AnalysisContextImpl2_AnalysisTaskResultRecorder(this);
5043 }
5044 void addSourceInfo(Source source, SourceEntry info) {
5045 _cache.put(source, info);
5046 }
5047 void applyChanges(ChangeSet changeSet) {
5048 if (changeSet.isEmpty) {
5049 return;
5050 }
5051 {
5052 List<Source> removedSources = new List<Source>.from(changeSet.removed);
5053 for (SourceContainer container in changeSet.removedContainers) {
5054 addSourcesInContainer(removedSources, container);
5055 }
5056 bool addedDartSource = false;
5057 for (Source source in changeSet.added3) {
5058 if (sourceAvailable(source)) {
5059 addedDartSource = true;
5060 }
5061 }
5062 for (Source source in changeSet.changed3) {
5063 sourceChanged(source);
5064 }
5065 for (Source source in removedSources) {
5066 sourceRemoved(source);
5067 }
5068 if (addedDartSource) {
5069 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
5070 if (!mapEntry.getKey().isInSystemLibrary && mapEntry.getValue() is Dar tEntry) {
5071 DartEntryImpl dartCopy = ((mapEntry.getValue() as DartEntry)).writab leCopy;
5072 dartCopy.invalidateAllResolutionInformation();
5073 mapEntry.setValue(dartCopy);
5074 }
5075 }
5076 }
5077 }
5078 }
5079 String computeDocumentationComment(Element element) {
5080 if (element == null) {
5081 return null;
5082 }
5083 Source source = element.source;
5084 if (source == null) {
5085 return null;
5086 }
5087 CompilationUnit unit = parseCompilationUnit(source);
5088 if (unit == null) {
5089 return null;
5090 }
5091 NodeLocator locator = new NodeLocator.con1(element.nameOffset);
5092 ASTNode nameNode = locator.searchWithin(unit);
5093 while (nameNode != null) {
5094 if (nameNode is AnnotatedNode) {
5095 Comment comment = ((nameNode as AnnotatedNode)).documentationComment;
5096 if (comment == null) {
5097 return null;
5098 }
5099 JavaStringBuilder builder = new JavaStringBuilder();
5100 List<Token> tokens = comment.tokens;
5101 for (int i = 0; i < tokens.length; i++) {
5102 if (i > 0) {
5103 builder.append('\n');
5104 }
5105 builder.append(tokens[i].lexeme);
5106 }
5107 return builder.toString();
5108 }
5109 nameNode = nameNode.parent;
5110 }
5111 return null;
5112 }
5113 List<AnalysisError> computeErrors(Source source) {
5114 SourceEntry sourceEntry = getReadableSourceEntry(source);
5115 if (sourceEntry is DartEntry) {
5116 List<AnalysisError> errors = new List<AnalysisError>();
5117 DartEntry dartEntry = sourceEntry as DartEntry;
5118 ListUtilities.addAll(errors, getDartParseData(source, dartEntry, DartEntry .PARSE_ERRORS));
5119 dartEntry = getReadableDartEntry(source);
5120 if (identical(dartEntry.getValue(DartEntry.SOURCE_KIND), SourceKind.LIBRAR Y)) {
5121 ListUtilities.addAll(errors, getDartResolutionData(source, source, dartE ntry, DartEntry.RESOLUTION_ERRORS));
5122 } else {
5123 List<Source> libraries = getLibrariesContaining(source);
5124 for (Source librarySource in libraries) {
5125 ListUtilities.addAll(errors, getDartResolutionData(source, librarySour ce, dartEntry, DartEntry.RESOLUTION_ERRORS));
5126 }
5127 }
5128 if (errors.isEmpty) {
5129 return AnalysisError.NO_ERRORS;
5130 }
5131 return new List.from(errors);
5132 } else if (sourceEntry is HtmlEntry) {
5133 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5134 return getHtmlResolutionData2(source, htmlEntry, HtmlEntry.RESOLUTION_ERRO RS);
5135 }
5136 return AnalysisError.NO_ERRORS;
5137 }
5138 List<Source> computeExportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY);
5139 HtmlElement computeHtmlElement(Source source) => getHtmlResolutionData(source, HtmlEntry.ELEMENT, null);
5140 List<Source> computeImportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY);
5141 SourceKind computeKindOf(Source source) {
5142 SourceEntry sourceEntry = getReadableSourceEntry(source);
5143 if (sourceEntry == null) {
5144 return SourceKind.UNKNOWN;
5145 } else if (sourceEntry is DartEntry) {
5146 try {
5147 return getDartParseData(source, sourceEntry as DartEntry, DartEntry.SOUR CE_KIND);
5148 } on AnalysisException catch (exception) {
5149 return SourceKind.UNKNOWN;
5150 }
5151 }
5152 return sourceEntry.kind;
5153 }
5154 LibraryElement computeLibraryElement(Source source) => getDartResolutionData2( source, source, DartEntry.ELEMENT, null);
5155 LineInfo computeLineInfo(Source source) {
5156 SourceEntry sourceEntry = getReadableSourceEntry(source);
5157 if (sourceEntry is HtmlEntry) {
5158 return getHtmlParseData(source, SourceEntry.LINE_INFO, null);
5159 } else if (sourceEntry is DartEntry) {
5160 return getDartParseData2(source, SourceEntry.LINE_INFO, null);
5161 }
5162 return null;
5163 }
5164 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) {
5165 while (true) {
5166 {
5167 DartEntry dartEntry = getReadableDartEntry(source);
5168 if (dartEntry == null) {
5169 throw new AnalysisException.con1("computeResolvableCompilationUnit for non-Dart: ${source.fullName}");
5170 }
5171 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.ERRO R)) {
5172 throw new AnalysisException.con1("Internal error: computeResolvableCom pilationUnit could not parse ${source.fullName}");
5173 }
5174 DartEntryImpl dartCopy = dartEntry.writableCopy;
5175 CompilationUnit unit = dartCopy.resolvableCompilationUnit;
5176 if (unit != null) {
5177 _cache.put(source, dartCopy);
5178 return new ResolvableCompilationUnit(dartCopy.modificationTime, unit);
5179 }
5180 }
5181 cacheDartParseData(source, getReadableDartEntry(source), DartEntry.PARSED_ UNIT);
5182 }
5183 }
5184 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) {
5185 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
5186 if (htmlEntry == null) {
5187 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}");
5188 }
5189 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT);
5190 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
5191 if (unit == null) {
5192 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}");
5193 }
5194 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
5195 }
5196 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context);
5197 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
5198 List<Source> sourcesToRemove = new List<Source>();
5199 {
5200 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5201 Source source = entry.getKey();
5202 if (container.contains(source)) {
5203 sourcesToRemove.add(source);
5204 newContext.addSourceInfo(source, entry.getValue().writableCopy);
5205 }
5206 }
5207 }
5208 return newContext;
5209 }
5210 AnalysisOptions get analysisOptions => _options;
5211 Element getElement(ElementLocation location) {
5212 try {
5213 List<String> components = ((location as ElementLocationImpl)).components;
5214 Source librarySource = computeSourceFromEncoding(components[0]);
5215 ElementImpl element = computeLibraryElement(librarySource) as ElementImpl;
5216 for (int i = 1; i < components.length; i++) {
5217 if (element == null) {
5218 return null;
5219 }
5220 element = element.getChild(components[i]);
5221 }
5222 return element;
5223 } on AnalysisException catch (exception) {
5224 return null;
5225 }
5226 }
5227 AnalysisErrorInfo getErrors(Source source) {
5228 SourceEntry sourceEntry = getReadableSourceEntry(source);
5229 if (sourceEntry is DartEntry) {
5230 DartEntry dartEntry = sourceEntry as DartEntry;
5231 return new AnalysisErrorInfoImpl(dartEntry.allErrors, dartEntry.getValue(S ourceEntry.LINE_INFO));
5232 } else if (sourceEntry is HtmlEntry) {
5233 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5234 return new AnalysisErrorInfoImpl(htmlEntry.allErrors, htmlEntry.getValue(S ourceEntry.LINE_INFO));
5235 }
5236 return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, null);
5237 }
5238 HtmlElement getHtmlElement(Source source) {
5239 SourceEntry sourceEntry = getReadableSourceEntry(source);
5240 if (sourceEntry is HtmlEntry) {
5241 return ((sourceEntry as HtmlEntry)).getValue(HtmlEntry.ELEMENT);
5242 }
5243 return null;
5244 }
5245 List<Source> getHtmlFilesReferencing(Source source) {
5246 SourceKind sourceKind = getKindOf(source);
5247 if (sourceKind == null) {
5248 return Source.EMPTY_ARRAY;
5249 }
5250 {
5251 List<Source> htmlSources = new List<Source>();
5252 while (true) {
5253 if (sourceKind == SourceKind.LIBRARY) {
5254 } else if (sourceKind == SourceKind.PART) {
5255 List<Source> librarySources = getLibrariesContaining(source);
5256 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5257 SourceEntry sourceEntry = entry.getValue();
5258 if (identical(sourceEntry.kind, SourceKind.HTML)) {
5259 List<Source> referencedLibraries = ((sourceEntry as HtmlEntry)).ge tValue(HtmlEntry.REFERENCED_LIBRARIES);
5260 if (containsAny(referencedLibraries, librarySources)) {
5261 htmlSources.add(entry.getKey());
5262 }
5263 }
5264 }
5265 }
5266 break;
5267 }
5268 if (htmlSources.isEmpty) {
5269 return Source.EMPTY_ARRAY;
5270 }
5271 return new List.from(htmlSources);
5272 }
5273 }
5274 List<Source> get htmlSources => getSources(SourceKind.HTML);
5275 SourceKind getKindOf(Source source) {
5276 SourceEntry sourceEntry = getReadableSourceEntry(source);
5277 if (sourceEntry == null) {
5278 return SourceKind.UNKNOWN;
5279 }
5280 return sourceEntry.kind;
5281 }
5282 List<Source> get launchableClientLibrarySources {
5283 List<Source> sources = new List<Source>();
5284 {
5285 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5286 Source source = entry.getKey();
5287 SourceEntry sourceEntry = entry.getValue();
5288 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
5289 sources.add(source);
5290 }
5291 }
5292 }
5293 return new List.from(sources);
5294 }
5295 List<Source> get launchableServerLibrarySources {
5296 List<Source> sources = new List<Source>();
5297 {
5298 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5299 Source source = entry.getKey();
5300 SourceEntry sourceEntry = entry.getValue();
5301 if (identical(sourceEntry.kind, SourceKind.LIBRARY) && !source.isInSyste mLibrary) {
5302 sources.add(source);
5303 }
5304 }
5305 }
5306 return new List.from(sources);
5307 }
5308 List<Source> getLibrariesContaining(Source source) {
5309 {
5310 SourceEntry sourceEntry = _cache.get(source);
5311 if (sourceEntry == null || sourceEntry.kind != SourceKind.PART) {
5312 return <Source> [source];
5313 }
5314 List<Source> librarySources = new List<Source>();
5315 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5316 sourceEntry = entry.getValue();
5317 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) {
5318 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.INCLUDED_ PARTS), source)) {
5319 librarySources.add(entry.getKey());
5320 }
5321 }
5322 }
5323 if (librarySources.isEmpty) {
5324 return Source.EMPTY_ARRAY;
5325 }
5326 return new List.from(librarySources);
5327 }
5328 }
5329 List<Source> getLibrariesDependingOn(Source librarySource) {
5330 {
5331 List<Source> dependentLibraries = new List<Source>();
5332 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5333 SourceEntry sourceEntry = entry.getValue();
5334 if (identical(sourceEntry.kind, SourceKind.LIBRARY)) {
5335 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.EXPORTED_ LIBRARIES), librarySource)) {
5336 dependentLibraries.add(entry.getKey());
5337 }
5338 if (contains(((sourceEntry as DartEntry)).getValue(DartEntry.IMPORTED_ LIBRARIES), librarySource)) {
5339 dependentLibraries.add(entry.getKey());
5340 }
5341 }
5342 }
5343 if (dependentLibraries.isEmpty) {
5344 return Source.EMPTY_ARRAY;
5345 }
5346 return new List.from(dependentLibraries);
5347 }
5348 }
5349 LibraryElement getLibraryElement(Source source) {
5350 SourceEntry sourceEntry = getReadableSourceEntry(source);
5351 if (sourceEntry is DartEntry) {
5352 return ((sourceEntry as DartEntry)).getValue(DartEntry.ELEMENT);
5353 }
5354 return null;
5355 }
5356 List<Source> get librarySources => getSources(SourceKind.LIBRARY);
5357 LineInfo getLineInfo(Source source) {
5358 SourceEntry sourceEntry = getReadableSourceEntry(source);
5359 if (sourceEntry != null) {
5360 return sourceEntry.getValue(SourceEntry.LINE_INFO);
5361 }
5362 return null;
5363 }
5364 Namespace getPublicNamespace(LibraryElement library) {
5365 Source source = library.definingCompilationUnit.source;
5366 DartEntry dartEntry = getReadableDartEntry(source);
5367 if (dartEntry == null) {
5368 return null;
5369 }
5370 Namespace namespace = null;
5371 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
5372 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
5373 }
5374 if (namespace == null) {
5375 NamespaceBuilder builder = new NamespaceBuilder();
5376 namespace = builder.createPublicNamespace(library);
5377 {
5378 dartEntry = getReadableDartEntry(source);
5379 if (dartEntry == null) {
5380 AnalysisEngine.instance.logger.logError3(new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}"));
5381 return null;
5382 }
5383 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
5384 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
5385 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
5386 _cache.put(source, dartCopy);
5387 }
5388 }
5389 }
5390 return namespace;
5391 }
5392 Namespace getPublicNamespace2(Source source) {
5393 DartEntry dartEntry = getReadableDartEntry(source);
5394 if (dartEntry == null) {
5395 return null;
5396 }
5397 Namespace namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE);
5398 if (namespace == null) {
5399 LibraryElement library = computeLibraryElement(source);
5400 if (library == null) {
5401 return null;
5402 }
5403 NamespaceBuilder builder = new NamespaceBuilder();
5404 namespace = builder.createPublicNamespace(library);
5405 {
5406 dartEntry = getReadableDartEntry(source);
5407 if (dartEntry == null) {
5408 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
5409 }
5410 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) {
5411 DartEntryImpl dartCopy = getReadableDartEntry(source).writableCopy;
5412 dartCopy.setValue(DartEntry.PUBLIC_NAMESPACE, namespace);
5413 _cache.put(source, dartCopy);
5414 }
5415 }
5416 }
5417 return namespace;
5418 }
5419 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
5420 if (library == null) {
5421 return null;
5422 }
5423 return getResolvedCompilationUnit2(unitSource, library.source);
5424 }
5425 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
5426 SourceEntry sourceEntry = getReadableSourceEntry(unitSource);
5427 if (sourceEntry is DartEntry) {
5428 return ((sourceEntry as DartEntry)).getValue2(DartEntry.RESOLVED_UNIT, lib rarySource);
5429 }
5430 return null;
5431 }
5432 SourceFactory get sourceFactory => _sourceFactory;
5433
5434 /**
5435 * Return a list of the sources that would be processed by [performAnalysisTas k]. This
5436 * method duplicates, and must therefore be kept in sync with, [getNextTaskAna lysisTask].
5437 * This method is intended to be used for testing purposes only.
5438 *
5439 * @return a list of the sources that would be processed by [performAnalysisTa sk]
5440 */
5441 List<Source> get sourcesNeedingProcessing {
5442 Set<Source> sources = new Set<Source>();
5443 {
5444 for (Source source in _cache.priorityOrder) {
5445 SourceEntry sourceEntry = _cache.get(source);
5446 if (sourceEntry is DartEntry) {
5447 DartEntry dartEntry = sourceEntry as DartEntry;
5448 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERROR S);
5449 if (identical(parseErrorsState, CacheState.INVALID) || identical(parse ErrorsState, CacheState.FLUSHED)) {
5450 javaSetAdd(sources, source);
5451 }
5452 CacheState parseUnitState = dartEntry.getState(DartEntry.PARSED_UNIT);
5453 if (identical(parseUnitState, CacheState.INVALID) || identical(parseUn itState, CacheState.FLUSHED)) {
5454 javaSetAdd(sources, source);
5455 }
5456 for (Source librarySource in getLibrariesContaining(source)) {
5457 SourceEntry libraryEntry = _cache.get(librarySource);
5458 if (libraryEntry is DartEntry) {
5459 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT) ;
5460 if (identical(elementState, CacheState.INVALID) || identical(eleme ntState, CacheState.FLUSHED)) {
5461 javaSetAdd(sources, source);
5462 }
5463 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOL VED_UNIT, librarySource);
5464 if (identical(resolvedUnitState, CacheState.INVALID) || identical( resolvedUnitState, CacheState.FLUSHED)) {
5465 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
5466 if (libraryElement != null) {
5467 javaSetAdd(sources, source);
5468 }
5469 }
5470 }
5471 }
5472 } else if (sourceEntry is HtmlEntry) {
5473 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5474 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ;
5475 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsed UnitState, CacheState.FLUSHED)) {
5476 javaSetAdd(sources, source);
5477 }
5478 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
5479 if (identical(elementState, CacheState.INVALID) || identical(elementSt ate, CacheState.FLUSHED)) {
5480 javaSetAdd(sources, source);
5481 }
5482 }
5483 }
5484 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5485 SourceEntry sourceEntry = entry.getValue();
5486 if (sourceEntry is DartEntry) {
5487 DartEntry dartEntry = sourceEntry as DartEntry;
5488 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.IN VALID)) {
5489 javaSetAdd(sources, entry.getKey());
5490 }
5491 } else if (sourceEntry is HtmlEntry) {
5492 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5493 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.IN VALID)) {
5494 javaSetAdd(sources, entry.getKey());
5495 }
5496 }
5497 }
5498 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5499 SourceEntry sourceEntry = entry.getValue();
5500 if (sourceEntry is DartEntry && identical(sourceEntry.kind, SourceKind.L IBRARY)) {
5501 DartEntry dartEntry = sourceEntry as DartEntry;
5502 if (identical(dartEntry.getState(DartEntry.ELEMENT), CacheState.INVALI D)) {
5503 javaSetAdd(sources, entry.getKey());
5504 }
5505 } else if (sourceEntry is HtmlEntry) {
5506 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
5507 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALI D)) {
5508 javaSetAdd(sources, entry.getKey());
5509 }
5510 }
5511 }
5512 }
5513 return new List<Source>.from(sources);
5514 }
5515 AnalysisContentStatistics get statistics {
5516 AnalysisContentStatisticsImpl statistics = new AnalysisContentStatisticsImpl ();
5517 {
5518 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
5519 SourceEntry entry = mapEntry.getValue();
5520 if (entry is DartEntry) {
5521 Source source = mapEntry.getKey();
5522 DartEntry dartEntry = entry as DartEntry;
5523 SourceKind kind = dartEntry.getValue(DartEntry.SOURCE_KIND);
5524 statistics.putCacheItem(dartEntry, DartEntry.PARSE_ERRORS);
5525 statistics.putCacheItem(dartEntry, DartEntry.PARSED_UNIT);
5526 statistics.putCacheItem(dartEntry, DartEntry.SOURCE_KIND);
5527 statistics.putCacheItem(dartEntry, DartEntry.LINE_INFO);
5528 if (identical(kind, SourceKind.LIBRARY)) {
5529 statistics.putCacheItem(dartEntry, DartEntry.ELEMENT);
5530 statistics.putCacheItem(dartEntry, DartEntry.EXPORTED_LIBRARIES);
5531 statistics.putCacheItem(dartEntry, DartEntry.IMPORTED_LIBRARIES);
5532 statistics.putCacheItem(dartEntry, DartEntry.INCLUDED_PARTS);
5533 statistics.putCacheItem(dartEntry, DartEntry.IS_CLIENT);
5534 statistics.putCacheItem(dartEntry, DartEntry.IS_LAUNCHABLE);
5535 }
5536 List<Source> librarySources = getLibrariesContaining(source);
5537 for (Source librarySource in librarySources) {
5538 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLUT ION_ERRORS);
5539 statistics.putCacheItem2(dartEntry, librarySource, DartEntry.RESOLVE D_UNIT);
5540 }
5541 }
5542 }
5543 }
5544 return statistics;
5545 }
5546 bool isClientLibrary(Source librarySource) {
5547 SourceEntry sourceEntry = getReadableSourceEntry(librarySource);
5548 if (sourceEntry is DartEntry) {
5549 DartEntry dartEntry = sourceEntry as DartEntry;
5550 return dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(DartE ntry.IS_LAUNCHABLE);
5551 }
5552 return false;
5553 }
5554 bool isServerLibrary(Source librarySource) {
5555 SourceEntry sourceEntry = getReadableSourceEntry(librarySource);
5556 if (sourceEntry is DartEntry) {
5557 DartEntry dartEntry = sourceEntry as DartEntry;
5558 return !dartEntry.getValue(DartEntry.IS_CLIENT) && dartEntry.getValue(Dart Entry.IS_LAUNCHABLE);
5559 }
5560 return false;
5561 }
5562 void mergeContext(AnalysisContext context) {
5563 if (context is InstrumentedAnalysisContextImpl) {
5564 context = ((context as InstrumentedAnalysisContextImpl)).basis;
5565 }
5566 if (context is! AnalysisContextImpl2) {
5567 return;
5568 }
5569 {
5570 for (MapEntry<Source, SourceEntry> entry in ((context as AnalysisContextIm pl2))._cache.entrySet()) {
5571 Source newSource = entry.getKey();
5572 SourceEntry existingEntry = getReadableSourceEntry(newSource);
5573 if (existingEntry == null) {
5574 _cache.put(newSource, entry.getValue().writableCopy);
5575 } else {
5576 }
5577 }
5578 }
5579 }
5580 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null);
5581 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA RSED_UNIT, null);
5582 List<ChangeNotice> performAnalysisTask() {
5583 AnalysisTask task = nextTaskAnalysisTask;
5584 if (task == null) {
5585 return getChangeNotices(true);
5586 }
5587 try {
5588 task.perform(_resultRecorder);
5589 } on AnalysisException catch (exception) {
5590 if (exception.cause is! JavaIOException) {
5591 AnalysisEngine.instance.logger.logError2("Internal error while performin g the task: ${task}", exception);
5592 }
5593 }
5594 return getChangeNotices(false);
5595 }
5596 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
5597 {
5598 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML);
5599 for (MapEntry<Source, LibraryElement> entry in getMapEntrySet(elementMap)) {
5600 Source librarySource = entry.getKey();
5601 LibraryElement library = entry.getValue();
5602 DartEntry dartEntry = getReadableDartEntry(librarySource);
5603 if (dartEntry != null) {
5604 DartEntryImpl dartCopy = dartEntry.writableCopy;
5605 recordElementData(dartCopy, library, htmlSource);
5606 _cache.put(librarySource, dartCopy);
5607 }
5608 }
5609 }
5610 }
5611 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) {
5612 if (library == null) {
5613 return null;
5614 }
5615 return resolveCompilationUnit2(unitSource, library.source);
5616 }
5617 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT, null);
5618 HtmlUnit resolveHtmlUnit(Source htmlSource) => parseHtmlUnit(htmlSource);
5619 void set analysisOptions(AnalysisOptions options2) {
5620 {
5621 this._options = options2;
5622 invalidateAllResolutionInformation();
5623 }
5624 }
5625 void set analysisPriorityOrder(List<Source> sources) {
5626 {
5627 if (sources == null || sources.isEmpty) {
5628 _cache.priorityOrder = Source.EMPTY_ARRAY;
5629 } else {
5630 while (sources.remove(null)) {
5631 }
5632 if (sources.isEmpty) {
5633 _cache.priorityOrder = Source.EMPTY_ARRAY;
5634 }
5635 int count = Math.min(sources.length, _MAX_PRIORITY_LIST_SIZE);
5636 List<Source> priorityOrder = new List<Source>(count);
5637 for (int i = 0; i < count; i++) {
5638 priorityOrder[i] = sources[i];
5639 }
5640 _cache.priorityOrder = priorityOrder;
5641 }
5642 }
5643 }
5644 void setContents(Source source, String contents) {
5645 {
5646 if (_sourceFactory.setContents(source, contents)) {
5647 sourceChanged(source);
5648 }
5649 }
5650 }
5651 void set sourceFactory(SourceFactory factory) {
5652 {
5653 if (identical(_sourceFactory, factory)) {
5654 return;
5655 } else if (factory.context != null) {
5656 throw new IllegalStateException("Source factories cannot be shared betwe en contexts");
5657 }
5658 if (_sourceFactory != null) {
5659 _sourceFactory.context = null;
5660 }
5661 factory.context = this;
5662 _sourceFactory = factory;
5663 invalidateAllResolutionInformation();
5664 }
5665 }
5666 Iterable<Source> sourcesToResolve(List<Source> changedSources) {
5667 List<Source> librarySources = new List<Source>();
5668 for (Source source in changedSources) {
5669 if (identical(computeKindOf(source), SourceKind.LIBRARY)) {
5670 librarySources.add(source);
5671 }
5672 }
5673 return librarySources;
5674 }
5675
5676 /**
5677 * Add all of the sources contained in the given source container to the given list of sources.
5678 *
5679 * Note: This method must only be invoked while we are synchronized on [cacheL ock].
5680 *
5681 * @param sources the list to which sources are to be added
5682 * @param container the source container containing the sources to be added to the list
5683 */
5684 void addSourcesInContainer(List<Source> sources, SourceContainer container) {
5685 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
5686 Source source = entry.getKey();
5687 if (container.contains(source)) {
5688 sources.add(source);
5689 }
5690 }
5691 }
5692
5693 /**
5694 * Return `true` if the modification times of the sources used by the given li brary resolver
5695 * to resolve one or more libraries are consistent with the modification times in the cache.
5696 *
5697 * @param resolver the library resolver used to resolve one or more libraries
5698 * @return `true` if we should record the results of the resolution
5699 * @throws AnalysisException if any of the modification times could not be det ermined (this should
5700 * not happen)
5701 */
5702 bool allModificationTimesMatch(LibraryResolver resolver) {
5703 bool allTimesMatch = true;
5704 for (Library library in resolver.resolvedLibraries) {
5705 for (Source source in library.compilationUnitSources) {
5706 DartEntry dartEntry = getReadableDartEntry(source);
5707 if (dartEntry == null) {
5708 throw new AnalysisException.con1("Internal error: attempting to reolve non-Dart file as a Dart file: ${source.fullName}");
5709 }
5710 int sourceTime = source.modificationStamp;
5711 int resultTime = library.getModificationTime(source);
5712 if (sourceTime != resultTime) {
5713 sourceChanged(source);
5714 allTimesMatch = false;
5715 }
5716 }
5717 }
5718 return allTimesMatch;
5719 }
5720
5721 /**
5722 * Given a source for a Dart file, return a cache entry in which the data repr esented by the given
5723 * descriptor is available. This method assumes that the data can be produced by parsing the
5724 * source if it is not already cached.
5725 *
5726 * @param source the source representing the Dart file
5727 * @param dartEntry the cache entry associated with the Dart file
5728 * @param descriptor the descriptor representing the data to be returned
5729 * @return a cache entry containing the required data
5730 * @throws AnalysisException if data could not be returned because the source could not be
5731 * resolved
5732 */
5733 DartEntry cacheDartParseData(Source source, DartEntry dartEntry, DataDescripto r descriptor) {
5734 if (identical(descriptor, DartEntry.PARSED_UNIT)) {
5735 CompilationUnit unit = dartEntry.anyParsedCompilationUnit;
5736 if (unit != null) {
5737 return dartEntry;
5738 }
5739 }
5740 CacheState state = dartEntry.getState(descriptor);
5741 while (state != CacheState.ERROR && state != CacheState.VALID) {
5742 dartEntry = new ParseDartTask(this, source).perform(_resultRecorder) as Da rtEntry;
5743 state = dartEntry.getState(descriptor);
5744 }
5745 return dartEntry;
5746 }
5747
5748 /**
5749 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
5750 * the data represented by the given descriptor is available. This method assu mes that the data
5751 * can be produced by resolving the source in the context of the library if it is not already
5752 * cached.
5753 *
5754 * @param unitSource the source representing the Dart file
5755 * @param librarySource the source representing the library containing the Dar t file
5756 * @param dartEntry the cache entry associated with the Dart file
5757 * @param descriptor the descriptor representing the data to be returned
5758 * @return a cache entry containing the required data
5759 * @throws AnalysisException if data could not be returned because the source could not be parsed
5760 */
5761 DartEntry cacheDartResolutionData(Source unitSource, Source librarySource, Dar tEntry dartEntry, DataDescriptor descriptor) {
5762 CacheState state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.ge tState(descriptor) : dartEntry.getState2(descriptor, librarySource);
5763 while (state != CacheState.ERROR && state != CacheState.VALID) {
5764 dartEntry = new ResolveDartLibraryTask(this, unitSource, librarySource).pe rform(_resultRecorder) as DartEntry;
5765 state = (identical(descriptor, DartEntry.ELEMENT)) ? dartEntry.getState(de scriptor) : dartEntry.getState2(descriptor, librarySource);
5766 }
5767 return dartEntry;
5768 }
5769
5770 /**
5771 * Given a source for an HTML file, return a cache entry in which all of the d ata represented by
5772 * the given descriptors is available. This method assumes that the data can b e produced by
5773 * parsing the source if it is not already cached.
5774 *
5775 * @param source the source representing the HTML file
5776 * @param htmlEntry the cache entry associated with the HTML 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
5780 * resolved
5781 */
5782 HtmlEntry cacheHtmlParseData(Source source, HtmlEntry htmlEntry, DataDescripto r descriptor) {
5783 CacheState state = htmlEntry.getState(descriptor);
5784 while (state != CacheState.ERROR && state != CacheState.VALID) {
5785 htmlEntry = new ParseHtmlTask(this, source).perform(_resultRecorder) as Ht mlEntry;
5786 state = htmlEntry.getState(descriptor);
5787 }
5788 return htmlEntry;
5789 }
5790
5791 /**
5792 * Given a source for an HTML file, return a cache entry in which the the data represented by the
5793 * given descriptor is available. This method assumes that the data can be pro duced by resolving
5794 * the source if it is not already cached.
5795 *
5796 * @param source the source representing the HTML file
5797 * @param dartEntry the cache entry associated with the HTML file
5798 * @param descriptor the descriptor representing the data to be returned
5799 * @return a cache entry containing the required data
5800 * @throws AnalysisException if data could not be returned because the source could not be
5801 * resolved
5802 */
5803 HtmlEntry cacheHtmlResolutionData(Source source, HtmlEntry htmlEntry, DataDesc riptor descriptor) {
5804 CacheState state = htmlEntry.getState(descriptor);
5805 while (state != CacheState.ERROR && state != CacheState.VALID) {
5806 htmlEntry = new ResolveHtmlTask(this, source).perform(_resultRecorder) as HtmlEntry;
5807 state = htmlEntry.getState(descriptor);
5808 }
5809 return htmlEntry;
5810 }
5811
5812 /**
5813 * Given the encoded form of a source, use the source factory to reconstitute the original source.
5814 *
5815 * @param encoding the encoded form of a source
5816 * @return the source represented by the encoding
5817 */
5818 Source computeSourceFromEncoding(String encoding) {
5819 {
5820 return _sourceFactory.fromEncoding(encoding);
5821 }
5822 }
5823
5824 /**
5825 * Return `true` if the given array of sources contains the given source.
5826 *
5827 * @param sources the sources being searched
5828 * @param targetSource the source being searched for
5829 * @return `true` if the given source is in the array
5830 */
5831 bool contains(List<Source> sources, Source targetSource) {
5832 for (Source source in sources) {
5833 if (source == targetSource) {
5834 return true;
5835 }
5836 }
5837 return false;
5838 }
5839
5840 /**
5841 * Return `true` if the given array of sources contains any of the given targe t sources.
5842 *
5843 * @param sources the sources being searched
5844 * @param targetSources the sources being searched for
5845 * @return `true` if any of the given target sources are in the array
5846 */
5847 bool containsAny(List<Source> sources, List<Source> targetSources) {
5848 for (Source targetSource in targetSources) {
5849 if (contains(sources, targetSource)) {
5850 return true;
5851 }
5852 }
5853 return false;
5854 }
5855
5856 /**
5857 * Create a source information object suitable for the given source. Return th e source information
5858 * object that was created, or `null` if the source should not be tracked by t his context.
5859 *
5860 * @param source the source for which an information object is being created
5861 * @return the source information object that was created
5862 */
5863 SourceEntry createSourceEntry(Source source) {
5864 String name = source.shortName;
5865 if (AnalysisEngine.isHtmlFileName(name)) {
5866 HtmlEntryImpl htmlEntry = new HtmlEntryImpl();
5867 htmlEntry.modificationTime = source.modificationStamp;
5868 _cache.put(source, htmlEntry);
5869 return htmlEntry;
5870 } else {
5871 DartEntryImpl dartEntry = new DartEntryImpl();
5872 dartEntry.modificationTime = source.modificationStamp;
5873 _cache.put(source, dartEntry);
5874 return dartEntry;
5875 }
5876 }
5877
5878 /**
5879 * Return an array containing all of the change notices that are waiting to be returned. If there
5880 * are no notices, then return either `null` or an empty array, depending on t he value of
5881 * the argument.
5882 *
5883 * @param nullIfEmpty `true` if `null` should be returned when there are no no tices
5884 * @return the change notices that are waiting to be returned
5885 */
5886 List<ChangeNotice> getChangeNotices(bool nullIfEmpty) {
5887 {
5888 if (_pendingNotices.isEmpty) {
5889 if (nullIfEmpty) {
5890 return null;
5891 }
5892 return ChangeNoticeImpl.EMPTY_ARRAY;
5893 }
5894 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
5895 _pendingNotices.clear();
5896 return notices;
5897 }
5898 }
5899
5900 /**
5901 * Given a source for a Dart file, return the data represented by the given de scriptor that is
5902 * associated with that source. This method assumes that the data can be produ ced by parsing the
5903 * source if it is not already cached.
5904 *
5905 * @param source the source representing the Dart file
5906 * @param dartEntry the cache entry associated with the Dart file
5907 * @param descriptor the descriptor representing the data to be returned
5908 * @return the requested data about the given source
5909 * @throws AnalysisException if data could not be returned because the source could not be parsed
5910 */
5911 Object getDartParseData(Source source, DartEntry dartEntry, DataDescriptor des criptor) {
5912 dartEntry = cacheDartParseData(source, dartEntry, descriptor);
5913 if (identical(descriptor, DartEntry.PARSED_UNIT)) {
5914 return dartEntry.anyParsedCompilationUnit as Object;
5915 }
5916 return dartEntry.getValue(descriptor);
5917 }
5918
5919 /**
5920 * Given a source for a Dart file, return the data represented by the given de scriptor that is
5921 * associated with that source, or the given default value if the source is no t a Dart file. This
5922 * method assumes that the data can be produced by parsing the source if it is not already cached.
5923 *
5924 * @param source the source representing the Dart file
5925 * @param descriptor the descriptor representing the data to be returned
5926 * @param defaultValue the value to be returned if the source is not a Dart fi le
5927 * @return the requested data about the given source
5928 * @throws AnalysisException if data could not be returned because the source could not be parsed
5929 */
5930 Object getDartParseData2(Source source, DataDescriptor descriptor, Object defa ultValue) {
5931 DartEntry dartEntry = getReadableDartEntry(source);
5932 if (dartEntry == null) {
5933 return defaultValue;
5934 }
5935 return getDartParseData(source, dartEntry, descriptor);
5936 }
5937
5938 /**
5939 * Given a source for a Dart file and the library that contains it, return the data represented by
5940 * the given descriptor that is associated with that source. This method assum es that the data can
5941 * be produced by resolving the source in the context of the library if it is not already cached.
5942 *
5943 * @param unitSource the source representing the Dart file
5944 * @param librarySource the source representing the library containing the Dar t file
5945 * @param dartEntry the entry representing the Dart file
5946 * @param descriptor the descriptor representing the data to be returned
5947 * @return the requested data about the given source
5948 * @throws AnalysisException if data could not be returned because the source could not be
5949 * resolved
5950 */
5951 Object getDartResolutionData(Source unitSource, Source librarySource, DartEntr y dartEntry, DataDescriptor descriptor) {
5952 dartEntry = cacheDartResolutionData(unitSource, librarySource, dartEntry, de scriptor);
5953 if (identical(descriptor, DartEntry.ELEMENT)) {
5954 return dartEntry.getValue(descriptor);
5955 }
5956 return dartEntry.getValue2(descriptor, librarySource);
5957 }
5958
5959 /**
5960 * Given a source for a Dart file and the library that contains it, return the data represented by
5961 * the given descriptor that is associated with that source, or the given defa ult value if the
5962 * source is not a Dart file. This method assumes that the data can be produce d by resolving the
5963 * source in the context of the library if it is not already cached.
5964 *
5965 * @param unitSource the source representing the Dart file
5966 * @param librarySource the source representing the library containing the Dar t file
5967 * @param descriptor the descriptor representing the data to be returned
5968 * @param defaultValue the value to be returned if the source is not a Dart fi le
5969 * @return the requested data about the given source
5970 * @throws AnalysisException if data could not be returned because the source could not be
5971 * resolved
5972 */
5973 Object getDartResolutionData2(Source unitSource, Source librarySource, DataDes criptor descriptor, Object defaultValue) {
5974 DartEntry dartEntry = getReadableDartEntry(unitSource);
5975 if (dartEntry == null) {
5976 return defaultValue;
5977 }
5978 return getDartResolutionData(unitSource, librarySource, dartEntry, descripto r);
5979 }
5980
5981 /**
5982 * Given a source for an HTML file, return the data represented by the given d escriptor that is
5983 * associated with that source, or the given default value if the source is no t an HTML file. This
5984 * method assumes that the data can be produced by parsing the source if it is not already cached.
5985 *
5986 * @param source the source representing the Dart 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 an HTML f ile
5989 * @return the requested data about the given source
5990 * @throws AnalysisException if data could not be returned because the source could not be parsed
5991 */
5992 Object getHtmlParseData(Source source, DataDescriptor descriptor, Object defau ltValue) {
5993 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
5994 if (htmlEntry == null) {
5995 return defaultValue;
5996 }
5997 htmlEntry = cacheHtmlParseData(source, htmlEntry, descriptor);
5998 return htmlEntry.getValue(descriptor);
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 resolving the source if it is not already
6005 * cached.
6006 *
6007 * @param source the source representing the HTML file
6008 * @param descriptor the descriptor representing the data to be returned
6009 * @param defaultValue the value to be returned if the source is not an HTML f ile
6010 * @return the requested data about the given source
6011 * @throws AnalysisException if data could not be returned because the source could not be
6012 * resolved
6013 */
6014 Object getHtmlResolutionData(Source source, DataDescriptor descriptor, Object defaultValue) {
6015 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
6016 if (htmlEntry == null) {
6017 return defaultValue;
6018 }
6019 return getHtmlResolutionData2(source, htmlEntry, descriptor);
6020 }
6021
6022 /**
6023 * Given a source for an HTML file, return the data represented by the given d escriptor that is
6024 * associated with that source. This method assumes that the data can be produ ced by resolving the
6025 * source if it is not already cached.
6026 *
6027 * @param source the source representing the HTML file
6028 * @param htmlEntry the entry representing the HTML file
6029 * @param descriptor the descriptor representing the data to be returned
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 getHtmlResolutionData2(Source source, HtmlEntry htmlEntry, DataDescript or descriptor) {
6035 htmlEntry = cacheHtmlResolutionData(source, htmlEntry, descriptor);
6036 return htmlEntry.getValue(descriptor);
6037 }
6038
6039 /**
6040 * Look through the cache for a task that needs to be performed. Return the ta sk that was found,
6041 * or `null` if there is no more work to be done.
6042 *
6043 * @return the next task that needs to be performed
6044 */
6045 AnalysisTask get nextTaskAnalysisTask {
6046 {
6047 for (Source source in _cache.priorityOrder) {
6048 SourceEntry sourceEntry = _cache.get(source);
6049 if (sourceEntry is DartEntry) {
6050 DartEntry dartEntry = sourceEntry as DartEntry;
6051 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERROR S);
6052 if (identical(parseErrorsState, CacheState.INVALID) || identical(parse ErrorsState, CacheState.FLUSHED)) {
6053 DartEntryImpl dartCopy = dartEntry.writableCopy;
6054 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
6055 _cache.put(source, dartCopy);
6056 return new ParseDartTask(this, source);
6057 }
6058 CacheState parseUnitState = dartEntry.getState(DartEntry.PARSED_UNIT);
6059 if (identical(parseUnitState, CacheState.INVALID) || identical(parseUn itState, CacheState.FLUSHED)) {
6060 DartEntryImpl dartCopy = dartEntry.writableCopy;
6061 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS);
6062 _cache.put(source, dartCopy);
6063 return new ParseDartTask(this, source);
6064 }
6065 for (Source librarySource in getLibrariesContaining(source)) {
6066 SourceEntry libraryEntry = _cache.get(librarySource);
6067 if (libraryEntry is DartEntry) {
6068 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT) ;
6069 if (identical(elementState, CacheState.INVALID) || identical(eleme ntState, CacheState.FLUSHED)) {
6070 DartEntryImpl libraryCopy = ((libraryEntry as DartEntry)).writab leCopy;
6071 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
6072 _cache.put(librarySource, libraryCopy);
6073 return new ResolveDartLibraryTask(this, source, librarySource);
6074 }
6075 CacheState resolvedUnitState = dartEntry.getState2(DartEntry.RESOL VED_UNIT, librarySource);
6076 if (identical(resolvedUnitState, CacheState.INVALID) || identical( resolvedUnitState, CacheState.FLUSHED)) {
6077 LibraryElement libraryElement = libraryEntry.getValue(DartEntry. ELEMENT);
6078 if (libraryElement != null) {
6079 DartEntryImpl dartCopy = dartEntry.writableCopy;
6080 dartCopy.setState2(DartEntry.RESOLVED_UNIT, librarySource, Cac heState.IN_PROCESS);
6081 _cache.put(source, dartCopy);
6082 return new ResolveDartUnitTask(this, source, libraryElement);
6083 }
6084 }
6085 }
6086 }
6087 } else if (sourceEntry is HtmlEntry) {
6088 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
6089 CacheState parsedUnitState = htmlEntry.getState(HtmlEntry.PARSED_UNIT) ;
6090 if (identical(parsedUnitState, CacheState.INVALID) || identical(parsed UnitState, CacheState.FLUSHED)) {
6091 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6092 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
6093 _cache.put(source, htmlCopy);
6094 return new ParseHtmlTask(this, source);
6095 }
6096 CacheState elementState = htmlEntry.getState(HtmlEntry.ELEMENT);
6097 if (identical(elementState, CacheState.INVALID) || identical(elementSt ate, CacheState.FLUSHED)) {
6098 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6099 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
6100 _cache.put(source, htmlCopy);
6101 return new ResolveHtmlTask(this, source);
6102 }
6103 }
6104 }
6105 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
6106 SourceEntry sourceEntry = entry.getValue();
6107 if (sourceEntry is DartEntry) {
6108 DartEntry dartEntry = sourceEntry as DartEntry;
6109 if (identical(dartEntry.getState(DartEntry.PARSED_UNIT), CacheState.IN VALID)) {
6110 Source source = entry.getKey();
6111 DartEntryImpl dartCopy = dartEntry.writableCopy;
6112 dartCopy.setState(DartEntry.PARSE_ERRORS, CacheState.IN_PROCESS);
6113 _cache.put(source, dartCopy);
6114 return new ParseDartTask(this, source);
6115 }
6116 } else if (sourceEntry is HtmlEntry) {
6117 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
6118 if (identical(htmlEntry.getState(HtmlEntry.PARSED_UNIT), CacheState.IN VALID)) {
6119 Source source = entry.getKey();
6120 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6121 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.IN_PROCESS);
6122 _cache.put(source, htmlCopy);
6123 return new ParseHtmlTask(this, source);
6124 }
6125 }
6126 }
6127 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
6128 SourceEntry sourceEntry = entry.getValue();
6129 if (sourceEntry is DartEntry && identical(sourceEntry.kind, SourceKind.L IBRARY)) {
6130 DartEntry dartEntry = sourceEntry as DartEntry;
6131 if (identical(dartEntry.getState(DartEntry.ELEMENT), CacheState.INVALI D)) {
6132 Source source = entry.getKey();
6133 DartEntryImpl dartCopy = dartEntry.writableCopy;
6134 dartCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
6135 _cache.put(source, dartCopy);
6136 return new ResolveDartLibraryTask(this, source, source);
6137 }
6138 } else if (sourceEntry is HtmlEntry) {
6139 HtmlEntry htmlEntry = sourceEntry as HtmlEntry;
6140 if (identical(htmlEntry.getState(HtmlEntry.ELEMENT), CacheState.INVALI D)) {
6141 Source source = entry.getKey();
6142 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6143 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.IN_PROCESS);
6144 _cache.put(source, htmlCopy);
6145 return new ResolveHtmlTask(this, source);
6146 }
6147 }
6148 }
6149 return null;
6150 }
6151 }
6152
6153 /**
6154 * Return a change notice for the given source, creating one if one does not a lready exist.
6155 *
6156 * @param source the source for which changes are being reported
6157 * @return a change notice for the given source
6158 */
6159 ChangeNoticeImpl getNotice(Source source) {
6160 ChangeNoticeImpl notice = _pendingNotices[source];
6161 if (notice == null) {
6162 notice = new ChangeNoticeImpl(source);
6163 _pendingNotices[source] = notice;
6164 }
6165 return notice;
6166 }
6167
6168 /**
6169 * Return the cache entry associated with the given source, or `null` if the s ource is not a
6170 * Dart file.
6171 *
6172 * @param source the source for which a cache entry is being sought
6173 * @return the source cache entry associated with the given source
6174 */
6175 DartEntry getReadableDartEntry(Source source) {
6176 {
6177 SourceEntry sourceEntry = _cache.get(source);
6178 if (sourceEntry == null) {
6179 sourceEntry = createSourceEntry(source);
6180 }
6181 if (sourceEntry is DartEntry) {
6182 _cache.accessed(source);
6183 return sourceEntry as DartEntry;
6184 }
6185 return null;
6186 }
6187 }
6188
6189 /**
6190 * Return the cache entry associated with the given source, or `null` if the s ource is not
6191 * an HTML file.
6192 *
6193 * @param source the source for which a cache entry is being sought
6194 * @return the source cache entry associated with the given source
6195 */
6196 HtmlEntry getReadableHtmlEntry(Source source) {
6197 {
6198 SourceEntry sourceEntry = _cache.get(source);
6199 if (sourceEntry == null) {
6200 sourceEntry = createSourceEntry(source);
6201 }
6202 if (sourceEntry is HtmlEntry) {
6203 _cache.accessed(source);
6204 return sourceEntry as HtmlEntry;
6205 }
6206 return null;
6207 }
6208 }
6209
6210 /**
6211 * Return the cache entry associated with the given source, or `null` if there is no entry
6212 * associated with the source.
6213 *
6214 * @param source the source for which a cache entry is being sought
6215 * @return the source cache entry associated with the given source
6216 */
6217 SourceEntry getReadableSourceEntry(Source source) {
6218 {
6219 SourceEntry sourceEntry = _cache.get(source);
6220 if (sourceEntry == null) {
6221 sourceEntry = createSourceEntry(source);
6222 }
6223 if (sourceEntry != null) {
6224 _cache.accessed(source);
6225 }
6226 return sourceEntry;
6227 }
6228 }
6229
6230 /**
6231 * Return an array containing all of the sources known to this context that ha ve the given kind.
6232 *
6233 * @param kind the kind of sources to be returned
6234 * @return all of the sources known to this context that have the given kind
6235 */
6236 List<Source> getSources(SourceKind kind2) {
6237 List<Source> sources = new List<Source>();
6238 {
6239 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
6240 if (identical(entry.getValue().kind, kind2)) {
6241 sources.add(entry.getKey());
6242 }
6243 }
6244 }
6245 return new List.from(sources);
6246 }
6247
6248 /**
6249 * Invalidate all of the resolution results computed by this context.
6250 *
6251 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6252 */
6253 void invalidateAllResolutionInformation() {
6254 for (MapEntry<Source, SourceEntry> mapEntry in _cache.entrySet()) {
6255 SourceEntry sourceEntry = mapEntry.getValue();
6256 if (sourceEntry is HtmlEntry) {
6257 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6258 htmlCopy.invalidateAllResolutionInformation();
6259 mapEntry.setValue(htmlCopy);
6260 } else if (sourceEntry is DartEntry) {
6261 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
6262 dartCopy.invalidateAllResolutionInformation();
6263 mapEntry.setValue(dartCopy);
6264 }
6265 }
6266 }
6267
6268 /**
6269 * In response to a change to at least one of the compilation units in the giv en library,
6270 * invalidate any results that are dependent on the result of resolving that l ibrary.
6271 *
6272 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6273 *
6274 * @param librarySource the source of the library being invalidated
6275 */
6276 void invalidateLibraryResolution(Source librarySource) {
6277 DartEntry libraryEntry = getReadableDartEntry(librarySource);
6278 if (libraryEntry != null) {
6279 List<Source> includedParts = libraryEntry.getValue(DartEntry.INCLUDED_PART S);
6280 DartEntryImpl libraryCopy = libraryEntry.writableCopy;
6281 libraryCopy.invalidateAllResolutionInformation();
6282 libraryCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.INVALID);
6283 _cache.put(librarySource, libraryCopy);
6284 for (Source partSource in includedParts) {
6285 DartEntry partEntry = getReadableDartEntry(partSource);
6286 if (partEntry != null) {
6287 DartEntryImpl partCopy = partEntry.writableCopy;
6288 partCopy.invalidateAllResolutionInformation();
6289 _cache.put(partSource, partCopy);
6290 }
6291 }
6292 }
6293 }
6294
6295 /**
6296 * Return `true` if this library is, or depends on, dart:html.
6297 *
6298 * @param library the library being tested
6299 * @param visitedLibraries a collection of the libraries that have been visite d, used to prevent
6300 * infinite recursion
6301 * @return `true` if this library is, or depends on, dart:html
6302 */
6303 bool isClient(LibraryElement library, Source htmlSource, Set<LibraryElement> v isitedLibraries) {
6304 if (visitedLibraries.contains(library)) {
6305 return false;
6306 }
6307 if (library.source == htmlSource) {
6308 return true;
6309 }
6310 javaSetAdd(visitedLibraries, library);
6311 for (LibraryElement imported in library.importedLibraries) {
6312 if (isClient(imported, htmlSource, visitedLibraries)) {
6313 return true;
6314 }
6315 }
6316 for (LibraryElement exported in library.exportedLibraries) {
6317 if (isClient(exported, htmlSource, visitedLibraries)) {
6318 return true;
6319 }
6320 }
6321 return false;
6322 }
6323
6324 /**
6325 * Given a cache entry and a library element, record the library element and o ther information
6326 * gleaned from the element in the cache entry.
6327 *
6328 * @param dartCopy the cache entry in which data is to be recorded
6329 * @param library the library element used to record information
6330 * @param htmlSource the source for the HTML library
6331 */
6332 void recordElementData(DartEntryImpl dartCopy, LibraryElement library, Source htmlSource) {
6333 dartCopy.setValue(DartEntry.ELEMENT, library);
6334 dartCopy.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null);
6335 dartCopy.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set <LibraryElement>()));
6336 List<Source> unitSources = new List<Source>();
6337 unitSources.add(library.definingCompilationUnit.source);
6338 for (CompilationUnitElement part in library.parts) {
6339 Source partSource = part.source;
6340 unitSources.add(partSource);
6341 }
6342 dartCopy.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources));
6343 }
6344
6345 /**
6346 * Record the results produced by performing a [ParseDartTask]. If the results were computed
6347 * from data that is now out-of-date, then the results will not be recorded.
6348 *
6349 * @param task the task that was performed
6350 * @return an entry containing the computed results
6351 * @throws AnalysisException if the results could not be recorded
6352 */
6353 DartEntry recordParseDartTaskResults(ParseDartTask task) {
6354 Source source = task.source;
6355 AnalysisException thrownException = task.exception;
6356 DartEntry dartEntry = null;
6357 {
6358 SourceEntry sourceEntry = _cache.get(source);
6359 if (sourceEntry is! DartEntry) {
6360 throw new AnalysisException.con1("Internal error: attempting to parse no n-Dart file as a Dart file: ${source.fullName}");
6361 }
6362 dartEntry = sourceEntry as DartEntry;
6363 _cache.accessed(source);
6364 int sourceTime = source.modificationStamp;
6365 int resultTime = task.modificationTime;
6366 if (sourceTime == resultTime) {
6367 if (dartEntry.modificationTime != sourceTime) {
6368 sourceChanged(source);
6369 dartEntry = getReadableDartEntry(source);
6370 if (dartEntry == null) {
6371 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
6372 }
6373 }
6374 DartEntryImpl dartCopy = dartEntry.writableCopy;
6375 if (thrownException == null) {
6376 LineInfo lineInfo = task.lineInfo;
6377 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6378 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) {
6379 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
6380 } else {
6381 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
6382 }
6383 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit);
6384 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors);
6385 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
6386 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
6387 dartCopy.setValue(DartEntry.INCLUDED_PARTS, task.includedSources);
6388 } else {
6389 dartCopy.recordParseError();
6390 }
6391 _cache.put(source, dartCopy);
6392 dartEntry = dartCopy;
6393 } else {
6394 DartEntryImpl dartCopy = dartEntry.writableCopy;
6395 dartCopy.recordParseNotInProcess();
6396 _cache.put(source, dartCopy);
6397 dartEntry = dartCopy;
6398 }
6399 }
6400 if (thrownException != null) {
6401 throw thrownException;
6402 }
6403 return dartEntry;
6404 }
6405
6406 /**
6407 * Record the results produced by performing a [ParseHtmlTask]. If the results were computed
6408 * from data that is now out-of-date, then the results will not be recorded.
6409 *
6410 * @param task the task that was performed
6411 * @return an entry containing the computed results
6412 * @throws AnalysisException if the results could not be recorded
6413 */
6414 HtmlEntry recordParseHtmlTaskResults(ParseHtmlTask task) {
6415 Source source = task.source;
6416 AnalysisException thrownException = task.exception;
6417 HtmlEntry htmlEntry = null;
6418 {
6419 SourceEntry sourceEntry = _cache.get(source);
6420 if (sourceEntry is! HtmlEntry) {
6421 throw new AnalysisException.con1("Internal error: attempting to parse no n-HTML file as a HTML file: ${source.fullName}");
6422 }
6423 htmlEntry = sourceEntry as HtmlEntry;
6424 _cache.accessed(source);
6425 int sourceTime = source.modificationStamp;
6426 int resultTime = task.modificationTime;
6427 if (sourceTime == resultTime) {
6428 if (htmlEntry.modificationTime != sourceTime) {
6429 sourceChanged(source);
6430 htmlEntry = getReadableHtmlEntry(source);
6431 if (htmlEntry == null) {
6432 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
6433 }
6434 }
6435 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6436 if (thrownException == null) {
6437 LineInfo lineInfo = task.lineInfo;
6438 HtmlUnit unit = task.htmlUnit;
6439 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6440 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit);
6441 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries);
6442 ChangeNoticeImpl notice = getNotice(source);
6443 notice.setErrors(htmlEntry.allErrors, lineInfo);
6444 } else {
6445 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.ERROR);
6446 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
6447 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
6448 }
6449 _cache.put(source, htmlCopy);
6450 htmlEntry = htmlCopy;
6451 } else {
6452 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6453 if (identical(htmlCopy.getState(SourceEntry.LINE_INFO), CacheState.IN_PR OCESS)) {
6454 htmlCopy.setState(SourceEntry.LINE_INFO, CacheState.INVALID);
6455 }
6456 if (identical(htmlCopy.getState(HtmlEntry.PARSED_UNIT), CacheState.IN_PR OCESS)) {
6457 htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.INVALID);
6458 }
6459 if (identical(htmlCopy.getState(HtmlEntry.REFERENCED_LIBRARIES), CacheSt ate.IN_PROCESS)) {
6460 htmlCopy.setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.INVALID);
6461 }
6462 _cache.put(source, htmlCopy);
6463 htmlEntry = htmlCopy;
6464 }
6465 }
6466 if (thrownException != null) {
6467 throw thrownException;
6468 }
6469 return htmlEntry;
6470 }
6471
6472 /**
6473 * Record the results produced by performing a [ResolveDartLibraryTask]. If th e results were
6474 * computed from data that is now out-of-date, then the results will not be re corded.
6475 *
6476 * @param task the task that was performed
6477 * @return an entry containing the computed results
6478 * @throws AnalysisException if the results could not be recorded
6479 */
6480 DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibraryTask task) {
6481 LibraryResolver resolver = task.libraryResolver;
6482 AnalysisException thrownException = task.exception;
6483 DartEntry unitEntry = null;
6484 {
6485 if (allModificationTimesMatch(resolver)) {
6486 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
6487 Source unitSource = task.unitSource;
6488 RecordingErrorListener errorListener = resolver.errorListener;
6489 for (Library library in resolver.resolvedLibraries) {
6490 Source librarySource = library.librarySource;
6491 for (Source source in library.compilationUnitSources) {
6492 CompilationUnit unit = library.getAST(source);
6493 List<AnalysisError> errors = errorListener.getErrors2(source);
6494 unit.resolutionErrors = errors;
6495 LineInfo lineInfo = unit.lineInfo;
6496 DartEntry dartEntry = _cache.get(source) as DartEntry;
6497 int sourceTime = source.modificationStamp;
6498 if (dartEntry.modificationTime != sourceTime) {
6499 sourceChanged(source);
6500 dartEntry = getReadableDartEntry(source);
6501 if (dartEntry == null) {
6502 throw new AnalysisException.con1("A Dart file became a non-Dart file: ${source.fullName}");
6503 }
6504 }
6505 DartEntryImpl dartCopy = dartEntry.writableCopy;
6506 if (thrownException == null) {
6507 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
6508 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
6509 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit);
6510 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, err ors);
6511 if (identical(source, librarySource)) {
6512 recordElementData(dartCopy, library.libraryElement, htmlSource);
6513 }
6514 } else {
6515 dartCopy.recordResolutionError();
6516 }
6517 _cache.put(source, dartCopy);
6518 if (source == unitSource) {
6519 unitEntry = dartCopy;
6520 }
6521 ChangeNoticeImpl notice = getNotice(source);
6522 notice.compilationUnit = unit;
6523 notice.setErrors(dartCopy.allErrors, lineInfo);
6524 }
6525 }
6526 } else {
6527 for (Library library in resolver.resolvedLibraries) {
6528 for (Source source in library.compilationUnitSources) {
6529 DartEntry dartEntry = getReadableDartEntry(source);
6530 if (dartEntry != null) {
6531 DartEntryImpl dartCopy = dartEntry.writableCopy;
6532 dartCopy.recordResolutionNotInProcess();
6533 _cache.put(source, dartCopy);
6534 }
6535 }
6536 }
6537 }
6538 }
6539 if (thrownException != null) {
6540 throw thrownException;
6541 }
6542 return unitEntry;
6543 }
6544
6545 /**
6546 * Record the results produced by performing a [ResolveDartUnitTask]. If the r esults were
6547 * computed from data that is now out-of-date, then the results will not be re corded.
6548 *
6549 * @param task the task that was performed
6550 * @return an entry containing the computed results
6551 * @throws AnalysisException if the results could not be recorded
6552 */
6553 SourceEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) {
6554 Source source = task.source;
6555 AnalysisException thrownException = task.exception;
6556 DartEntry dartEntry = null;
6557 {
6558 SourceEntry sourceEntry = _cache.get(source);
6559 if (sourceEntry is! DartEntry) {
6560 throw new AnalysisException.con1("Internal error: attempting to reolve n on-Dart file as a Dart file: ${source.fullName}");
6561 }
6562 dartEntry = sourceEntry as DartEntry;
6563 _cache.accessed(source);
6564 int sourceTime = source.modificationStamp;
6565 int resultTime = task.modificationTime;
6566 if (sourceTime == resultTime) {
6567 if (dartEntry.modificationTime != sourceTime) {
6568 sourceChanged(source);
6569 dartEntry = getReadableDartEntry(source);
6570 if (dartEntry == null) {
6571 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
6572 }
6573 }
6574 DartEntryImpl dartCopy = dartEntry.writableCopy;
6575 if (thrownException == null) {
6576 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, task.librarySource, task.r esolvedUnit);
6577 } else {
6578 dartCopy.setState(DartEntry.RESOLVED_UNIT, CacheState.ERROR);
6579 }
6580 _cache.put(source, dartCopy);
6581 dartEntry = dartCopy;
6582 } else {
6583 DartEntryImpl dartCopy = dartEntry.writableCopy;
6584 if (identical(dartCopy.getState(DartEntry.RESOLVED_UNIT), CacheState.IN_ PROCESS)) {
6585 dartCopy.setState(DartEntry.RESOLVED_UNIT, CacheState.INVALID);
6586 }
6587 _cache.put(source, dartCopy);
6588 dartEntry = dartCopy;
6589 }
6590 }
6591 if (thrownException != null) {
6592 throw thrownException;
6593 }
6594 return dartEntry;
6595 }
6596
6597 /**
6598 * Record the results produced by performing a [ResolveHtmlTask]. If the resul ts were
6599 * computed from data that is now out-of-date, then the results will not be re corded.
6600 *
6601 * @param task the task that was performed
6602 * @return an entry containing the computed results
6603 * @throws AnalysisException if the results could not be recorded
6604 */
6605 SourceEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) {
6606 Source source = task.source;
6607 AnalysisException thrownException = task.exception;
6608 HtmlEntry htmlEntry = null;
6609 {
6610 SourceEntry sourceEntry = _cache.get(source);
6611 if (sourceEntry is! HtmlEntry) {
6612 throw new AnalysisException.con1("Internal error: attempting to reolve n on-HTML file as an HTML file: ${source.fullName}");
6613 }
6614 htmlEntry = sourceEntry as HtmlEntry;
6615 _cache.accessed(source);
6616 int sourceTime = source.modificationStamp;
6617 int resultTime = task.modificationTime;
6618 if (sourceTime == resultTime) {
6619 if (htmlEntry.modificationTime != sourceTime) {
6620 sourceChanged(source);
6621 htmlEntry = getReadableHtmlEntry(source);
6622 if (htmlEntry == null) {
6623 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
6624 }
6625 }
6626 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6627 if (thrownException == null) {
6628 htmlCopy.setValue(HtmlEntry.ELEMENT, task.element);
6629 htmlCopy.setValue(HtmlEntry.RESOLUTION_ERRORS, task.resolutionErrors);
6630 } else {
6631 htmlCopy.recordResolutionError();
6632 }
6633 _cache.put(source, htmlCopy);
6634 htmlEntry = htmlCopy;
6635 } else {
6636 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
6637 if (identical(htmlCopy.getState(HtmlEntry.ELEMENT), CacheState.IN_PROCES S)) {
6638 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
6639 }
6640 if (identical(htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS), CacheState .IN_PROCESS)) {
6641 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.INVALID);
6642 }
6643 _cache.put(source, htmlCopy);
6644 htmlEntry = htmlCopy;
6645 }
6646 }
6647 if (thrownException != null) {
6648 throw thrownException;
6649 }
6650 return htmlEntry;
6651 }
6652
6653 /**
6654 * Create an entry for the newly added source. Return `true` if the new source is a Dart
6655 * file.
6656 *
6657 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6658 *
6659 * @param source the source that has been added
6660 * @return `true` if the new source is a Dart file
6661 */
6662 bool sourceAvailable(Source source) {
6663 SourceEntry sourceEntry = _cache.get(source);
6664 if (sourceEntry == null) {
6665 sourceEntry = createSourceEntry(source);
6666 } else {
6667 SourceEntryImpl sourceCopy = sourceEntry.writableCopy;
6668 sourceCopy.modificationTime = source.modificationStamp;
6669 _cache.put(source, sourceCopy);
6670 }
6671 return sourceEntry is DartEntry;
6672 }
6673
6674 /**
6675 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6676 *
6677 * @param source the source that has been changed
6678 */
6679 void sourceChanged(Source source) {
6680 SourceEntry sourceEntry = _cache.get(source);
6681 if (sourceEntry is HtmlEntry) {
6682 HtmlEntryImpl htmlCopy = ((sourceEntry as HtmlEntry)).writableCopy;
6683 htmlCopy.modificationTime = source.modificationStamp;
6684 htmlCopy.invalidateAllInformation();
6685 _cache.put(source, htmlCopy);
6686 } else if (sourceEntry is DartEntry) {
6687 List<Source> containingLibraries = getLibrariesContaining(source);
6688 for (Source library in containingLibraries) {
6689 invalidateLibraryResolution(library);
6690 }
6691 DartEntryImpl dartCopy = ((sourceEntry as DartEntry)).writableCopy;
6692 dartCopy.modificationTime = source.modificationStamp;
6693 dartCopy.invalidateAllInformation();
6694 _cache.put(source, dartCopy);
6695 }
6696 }
6697
6698 /**
6699 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
6700 *
6701 * @param source the source that has been deleted
6702 */
6703 void sourceRemoved(Source source) {
6704 SourceEntry sourceEntry = _cache.get(source);
6705 if (sourceEntry is DartEntry) {
6706 Set<Source> libraries = new Set<Source>();
6707 for (Source librarySource in getLibrariesContaining(source)) {
6708 javaSetAdd(libraries, librarySource);
6709 for (Source dependentLibrary in getLibrariesDependingOn(librarySource)) {
6710 javaSetAdd(libraries, dependentLibrary);
6711 }
6712 }
6713 for (Source librarySource in libraries) {
6714 invalidateLibraryResolution(librarySource);
6715 }
6716 }
6717 _cache.remove(source);
6718 }
6719 }
6720 /**
6721 * Instances of the class `AnalysisTaskResultRecorder` are used by an analysis c ontext to
6722 * record the results of a task.
6723 */
6724 class AnalysisContextImpl2_AnalysisTaskResultRecorder implements AnalysisTaskVis itor<SourceEntry> {
6725 final AnalysisContextImpl2 AnalysisContextImpl2_this;
6726 AnalysisContextImpl2_AnalysisTaskResultRecorder(this.AnalysisContextImpl2_this );
6727 DartEntry visitParseDartTask(ParseDartTask task) => AnalysisContextImpl2_this. recordParseDartTaskResults(task);
6728 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => AnalysisContextImpl2_this. recordParseHtmlTaskResults(task);
6729 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => Analysis ContextImpl2_this.recordResolveDartLibraryTaskResults(task);
6730 SourceEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => AnalysisCont extImpl2_this.recordResolveDartUnitTaskResults(task);
6731 SourceEntry visitResolveHtmlTask(ResolveHtmlTask task) => AnalysisContextImpl2 _this.recordResolveHtmlTaskResults(task);
6732 }
6733 /**
4829 * Instances of the class `AnalysisErrorInfoImpl` represent the analysis errors and line info 6734 * Instances of the class `AnalysisErrorInfoImpl` represent the analysis errors and line info
4830 * associated with a source. 6735 * associated with a source.
4831 */ 6736 */
4832 class AnalysisErrorInfoImpl implements AnalysisErrorInfo { 6737 class AnalysisErrorInfoImpl implements AnalysisErrorInfo {
4833 6738
4834 /** 6739 /**
4835 * The analysis errors associated with a source, or `null` if there are no err ors. 6740 * The analysis errors associated with a source, or `null` if there are no err ors.
4836 */ 6741 */
4837 List<AnalysisError> _errors; 6742 List<AnalysisError> _errors;
4838 6743
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
5313 if (_sdkAnalysisContext is DelegatingAnalysisContextImpl) { 7218 if (_sdkAnalysisContext is DelegatingAnalysisContextImpl) {
5314 _sdkAnalysisContext = null; 7219 _sdkAnalysisContext = null;
5315 throw new IllegalStateException("The context provided by an SDK cannot i tself be a delegating analysis context"); 7220 throw new IllegalStateException("The context provided by an SDK cannot i tself be a delegating analysis context");
5316 } 7221 }
5317 } else { 7222 } else {
5318 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. "); 7223 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. ");
5319 } 7224 }
5320 } 7225 }
5321 } 7226 }
5322 /** 7227 /**
7228 * Instances of the class `DelegatingAnalysisContextImpl` extend [AnalysisContex tImpl
7229 ] to delegate sources to the appropriate analysis context. For instance, if the
7230 * source is in a system library then the analysis context from the [DartSdk] is used.
7231 *
7232 * @coverage dart.engine
7233 */
7234 class DelegatingAnalysisContextImpl2 extends AnalysisContextImpl2 {
7235
7236 /**
7237 * This references the [InternalAnalysisContext] held onto by the [DartSdk] wh ich is
7238 * used (instead of this [AnalysisContext]) for SDK sources. This field is set when
7239 * #setSourceFactory(SourceFactory) is called, and references the analysis con text in the
7240 * [DartUriResolver] in the [SourceFactory], this analysis context assumes tha t there
7241 * will be such a resolver.
7242 */
7243 InternalAnalysisContext _sdkAnalysisContext;
7244 void addSourceInfo(Source source, SourceEntry info) {
7245 if (source.isInSystemLibrary) {
7246 _sdkAnalysisContext.addSourceInfo(source, info);
7247 } else {
7248 super.addSourceInfo(source, info);
7249 }
7250 }
7251 List<AnalysisError> computeErrors(Source source) {
7252 if (source.isInSystemLibrary) {
7253 return _sdkAnalysisContext.computeErrors(source);
7254 } else {
7255 return super.computeErrors(source);
7256 }
7257 }
7258 List<Source> computeExportedLibraries(Source source) {
7259 if (source.isInSystemLibrary) {
7260 return _sdkAnalysisContext.computeExportedLibraries(source);
7261 } else {
7262 return super.computeExportedLibraries(source);
7263 }
7264 }
7265 HtmlElement computeHtmlElement(Source source) {
7266 if (source.isInSystemLibrary) {
7267 return _sdkAnalysisContext.computeHtmlElement(source);
7268 } else {
7269 return super.computeHtmlElement(source);
7270 }
7271 }
7272 List<Source> computeImportedLibraries(Source source) {
7273 if (source.isInSystemLibrary) {
7274 return _sdkAnalysisContext.computeImportedLibraries(source);
7275 } else {
7276 return super.computeImportedLibraries(source);
7277 }
7278 }
7279 SourceKind computeKindOf(Source source) {
7280 if (source.isInSystemLibrary) {
7281 return _sdkAnalysisContext.computeKindOf(source);
7282 } else {
7283 return super.computeKindOf(source);
7284 }
7285 }
7286 LibraryElement computeLibraryElement(Source source) {
7287 if (source.isInSystemLibrary) {
7288 return _sdkAnalysisContext.computeLibraryElement(source);
7289 } else {
7290 return super.computeLibraryElement(source);
7291 }
7292 }
7293 LineInfo computeLineInfo(Source source) {
7294 if (source.isInSystemLibrary) {
7295 return _sdkAnalysisContext.computeLineInfo(source);
7296 } else {
7297 return super.computeLineInfo(source);
7298 }
7299 }
7300 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) {
7301 if (source.isInSystemLibrary) {
7302 return _sdkAnalysisContext.computeResolvableCompilationUnit(source);
7303 } else {
7304 return super.computeResolvableCompilationUnit(source);
7305 }
7306 }
7307 AnalysisErrorInfo getErrors(Source source) {
7308 if (source.isInSystemLibrary) {
7309 return _sdkAnalysisContext.getErrors(source);
7310 } else {
7311 return super.getErrors(source);
7312 }
7313 }
7314 HtmlElement getHtmlElement(Source source) {
7315 if (source.isInSystemLibrary) {
7316 return _sdkAnalysisContext.getHtmlElement(source);
7317 } else {
7318 return super.getHtmlElement(source);
7319 }
7320 }
7321 List<Source> getHtmlFilesReferencing(Source source) {
7322 if (source.isInSystemLibrary) {
7323 return _sdkAnalysisContext.getHtmlFilesReferencing(source);
7324 } else {
7325 return super.getHtmlFilesReferencing(source);
7326 }
7327 }
7328 SourceKind getKindOf(Source source) {
7329 if (source.isInSystemLibrary) {
7330 return _sdkAnalysisContext.getKindOf(source);
7331 } else {
7332 return super.getKindOf(source);
7333 }
7334 }
7335 List<Source> getLibrariesContaining(Source source) {
7336 if (source.isInSystemLibrary) {
7337 return _sdkAnalysisContext.getLibrariesContaining(source);
7338 } else {
7339 return super.getLibrariesContaining(source);
7340 }
7341 }
7342 List<Source> getLibrariesDependingOn(Source librarySource) {
7343 if (librarySource.isInSystemLibrary) {
7344 return _sdkAnalysisContext.getLibrariesDependingOn(librarySource);
7345 } else {
7346 return super.getLibrariesDependingOn(librarySource);
7347 }
7348 }
7349 LibraryElement getLibraryElement(Source source) {
7350 if (source.isInSystemLibrary) {
7351 return _sdkAnalysisContext.getLibraryElement(source);
7352 } else {
7353 return super.getLibraryElement(source);
7354 }
7355 }
7356 List<Source> get librarySources => ArrayUtils.addAll(super.librarySources, _sd kAnalysisContext.librarySources);
7357 LineInfo getLineInfo(Source source) {
7358 if (source.isInSystemLibrary) {
7359 return _sdkAnalysisContext.getLineInfo(source);
7360 } else {
7361 return super.getLineInfo(source);
7362 }
7363 }
7364 Namespace getPublicNamespace(LibraryElement library) {
7365 Source source = library.source;
7366 if (source.isInSystemLibrary) {
7367 return _sdkAnalysisContext.getPublicNamespace(library);
7368 } else {
7369 return super.getPublicNamespace(library);
7370 }
7371 }
7372 Namespace getPublicNamespace2(Source source) {
7373 if (source.isInSystemLibrary) {
7374 return _sdkAnalysisContext.getPublicNamespace2(source);
7375 } else {
7376 return super.getPublicNamespace2(source);
7377 }
7378 }
7379 CompilationUnit getResolvedCompilationUnit(Source unitSource, LibraryElement l ibrary) {
7380 if (unitSource.isInSystemLibrary) {
7381 return _sdkAnalysisContext.getResolvedCompilationUnit(unitSource, library) ;
7382 } else {
7383 return super.getResolvedCompilationUnit(unitSource, library);
7384 }
7385 }
7386 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
7387 if (unitSource.isInSystemLibrary) {
7388 return _sdkAnalysisContext.getResolvedCompilationUnit2(unitSource, library Source);
7389 } else {
7390 return super.getResolvedCompilationUnit2(unitSource, librarySource);
7391 }
7392 }
7393 bool isClientLibrary(Source librarySource) {
7394 if (librarySource.isInSystemLibrary) {
7395 return _sdkAnalysisContext.isClientLibrary(librarySource);
7396 } else {
7397 return super.isClientLibrary(librarySource);
7398 }
7399 }
7400 bool isServerLibrary(Source librarySource) {
7401 if (librarySource.isInSystemLibrary) {
7402 return _sdkAnalysisContext.isServerLibrary(librarySource);
7403 } else {
7404 return super.isServerLibrary(librarySource);
7405 }
7406 }
7407 CompilationUnit parseCompilationUnit(Source source) {
7408 if (source.isInSystemLibrary) {
7409 return _sdkAnalysisContext.parseCompilationUnit(source);
7410 } else {
7411 return super.parseCompilationUnit(source);
7412 }
7413 }
7414 HtmlUnit parseHtmlUnit(Source source) {
7415 if (source.isInSystemLibrary) {
7416 return _sdkAnalysisContext.parseHtmlUnit(source);
7417 } else {
7418 return super.parseHtmlUnit(source);
7419 }
7420 }
7421 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
7422 if (elementMap.isEmpty) {
7423 return;
7424 }
7425 Source source = new JavaIterator(elementMap.keys.toSet()).next();
7426 if (source.isInSystemLibrary) {
7427 _sdkAnalysisContext.recordLibraryElements(elementMap);
7428 } else {
7429 super.recordLibraryElements(elementMap);
7430 }
7431 }
7432 CompilationUnit resolveCompilationUnit(Source source, LibraryElement library) {
7433 if (source.isInSystemLibrary) {
7434 return _sdkAnalysisContext.resolveCompilationUnit(source, library);
7435 } else {
7436 return super.resolveCompilationUnit(source, library);
7437 }
7438 }
7439 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
7440 if (unitSource.isInSystemLibrary) {
7441 return _sdkAnalysisContext.resolveCompilationUnit2(unitSource, librarySour ce);
7442 } else {
7443 return super.resolveCompilationUnit2(unitSource, librarySource);
7444 }
7445 }
7446 HtmlUnit resolveHtmlUnit(Source unitSource) {
7447 if (unitSource.isInSystemLibrary) {
7448 return _sdkAnalysisContext.resolveHtmlUnit(unitSource);
7449 } else {
7450 return super.resolveHtmlUnit(unitSource);
7451 }
7452 }
7453 void setContents(Source source, String contents) {
7454 if (source.isInSystemLibrary) {
7455 _sdkAnalysisContext.setContents(source, contents);
7456 } else {
7457 super.setContents(source, contents);
7458 }
7459 }
7460 void set sourceFactory(SourceFactory factory) {
7461 super.sourceFactory = factory;
7462 DartSdk sdk = factory.dartSdk;
7463 if (sdk != null) {
7464 _sdkAnalysisContext = sdk.context as InternalAnalysisContext;
7465 if (_sdkAnalysisContext is DelegatingAnalysisContextImpl2) {
7466 _sdkAnalysisContext = null;
7467 throw new IllegalStateException("The context provided by an SDK cannot i tself be a delegating analysis context");
7468 }
7469 } else {
7470 throw new IllegalStateException("SourceFactorys provided to DelegatingAnal ysisContextImpls must have a DartSdk associated with the provided SourceFactory. ");
7471 }
7472 }
7473 }
7474 /**
5323 * Instances of the class `InstrumentedAnalysisContextImpl` implement an 7475 * Instances of the class `InstrumentedAnalysisContextImpl` implement an
5324 * [AnalysisContext] by recording instrumentation data and delegating to 7476 * [AnalysisContext] by recording instrumentation data and delegating to
5325 * another analysis context to do the non-instrumentation work. 7477 * another analysis context to do the non-instrumentation work.
5326 * 7478 *
5327 * @coverage dart.engine 7479 * @coverage dart.engine
5328 */ 7480 */
5329 class InstrumentedAnalysisContextImpl implements InternalAnalysisContext { 7481 class InstrumentedAnalysisContextImpl implements InternalAnalysisContext {
5330 7482
5331 /** 7483 /**
5332 * Record an exception that was thrown during analysis. 7484 * Record an exception that was thrown during analysis.
(...skipping 12 matching lines...) Expand all
5345 7497
5346 /** 7498 /**
5347 * The analysis context to which all of the non-instrumentation work is delega ted. 7499 * The analysis context to which all of the non-instrumentation work is delega ted.
5348 */ 7500 */
5349 InternalAnalysisContext _basis; 7501 InternalAnalysisContext _basis;
5350 7502
5351 /** 7503 /**
5352 * Create a new [InstrumentedAnalysisContextImpl] which wraps a new 7504 * Create a new [InstrumentedAnalysisContextImpl] which wraps a new
5353 * [AnalysisContextImpl] as the basis context. 7505 * [AnalysisContextImpl] as the basis context.
5354 */ 7506 */
5355 InstrumentedAnalysisContextImpl() : this.con1(new AnalysisContextImpl()); 7507 InstrumentedAnalysisContextImpl() : this.con1(AnalysisEngine.instance.useExper imentalContext ? new DelegatingAnalysisContextImpl2() : new DelegatingAnalysisCo ntextImpl());
5356 7508
5357 /** 7509 /**
5358 * Create a new [InstrumentedAnalysisContextImpl] with a specified basis conte xt, aka the 7510 * Create a new [InstrumentedAnalysisContextImpl] with a specified basis conte xt, aka the
5359 * context to wrap and instrument. 7511 * context to wrap and instrument.
5360 * 7512 *
5361 * @param context some [InstrumentedAnalysisContext] to wrap and instrument 7513 * @param context some [InstrumentedAnalysisContext] to wrap and instrument
5362 */ 7514 */
5363 InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) { 7515 InstrumentedAnalysisContextImpl.con1(InternalAnalysisContext context) {
5364 _basis = context; 7516 _basis = context;
5365 } 7517 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
5452 instrumentation.metric3("contextId", _contextId); 7604 instrumentation.metric3("contextId", _contextId);
5453 return _basis.computeLineInfo(source); 7605 return _basis.computeLineInfo(source);
5454 } on AnalysisException catch (e) { 7606 } on AnalysisException catch (e) {
5455 recordAnalysisException(instrumentation, e); 7607 recordAnalysisException(instrumentation, e);
5456 throw e; 7608 throw e;
5457 } finally { 7609 } finally {
5458 instrumentation.log(); 7610 instrumentation.log();
5459 } 7611 }
5460 } 7612 }
5461 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) => _ basis.computeResolvableCompilationUnit(source); 7613 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source) => _ basis.computeResolvableCompilationUnit(source);
7614 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) => _basis.computeR esolvableHtmlUnit(source);
5462 AnalysisContext extractContext(SourceContainer container) { 7615 AnalysisContext extractContext(SourceContainer container) {
5463 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- extractContext"); 7616 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- extractContext");
5464 try { 7617 try {
5465 instrumentation.metric3("contextId", _contextId); 7618 instrumentation.metric3("contextId", _contextId);
5466 InstrumentedAnalysisContextImpl newContext = new InstrumentedAnalysisConte xtImpl(); 7619 InstrumentedAnalysisContextImpl newContext = new InstrumentedAnalysisConte xtImpl();
5467 _basis.extractContextInto(container, newContext._basis); 7620 _basis.extractContextInto(container, newContext._basis);
5468 return newContext; 7621 return newContext;
5469 } finally { 7622 } finally {
5470 instrumentation.log(); 7623 instrumentation.log();
5471 } 7624 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
5857 * not already been resolved and will not be resolved by any other threads or in any other 8010 * not already been resolved and will not be resolved by any other threads or in any other
5858 * library. 8011 * library.
5859 * 8012 *
5860 * @param source the compilation unit for which an AST structure should be ret urned 8013 * @param source the compilation unit for which an AST structure should be ret urned
5861 * @return the AST structure representing the content of the source 8014 * @return the AST structure representing the content of the source
5862 * @throws AnalysisException if the analysis could not be performed 8015 * @throws AnalysisException if the analysis could not be performed
5863 */ 8016 */
5864 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source); 8017 ResolvableCompilationUnit computeResolvableCompilationUnit(Source source);
5865 8018
5866 /** 8019 /**
8020 * Return an AST structure corresponding to the given source, but ensure that the structure has
8021 * not already been resolved and will not be resolved by any other threads.
8022 *
8023 * @param source the compilation unit for which an AST structure should be ret urned
8024 * @return the AST structure representing the content of the source
8025 * @throws AnalysisException if the analysis could not be performed
8026 */
8027 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source);
8028
8029 /**
5867 * Initialize the specified context by removing the specified sources from the receiver and adding 8030 * Initialize the specified context by removing the specified sources from the receiver and adding
5868 * them to the specified context. 8031 * them to the specified context.
5869 * 8032 *
5870 * @param container the container containing sources that should be removed fr om this context and 8033 * @param container the container containing sources that should be removed fr om this context and
5871 * added to the returned context 8034 * added to the returned context
5872 * @param newContext the context to be initialized 8035 * @param newContext the context to be initialized
5873 * @return the analysis context that was initialized 8036 * @return the analysis context that was initialized
5874 */ 8037 */
5875 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext); 8038 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext);
5876 8039
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
6060 /** 8223 /**
6061 * Instances of the class `ResolvableCompilationUnit` represent a compilation un it that is not 8224 * Instances of the class `ResolvableCompilationUnit` represent a compilation un it that is not
6062 * referenced by any other objects and for which we have modification stamp info rmation. It is used 8225 * referenced by any other objects and for which we have modification stamp info rmation. It is used
6063 * by the [LibraryResolver] to resolve a library. 8226 * by the [LibraryResolver] to resolve a library.
6064 */ 8227 */
6065 class ResolvableCompilationUnit { 8228 class ResolvableCompilationUnit {
6066 8229
6067 /** 8230 /**
6068 * The modification time of the source from which the AST was created. 8231 * The modification time of the source from which the AST was created.
6069 */ 8232 */
6070 int _modificationStamp = 0; 8233 int _modificationTime = 0;
6071 8234
6072 /** 8235 /**
6073 * The AST that was created from the source. 8236 * The AST that was created from the source.
6074 */ 8237 */
6075 CompilationUnit _unit; 8238 CompilationUnit _unit;
6076 8239
6077 /** 8240 /**
6078 * Initialize a newly created holder to hold the given values. 8241 * Initialize a newly created holder to hold the given values.
6079 * 8242 *
6080 * @param modificationStamp the modification time of the source from which the AST was created 8243 * @param modificationTime the modification time of the source from which the AST was created
6081 * @param unit the AST that was created from the source 8244 * @param unit the AST that was created from the source
6082 */ 8245 */
6083 ResolvableCompilationUnit(int modificationStamp, CompilationUnit unit) { 8246 ResolvableCompilationUnit(int modificationTime, CompilationUnit unit) {
6084 this._modificationStamp = modificationStamp; 8247 this._modificationTime = modificationTime;
6085 this._unit = unit; 8248 this._unit = unit;
6086 } 8249 }
6087 8250
6088 /** 8251 /**
6089 * Return the AST that was created from the source. 8252 * Return the AST that was created from the source.
6090 * 8253 *
6091 * @return the AST that was created from the source 8254 * @return the AST that was created from the source
6092 */ 8255 */
6093 CompilationUnit get compilationUnit => _unit; 8256 CompilationUnit get compilationUnit => _unit;
6094 8257
6095 /** 8258 /**
6096 * Return the modification time of the source from which the AST was created. 8259 * Return the modification time of the source from which the AST was created.
6097 * 8260 *
6098 * @return the modification time of the source from which the AST was created 8261 * @return the modification time of the source from which the AST was created
6099 */ 8262 */
6100 int get modificationStamp => _modificationStamp; 8263 int get modificationTime => _modificationTime;
8264 }
8265 /**
8266 * Instances of the class `ResolvableHtmlUnit` represent an HTML unit that is no t referenced
8267 * by any other objects and for which we have modification stamp information. It is used by the
8268 * [ResolveHtmlTask] to resolve an HTML source.
8269 */
8270 class ResolvableHtmlUnit {
8271
8272 /**
8273 * The modification time of the source from which the AST was created.
8274 */
8275 int _modificationTime = 0;
8276
8277 /**
8278 * The AST that was created from the source.
8279 */
8280 HtmlUnit _unit;
8281
8282 /**
8283 * Initialize a newly created holder to hold the given values.
8284 *
8285 * @param modificationTime the modification time of the source from which the AST was created
8286 * @param unit the AST that was created from the source
8287 */
8288 ResolvableHtmlUnit(int modificationTime, HtmlUnit unit) {
8289 this._modificationTime = modificationTime;
8290 this._unit = unit;
8291 }
8292
8293 /**
8294 * Return the AST that was created from the source.
8295 *
8296 * @return the AST that was created from the source
8297 */
8298 HtmlUnit get compilationUnit => _unit;
8299
8300 /**
8301 * Return the modification time of the source from which the AST was created.
8302 *
8303 * @return the modification time of the source from which the AST was created
8304 */
8305 int get modificationTime => _modificationTime;
8306 }
8307 /**
8308 * The abstract class `AnalysisTask` defines the behavior of objects used to per form an
8309 * analysis task.
8310 */
8311 abstract class AnalysisTask {
8312
8313 /**
8314 * The context in which the task is to be performed.
8315 */
8316 InternalAnalysisContext _context;
8317
8318 /**
8319 * The exception that was thrown while performing this task, or `null` if the task completed
8320 * successfully.
8321 */
8322 AnalysisException _thrownException;
8323
8324 /**
8325 * Initialize a newly created task to perform analysis within the given contex t.
8326 *
8327 * @param context the context in which the task is to be performed
8328 */
8329 AnalysisTask(InternalAnalysisContext context) {
8330 this._context = context;
8331 }
8332
8333 /**
8334 * Use the given visitor to visit this task.
8335 *
8336 * @param visitor the visitor that should be used to visit this task
8337 * @return the value returned by the visitor
8338 * @throws AnalysisException if the visitor throws the exception
8339 */
8340 accept(AnalysisTaskVisitor visitor);
8341
8342 /**
8343 * Return the exception that was thrown while performing this task, or `null` if the task
8344 * completed successfully.
8345 *
8346 * @return the exception that was thrown while performing this task
8347 */
8348 AnalysisException get exception => _thrownException;
8349
8350 /**
8351 * Perform this analysis task and use the given visitor to visit this task aft er it has completed.
8352 *
8353 * @param visitor the visitor used to visit this task after it has completed
8354 * @return the value returned by the visitor
8355 * @throws AnalysisException if the visitor throws the exception
8356 */
8357 Object perform(AnalysisTaskVisitor visitor) {
8358 try {
8359 safelyPerform();
8360 } on AnalysisException catch (exception) {
8361 _thrownException = exception;
8362 AnalysisEngine.instance.logger.logInformation2("Task failed: ${taskDescrip tion}", exception);
8363 }
8364 return accept(visitor);
8365 }
8366 String toString() => taskDescription;
8367
8368 /**
8369 * Return the context in which the task is to be performed.
8370 *
8371 * @return the context in which the task is to be performed
8372 */
8373 InternalAnalysisContext get context => _context;
8374
8375 /**
8376 * Return a textual description of this task.
8377 *
8378 * @return a textual description of this task
8379 */
8380 String get taskDescription;
8381
8382 /**
8383 * Perform this analysis task, protected by an exception handler.
8384 *
8385 * @throws AnalysisException if an exception occurs while performing the task
8386 */
8387 void internalPerform();
8388
8389 /**
8390 * Perform this analysis task, ensuring that all exceptions are wrapped in an
8391 * [AnalysisException].
8392 *
8393 * @throws AnalysisException if any exception occurs while performing the task
8394 */
8395 void safelyPerform() {
8396 try {
8397 internalPerform();
8398 } on AnalysisException catch (exception) {
8399 throw exception;
8400 } catch (exception) {
8401 throw new AnalysisException.con3(exception);
8402 }
8403 }
8404 }
8405 /**
8406 * The interface `AnalysisTaskVisitor` defines the behavior of objects that can visit tasks.
8407 * While tasks are not structured in any interesting way, this class provides th e ability to
8408 * dispatch to an appropriate method.
8409 */
8410 abstract class AnalysisTaskVisitor<E> {
8411
8412 /**
8413 * Visit a [ParseDartTask].
8414 *
8415 * @param task the task to be visited
8416 * @return the result of visiting the task
8417 * @throws AnalysisException if the visitor throws an exception for some reaso n
8418 */
8419 E visitParseDartTask(ParseDartTask task);
8420
8421 /**
8422 * Visit a [ParseHtmlTask].
8423 *
8424 * @param task the task to be visited
8425 * @return the result of visiting the task
8426 * @throws AnalysisException if the visitor throws an exception for some reaso n
8427 */
8428 E visitParseHtmlTask(ParseHtmlTask task);
8429
8430 /**
8431 * Visit a [ResolveDartLibraryTask].
8432 *
8433 * @param task the task to be visited
8434 * @return the result of visiting the task
8435 * @throws AnalysisException if the visitor throws an exception for some reaso n
8436 */
8437 E visitResolveDartLibraryTask(ResolveDartLibraryTask task);
8438
8439 /**
8440 * Visit a [ResolveDartUnitTask].
8441 *
8442 * @param task the task to be visited
8443 * @return the result of visiting the task
8444 * @throws AnalysisException if the visitor throws an exception for some reaso n
8445 */
8446 E visitResolveDartUnitTask(ResolveDartUnitTask task);
8447
8448 /**
8449 * Visit a [ResolveHtmlTask].
8450 *
8451 * @param task the task to be visited
8452 * @return the result of visiting the task
8453 * @throws AnalysisException if the visitor throws an exception for some reaso n
8454 */
8455 E visitResolveHtmlTask(ResolveHtmlTask task);
8456 }
8457 /**
8458 * Instances of the class `ParseDartTask` parse a specific source as a Dart file .
8459 */
8460 class ParseDartTask extends AnalysisTask {
8461
8462 /**
8463 * The source to be parsed.
8464 */
8465 Source _source;
8466
8467 /**
8468 * The time at which the contents of the source were last modified.
8469 */
8470 int _modificationTime = -1;
8471
8472 /**
8473 * The line information that was produced.
8474 */
8475 LineInfo _lineInfo;
8476
8477 /**
8478 * The compilation unit that was produced by parsing the source.
8479 */
8480 CompilationUnit _unit;
8481
8482 /**
8483 * The errors that were produced by scanning and parsing the source.
8484 */
8485 List<AnalysisError> _errors = AnalysisError.NO_ERRORS;
8486
8487 /**
8488 * A flag indicating whether the source contains a 'part of' directive.
8489 */
8490 bool _hasPartOfDirective2 = false;
8491
8492 /**
8493 * A flag indicating whether the source contains a 'library' directive.
8494 */
8495 bool _hasLibraryDirective2 = false;
8496
8497 /**
8498 * A set containing the sources referenced by 'export' directives.
8499 */
8500 Set<Source> _exportedSources = new Set<Source>();
8501
8502 /**
8503 * A set containing the sources referenced by 'import' directives.
8504 */
8505 Set<Source> _importedSources = new Set<Source>();
8506
8507 /**
8508 * A set containing the sources referenced by 'part' directives.
8509 */
8510 Set<Source> _includedSources = new Set<Source>();
8511
8512 /**
8513 * Initialize a newly created task to perform analysis within the given contex t.
8514 *
8515 * @param context the context in which the task is to be performed
8516 * @param source the source to be parsed
8517 */
8518 ParseDartTask(InternalAnalysisContext context, Source source) : super(context) {
8519 this._source = source;
8520 }
8521 accept(AnalysisTaskVisitor visitor) => visitor.visitParseDartTask(this);
8522
8523 /**
8524 * Return the compilation unit that was produced by parsing the source, or `nu ll` if the
8525 * task has not yet been performed or if an exception occurred.
8526 *
8527 * @return the compilation unit that was produced by parsing the source
8528 */
8529 CompilationUnit get compilationUnit => _unit;
8530
8531 /**
8532 * Return the errors that were produced by scanning and parsing the source, or `null` if the
8533 * task has not yet been performed or if an exception occurred.
8534 *
8535 * @return the errors that were produced by scanning and parsing the source
8536 */
8537 List<AnalysisError> get errors => _errors;
8538
8539 /**
8540 * Return an array containing the sources referenced by 'export' directives, o r an empty array if
8541 * the task has not yet been performed or if an exception occurred.
8542 *
8543 * @return an array containing the sources referenced by 'export' directives
8544 */
8545 List<Source> get exportedSources => toArray(_exportedSources);
8546
8547 /**
8548 * Return an array containing the sources referenced by 'import' directives, o r an empty array if
8549 * the task has not yet been performed or if an exception occurred.
8550 *
8551 * @return an array containing the sources referenced by 'import' directives
8552 */
8553 List<Source> get importedSources => toArray(_importedSources);
8554
8555 /**
8556 * Return an array containing the sources referenced by 'part' directives, or an empty array if
8557 * the task has not yet been performed or if an exception occurred.
8558 *
8559 * @return an array containing the sources referenced by 'part' directives
8560 */
8561 List<Source> get includedSources => toArray(_includedSources);
8562
8563 /**
8564 * Return the line information that was produced, or `null` if the task has no t yet been
8565 * performed or if an exception occurred.
8566 *
8567 * @return the line information that was produced
8568 */
8569 LineInfo get lineInfo => _lineInfo;
8570
8571 /**
8572 * Return the time at which the contents of the source that was parsed were la st modified, or a
8573 * negative value if the task has not yet been performed or if an exception oc curred.
8574 *
8575 * @return the time at which the contents of the source that was parsed were l ast modified
8576 */
8577 int get modificationTime => _modificationTime;
8578
8579 /**
8580 * Return the source that is to be parsed.
8581 *
8582 * @return the source to be parsed
8583 */
8584 Source get source => _source;
8585
8586 /**
8587 * Return `true` if the source contains a 'library' directive, or `false` if t he task
8588 * has not yet been performed or if an exception occurred.
8589 *
8590 * @return `true` if the source contains a 'library' directive
8591 */
8592 bool hasLibraryDirective() => _hasLibraryDirective2;
8593
8594 /**
8595 * Return `true` if the source contains a 'part of' directive, or `false` if t he task
8596 * has not yet been performed or if an exception occurred.
8597 *
8598 * @return `true` if the source contains a 'part of' directive
8599 */
8600 bool hasPartOfDirective() => _hasPartOfDirective2;
8601 String get taskDescription => "parse as dart ${_source.fullName}";
8602 void internalPerform() {
8603 RecordingErrorListener errorListener = new RecordingErrorListener();
8604 List<Token> token = [null];
8605 Source_ContentReceiver receiver = new Source_ContentReceiver_10(this, errorL istener, token);
8606 try {
8607 _source.getContents(receiver);
8608 } catch (exception) {
8609 _modificationTime = _source.modificationStamp;
8610 throw new AnalysisException.con3(exception);
8611 }
8612 Parser parser = new Parser(_source, errorListener);
8613 _unit = parser.parseCompilationUnit(token[0]);
8614 _errors = errorListener.getErrors2(_source);
8615 for (Directive directive in _unit.directives) {
8616 if (directive is ExportDirective) {
8617 Source exportSource = resolveSource(_source, directive as ExportDirectiv e);
8618 if (exportSource != null) {
8619 javaSetAdd(_exportedSources, exportSource);
8620 }
8621 } else if (directive is ImportDirective) {
8622 Source importSource = resolveSource(_source, directive as ImportDirectiv e);
8623 if (importSource != null) {
8624 javaSetAdd(_importedSources, importSource);
8625 }
8626 } else if (directive is LibraryDirective) {
8627 _hasLibraryDirective2 = true;
8628 } else if (directive is PartDirective) {
8629 Source partSource = resolveSource(_source, directive as PartDirective);
8630 if (partSource != null) {
8631 javaSetAdd(_includedSources, partSource);
8632 }
8633 } else if (directive is PartOfDirective) {
8634 _hasPartOfDirective2 = true;
8635 }
8636 }
8637 _unit.parsingErrors = _errors;
8638 _unit.lineInfo = _lineInfo;
8639 }
8640
8641 /**
8642 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
8643 * given library, or `null` if the URI is not valid.
8644 *
8645 * @param librarySource the source representing the library containing the dir ective
8646 * @param directive the directive which URI should be resolved
8647 * @return the result of resolving the URI against the URI of the library
8648 */
8649 Source resolveSource(Source librarySource, UriBasedDirective directive) {
8650 StringLiteral uriLiteral = directive.uri;
8651 if (uriLiteral is StringInterpolation) {
8652 return null;
8653 }
8654 String uriContent = uriLiteral.stringValue.trim();
8655 if (uriContent == null) {
8656 return null;
8657 }
8658 uriContent = Uri.encodeFull(uriContent);
8659 try {
8660 parseUriWithException(uriContent);
8661 return context.sourceFactory.resolveUri(librarySource, uriContent);
8662 } on URISyntaxException catch (exception) {
8663 return null;
8664 }
8665 }
8666
8667 /**
8668 * Efficiently convert the given set of sources to an array.
8669 *
8670 * @param sources the set to be converted
8671 * @return an array containing all of the sources in the given set
8672 */
8673 List<Source> toArray(Set<Source> sources) {
8674 int size = sources.length;
8675 if (size == 0) {
8676 return Source.EMPTY_ARRAY;
8677 }
8678 return new List.from(sources);
8679 }
8680 }
8681 class Source_ContentReceiver_10 implements Source_ContentReceiver {
8682 final ParseDartTask ParseDartTask_this;
8683 RecordingErrorListener errorListener;
8684 List<Token> token;
8685 Source_ContentReceiver_10(this.ParseDartTask_this, this.errorListener, this.to ken);
8686 void accept(CharBuffer contents, int modificationTime2) {
8687 ParseDartTask_this._modificationTime = modificationTime2;
8688 CharBufferScanner scanner = new CharBufferScanner(ParseDartTask_this._source , contents, errorListener);
8689 token[0] = scanner.tokenize();
8690 ParseDartTask_this._lineInfo = new LineInfo(scanner.lineStarts);
8691 }
8692 void accept2(String contents, int modificationTime2) {
8693 ParseDartTask_this._modificationTime = modificationTime2;
8694 StringScanner scanner = new StringScanner(ParseDartTask_this._source, conten ts, errorListener);
8695 token[0] = scanner.tokenize();
8696 ParseDartTask_this._lineInfo = new LineInfo(scanner.lineStarts);
8697 }
8698 }
8699 /**
8700 * Instances of the class `ParseHtmlTask` parse a specific source as an HTML fil e.
8701 */
8702 class ParseHtmlTask extends AnalysisTask {
8703
8704 /**
8705 * The source to be parsed.
8706 */
8707 Source _source;
8708
8709 /**
8710 * The time at which the contents of the source were last modified.
8711 */
8712 int _modificationTime = -1;
8713
8714 /**
8715 * The line information that was produced.
8716 */
8717 LineInfo _lineInfo;
8718
8719 /**
8720 * The HTML unit that was produced by parsing the source.
8721 */
8722 HtmlUnit _unit;
8723
8724 /**
8725 * An array containing the sources of the libraries that are referenced within the HTML.
8726 */
8727 List<Source> _referencedLibraries = Source.EMPTY_ARRAY;
8728
8729 /**
8730 * The name of the 'src' attribute in a HTML tag.
8731 */
8732 static String _ATTRIBUTE_SRC = "src";
8733
8734 /**
8735 * The name of the 'type' attribute in a HTML tag.
8736 */
8737 static String _ATTRIBUTE_TYPE = "type";
8738
8739 /**
8740 * The name of the 'script' tag in an HTML file.
8741 */
8742 static String _TAG_SCRIPT = "script";
8743
8744 /**
8745 * The value of the 'type' attribute of a 'script' tag that indicates that the script is written
8746 * in Dart.
8747 */
8748 static String _TYPE_DART = "application/dart";
8749
8750 /**
8751 * Initialize a newly created task to perform analysis within the given contex t.
8752 *
8753 * @param context the context in which the task is to be performed
8754 * @param source the source to be parsed
8755 */
8756 ParseHtmlTask(InternalAnalysisContext context, Source source) : super(context) {
8757 this._source = source;
8758 }
8759 accept(AnalysisTaskVisitor visitor) => visitor.visitParseHtmlTask(this);
8760
8761 /**
8762 * Return the HTML unit that was produced by parsing the source.
8763 *
8764 * @return the HTML unit that was produced by parsing the source
8765 */
8766 HtmlUnit get htmlUnit => _unit;
8767
8768 /**
8769 * Return the line information that was produced, or `null` if the task has no t yet been
8770 * performed or if an exception occurred.
8771 *
8772 * @return the line information that was produced
8773 */
8774 LineInfo get lineInfo => _lineInfo;
8775
8776 /**
8777 * Return the time at which the contents of the source that was parsed were la st modified, or a
8778 * negative value if the task has not yet been performed or if an exception oc curred.
8779 *
8780 * @return the time at which the contents of the source that was parsed were l ast modified
8781 */
8782 int get modificationTime => _modificationTime;
8783
8784 /**
8785 * Return an array containing the sources of the libraries that are referenced within the HTML.
8786 *
8787 * @return the sources of the libraries that are referenced within the HTML
8788 */
8789 List<Source> get referencedLibraries => _referencedLibraries;
8790
8791 /**
8792 * Return the source that was or is to be parsed.
8793 *
8794 * @return the source was or is to be parsed
8795 */
8796 Source get source => _source;
8797 String get taskDescription => "parse as html ${_source.fullName}";
8798 void internalPerform() {
8799 HtmlScanner scanner = new HtmlScanner(_source);
8800 try {
8801 _source.getContents(scanner);
8802 } catch (exception) {
8803 throw new AnalysisException.con3(exception);
8804 }
8805 HtmlScanResult scannerResult = scanner.result;
8806 _modificationTime = scannerResult.modificationTime;
8807 _lineInfo = new LineInfo(scannerResult.lineStarts);
8808 HtmlParseResult result = new HtmlParser(_source).parse(scannerResult);
8809 _unit = result.htmlUnit;
8810 _referencedLibraries = librarySources;
8811 }
8812
8813 /**
8814 * Return the sources of libraries that are referenced in the specified HTML f ile.
8815 *
8816 * @return the sources of libraries that are referenced in the HTML file
8817 */
8818 List<Source> get librarySources {
8819 List<Source> libraries = new List<Source>();
8820 _unit.accept(new RecursiveXmlVisitor_11(this, libraries));
8821 if (libraries.isEmpty) {
8822 return Source.EMPTY_ARRAY;
8823 }
8824 return new List.from(libraries);
8825 }
8826 }
8827 class RecursiveXmlVisitor_11 extends RecursiveXmlVisitor<Object> {
8828 final ParseHtmlTask ParseHtmlTask_this;
8829 List<Source> libraries;
8830 RecursiveXmlVisitor_11(this.ParseHtmlTask_this, this.libraries) : super();
8831 Object visitXmlTagNode(XmlTagNode node) {
8832 if (javaStringEqualsIgnoreCase(node.tag.lexeme, ParseHtmlTask._TAG_SCRIPT)) {
8833 bool isDartScript = false;
8834 XmlAttributeNode scriptAttribute = null;
8835 for (XmlAttributeNode attribute in node.attributes) {
8836 if (javaStringEqualsIgnoreCase(attribute.name.lexeme, ParseHtmlTask._ATT RIBUTE_SRC)) {
8837 scriptAttribute = attribute;
8838 } else if (javaStringEqualsIgnoreCase(attribute.name.lexeme, ParseHtmlTa sk._ATTRIBUTE_TYPE)) {
8839 if (javaStringEqualsIgnoreCase(attribute.text, ParseHtmlTask._TYPE_DAR T)) {
8840 isDartScript = true;
8841 }
8842 }
8843 }
8844 if (isDartScript && scriptAttribute != null) {
8845 try {
8846 Uri uri = new Uri(path: scriptAttribute.text);
8847 String fileName = uri.path;
8848 Source librarySource = ParseHtmlTask_this.context.sourceFactory.resolv eUri(ParseHtmlTask_this._source, fileName);
8849 if (librarySource.exists()) {
8850 libraries.add(librarySource);
8851 }
8852 } catch (exception) {
8853 AnalysisEngine.instance.logger.logInformation2("Invalid URL ('${script Attribute.text}') in script tag in '${ParseHtmlTask_this._source.fullName}'", ex ception);
8854 }
8855 }
8856 }
8857 return super.visitXmlTagNode(node);
8858 }
8859 }
8860 /**
8861 * Instances of the class `ResolveDartLibraryTask` parse a specific Dart library .
8862 */
8863 class ResolveDartLibraryTask extends AnalysisTask {
8864
8865 /**
8866 * The source representing the file whose compilation unit is to be returned.
8867 */
8868 Source _unitSource;
8869
8870 /**
8871 * The source representing the library to be resolved.
8872 */
8873 Source _librarySource;
8874
8875 /**
8876 * The library resolver holding information about the libraries that were reso lved.
8877 */
8878 LibraryResolver _resolver;
8879
8880 /**
8881 * Initialize a newly created task to perform analysis within the given contex t.
8882 *
8883 * @param context the context in which the task is to be performed
8884 * @param unitSource the source representing the file whose compilation unit i s to be returned
8885 * @param librarySource the source representing the library to be resolved
8886 */
8887 ResolveDartLibraryTask(InternalAnalysisContext context, Source unitSource, Sou rce librarySource) : super(context) {
8888 this._unitSource = unitSource;
8889 this._librarySource = librarySource;
8890 }
8891 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveDartLibraryTask(thi s);
8892
8893 /**
8894 * Return the library resolver holding information about the libraries that we re resolved.
8895 *
8896 * @return the library resolver holding information about the libraries that w ere resolved
8897 */
8898 LibraryResolver get libraryResolver => _resolver;
8899
8900 /**
8901 * Return the source representing the library to be resolved.
8902 *
8903 * @return the source representing the library to be resolved
8904 */
8905 Source get librarySource => _librarySource;
8906
8907 /**
8908 * Return the source representing the file whose compilation unit is to be ret urned.
8909 *
8910 * @return the source representing the file whose compilation unit is to be re turned
8911 */
8912 Source get unitSource => _unitSource;
8913 String get taskDescription => "resolve library ${_librarySource.fullName}";
8914 void internalPerform() {
8915 _resolver = new LibraryResolver(context);
8916 _resolver.resolveLibrary(_librarySource, true);
8917 }
8918 }
8919 /**
8920 * Instances of the class `ResolveDartUnitTask` resolve a single Dart file based on a existing
8921 * element model.
8922 */
8923 class ResolveDartUnitTask extends AnalysisTask {
8924
8925 /**
8926 * The source that is to be resolved.
8927 */
8928 Source _source;
8929
8930 /**
8931 * The element model for the library containing the source.
8932 */
8933 LibraryElement _libraryElement;
8934
8935 /**
8936 * The time at which the contents of the source were last modified.
8937 */
8938 int _modificationTime = -1;
8939
8940 /**
8941 * The compilation unit that was resolved by this task.
8942 */
8943 CompilationUnit _resolvedUnit;
8944
8945 /**
8946 * Initialize a newly created task to perform analysis within the given contex t.
8947 *
8948 * @param context the context in which the task is to be performed
8949 * @param source the source to be parsed
8950 * @param libraryElement the element model for the library containing the sour ce
8951 */
8952 ResolveDartUnitTask(InternalAnalysisContext context, Source source, LibraryEle ment libraryElement) : super(context) {
8953 this._source = source;
8954 this._libraryElement = libraryElement;
8955 }
8956 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveDartUnitTask(this);
8957
8958 /**
8959 * Return the source for the library containing the source that is to be resol ved.
8960 *
8961 * @return the source for the library containing the source that is to be reso lved
8962 */
8963 Source get librarySource => _libraryElement.source;
8964
8965 /**
8966 * Return the time at which the contents of the source that was parsed were la st modified, or a
8967 * negative value if the task has not yet been performed or if an exception oc curred.
8968 *
8969 * @return the time at which the contents of the source that was parsed were l ast modified
8970 */
8971 int get modificationTime => _modificationTime;
8972
8973 /**
8974 * Return the compilation unit that was resolved by this task.
8975 *
8976 * @return the compilation unit that was resolved by this task
8977 */
8978 CompilationUnit get resolvedUnit => _resolvedUnit;
8979
8980 /**
8981 * Return the source that is to be resolved.
8982 *
8983 * @return the source to be resolved
8984 */
8985 Source get source => _source;
8986 String get taskDescription => "resolve unit ${_libraryElement.source.fullName} ";
8987 void internalPerform() {
8988 Source coreLibrarySource = _libraryElement.context.sourceFactory.forUri(Dart Sdk.DART_CORE);
8989 LibraryElement coreElement = context.computeLibraryElement(coreLibrarySource );
8990 TypeProvider typeProvider = new TypeProviderImpl(coreElement);
8991 ResolvableCompilationUnit resolvableUnit = context.computeResolvableCompilat ionUnit(_source);
8992 _modificationTime = resolvableUnit.modificationTime;
8993 CompilationUnit unit = resolvableUnit.compilationUnit;
8994 if (unit == null) {
8995 throw new AnalysisException.con1("Internal error: computeResolvableCompila tionUnit returned a value without a parsed Dart unit");
8996 }
8997 new DeclarationResolver().resolve(unit, find(_libraryElement, _source));
8998 RecordingErrorListener errorListener = new RecordingErrorListener();
8999 TypeResolverVisitor typeResolverVisitor = new TypeResolverVisitor.con2(_libr aryElement, _source, typeProvider, errorListener);
9000 unit.accept(typeResolverVisitor);
9001 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt);
9002 ResolverVisitor resolverVisitor = new ResolverVisitor.con2(_libraryElement, _source, typeProvider, inheritanceManager, errorListener);
9003 unit.accept(resolverVisitor);
9004 for (ProxyConditionalAnalysisError conditionalCode in resolverVisitor.proxyC onditionalAnalysisErrors) {
9005 if (conditionalCode.shouldIncludeErrorCode()) {
9006 resolverVisitor.reportError(conditionalCode.analysisError);
9007 }
9008 }
9009 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source);
9010 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, _libraryEleme nt, typeProvider, inheritanceManager);
9011 unit.accept(errorVerifier);
9012 ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, type Provider);
9013 unit.accept(constantVerifier);
9014 unit.resolutionErrors = errorListener.errors;
9015 _resolvedUnit = unit;
9016 }
9017
9018 /**
9019 * Search the compilation units that are part of the given library and return the element
9020 * representing the compilation unit with the given source. Return `null` if t here is no
9021 * such compilation unit.
9022 *
9023 * @param libraryElement the element representing the library being searched t hrough
9024 * @param unitSource the source for the compilation unit whose element is to b e returned
9025 * @return the element representing the compilation unit
9026 */
9027 CompilationUnitElement find(LibraryElement libraryElement, Source unitSource) {
9028 CompilationUnitElement element = libraryElement.definingCompilationUnit;
9029 if (element.source == unitSource) {
9030 return element;
9031 }
9032 for (CompilationUnitElement partElement in libraryElement.parts) {
9033 if (partElement.source == unitSource) {
9034 return partElement;
9035 }
9036 }
9037 return null;
9038 }
9039 }
9040 /**
9041 * Instances of the class `ResolveHtmlTask` resolve a specific source as an HTML file.
9042 */
9043 class ResolveHtmlTask extends AnalysisTask {
9044
9045 /**
9046 * The source to be resolved.
9047 */
9048 Source _source;
9049
9050 /**
9051 * The time at which the contents of the source were last modified.
9052 */
9053 int _modificationTime = -1;
9054
9055 /**
9056 * The element produced by resolving the source.
9057 */
9058 HtmlElement _element = null;
9059
9060 /**
9061 * The resolution errors that were discovered while resolving the source.
9062 */
9063 List<AnalysisError> _resolutionErrors = AnalysisError.NO_ERRORS;
9064
9065 /**
9066 * Initialize a newly created task to perform analysis within the given contex t.
9067 *
9068 * @param context the context in which the task is to be performed
9069 * @param source the source to be resolved
9070 */
9071 ResolveHtmlTask(InternalAnalysisContext context, Source source) : super(contex t) {
9072 this._source = source;
9073 }
9074 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveHtmlTask(this);
9075 HtmlElement get element => _element;
9076
9077 /**
9078 * Return the time at which the contents of the source that was parsed were la st modified, or a
9079 * negative value if the task has not yet been performed or if an exception oc curred.
9080 *
9081 * @return the time at which the contents of the source that was parsed were l ast modified
9082 */
9083 int get modificationTime => _modificationTime;
9084 List<AnalysisError> get resolutionErrors => _resolutionErrors;
9085
9086 /**
9087 * Return the source that was or is to be resolved.
9088 *
9089 * @return the source was or is to be resolved
9090 */
9091 Source get source => _source;
9092 String get taskDescription => "resolve as html ${_source.fullName}";
9093 void internalPerform() {
9094 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(_s ource);
9095 HtmlUnit unit = resolvableHtmlUnit.compilationUnit;
9096 if (unit == null) {
9097 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit");
9098 }
9099 _modificationTime = resolvableHtmlUnit.modificationTime;
9100 HtmlUnitBuilder builder = new HtmlUnitBuilder(context);
9101 _element = builder.buildHtmlElement2(_source, _modificationTime, unit);
9102 _resolutionErrors = builder.errorListener.getErrors2(_source);
9103 }
6101 } 9104 }
6102 /** 9105 /**
6103 * The interface `Logger` defines the behavior of objects that can be used to re ceive 9106 * The interface `Logger` defines the behavior of objects that can be used to re ceive
6104 * information about errors within the analysis engine. Implementations usually write this 9107 * information about errors within the analysis engine. Implementations usually write this
6105 * information to a file, but can also record the information for later use (suc h as during testing) 9108 * information to a file, but can also record the information for later use (suc h as during testing)
6106 * or even ignore the information. 9109 * or even ignore the information.
6107 * 9110 *
6108 * @coverage dart.engine.utilities 9111 * @coverage dart.engine.utilities
6109 */ 9112 */
6110 abstract class Logger { 9113 abstract class Logger {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6156 } 9159 }
6157 void logError2(String message, Exception exception) { 9160 void logError2(String message, Exception exception) {
6158 } 9161 }
6159 void logError3(Exception exception) { 9162 void logError3(Exception exception) {
6160 } 9163 }
6161 void logInformation(String message) { 9164 void logInformation(String message) {
6162 } 9165 }
6163 void logInformation2(String message, Exception exception) { 9166 void logInformation2(String message, Exception exception) {
6164 } 9167 }
6165 } 9168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698