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

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

Issue 137143010: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine; 8 library engine;
9 9
10 import 'java_core.dart'; 10 import 'java_core.dart';
11 import 'java_engine.dart'; 11 import 'java_engine.dart';
12 import 'utilities_collection.dart'; 12 import 'utilities_collection.dart';
13 import 'utilities_general.dart'; 13 import 'utilities_general.dart';
14 import 'instrumentation.dart'; 14 import 'instrumentation.dart';
15 import 'error.dart'; 15 import 'error.dart';
16 import 'source.dart'; 16 import 'source.dart';
17 import 'scanner.dart' show Token, Scanner, CharSequenceReader, CharacterReader, IncrementalScanner; 17 import 'scanner.dart';
18 import 'ast.dart'; 18 import 'ast.dart';
19 import 'parser.dart' show Parser, IncrementalParser; 19 import 'parser.dart' show Parser, IncrementalParser;
20 import 'sdk.dart' show DartSdk; 20 import 'sdk.dart' show DartSdk;
21 import 'element.dart'; 21 import 'element.dart';
22 import 'resolver.dart'; 22 import 'resolver.dart';
23 import 'html.dart' show XmlTagNode, XmlAttributeNode, RecursiveXmlVisitor, HtmlS canner, HtmlScanResult, HtmlParser, HtmlParseResult, HtmlScriptTagNode, HtmlUnit ; 23 import 'html.dart' as ht;
24 24
25 /** 25 /**
26 * The unique instance of the class `AnalysisEngine` serves as the entry point f or the 26 * The unique instance of the class `AnalysisEngine` serves as the entry point f or the
27 * functionality provided by the analysis engine. 27 * functionality provided by the analysis engine.
28 * 28 *
29 * @coverage dart.engine 29 * @coverage dart.engine
30 */ 30 */
31 class AnalysisEngine { 31 class AnalysisEngine {
32 /** 32 /**
33 * The suffix used for Dart source files. 33 * The suffix used for Dart source files.
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 * Return the sources for the defining compilation units of any libraries that depend on the given 401 * Return the sources for the defining compilation units of any libraries that depend on the given
402 * library. One library depends on another if it either imports or exports tha t library. 402 * library. One library depends on another if it either imports or exports tha t library.
403 * 403 *
404 * @param librarySource the source for the defining compilation unit of the li brary being depended 404 * @param librarySource the source for the defining compilation unit of the li brary being depended
405 * on 405 * on
406 * @return the sources for the libraries that depend on the given library 406 * @return the sources for the libraries that depend on the given library
407 */ 407 */
408 List<Source> getLibrariesDependingOn(Source librarySource); 408 List<Source> getLibrariesDependingOn(Source librarySource);
409 409
410 /** 410 /**
411 * Return the [AngularElement]s accessible in the library defined by the given source, or an
412 * empty array if given source is not a library, not resolved or cannot be ana lyzed for some
413 * reason.
414 *
415 * @param source the source defining the library whose [AngularElement]s is to be returned
416 * @return the [AngularElement]s accessible in the library defined by the give n source
417 */
418 List<AngularElement> getLibraryAngularElements(Source source);
419
420 /**
411 * Return the element model corresponding to the library defined by the given source, or 421 * Return the element model corresponding to the library defined by the given source, or
412 * `null` if the element model does not currently exist or if the library cann ot be analyzed 422 * `null` if the element model does not currently exist or if the library cann ot be analyzed
413 * for some reason. 423 * for some reason.
414 * 424 *
415 * @param source the source defining the library whose element model is to be returned 425 * @param source the source defining the library whose element model is to be returned
416 * @return the element model corresponding to the library defined by the given source 426 * @return the element model corresponding to the library defined by the given source
417 */ 427 */
418 LibraryElement getLibraryElement(Source source); 428 LibraryElement getLibraryElement(Source source);
419 429
420 /** 430 /**
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource); 480 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource);
471 481
472 /** 482 /**
473 * Return a fully resolved HTML unit, or `null` if the resolved unit is not al ready 483 * Return a fully resolved HTML unit, or `null` if the resolved unit is not al ready
474 * computed. 484 * computed.
475 * 485 *
476 * @param htmlSource the source of the HTML unit 486 * @param htmlSource the source of the HTML unit
477 * @return a fully resolved HTML unit 487 * @return a fully resolved HTML unit
478 * @see #resolveHtmlUnit(Source) 488 * @see #resolveHtmlUnit(Source)
479 */ 489 */
480 HtmlUnit getResolvedHtmlUnit(Source htmlSource); 490 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource);
481 491
482 /** 492 /**
483 * Return the source factory used to create the sources that can be analyzed i n this context. 493 * Return the source factory used to create the sources that can be analyzed i n this context.
484 * 494 *
485 * @return the source factory used to create the sources that can be analyzed in this context 495 * @return the source factory used to create the sources that can be analyzed in this context
486 */ 496 */
487 SourceFactory get sourceFactory; 497 SourceFactory get sourceFactory;
488 498
489 /** 499 /**
490 * Return `true` if the given source is known to be the defining compilation u nit of a 500 * Return `true` if the given source is known to be the defining compilation u nit of a
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 545
536 /** 546 /**
537 * Parse a single HTML source to produce an AST structure. The resulting HTML AST structure may or 547 * Parse a single HTML source to produce an AST structure. The resulting HTML AST structure may or
538 * may not be resolved, and may have a slightly different structure depending upon whether it is 548 * may not be resolved, and may have a slightly different structure depending upon whether it is
539 * resolved. 549 * resolved.
540 * 550 *
541 * @param source the HTML source to be parsed 551 * @param source the HTML source to be parsed
542 * @return the parse result (not `null`) 552 * @return the parse result (not `null`)
543 * @throws AnalysisException if the analysis could not be performed 553 * @throws AnalysisException if the analysis could not be performed
544 */ 554 */
545 HtmlUnit parseHtmlUnit(Source source); 555 ht.HtmlUnit parseHtmlUnit(Source source);
546 556
547 /** 557 /**
548 * Perform the next unit of work required to keep the analysis results up-to-d ate and return 558 * Perform the next unit of work required to keep the analysis results up-to-d ate and return
549 * information about the consequent changes to the analysis results. This meth od can be long 559 * information about the consequent changes to the analysis results. This meth od can be long
550 * running. 560 * running.
551 * 561 *
552 * @return the results of performing the analysis 562 * @return the results of performing the analysis
553 */ 563 */
554 AnalysisResult performAnalysisTask(); 564 AnalysisResult performAnalysisTask();
555 565
(...skipping 24 matching lines...) Expand all
580 */ 590 */
581 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e); 591 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e);
582 592
583 /** 593 /**
584 * Parse and resolve a single source within the given context to produce a ful ly resolved AST. 594 * Parse and resolve a single source within the given context to produce a ful ly resolved AST.
585 * 595 *
586 * @param htmlSource the source to be parsed and resolved 596 * @param htmlSource the source to be parsed and resolved
587 * @return the result of resolving the AST structure representing the content of the source 597 * @return the result of resolving the AST structure representing the content of the source
588 * @throws AnalysisException if the analysis could not be performed 598 * @throws AnalysisException if the analysis could not be performed
589 */ 599 */
590 HtmlUnit resolveHtmlUnit(Source htmlSource); 600 ht.HtmlUnit resolveHtmlUnit(Source htmlSource);
591 601
592 /** 602 /**
593 * Set the set of analysis options controlling the behavior of this context to the given options. 603 * Set the set of analysis options controlling the behavior of this context to the given options.
594 * Clients can safely assume that all necessary analysis results have been inv alidated. 604 * Clients can safely assume that all necessary analysis results have been inv alidated.
595 * 605 *
596 * @param options the set of analysis options that will control the behavior o f this context 606 * @param options the set of analysis options that will control the behavior o f this context
597 */ 607 */
598 void set analysisOptions(AnalysisOptions options); 608 void set analysisOptions(AnalysisOptions options);
599 609
600 /** 610 /**
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 * @return the fully resolved AST that changed as a result of the analysis 828 * @return the fully resolved AST that changed as a result of the analysis
819 */ 829 */
820 CompilationUnit get compilationUnit; 830 CompilationUnit get compilationUnit;
821 831
822 /** 832 /**
823 * Return the fully resolved HTML that changed as a result of the analysis, or `null` if the 833 * Return the fully resolved HTML that changed as a result of the analysis, or `null` if the
824 * HTML was not changed. 834 * HTML was not changed.
825 * 835 *
826 * @return the fully resolved HTML that changed as a result of the analysis 836 * @return the fully resolved HTML that changed as a result of the analysis
827 */ 837 */
828 HtmlUnit get htmlUnit; 838 ht.HtmlUnit get htmlUnit;
829 839
830 /** 840 /**
831 * Return the source for which the result is being reported. 841 * Return the source for which the result is being reported.
832 * 842 *
833 * @return the source for which the result is being reported 843 * @return the source for which the result is being reported
834 */ 844 */
835 Source get source; 845 Source get source;
836 } 846 }
837 847
838 /** 848 /**
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 */ 1048 */
1039 SourceEntry get(Source source) => _sourceMap[source]; 1049 SourceEntry get(Source source) => _sourceMap[source];
1040 1050
1041 /** 1051 /**
1042 * Associate the given entry with the given source. 1052 * Associate the given entry with the given source.
1043 * 1053 *
1044 * @param source the source with which the entry is to be associated 1054 * @param source the source with which the entry is to be associated
1045 * @param entry the entry to be associated with the source 1055 * @param entry the entry to be associated with the source
1046 */ 1056 */
1047 void put(Source source, SourceEntry entry) { 1057 void put(Source source, SourceEntry entry) {
1058 (entry as SourceEntryImpl).fixExceptionState();
1048 _sourceMap[source] = entry; 1059 _sourceMap[source] = entry;
1049 } 1060 }
1050 1061
1051 /** 1062 /**
1052 * Remove all information related to the given source from this cache. 1063 * Remove all information related to the given source from this cache.
1053 * 1064 *
1054 * @param source the source to be removed 1065 * @param source the source to be removed
1055 */ 1066 */
1056 void remove(Source source) { 1067 void remove(Source source) {
1057 _sourceMap.remove(source); 1068 _sourceMap.remove(source);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 } 1218 }
1208 1219
1209 /** 1220 /**
1210 * The interface `DartEntry` defines the behavior of objects that maintain the i nformation 1221 * The interface `DartEntry` defines the behavior of objects that maintain the i nformation
1211 * cached by an analysis context about an individual Dart file. 1222 * cached by an analysis context about an individual Dart file.
1212 * 1223 *
1213 * @coverage dart.engine 1224 * @coverage dart.engine
1214 */ 1225 */
1215 abstract class DartEntry implements SourceEntry { 1226 abstract class DartEntry implements SourceEntry {
1216 /** 1227 /**
1228 * The data descriptor representing the Angular elements accessible in the lib rary. This data is
1229 * only available for Dart files that are the defining compilation unit of a l ibrary.
1230 */
1231 static final DataDescriptor<List<AngularElement>> ANGULAR_ELEMENTS = new DataD escriptor<List<AngularElement>>("DartEntry.ANGULAR_ELEMENTS");
1232
1233 /**
1217 * The data descriptor representing the library element for the library. This data is only 1234 * The data descriptor representing the library element for the library. This data is only
1218 * available for Dart files that are the defining compilation unit of a librar y. 1235 * available for Dart files that are the defining compilation unit of a librar y.
1219 */ 1236 */
1220 static final DataDescriptor<LibraryElement> ELEMENT = new DataDescriptor<Libra ryElement>("DartEntry.ELEMENT"); 1237 static final DataDescriptor<LibraryElement> ELEMENT = new DataDescriptor<Libra ryElement>("DartEntry.ELEMENT");
1221 1238
1222 /** 1239 /**
1223 * The data descriptor representing the list of exported libraries. This data is only available 1240 * The data descriptor representing the list of exported libraries. This data is only available
1224 * for Dart files that are the defining compilation unit of a library. 1241 * for Dart files that are the defining compilation unit of a library.
1225 */ 1242 */
1226 static final DataDescriptor<List<Source>> EXPORTED_LIBRARIES = new DataDescrip tor<List<Source>>("DartEntry.EXPORTED_LIBRARIES"); 1243 static final DataDescriptor<List<Source>> EXPORTED_LIBRARIES = new DataDescrip tor<List<Source>>("DartEntry.EXPORTED_LIBRARIES");
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 * The state of the cached library element. 1458 * The state of the cached library element.
1442 */ 1459 */
1443 CacheState _elementState = CacheState.INVALID; 1460 CacheState _elementState = CacheState.INVALID;
1444 1461
1445 /** 1462 /**
1446 * The element representing the library, or `null` if the element is not curre ntly cached. 1463 * The element representing the library, or `null` if the element is not curre ntly cached.
1447 */ 1464 */
1448 LibraryElement _element; 1465 LibraryElement _element;
1449 1466
1450 /** 1467 /**
1468 * The state of the cached [angularElements].
1469 */
1470 CacheState _angularElementsState = CacheState.INVALID;
1471
1472 /**
1473 * The array of Angular elements accessible in the library, or an empty array if the elements are
1474 * not currently cached.
1475 */
1476 List<AngularElement> _angularElements = AngularElement.EMPTY_ARRAY;
1477
1478 /**
1451 * The state of the cached public namespace. 1479 * The state of the cached public namespace.
1452 */ 1480 */
1453 CacheState _publicNamespaceState = CacheState.INVALID; 1481 CacheState _publicNamespaceState = CacheState.INVALID;
1454 1482
1455 /** 1483 /**
1456 * The public namespace of the library, or `null` if the namespace is not curr ently cached. 1484 * The public namespace of the library, or `null` if the namespace is not curr ently cached.
1457 */ 1485 */
1458 Namespace _publicNamespace; 1486 Namespace _publicNamespace;
1459 1487
1460 /** 1488 /**
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 if (identical(state._resolvedUnitState, CacheState.VALID)) { 1609 if (identical(state._resolvedUnitState, CacheState.VALID)) {
1582 return state._resolvedUnit.accept(new ASTCloner()) as CompilationUnit; 1610 return state._resolvedUnit.accept(new ASTCloner()) as CompilationUnit;
1583 } 1611 }
1584 state = state._nextState; 1612 state = state._nextState;
1585 } 1613 }
1586 ; 1614 ;
1587 return null; 1615 return null;
1588 } 1616 }
1589 1617
1590 CacheState getState(DataDescriptor descriptor) { 1618 CacheState getState(DataDescriptor descriptor) {
1591 if (identical(descriptor, DartEntry.ELEMENT)) { 1619 if (identical(descriptor, DartEntry.ANGULAR_ELEMENTS)) {
1620 return _angularElementsState;
1621 } else if (identical(descriptor, DartEntry.ELEMENT)) {
1592 return _elementState; 1622 return _elementState;
1593 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { 1623 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) {
1594 return _exportedLibrariesState; 1624 return _exportedLibrariesState;
1595 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { 1625 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) {
1596 return _importedLibrariesState; 1626 return _importedLibrariesState;
1597 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { 1627 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) {
1598 return _includedPartsState; 1628 return _includedPartsState;
1599 } else if (identical(descriptor, DartEntry.IS_CLIENT)) { 1629 } else if (identical(descriptor, DartEntry.IS_CLIENT)) {
1600 return _clientServerState; 1630 return _clientServerState;
1601 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) { 1631 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 } 1663 }
1634 ; 1664 ;
1635 if (identical(descriptor, DartEntry.RESOLUTION_ERRORS) || identical(descript or, DartEntry.RESOLVED_UNIT) || identical(descriptor, DartEntry.VERIFICATION_ERR ORS) || identical(descriptor, DartEntry.HINTS)) { 1665 if (identical(descriptor, DartEntry.RESOLUTION_ERRORS) || identical(descript or, DartEntry.RESOLVED_UNIT) || identical(descriptor, DartEntry.VERIFICATION_ERR ORS) || identical(descriptor, DartEntry.HINTS)) {
1636 return CacheState.INVALID; 1666 return CacheState.INVALID;
1637 } else { 1667 } else {
1638 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 1668 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
1639 } 1669 }
1640 } 1670 }
1641 1671
1642 Object getValue(DataDescriptor descriptor) { 1672 Object getValue(DataDescriptor descriptor) {
1643 if (identical(descriptor, DartEntry.ELEMENT)) { 1673 if (identical(descriptor, DartEntry.ANGULAR_ELEMENTS)) {
1674 return _angularElements;
1675 } else if (identical(descriptor, DartEntry.ELEMENT)) {
1644 return _element; 1676 return _element;
1645 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { 1677 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) {
1646 return _exportedLibraries; 1678 return _exportedLibraries;
1647 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { 1679 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) {
1648 return _importedLibraries; 1680 return _importedLibraries;
1649 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { 1681 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) {
1650 return _includedParts; 1682 return _includedParts;
1651 } else if (identical(descriptor, DartEntry.IS_CLIENT)) { 1683 } else if (identical(descriptor, DartEntry.IS_CLIENT)) {
1652 return BooleanArray.get2(_bitmask, _CLIENT_CODE_INDEX); 1684 return BooleanArray.get2(_bitmask, _CLIENT_CODE_INDEX);
1653 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) { 1685 } else if (identical(descriptor, DartEntry.IS_LAUNCHABLE)) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 CacheState resolvedState = state._resolvedUnitState; 1808 CacheState resolvedState = state._resolvedUnitState;
1777 if (resolvedState != CacheState.VALID && resolvedState != CacheState.FLUSH ED) { 1809 if (resolvedState != CacheState.VALID && resolvedState != CacheState.FLUSH ED) {
1778 return false; 1810 return false;
1779 } 1811 }
1780 state = state._nextState; 1812 state = state._nextState;
1781 } 1813 }
1782 return true; 1814 return true;
1783 } 1815 }
1784 1816
1785 /** 1817 /**
1818 * Record that an error occurred while attempting to resolve the directives in the source
1819 * represented by this entry.
1820 */
1821 void recordDependencyError() {
1822 _exportedLibraries = Source.EMPTY_ARRAY;
1823 _exportedLibrariesState = CacheState.ERROR;
1824 _importedLibraries = Source.EMPTY_ARRAY;
1825 _importedLibrariesState = CacheState.ERROR;
1826 _includedParts = Source.EMPTY_ARRAY;
1827 _includedPartsState = CacheState.ERROR;
1828 }
1829
1830 /**
1831 * Record that the information related to resolving dependencies for the assoc iated source is
1832 * about to be computed by the current thread.
1833 */
1834 void recordDependencyInProcess() {
1835 if (_exportedLibrariesState != CacheState.VALID) {
1836 _exportedLibrariesState = CacheState.IN_PROCESS;
1837 }
1838 if (_importedLibrariesState != CacheState.VALID) {
1839 _importedLibrariesState = CacheState.IN_PROCESS;
1840 }
1841 if (_includedPartsState != CacheState.VALID) {
1842 _includedPartsState = CacheState.IN_PROCESS;
1843 }
1844 }
1845
1846 /**
1847 * Record that an in-process dependency resolution has stopped without recordi ng results because
1848 * the results were invalidated before they could be recorded.
1849 */
1850 void recordDependencyNotInProcess() {
1851 if (identical(_exportedLibrariesState, CacheState.IN_PROCESS)) {
1852 _exportedLibrariesState = CacheState.INVALID;
1853 }
1854 if (identical(_importedLibrariesState, CacheState.IN_PROCESS)) {
1855 _importedLibrariesState = CacheState.INVALID;
1856 }
1857 if (identical(_includedPartsState, CacheState.IN_PROCESS)) {
1858 _includedPartsState = CacheState.INVALID;
1859 }
1860 }
1861
1862 /**
1786 * Record that an error occurred while attempting to scan or parse the entry r epresented by this 1863 * Record that an error occurred while attempting to scan or parse the entry r epresented by this
1787 * entry. This will set the state of all information, including any resolution -based information, 1864 * entry. This will set the state of all information, including any resolution -based information,
1788 * as being in error. 1865 * as being in error.
1789 */ 1866 */
1790 void recordParseError() { 1867 void recordParseError() {
1791 setState(SourceEntry.LINE_INFO, CacheState.ERROR); 1868 setState(SourceEntry.LINE_INFO, CacheState.ERROR);
1792 _sourceKind = SourceKind.UNKNOWN; 1869 _sourceKind = SourceKind.UNKNOWN;
1793 _sourceKindState = CacheState.ERROR; 1870 _sourceKindState = CacheState.ERROR;
1794 _parseErrors = AnalysisError.NO_ERRORS; 1871 _parseErrors = AnalysisError.NO_ERRORS;
1795 _parseErrorsState = CacheState.ERROR; 1872 _parseErrorsState = CacheState.ERROR;
1796 _parsedUnit = null; 1873 _parsedUnit = null;
1797 _parsedUnitAccessed = false; 1874 _parsedUnitAccessed = false;
1798 _parsedUnitState = CacheState.ERROR; 1875 _parsedUnitState = CacheState.ERROR;
1799 _exportedLibraries = Source.EMPTY_ARRAY; 1876 recordDependencyError();
1800 _exportedLibrariesState = CacheState.ERROR;
1801 _importedLibraries = Source.EMPTY_ARRAY;
1802 _importedLibrariesState = CacheState.ERROR;
1803 _includedParts = Source.EMPTY_ARRAY;
1804 _includedPartsState = CacheState.ERROR;
1805 recordResolutionError(); 1877 recordResolutionError();
1806 } 1878 }
1807 1879
1808 /** 1880 /**
1809 * Record that the parse-related information for the associated source is abou t to be computed by 1881 * Record that the parse-related information for the associated source is abou t to be computed by
1810 * the current thread. 1882 * the current thread.
1811 */ 1883 */
1812 void recordParseInProcess() { 1884 void recordParseInProcess() {
1813 if (getState(SourceEntry.LINE_INFO) != CacheState.VALID) { 1885 if (getState(SourceEntry.LINE_INFO) != CacheState.VALID) {
1814 setState(SourceEntry.LINE_INFO, CacheState.IN_PROCESS); 1886 setState(SourceEntry.LINE_INFO, CacheState.IN_PROCESS);
1815 } 1887 }
1816 if (_sourceKindState != CacheState.VALID) { 1888 if (_sourceKindState != CacheState.VALID) {
1817 _sourceKindState = CacheState.IN_PROCESS; 1889 _sourceKindState = CacheState.IN_PROCESS;
1818 } 1890 }
1819 if (_parseErrorsState != CacheState.VALID) { 1891 if (_parseErrorsState != CacheState.VALID) {
1820 _parseErrorsState = CacheState.IN_PROCESS; 1892 _parseErrorsState = CacheState.IN_PROCESS;
1821 } 1893 }
1822 if (_parsedUnitState != CacheState.VALID) { 1894 if (_parsedUnitState != CacheState.VALID) {
1823 _parsedUnitState = CacheState.IN_PROCESS; 1895 _parsedUnitState = CacheState.IN_PROCESS;
1824 } 1896 }
1825 if (_exportedLibrariesState != CacheState.VALID) {
1826 _exportedLibrariesState = CacheState.IN_PROCESS;
1827 }
1828 if (_importedLibrariesState != CacheState.VALID) {
1829 _importedLibrariesState = CacheState.IN_PROCESS;
1830 }
1831 if (_includedPartsState != CacheState.VALID) {
1832 _includedPartsState = CacheState.IN_PROCESS;
1833 }
1834 } 1897 }
1835 1898
1836 /** 1899 /**
1837 * Record that an in-process parse has stopped without recording results becau se the results were 1900 * Record that an in-process parse has stopped without recording results becau se the results were
1838 * invalidated before they could be recorded. 1901 * invalidated before they could be recorded.
1839 */ 1902 */
1840 void recordParseNotInProcess() { 1903 void recordParseNotInProcess() {
1841 if (identical(getState(SourceEntry.LINE_INFO), CacheState.IN_PROCESS)) { 1904 if (identical(getState(SourceEntry.LINE_INFO), CacheState.IN_PROCESS)) {
1842 setState(SourceEntry.LINE_INFO, CacheState.INVALID); 1905 setState(SourceEntry.LINE_INFO, CacheState.INVALID);
1843 } 1906 }
1844 if (identical(_sourceKindState, CacheState.IN_PROCESS)) { 1907 if (identical(_sourceKindState, CacheState.IN_PROCESS)) {
1845 _sourceKindState = CacheState.INVALID; 1908 _sourceKindState = CacheState.INVALID;
1846 } 1909 }
1847 if (identical(_parseErrorsState, CacheState.IN_PROCESS)) { 1910 if (identical(_parseErrorsState, CacheState.IN_PROCESS)) {
1848 _parseErrorsState = CacheState.INVALID; 1911 _parseErrorsState = CacheState.INVALID;
1849 } 1912 }
1850 if (identical(_parsedUnitState, CacheState.IN_PROCESS)) { 1913 if (identical(_parsedUnitState, CacheState.IN_PROCESS)) {
1851 _parsedUnitState = CacheState.INVALID; 1914 _parsedUnitState = CacheState.INVALID;
1852 } 1915 }
1853 if (identical(_exportedLibrariesState, CacheState.IN_PROCESS)) {
1854 _exportedLibrariesState = CacheState.INVALID;
1855 }
1856 if (identical(_importedLibrariesState, CacheState.IN_PROCESS)) {
1857 _importedLibrariesState = CacheState.INVALID;
1858 }
1859 if (identical(_includedPartsState, CacheState.IN_PROCESS)) {
1860 _includedPartsState = CacheState.INVALID;
1861 }
1862 } 1916 }
1863 1917
1864 /** 1918 /**
1865 * Record that an error occurred while attempting to scan or parse the entry r epresented by this 1919 * Record that an error occurred while attempting to scan or parse the entry r epresented by this
1866 * entry. This will set the state of all resolution-based information as being in error, but will 1920 * entry. This will set the state of all resolution-based information as being in error, but will
1867 * not change the state of any parse results. 1921 * not change the state of any parse results.
1868 */ 1922 */
1869 void recordResolutionError() { 1923 void recordResolutionError() {
1924 _angularElements = AngularElement.EMPTY_ARRAY;
1925 _angularElementsState = CacheState.ERROR;
1870 _element = null; 1926 _element = null;
1871 _elementState = CacheState.ERROR; 1927 _elementState = CacheState.ERROR;
1872 _bitmask = 0; 1928 _bitmask = 0;
1873 _clientServerState = CacheState.ERROR; 1929 _clientServerState = CacheState.ERROR;
1874 _launchableState = CacheState.ERROR; 1930 _launchableState = CacheState.ERROR;
1875 _publicNamespace = null; 1931 _publicNamespace = null;
1876 _publicNamespaceState = CacheState.ERROR; 1932 _publicNamespaceState = CacheState.ERROR;
1877 _resolutionState.recordResolutionError(); 1933 _resolutionState.recordResolutionError();
1878 } 1934 }
1879 1935
1880 /** 1936 /**
1881 * Record that an in-process parse has stopped without recording results becau se the results were 1937 * Record that an in-process parse has stopped without recording results becau se the results were
1882 * invalidated before they could be recorded. 1938 * invalidated before they could be recorded.
1883 */ 1939 */
1884 void recordResolutionNotInProcess() { 1940 void recordResolutionNotInProcess() {
1941 if (identical(_angularElementsState, CacheState.IN_PROCESS)) {
1942 _angularElementsState = CacheState.INVALID;
1943 }
1885 if (identical(_elementState, CacheState.IN_PROCESS)) { 1944 if (identical(_elementState, CacheState.IN_PROCESS)) {
1886 _elementState = CacheState.INVALID; 1945 _elementState = CacheState.INVALID;
1887 } 1946 }
1888 if (identical(_clientServerState, CacheState.IN_PROCESS)) { 1947 if (identical(_clientServerState, CacheState.IN_PROCESS)) {
1889 _clientServerState = CacheState.INVALID; 1948 _clientServerState = CacheState.INVALID;
1890 } 1949 }
1891 if (identical(_launchableState, CacheState.IN_PROCESS)) { 1950 if (identical(_launchableState, CacheState.IN_PROCESS)) {
1892 _launchableState = CacheState.INVALID; 1951 _launchableState = CacheState.INVALID;
1893 } 1952 }
1894 if (identical(_publicNamespaceState, CacheState.IN_PROCESS)) { 1953 if (identical(_publicNamespaceState, CacheState.IN_PROCESS)) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 _parsedUnitAccessed = false; 2004 _parsedUnitAccessed = false;
1946 _parsedUnitState = CacheState.VALID; 2005 _parsedUnitState = CacheState.VALID;
1947 } 2006 }
1948 if (_parseErrorsState != CacheState.VALID) { 2007 if (_parseErrorsState != CacheState.VALID) {
1949 _parseErrors = errors == null ? AnalysisError.NO_ERRORS : errors; 2008 _parseErrors = errors == null ? AnalysisError.NO_ERRORS : errors;
1950 _parseErrorsState = CacheState.VALID; 2009 _parseErrorsState = CacheState.VALID;
1951 } 2010 }
1952 } 2011 }
1953 2012
1954 void setState(DataDescriptor descriptor, CacheState state) { 2013 void setState(DataDescriptor descriptor, CacheState state) {
1955 if (identical(descriptor, DartEntry.ELEMENT)) { 2014 if (identical(descriptor, DartEntry.ANGULAR_ELEMENTS)) {
2015 _angularElements = updatedValue(state, _angularElements, AngularElement.EM PTY_ARRAY);
2016 _angularElementsState = state;
2017 } else if (identical(descriptor, DartEntry.ELEMENT)) {
1956 _element = updatedValue(state, _element, null); 2018 _element = updatedValue(state, _element, null);
1957 _elementState = state; 2019 _elementState = state;
1958 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { 2020 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) {
1959 _exportedLibraries = updatedValue(state, _exportedLibraries, Source.EMPTY_ ARRAY); 2021 _exportedLibraries = updatedValue(state, _exportedLibraries, Source.EMPTY_ ARRAY);
1960 _exportedLibrariesState = state; 2022 _exportedLibrariesState = state;
1961 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { 2023 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) {
1962 _importedLibraries = updatedValue(state, _importedLibraries, Source.EMPTY_ ARRAY); 2024 _importedLibraries = updatedValue(state, _importedLibraries, Source.EMPTY_ ARRAY);
1963 _importedLibrariesState = state; 2025 _importedLibrariesState = state;
1964 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { 2026 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) {
1965 _includedParts = updatedValue(state, _includedParts, Source.EMPTY_ARRAY); 2027 _includedParts = updatedValue(state, _includedParts, Source.EMPTY_ARRAY);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 state._verificationErrorsState = cacheState; 2075 state._verificationErrorsState = cacheState;
2014 } else if (identical(descriptor, DartEntry.HINTS)) { 2076 } else if (identical(descriptor, DartEntry.HINTS)) {
2015 state._hints = updatedValue(cacheState, state._hints, AnalysisError.NO_ERR ORS); 2077 state._hints = updatedValue(cacheState, state._hints, AnalysisError.NO_ERR ORS);
2016 state._hintsState = cacheState; 2078 state._hintsState = cacheState;
2017 } else { 2079 } else {
2018 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 2080 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
2019 } 2081 }
2020 } 2082 }
2021 2083
2022 void setValue(DataDescriptor descriptor, Object value) { 2084 void setValue(DataDescriptor descriptor, Object value) {
2023 if (identical(descriptor, DartEntry.ELEMENT)) { 2085 if (identical(descriptor, DartEntry.ANGULAR_ELEMENTS)) {
2086 _angularElements = value as List<AngularElement>;
2087 _angularElementsState = CacheState.VALID;
2088 } else if (identical(descriptor, DartEntry.ELEMENT)) {
2024 _element = value as LibraryElement; 2089 _element = value as LibraryElement;
2025 _elementState = CacheState.VALID; 2090 _elementState = CacheState.VALID;
2026 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) { 2091 } else if (identical(descriptor, DartEntry.EXPORTED_LIBRARIES)) {
2027 _exportedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>); 2092 _exportedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>);
2028 _exportedLibrariesState = CacheState.VALID; 2093 _exportedLibrariesState = CacheState.VALID;
2029 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) { 2094 } else if (identical(descriptor, DartEntry.IMPORTED_LIBRARIES)) {
2030 _importedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>); 2095 _importedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List<S ource>);
2031 _importedLibrariesState = CacheState.VALID; 2096 _importedLibrariesState = CacheState.VALID;
2032 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) { 2097 } else if (identical(descriptor, DartEntry.INCLUDED_PARTS)) {
2033 _includedParts = value == null ? Source.EMPTY_ARRAY : (value as List<Sourc e>); 2098 _includedParts = value == null ? Source.EMPTY_ARRAY : (value as List<Sourc e>);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 _exportedLibraries = other._exportedLibraries; 2163 _exportedLibraries = other._exportedLibraries;
2099 _importedLibrariesState = other._importedLibrariesState; 2164 _importedLibrariesState = other._importedLibrariesState;
2100 _importedLibraries = other._importedLibraries; 2165 _importedLibraries = other._importedLibraries;
2101 _resolutionState.copyFrom(other._resolutionState); 2166 _resolutionState.copyFrom(other._resolutionState);
2102 _elementState = other._elementState; 2167 _elementState = other._elementState;
2103 _element = other._element; 2168 _element = other._element;
2104 _publicNamespaceState = other._publicNamespaceState; 2169 _publicNamespaceState = other._publicNamespaceState;
2105 _publicNamespace = other._publicNamespace; 2170 _publicNamespace = other._publicNamespace;
2106 _clientServerState = other._clientServerState; 2171 _clientServerState = other._clientServerState;
2107 _launchableState = other._launchableState; 2172 _launchableState = other._launchableState;
2173 _angularElementsState = other._angularElementsState;
2174 _angularElements = other._angularElements;
2108 _bitmask = other._bitmask; 2175 _bitmask = other._bitmask;
2109 } 2176 }
2110 2177
2178 bool hasErrorState() => super.hasErrorState() || identical(_sourceKindState, C acheState.ERROR) || identical(_parsedUnitState, CacheState.ERROR) || identical(_ parseErrorsState, CacheState.ERROR) || identical(_importedLibrariesState, CacheS tate.ERROR) || identical(_exportedLibrariesState, CacheState.ERROR) || identical (_includedPartsState, CacheState.ERROR) || identical(_elementState, CacheState.E RROR) || identical(_angularElementsState, CacheState.ERROR) || identical(_public NamespaceState, CacheState.ERROR) || identical(_clientServerState, CacheState.ER ROR) || identical(_launchableState, CacheState.ERROR) || _resolutionState.hasErr orState();
2179
2111 void writeOn(JavaStringBuilder builder) { 2180 void writeOn(JavaStringBuilder builder) {
2112 builder.append("Dart: "); 2181 builder.append("Dart: ");
2113 super.writeOn(builder); 2182 super.writeOn(builder);
2114 builder.append("; sourceKind = "); 2183 builder.append("; sourceKind = ");
2115 builder.append(_sourceKindState); 2184 builder.append(_sourceKindState);
2116 builder.append("; parsedUnit = "); 2185 builder.append("; parsedUnit = ");
2117 builder.append(_parsedUnitState); 2186 builder.append(_parsedUnitState);
2118 builder.append(" ("); 2187 builder.append(" (");
2119 builder.append(_parsedUnitAccessed ? "T" : "F"); 2188 builder.append(_parsedUnitAccessed ? "T" : "F");
2120 builder.append("); parseErrors = "); 2189 builder.append("); parseErrors = ");
2121 builder.append(_parseErrorsState); 2190 builder.append(_parseErrorsState);
2122 builder.append("; exportedLibraries = "); 2191 builder.append("; exportedLibraries = ");
2123 builder.append(_exportedLibrariesState); 2192 builder.append(_exportedLibrariesState);
2124 builder.append("; importedLibraries = "); 2193 builder.append("; importedLibraries = ");
2125 builder.append(_importedLibrariesState); 2194 builder.append(_importedLibrariesState);
2126 builder.append("; includedParts = "); 2195 builder.append("; includedParts = ");
2127 builder.append(_includedPartsState); 2196 builder.append(_includedPartsState);
2128 builder.append("; element = "); 2197 builder.append("; element = ");
2129 builder.append(_elementState); 2198 builder.append(_elementState);
2130 builder.append("; publicNamespace = "); 2199 builder.append("; publicNamespace = ");
2131 builder.append(_publicNamespaceState); 2200 builder.append(_publicNamespaceState);
2132 builder.append("; clientServer = "); 2201 builder.append("; clientServer = ");
2133 builder.append(_clientServerState); 2202 builder.append(_clientServerState);
2134 builder.append("; launchable = "); 2203 builder.append("; launchable = ");
2135 builder.append(_launchableState); 2204 builder.append(_launchableState);
2205 builder.append("; angularElements = ");
2206 builder.append(_angularElementsState);
2136 _resolutionState.writeOn(builder); 2207 _resolutionState.writeOn(builder);
2137 } 2208 }
2138 2209
2139 /** 2210 /**
2140 * Invalidate all of the resolution information associated with the compilatio n unit. 2211 * Invalidate all of the resolution information associated with the compilatio n unit.
2141 */ 2212 */
2142 void discardCachedResolutionInformation() { 2213 void discardCachedResolutionInformation() {
2214 _angularElements = AngularElement.EMPTY_ARRAY;
2215 _angularElementsState = CacheState.INVALID;
2143 _element = null; 2216 _element = null;
2144 _elementState = CacheState.INVALID; 2217 _elementState = CacheState.INVALID;
2145 _includedParts = Source.EMPTY_ARRAY; 2218 _includedParts = Source.EMPTY_ARRAY;
2146 _includedPartsState = CacheState.INVALID; 2219 _includedPartsState = CacheState.INVALID;
2147 _exportedLibraries = Source.EMPTY_ARRAY; 2220 _exportedLibraries = Source.EMPTY_ARRAY;
2148 _exportedLibrariesState = CacheState.INVALID; 2221 _exportedLibrariesState = CacheState.INVALID;
2149 _importedLibraries = Source.EMPTY_ARRAY; 2222 _importedLibraries = Source.EMPTY_ARRAY;
2150 _importedLibrariesState = CacheState.INVALID; 2223 _importedLibrariesState = CacheState.INVALID;
2151 _bitmask = 0; 2224 _bitmask = 0;
2152 _clientServerState = CacheState.INVALID; 2225 _clientServerState = CacheState.INVALID;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 void flushAstStructures() { 2364 void flushAstStructures() {
2292 if (identical(_resolvedUnitState, CacheState.VALID)) { 2365 if (identical(_resolvedUnitState, CacheState.VALID)) {
2293 _resolvedUnitState = CacheState.FLUSHED; 2366 _resolvedUnitState = CacheState.FLUSHED;
2294 _resolvedUnit = null; 2367 _resolvedUnit = null;
2295 } 2368 }
2296 if (_nextState != null) { 2369 if (_nextState != null) {
2297 _nextState.flushAstStructures(); 2370 _nextState.flushAstStructures();
2298 } 2371 }
2299 } 2372 }
2300 2373
2374 bool hasErrorState() => identical(_resolvedUnitState, CacheState.ERROR) || ide ntical(_resolutionErrorsState, CacheState.ERROR) || identical(_verificationError sState, CacheState.ERROR) || identical(_hintsState, CacheState.ERROR) || (_nextS tate != null && _nextState.hasErrorState());
2375
2301 /** 2376 /**
2302 * Invalidate all of the resolution information associated with the compilatio n unit. 2377 * Invalidate all of the resolution information associated with the compilatio n unit.
2303 */ 2378 */
2304 void invalidateAllResolutionInformation() { 2379 void invalidateAllResolutionInformation() {
2305 _nextState = null; 2380 _nextState = null;
2306 _librarySource = null; 2381 _librarySource = null;
2307 _resolvedUnitState = CacheState.INVALID; 2382 _resolvedUnitState = CacheState.INVALID;
2308 _resolvedUnit = null; 2383 _resolvedUnit = null;
2309 _resolutionErrorsState = CacheState.INVALID; 2384 _resolutionErrorsState = CacheState.INVALID;
2310 _resolutionErrors = AnalysisError.NO_ERRORS; 2385 _resolutionErrors = AnalysisError.NO_ERRORS;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 } 2476 }
2402 2477
2403 /** 2478 /**
2404 * The interface `HtmlEntry` defines the behavior of objects that maintain the i nformation 2479 * The interface `HtmlEntry` defines the behavior of objects that maintain the i nformation
2405 * cached by an analysis context about an individual HTML file. 2480 * cached by an analysis context about an individual HTML file.
2406 * 2481 *
2407 * @coverage dart.engine 2482 * @coverage dart.engine
2408 */ 2483 */
2409 abstract class HtmlEntry implements SourceEntry { 2484 abstract class HtmlEntry implements SourceEntry {
2410 /** 2485 /**
2486 * The data descriptor representing the errors reported during Angular resolut ion.
2487 */
2488 static final DataDescriptor<List<AnalysisError>> ANGULAR_ERRORS = new DataDesc riptor<List<AnalysisError>>("HtmlEntry.ANGULAR_ERRORS");
2489
2490 /**
2411 * The data descriptor representing the HTML element. 2491 * The data descriptor representing the HTML element.
2412 */ 2492 */
2413 static final DataDescriptor<HtmlElement> ELEMENT = new DataDescriptor<HtmlElem ent>("HtmlEntry.ELEMENT"); 2493 static final DataDescriptor<HtmlElement> ELEMENT = new DataDescriptor<HtmlElem ent>("HtmlEntry.ELEMENT");
2414 2494
2415 /** 2495 /**
2416 * The data descriptor representing the hints resulting from auditing the sour ce. 2496 * The data descriptor representing the hints resulting from auditing the sour ce.
2417 */ 2497 */
2418 static final DataDescriptor<List<AnalysisError>> HINTS = new DataDescriptor<Li st<AnalysisError>>("HtmlEntry.HINTS"); 2498 static final DataDescriptor<List<AnalysisError>> HINTS = new DataDescriptor<Li st<AnalysisError>>("HtmlEntry.HINTS");
2419 2499
2420 /** 2500 /**
2421 * The data descriptor representing the errors resulting from parsing the sour ce. 2501 * The data descriptor representing the errors resulting from parsing the sour ce.
2422 */ 2502 */
2423 static final DataDescriptor<List<AnalysisError>> PARSE_ERRORS = new DataDescri ptor<List<AnalysisError>>("HtmlEntry.PARSE_ERRORS"); 2503 static final DataDescriptor<List<AnalysisError>> PARSE_ERRORS = new DataDescri ptor<List<AnalysisError>>("HtmlEntry.PARSE_ERRORS");
2424 2504
2425 /** 2505 /**
2426 * The data descriptor representing the parsed AST structure. 2506 * The data descriptor representing the parsed AST structure.
2427 */ 2507 */
2428 static final DataDescriptor<HtmlUnit> PARSED_UNIT = new DataDescriptor<HtmlUni t>("HtmlEntry.PARSED_UNIT"); 2508 static final DataDescriptor<ht.HtmlUnit> PARSED_UNIT = new DataDescriptor<ht.H tmlUnit>("HtmlEntry.PARSED_UNIT");
2429 2509
2430 /** 2510 /**
2431 * The data descriptor representing the list of referenced libraries. 2511 * The data descriptor representing the list of referenced libraries.
2432 */ 2512 */
2433 static final DataDescriptor<List<Source>> REFERENCED_LIBRARIES = new DataDescr iptor<List<Source>>("HtmlEntry.REFERENCED_LIBRARIES"); 2513 static final DataDescriptor<List<Source>> REFERENCED_LIBRARIES = new DataDescr iptor<List<Source>>("HtmlEntry.REFERENCED_LIBRARIES");
2434 2514
2435 /** 2515 /**
2436 * The data descriptor representing the errors resulting from resolving the so urce. 2516 * The data descriptor representing the errors resulting from resolving the so urce.
2437 */ 2517 */
2438 static final DataDescriptor<List<AnalysisError>> RESOLUTION_ERRORS = new DataD escriptor<List<AnalysisError>>("HtmlEntry.RESOLUTION_ERRORS"); 2518 static final DataDescriptor<List<AnalysisError>> RESOLUTION_ERRORS = new DataD escriptor<List<AnalysisError>>("HtmlEntry.RESOLUTION_ERRORS");
(...skipping 15 matching lines...) Expand all
2454 */ 2534 */
2455 class HtmlEntryImpl extends SourceEntryImpl implements HtmlEntry { 2535 class HtmlEntryImpl extends SourceEntryImpl implements HtmlEntry {
2456 /** 2536 /**
2457 * The state of the cached parsed (but not resolved) HTML unit. 2537 * The state of the cached parsed (but not resolved) HTML unit.
2458 */ 2538 */
2459 CacheState _parsedUnitState = CacheState.INVALID; 2539 CacheState _parsedUnitState = CacheState.INVALID;
2460 2540
2461 /** 2541 /**
2462 * The parsed HTML unit, or `null` if the parsed HTML unit is not currently ca ched. 2542 * The parsed HTML unit, or `null` if the parsed HTML unit is not currently ca ched.
2463 */ 2543 */
2464 HtmlUnit _parsedUnit; 2544 ht.HtmlUnit _parsedUnit;
2465 2545
2466 /** 2546 /**
2467 * The state of the cached parse errors. 2547 * The state of the cached parse errors.
2468 */ 2548 */
2469 CacheState _parseErrorsState = CacheState.INVALID; 2549 CacheState _parseErrorsState = CacheState.INVALID;
2470 2550
2471 /** 2551 /**
2472 * The errors produced while scanning and parsing the HTML, or `null` if the e rrors are not 2552 * The errors produced while scanning and parsing the HTML, or `null` if the e rrors are not
2473 * currently cached. 2553 * currently cached.
2474 */ 2554 */
(...skipping 25 matching lines...) Expand all
2500 * The state of the cached HTML element. 2580 * The state of the cached HTML element.
2501 */ 2581 */
2502 CacheState _elementState = CacheState.INVALID; 2582 CacheState _elementState = CacheState.INVALID;
2503 2583
2504 /** 2584 /**
2505 * The element representing the HTML file, or `null` if the element is not cur rently cached. 2585 * The element representing the HTML file, or `null` if the element is not cur rently cached.
2506 */ 2586 */
2507 HtmlElement _element; 2587 HtmlElement _element;
2508 2588
2509 /** 2589 /**
2590 * The state of the Angular resolution errors.
2591 */
2592 CacheState _angularErrorsState = CacheState.INVALID;
2593
2594 /**
2595 * The hints produced while performing Angular resolution, or an empty array i f the error are not
2596 * currently cached.
2597 */
2598 List<AnalysisError> _angularErrors = AnalysisError.NO_ERRORS;
2599
2600 /**
2510 * The state of the cached hints. 2601 * The state of the cached hints.
2511 */ 2602 */
2512 CacheState _hintsState = CacheState.INVALID; 2603 CacheState _hintsState = CacheState.INVALID;
2513 2604
2514 /** 2605 /**
2515 * The hints produced while auditing the compilation unit, or an empty array i f the hints are not 2606 * The hints produced while auditing the compilation unit, or an empty array i f the hints are not
2516 * currently cached. 2607 * currently cached.
2517 */ 2608 */
2518 List<AnalysisError> _hints = AnalysisError.NO_ERRORS; 2609 List<AnalysisError> _hints = AnalysisError.NO_ERRORS;
2519 2610
2520 List<AnalysisError> get allErrors { 2611 List<AnalysisError> get allErrors {
2521 List<AnalysisError> errors = new List<AnalysisError>(); 2612 List<AnalysisError> errors = new List<AnalysisError>();
2522 for (AnalysisError error in _parseErrors) { 2613 if (_parseErrors != null) {
2523 errors.add(error); 2614 for (AnalysisError error in _parseErrors) {
2615 errors.add(error);
2616 }
2524 } 2617 }
2525 for (AnalysisError error in _resolutionErrors) { 2618 if (_resolutionErrors != null) {
2526 errors.add(error); 2619 for (AnalysisError error in _resolutionErrors) {
2620 errors.add(error);
2621 }
2527 } 2622 }
2528 for (AnalysisError error in _hints) { 2623 if (_angularErrors != null) {
2529 errors.add(error); 2624 for (AnalysisError error in _angularErrors) {
2625 errors.add(error);
2626 }
2627 }
2628 if (_hints != null) {
2629 for (AnalysisError error in _hints) {
2630 errors.add(error);
2631 }
2530 } 2632 }
2531 if (errors.length == 0) { 2633 if (errors.length == 0) {
2532 return AnalysisError.NO_ERRORS; 2634 return AnalysisError.NO_ERRORS;
2533 } 2635 }
2534 return new List.from(errors); 2636 return new List.from(errors);
2535 } 2637 }
2536 2638
2537 SourceKind get kind => SourceKind.HTML; 2639 SourceKind get kind => SourceKind.HTML;
2538 2640
2539 CacheState getState(DataDescriptor descriptor) { 2641 CacheState getState(DataDescriptor descriptor) {
2540 if (identical(descriptor, HtmlEntry.ELEMENT)) { 2642 if (identical(descriptor, HtmlEntry.ANGULAR_ERRORS)) {
2643 return _angularErrorsState;
2644 } else if (identical(descriptor, HtmlEntry.ELEMENT)) {
2541 return _elementState; 2645 return _elementState;
2542 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) { 2646 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) {
2543 return _parseErrorsState; 2647 return _parseErrorsState;
2544 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { 2648 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) {
2545 return _parsedUnitState; 2649 return _parsedUnitState;
2546 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) { 2650 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) {
2547 return _referencedLibrariesState; 2651 return _referencedLibrariesState;
2548 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) { 2652 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) {
2549 return _resolutionErrorsState; 2653 return _resolutionErrorsState;
2550 } else if (identical(descriptor, HtmlEntry.HINTS)) { 2654 } else if (identical(descriptor, HtmlEntry.HINTS)) {
2551 return _hintsState; 2655 return _hintsState;
2552 } 2656 }
2553 return super.getState(descriptor); 2657 return super.getState(descriptor);
2554 } 2658 }
2555 2659
2556 Object getValue(DataDescriptor descriptor) { 2660 Object getValue(DataDescriptor descriptor) {
2557 if (identical(descriptor, HtmlEntry.ELEMENT)) { 2661 if (identical(descriptor, HtmlEntry.ANGULAR_ERRORS)) {
2662 return _angularErrors;
2663 } else if (identical(descriptor, HtmlEntry.ELEMENT)) {
2558 return _element; 2664 return _element;
2559 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) { 2665 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) {
2560 return _parseErrors; 2666 return _parseErrors;
2561 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { 2667 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) {
2562 return _parsedUnit; 2668 return _parsedUnit;
2563 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) { 2669 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) {
2564 return _referencedLibraries; 2670 return _referencedLibraries;
2565 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) { 2671 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) {
2566 return _resolutionErrors; 2672 return _resolutionErrors;
2567 } else if (identical(descriptor, HtmlEntry.HINTS)) { 2673 } else if (identical(descriptor, HtmlEntry.HINTS)) {
(...skipping 16 matching lines...) Expand all
2584 _parsedUnitState = CacheState.INVALID; 2690 _parsedUnitState = CacheState.INVALID;
2585 _referencedLibraries = Source.EMPTY_ARRAY; 2691 _referencedLibraries = Source.EMPTY_ARRAY;
2586 _referencedLibrariesState = CacheState.INVALID; 2692 _referencedLibrariesState = CacheState.INVALID;
2587 invalidateAllResolutionInformation(); 2693 invalidateAllResolutionInformation();
2588 } 2694 }
2589 2695
2590 /** 2696 /**
2591 * Invalidate all of the resolution information associated with the HTML file. 2697 * Invalidate all of the resolution information associated with the HTML file.
2592 */ 2698 */
2593 void invalidateAllResolutionInformation() { 2699 void invalidateAllResolutionInformation() {
2700 _angularErrors = AnalysisError.NO_ERRORS;
2701 _angularErrorsState = CacheState.INVALID;
2594 _element = null; 2702 _element = null;
2595 _elementState = CacheState.INVALID; 2703 _elementState = CacheState.INVALID;
2596 _resolutionErrors = AnalysisError.NO_ERRORS; 2704 _resolutionErrors = AnalysisError.NO_ERRORS;
2597 _resolutionErrorsState = CacheState.INVALID; 2705 _resolutionErrorsState = CacheState.INVALID;
2598 _hints = AnalysisError.NO_ERRORS; 2706 _hints = AnalysisError.NO_ERRORS;
2599 _hintsState = CacheState.INVALID; 2707 _hintsState = CacheState.INVALID;
2600 } 2708 }
2601 2709
2602 /** 2710 /**
2603 * Record that an error was encountered while attempting to parse the source a ssociated with this 2711 * Record that an error was encountered while attempting to parse the source a ssociated with this
2604 * entry. 2712 * entry.
2605 */ 2713 */
2606 void recordParseError() { 2714 void recordParseError() {
2607 setState(SourceEntry.LINE_INFO, CacheState.ERROR); 2715 setState(SourceEntry.LINE_INFO, CacheState.ERROR);
2608 setState(HtmlEntry.PARSE_ERRORS, CacheState.ERROR); 2716 setState(HtmlEntry.PARSE_ERRORS, CacheState.ERROR);
2609 setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR); 2717 setState(HtmlEntry.PARSED_UNIT, CacheState.ERROR);
2610 setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR); 2718 setState(HtmlEntry.REFERENCED_LIBRARIES, CacheState.ERROR);
2611 recordResolutionError(); 2719 recordResolutionError();
2612 } 2720 }
2613 2721
2614 /** 2722 /**
2615 * Record that an error was encountered while attempting to resolve the source associated with 2723 * Record that an error was encountered while attempting to resolve the source associated with
2616 * this entry. 2724 * this entry.
2617 */ 2725 */
2618 void recordResolutionError() { 2726 void recordResolutionError() {
2727 setState(HtmlEntry.ANGULAR_ERRORS, CacheState.ERROR);
2619 setState(HtmlEntry.ELEMENT, CacheState.ERROR); 2728 setState(HtmlEntry.ELEMENT, CacheState.ERROR);
2620 setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.ERROR); 2729 setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.ERROR);
2621 setState(HtmlEntry.HINTS, CacheState.ERROR); 2730 setState(HtmlEntry.HINTS, CacheState.ERROR);
2622 } 2731 }
2623 2732
2624 void setState(DataDescriptor descriptor, CacheState state) { 2733 void setState(DataDescriptor descriptor, CacheState state) {
2625 if (identical(descriptor, HtmlEntry.ELEMENT)) { 2734 if (identical(descriptor, HtmlEntry.ANGULAR_ERRORS)) {
2735 _angularErrors = updatedValue(state, _angularErrors, null);
2736 _angularErrorsState = state;
2737 } else if (identical(descriptor, HtmlEntry.ELEMENT)) {
2626 _element = updatedValue(state, _element, null); 2738 _element = updatedValue(state, _element, null);
2627 _elementState = state; 2739 _elementState = state;
2628 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) { 2740 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) {
2629 _parseErrors = updatedValue(state, _parseErrors, null); 2741 _parseErrors = updatedValue(state, _parseErrors, null);
2630 _parseErrorsState = state; 2742 _parseErrorsState = state;
2631 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { 2743 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) {
2632 _parsedUnit = updatedValue(state, _parsedUnit, null); 2744 _parsedUnit = updatedValue(state, _parsedUnit, null);
2633 _parsedUnitState = state; 2745 _parsedUnitState = state;
2634 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) { 2746 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) {
2635 _referencedLibraries = updatedValue(state, _referencedLibraries, Source.EM PTY_ARRAY); 2747 _referencedLibraries = updatedValue(state, _referencedLibraries, Source.EM PTY_ARRAY);
2636 _referencedLibrariesState = state; 2748 _referencedLibrariesState = state;
2637 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) { 2749 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) {
2638 _resolutionErrors = updatedValue(state, _resolutionErrors, AnalysisError.N O_ERRORS); 2750 _resolutionErrors = updatedValue(state, _resolutionErrors, AnalysisError.N O_ERRORS);
2639 _resolutionErrorsState = state; 2751 _resolutionErrorsState = state;
2640 } else if (identical(descriptor, HtmlEntry.HINTS)) { 2752 } else if (identical(descriptor, HtmlEntry.HINTS)) {
2641 _hints = updatedValue(state, _hints, AnalysisError.NO_ERRORS); 2753 _hints = updatedValue(state, _hints, AnalysisError.NO_ERRORS);
2642 _hintsState = state; 2754 _hintsState = state;
2643 } else { 2755 } else {
2644 super.setState(descriptor, state); 2756 super.setState(descriptor, state);
2645 } 2757 }
2646 } 2758 }
2647 2759
2648 void setValue(DataDescriptor descriptor, Object value) { 2760 void setValue(DataDescriptor descriptor, Object value) {
2649 if (identical(descriptor, HtmlEntry.ELEMENT)) { 2761 if (identical(descriptor, HtmlEntry.ANGULAR_ERRORS)) {
2762 _angularErrors = value as List<AnalysisError>;
2763 _angularErrorsState = CacheState.VALID;
2764 } else if (identical(descriptor, HtmlEntry.ELEMENT)) {
2650 _element = value as HtmlElement; 2765 _element = value as HtmlElement;
2651 _elementState = CacheState.VALID; 2766 _elementState = CacheState.VALID;
2652 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) { 2767 } else if (identical(descriptor, HtmlEntry.PARSE_ERRORS)) {
2653 _parseErrors = value as List<AnalysisError>; 2768 _parseErrors = value as List<AnalysisError>;
2654 _parseErrorsState = CacheState.VALID; 2769 _parseErrorsState = CacheState.VALID;
2655 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) { 2770 } else if (identical(descriptor, HtmlEntry.PARSED_UNIT)) {
2656 _parsedUnit = value as HtmlUnit; 2771 _parsedUnit = value as ht.HtmlUnit;
2657 _parsedUnitState = CacheState.VALID; 2772 _parsedUnitState = CacheState.VALID;
2658 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) { 2773 } else if (identical(descriptor, HtmlEntry.REFERENCED_LIBRARIES)) {
2659 _referencedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List <Source>); 2774 _referencedLibraries = value == null ? Source.EMPTY_ARRAY : (value as List <Source>);
2660 _referencedLibrariesState = CacheState.VALID; 2775 _referencedLibrariesState = CacheState.VALID;
2661 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) { 2776 } else if (identical(descriptor, HtmlEntry.RESOLUTION_ERRORS)) {
2662 _resolutionErrors = value as List<AnalysisError>; 2777 _resolutionErrors = value as List<AnalysisError>;
2663 _resolutionErrorsState = CacheState.VALID; 2778 _resolutionErrorsState = CacheState.VALID;
2664 } else if (identical(descriptor, HtmlEntry.HINTS)) { 2779 } else if (identical(descriptor, HtmlEntry.HINTS)) {
2665 _hints = value as List<AnalysisError>; 2780 _hints = value as List<AnalysisError>;
2666 _hintsState = CacheState.VALID; 2781 _hintsState = CacheState.VALID;
2667 } else { 2782 } else {
2668 super.setValue(descriptor, value); 2783 super.setValue(descriptor, value);
2669 } 2784 }
2670 } 2785 }
2671 2786
2672 void copyFrom(SourceEntryImpl entry) { 2787 void copyFrom(SourceEntryImpl entry) {
2673 super.copyFrom(entry); 2788 super.copyFrom(entry);
2674 HtmlEntryImpl other = entry as HtmlEntryImpl; 2789 HtmlEntryImpl other = entry as HtmlEntryImpl;
2790 _angularErrorsState = other._angularErrorsState;
2791 _angularErrors = other._angularErrors;
2675 _parseErrorsState = other._parseErrorsState; 2792 _parseErrorsState = other._parseErrorsState;
2676 _parseErrors = other._parseErrors; 2793 _parseErrors = other._parseErrors;
2677 _parsedUnitState = other._parsedUnitState; 2794 _parsedUnitState = other._parsedUnitState;
2678 _parsedUnit = other._parsedUnit; 2795 _parsedUnit = other._parsedUnit;
2679 _referencedLibrariesState = other._referencedLibrariesState; 2796 _referencedLibrariesState = other._referencedLibrariesState;
2680 _referencedLibraries = other._referencedLibraries; 2797 _referencedLibraries = other._referencedLibraries;
2681 _resolutionErrors = other._resolutionErrors; 2798 _resolutionErrors = other._resolutionErrors;
2682 _resolutionErrorsState = other._resolutionErrorsState; 2799 _resolutionErrorsState = other._resolutionErrorsState;
2683 _elementState = other._elementState; 2800 _elementState = other._elementState;
2684 _element = other._element; 2801 _element = other._element;
2685 _hints = other._hints; 2802 _hints = other._hints;
2686 _hintsState = other._hintsState; 2803 _hintsState = other._hintsState;
2687 } 2804 }
2688 2805
2806 bool hasErrorState() => super.hasErrorState() || identical(_parsedUnitState, C acheState.ERROR) || identical(_parseErrorsState, CacheState.ERROR) || identical( _resolutionErrorsState, CacheState.ERROR) || identical(_referencedLibrariesState , CacheState.ERROR) || identical(_elementState, CacheState.ERROR) || identical(_ angularErrorsState, CacheState.ERROR) || identical(_hintsState, CacheState.ERROR );
2807
2689 void writeOn(JavaStringBuilder builder) { 2808 void writeOn(JavaStringBuilder builder) {
2690 builder.append("Html: "); 2809 builder.append("Html: ");
2691 super.writeOn(builder); 2810 super.writeOn(builder);
2692 builder.append("; parseErrors = "); 2811 builder.append("; parseErrors = ");
2693 builder.append(_parseErrorsState); 2812 builder.append(_parseErrorsState);
2694 builder.append("; parsedUnit = "); 2813 builder.append("; parsedUnit = ");
2695 builder.append(_parsedUnitState); 2814 builder.append(_parsedUnitState);
2696 builder.append("; resolutionErrors = "); 2815 builder.append("; resolutionErrors = ");
2697 builder.append(_resolutionErrorsState); 2816 builder.append(_resolutionErrorsState);
2698 builder.append("; referencedLibraries = "); 2817 builder.append("; referencedLibraries = ");
2699 builder.append(_referencedLibrariesState); 2818 builder.append(_referencedLibrariesState);
2700 builder.append("; element = "); 2819 builder.append("; element = ");
2701 builder.append(_elementState); 2820 builder.append(_elementState);
2821 builder.append("; angularErrors = ");
2822 builder.append(_angularErrorsState);
2702 } 2823 }
2703 } 2824 }
2704 2825
2705 /** 2826 /**
2706 * The enumerated type `RetentionPriority` represents the priority of data in th e cache in 2827 * The enumerated type `RetentionPriority` represents the priority of data in th e cache in
2707 * terms of the desirability of retaining some specified data about a specified source. 2828 * terms of the desirability of retaining some specified data about a specified source.
2708 */ 2829 */
2709 class RetentionPriority extends Enum<RetentionPriority> { 2830 class RetentionPriority extends Enum<RetentionPriority> {
2710 /** 2831 /**
2711 * A priority indicating that a given piece of data can be removed from the ca che without 2832 * A priority indicating that a given piece of data can be removed from the ca che without
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2817 * The state of the cached line information. 2938 * The state of the cached line information.
2818 */ 2939 */
2819 CacheState _lineInfoState = CacheState.INVALID; 2940 CacheState _lineInfoState = CacheState.INVALID;
2820 2941
2821 /** 2942 /**
2822 * The line information computed for the source, or `null` if the line informa tion is not 2943 * The line information computed for the source, or `null` if the line informa tion is not
2823 * currently cached. 2944 * currently cached.
2824 */ 2945 */
2825 LineInfo _lineInfo; 2946 LineInfo _lineInfo;
2826 2947
2948 /**
2949 * Fix the state of the [exception] to match the current state of the entry.
2950 */
2951 void fixExceptionState() {
2952 if (hasErrorState()) {
2953 if (exception == null) {
2954 //
2955 // This code should never be reached, but is a fail-safe in case an exce ption is not
2956 // recorded when it should be.
2957 //
2958 exception = new AnalysisException.con1("State set to ERROR without setti ng an exception");
2959 }
2960 } else {
2961 exception = null;
2962 }
2963 }
2964
2827 int get modificationTime => _modificationTime; 2965 int get modificationTime => _modificationTime;
2828 2966
2829 CacheState getState(DataDescriptor descriptor) { 2967 CacheState getState(DataDescriptor descriptor) {
2830 if (identical(descriptor, SourceEntry.LINE_INFO)) { 2968 if (identical(descriptor, SourceEntry.LINE_INFO)) {
2831 return _lineInfoState; 2969 return _lineInfoState;
2832 } else { 2970 } else {
2833 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}"); 2971 throw new IllegalArgumentException("Invalid descriptor: ${descriptor}");
2834 } 2972 }
2835 } 2973 }
2836 2974
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2896 return builder.toString(); 3034 return builder.toString();
2897 } 3035 }
2898 3036
2899 /** 3037 /**
2900 * Copy the information from the given cache entry. 3038 * Copy the information from the given cache entry.
2901 * 3039 *
2902 * @param entry the cache entry from which information will be copied 3040 * @param entry the cache entry from which information will be copied
2903 */ 3041 */
2904 void copyFrom(SourceEntryImpl entry) { 3042 void copyFrom(SourceEntryImpl entry) {
2905 _modificationTime = entry._modificationTime; 3043 _modificationTime = entry._modificationTime;
3044 exception = entry.exception;
2906 _lineInfoState = entry._lineInfoState; 3045 _lineInfoState = entry._lineInfoState;
2907 _lineInfo = entry._lineInfo; 3046 _lineInfo = entry._lineInfo;
2908 } 3047 }
2909 3048
2910 /** 3049 /**
3050 * Return `true` if the state of any data value is [CacheState#ERROR].
3051 *
3052 * @return `true` if the state of any data value is [CacheState#ERROR]
3053 */
3054 bool hasErrorState() => identical(_lineInfoState, CacheState.ERROR);
3055
3056 /**
2911 * Given that some data is being transitioned to the given state, return the v alue that should be 3057 * Given that some data is being transitioned to the given state, return the v alue that should be
2912 * kept in the cache. 3058 * kept in the cache.
2913 * 3059 *
2914 * @param state the state to which the data is being transitioned 3060 * @param state the state to which the data is being transitioned
2915 * @param currentValue the value of the data before the transition 3061 * @param currentValue the value of the data before the transition
2916 * @param defaultValue the value to be used if the current value is to be remo ved from the cache 3062 * @param defaultValue the value to be used if the current value is to be remo ved from the cache
2917 * @return the value of the data that should be kept in the cache 3063 * @return the value of the data that should be kept in the cache
2918 */ 3064 */
2919 Object updatedValue(CacheState state, Object currentValue, Object defaultValue ) { 3065 Object updatedValue(CacheState state, Object currentValue, Object defaultValue ) {
2920 if (identical(state, CacheState.VALID)) { 3066 if (identical(state, CacheState.VALID)) {
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
3222 return AnalysisError.NO_ERRORS; 3368 return AnalysisError.NO_ERRORS;
3223 } 3369 }
3224 return new List.from(errors); 3370 return new List.from(errors);
3225 } else if (sourceEntry is HtmlEntry) { 3371 } else if (sourceEntry is HtmlEntry) {
3226 HtmlEntry htmlEntry = sourceEntry; 3372 HtmlEntry htmlEntry = sourceEntry;
3227 return getHtmlResolutionData2(source, htmlEntry, HtmlEntry.RESOLUTION_ERRO RS); 3373 return getHtmlResolutionData2(source, htmlEntry, HtmlEntry.RESOLUTION_ERRO RS);
3228 } 3374 }
3229 return AnalysisError.NO_ERRORS; 3375 return AnalysisError.NO_ERRORS;
3230 } 3376 }
3231 3377
3232 List<Source> computeExportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY); 3378 List<Source> computeExportedLibraries(Source source) => getDartDependencyData2 (source, DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY);
3233 3379
3234 HtmlElement computeHtmlElement(Source source) => getHtmlResolutionData(source, HtmlEntry.ELEMENT, null); 3380 HtmlElement computeHtmlElement(Source source) => getHtmlResolutionData(source, HtmlEntry.ELEMENT, null);
3235 3381
3236 List<Source> computeImportedLibraries(Source source) => getDartParseData2(sour ce, DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY); 3382 List<Source> computeImportedLibraries(Source source) => getDartDependencyData2 (source, DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY);
3237 3383
3238 SourceKind computeKindOf(Source source) { 3384 SourceKind computeKindOf(Source source) {
3239 SourceEntry sourceEntry = getReadableSourceEntry(source); 3385 SourceEntry sourceEntry = getReadableSourceEntry(source);
3240 if (sourceEntry == null) { 3386 if (sourceEntry == null) {
3241 return SourceKind.UNKNOWN; 3387 return SourceKind.UNKNOWN;
3242 } else if (sourceEntry is DartEntry) { 3388 } else if (sourceEntry is DartEntry) {
3243 try { 3389 try {
3244 return getDartParseData(source, sourceEntry, DartEntry.SOURCE_KIND); 3390 return getDartParseData(source, sourceEntry, DartEntry.SOURCE_KIND);
3245 } on AnalysisException catch (exception) { 3391 } on AnalysisException catch (exception) {
3246 return SourceKind.UNKNOWN; 3392 return SourceKind.UNKNOWN;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3286 cacheDartParseData(source, getReadableDartEntry(source), DartEntry.PARSED_ UNIT); 3432 cacheDartParseData(source, getReadableDartEntry(source), DartEntry.PARSED_ UNIT);
3287 } 3433 }
3288 } 3434 }
3289 3435
3290 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) { 3436 ResolvableHtmlUnit computeResolvableHtmlUnit(Source source) {
3291 HtmlEntry htmlEntry = getReadableHtmlEntry(source); 3437 HtmlEntry htmlEntry = getReadableHtmlEntry(source);
3292 if (htmlEntry == null) { 3438 if (htmlEntry == null) {
3293 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}"); 3439 throw new AnalysisException.con1("computeResolvableHtmlUnit invoked for no n-HTML file: ${source.fullName}");
3294 } 3440 }
3295 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT); 3441 htmlEntry = cacheHtmlParseData(source, htmlEntry, HtmlEntry.PARSED_UNIT);
3296 HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT); 3442 ht.HtmlUnit unit = htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
3297 if (unit == null) { 3443 if (unit == null) {
3298 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}"); 3444 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t could not parse ${source.fullName}");
3299 } 3445 }
3300 // If the unit is ever modified by resolution then we will need to create a copy of it. 3446 // If the unit is ever modified by resolution then we will need to create a copy of it.
3301 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit); 3447 return new ResolvableHtmlUnit(htmlEntry.modificationTime, unit);
3302 } 3448 }
3303 3449
3304 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context); 3450 AnalysisContext extractContext(SourceContainer container) => extractContextInt o(container, AnalysisEngine.instance.createAnalysisContext() as InternalAnalysis Context);
3305 3451
3306 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) { 3452 InternalAnalysisContext extractContextInto(SourceContainer container, Internal AnalysisContext newContext) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3470 } 3616 }
3471 } 3617 }
3472 } 3618 }
3473 if (dependentLibraries.isEmpty) { 3619 if (dependentLibraries.isEmpty) {
3474 return Source.EMPTY_ARRAY; 3620 return Source.EMPTY_ARRAY;
3475 } 3621 }
3476 return new List.from(dependentLibraries); 3622 return new List.from(dependentLibraries);
3477 } 3623 }
3478 } 3624 }
3479 3625
3626 List<AngularElement> getLibraryAngularElements(Source source) {
3627 SourceEntry sourceEntry = getReadableSourceEntry(source);
3628 if (sourceEntry is DartEntry) {
3629 return sourceEntry.getValue(DartEntry.ANGULAR_ELEMENTS);
3630 }
3631 return AngularElement.EMPTY_ARRAY;
3632 }
3633
3480 LibraryElement getLibraryElement(Source source) { 3634 LibraryElement getLibraryElement(Source source) {
3481 SourceEntry sourceEntry = getReadableSourceEntry(source); 3635 SourceEntry sourceEntry = getReadableSourceEntry(source);
3482 if (sourceEntry is DartEntry) { 3636 if (sourceEntry is DartEntry) {
3483 return sourceEntry.getValue(DartEntry.ELEMENT); 3637 return sourceEntry.getValue(DartEntry.ELEMENT);
3484 } 3638 }
3485 return null; 3639 return null;
3486 } 3640 }
3487 3641
3488 List<Source> get librarySources => getSources(SourceKind.LIBRARY); 3642 List<Source> get librarySources => getSources(SourceKind.LIBRARY);
3489 3643
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3579 } 3733 }
3580 3734
3581 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) { 3735 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
3582 SourceEntry sourceEntry = getReadableSourceEntry(unitSource); 3736 SourceEntry sourceEntry = getReadableSourceEntry(unitSource);
3583 if (sourceEntry is DartEntry) { 3737 if (sourceEntry is DartEntry) {
3584 return sourceEntry.getValue2(DartEntry.RESOLVED_UNIT, librarySource); 3738 return sourceEntry.getValue2(DartEntry.RESOLVED_UNIT, librarySource);
3585 } 3739 }
3586 return null; 3740 return null;
3587 } 3741 }
3588 3742
3589 HtmlUnit getResolvedHtmlUnit(Source htmlSource) { 3743 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) {
3590 SourceEntry sourceEntry = getReadableSourceEntry(htmlSource); 3744 SourceEntry sourceEntry = getReadableSourceEntry(htmlSource);
3591 if (sourceEntry is HtmlEntry) { 3745 if (sourceEntry is HtmlEntry) {
3592 HtmlEntry htmlEntry = sourceEntry; 3746 HtmlEntry htmlEntry = sourceEntry;
3593 if (htmlEntry.getValue(HtmlEntry.ELEMENT) != null) { 3747 if (htmlEntry.getValue(HtmlEntry.ELEMENT) != null) {
3594 return htmlEntry.getValue(HtmlEntry.PARSED_UNIT); 3748 return htmlEntry.getValue(HtmlEntry.PARSED_UNIT);
3595 } 3749 }
3596 } 3750 }
3597 return null; 3751 return null;
3598 } 3752 }
3599 3753
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3711 // TODO(brianwilkerson) Decide whether we really need to copy the info . 3865 // TODO(brianwilkerson) Decide whether we really need to copy the info .
3712 _cache.put(newSource, entry.getValue().writableCopy); 3866 _cache.put(newSource, entry.getValue().writableCopy);
3713 } else { 3867 } else {
3714 } 3868 }
3715 } 3869 }
3716 } 3870 }
3717 } 3871 }
3718 3872
3719 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null); 3873 CompilationUnit parseCompilationUnit(Source source) => getDartParseData2(sourc e, DartEntry.PARSED_UNIT, null);
3720 3874
3721 HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry.PA RSED_UNIT, null); 3875 ht.HtmlUnit parseHtmlUnit(Source source) => getHtmlParseData(source, HtmlEntry .PARSED_UNIT, null);
3722 3876
3723 AnalysisResult performAnalysisTask() { 3877 AnalysisResult performAnalysisTask() {
3724 int getStart = JavaSystem.currentTimeMillis(); 3878 int getStart = JavaSystem.currentTimeMillis();
3725 AnalysisTask task = nextTaskAnalysisTask; 3879 AnalysisTask task = nextTaskAnalysisTask;
3726 int getEnd = JavaSystem.currentTimeMillis(); 3880 int getEnd = JavaSystem.currentTimeMillis();
3727 if (task == null && validateCacheConsistency()) { 3881 if (task == null && validateCacheConsistency()) {
3728 task = nextTaskAnalysisTask; 3882 task = nextTaskAnalysisTask;
3729 } 3883 }
3730 if (task == null) { 3884 if (task == null) {
3731 return new AnalysisResult(getChangeNotices(true), getEnd - getStart, null, -1); 3885 return new AnalysisResult(getChangeNotices(true), getEnd - getStart, null, -1);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3769 3923
3770 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) { 3924 CompilationUnit resolveCompilationUnit(Source unitSource, LibraryElement libra ry) {
3771 if (library == null) { 3925 if (library == null) {
3772 return null; 3926 return null;
3773 } 3927 }
3774 return resolveCompilationUnit2(unitSource, library.source); 3928 return resolveCompilationUnit2(unitSource, library.source);
3775 } 3929 }
3776 3930
3777 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT, null); 3931 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) => getDartResolutionData2(unitSource, librarySource, DartEntry.RESOLVED_UNIT, null);
3778 3932
3779 HtmlUnit resolveHtmlUnit(Source htmlSource) { 3933 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) {
3780 computeHtmlElement(htmlSource); 3934 computeHtmlElement(htmlSource);
3781 return parseHtmlUnit(htmlSource); 3935 return parseHtmlUnit(htmlSource);
3782 } 3936 }
3783 3937
3784 void set analysisOptions(AnalysisOptions options) { 3938 void set analysisOptions(AnalysisOptions options) {
3785 { 3939 {
3786 bool needsRecompute = this._options.analyzeFunctionBodies != options.analy zeFunctionBodies || this._options.dart2jsHint != options.dart2jsHint || (this._o ptions.hint && !options.hint) || this._options.preserveComments != options.prese rveComments; 3940 bool needsRecompute = this._options.analyzeFunctionBodies != options.analy zeFunctionBodies || this._options.dart2jsHint != options.dart2jsHint || (this._o ptions.hint && !options.hint) || this._options.preserveComments != options.prese rveComments;
3787 int cacheSize = options.cacheSize; 3941 int cacheSize = options.cacheSize;
3788 if (this._options.cacheSize != cacheSize) { 3942 if (this._options.cacheSize != cacheSize) {
3789 this._options.cacheSize = cacheSize; 3943 this._options.cacheSize = cacheSize;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3952 } 4106 }
3953 } 4107 }
3954 DartEntryImpl dartCopy = dartEntry.writableCopy; 4108 DartEntryImpl dartCopy = dartEntry.writableCopy;
3955 if (thrownException == null) { 4109 if (thrownException == null) {
3956 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 4110 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
3957 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); 4111 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED);
3958 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit) ; 4112 dartCopy.setValue2(DartEntry.RESOLVED_UNIT, librarySource, unit) ;
3959 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, e rrors); 4113 dartCopy.setValue2(DartEntry.RESOLUTION_ERRORS, librarySource, e rrors);
3960 if (identical(source, librarySource)) { 4114 if (identical(source, librarySource)) {
3961 recordElementData(dartCopy, library.libraryElement, htmlSource ); 4115 recordElementData(dartCopy, library.libraryElement, htmlSource );
4116 recordAngularComponents(library, dartCopy);
3962 } 4117 }
3963 } else { 4118 } else {
3964 dartCopy.recordResolutionError(); 4119 dartCopy.recordResolutionError();
3965 } 4120 }
3966 dartCopy.exception = thrownException; 4121 dartCopy.exception = thrownException;
3967 _cache.put(source, dartCopy); 4122 _cache.put(source, dartCopy);
3968 if (source == unitSource) { 4123 if (source == unitSource) {
3969 unitEntry = dartCopy; 4124 unitEntry = dartCopy;
3970 } 4125 }
3971 ChangeNoticeImpl notice = getNotice(source); 4126 ChangeNoticeImpl notice = getNotice(source);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
4050 * not happen) 4205 * not happen)
4051 */ 4206 */
4052 bool allModificationTimesMatch(Set<Library> resolvedLibraries) { 4207 bool allModificationTimesMatch(Set<Library> resolvedLibraries) {
4053 bool allTimesMatch = true; 4208 bool allTimesMatch = true;
4054 for (Library library in resolvedLibraries) { 4209 for (Library library in resolvedLibraries) {
4055 for (Source source in library.compilationUnitSources) { 4210 for (Source source in library.compilationUnitSources) {
4056 DartEntry dartEntry = getReadableDartEntry(source); 4211 DartEntry dartEntry = getReadableDartEntry(source);
4057 if (dartEntry == null) { 4212 if (dartEntry == null) {
4058 // This shouldn't be possible because we should never have performed t he task if the 4213 // This shouldn't be possible because we should never have performed t he task if the
4059 // source didn't represent a Dart file, but check to be safe. 4214 // source didn't represent a Dart file, but check to be safe.
4060 throw new AnalysisException.con1("Internal error: attempting to reolve non-Dart file as a Dart file: ${source.fullName}"); 4215 throw new AnalysisException.con1("Internal error: attempting to resolv e non-Dart file as a Dart file: ${source.fullName}");
4061 } 4216 }
4062 int sourceTime = source.modificationStamp; 4217 int sourceTime = source.modificationStamp;
4063 int resultTime = library.getModificationTime(source); 4218 int resultTime = library.getModificationTime(source);
4064 if (sourceTime != resultTime) { 4219 if (sourceTime != resultTime) {
4065 // The source has changed without the context being notified. Simulate notification. 4220 // The source has changed without the context being notified. Simulate notification.
4066 sourceChanged(source); 4221 sourceChanged(source);
4067 allTimesMatch = false; 4222 allTimesMatch = false;
4068 } 4223 }
4069 } 4224 }
4070 } 4225 }
4071 return allTimesMatch; 4226 return allTimesMatch;
4072 } 4227 }
4073 4228
4074 /** 4229 /**
4230 * Given a source for a Dart file, return a cache entry in which the data repr esented by the given
4231 * descriptor is available. This method assumes that the data can be produced by resolving the
4232 * directives in the source if they are not already cached.
4233 *
4234 * @param source the source representing the Dart file
4235 * @param dartEntry the cache entry associated with the Dart file
4236 * @param descriptor the descriptor representing the data to be returned
4237 * @return a cache entry containing the required data
4238 * @throws AnalysisException if data could not be returned because the source could not be
4239 * resolved
4240 */
4241 DartEntry cacheDartDependencyData(Source source, DartEntry dartEntry, DataDesc riptor descriptor) {
4242 //
4243 // Check to see whether we already have the information being requested.
4244 //
4245 CacheState state = dartEntry.getState(descriptor);
4246 while (state != CacheState.ERROR && state != CacheState.VALID) {
4247 //
4248 // If not, compute the information. Unless the modification date of the so urce continues to
4249 // change, this loop will eventually terminate.
4250 //
4251 dartEntry = new ResolveDartDependenciesTask(this, source).perform(_resultR ecorder) as DartEntry;
4252 state = dartEntry.getState(descriptor);
4253 }
4254 return dartEntry;
4255 }
4256
4257 /**
4075 * Given a source for a Dart file and the library that contains it, return a c ache entry in which 4258 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
4076 * the data represented by the given descriptor is available. This method assu mes that the data 4259 * the data represented by the given descriptor is available. This method assu mes that the data
4077 * can be produced by generating hints for the library if the data is not alre ady cached. 4260 * can be produced by generating hints for the library if the data is not alre ady cached.
4078 * 4261 *
4079 * @param unitSource the source representing the Dart file 4262 * @param unitSource the source representing the Dart file
4080 * @param librarySource the source representing the library containing the Dar t file 4263 * @param librarySource the source representing the library containing the Dar t file
4081 * @param dartEntry the cache entry associated with the Dart file 4264 * @param dartEntry the cache entry associated with the Dart file
4082 * @param descriptor the descriptor representing the data to be returned 4265 * @param descriptor the descriptor representing the data to be returned
4083 * @return a cache entry containing the required data 4266 * @return a cache entry containing the required data
4084 * @throws AnalysisException if data could not be returned because the source could not be parsed 4267 * @throws AnalysisException if data could not be returned because the source could not be parsed
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
4339 } 4522 }
4340 return ChangeNoticeImpl.EMPTY_ARRAY; 4523 return ChangeNoticeImpl.EMPTY_ARRAY;
4341 } 4524 }
4342 List<ChangeNotice> notices = new List.from(_pendingNotices.values); 4525 List<ChangeNotice> notices = new List.from(_pendingNotices.values);
4343 _pendingNotices.clear(); 4526 _pendingNotices.clear();
4344 return notices; 4527 return notices;
4345 } 4528 }
4346 } 4529 }
4347 4530
4348 /** 4531 /**
4532 * Given a source for a Dart file, return the data represented by the given de scriptor that is
4533 * associated with that source. This method assumes that the data can be produ ced by resolving the
4534 * directives in the source if they are not already cached.
4535 *
4536 * @param source the source representing the Dart file
4537 * @param dartEntry the cache entry associated with the Dart file
4538 * @param descriptor the descriptor representing the data to be returned
4539 * @return the requested data about the given source
4540 * @throws AnalysisException if data could not be returned because the source could not be parsed
4541 */
4542 Object getDartDependencyData(Source source, DartEntry dartEntry, DataDescripto r descriptor) {
4543 dartEntry = cacheDartDependencyData(source, dartEntry, descriptor);
4544 return dartEntry.getValue(descriptor);
4545 }
4546
4547 /**
4548 * Given a source for a Dart file, return the data represented by the given de scriptor that is
4549 * associated with that source, or the given default value if the source is no t a Dart file. This
4550 * method assumes that the data can be produced by resolving the directives in the source if they
4551 * are not already cached.
4552 *
4553 * @param source the source representing the Dart file
4554 * @param descriptor the descriptor representing the data to be returned
4555 * @param defaultValue the value to be returned if the source is not a Dart fi le
4556 * @return the requested data about the given source
4557 * @throws AnalysisException if data could not be returned because the source could not be parsed
4558 */
4559 Object getDartDependencyData2(Source source, DataDescriptor descriptor, Object defaultValue) {
4560 DartEntry dartEntry = getReadableDartEntry(source);
4561 if (dartEntry == null) {
4562 return defaultValue;
4563 }
4564 return getDartDependencyData(source, dartEntry, descriptor);
4565 }
4566
4567 /**
4349 * Given a source for a Dart file and the library that contains it, return the data represented by 4568 * Given a source for a Dart file and the library that contains it, return the data represented by
4350 * the given descriptor that is associated with that source. This method assum es that the data can 4569 * the given descriptor that is associated with that source. This method assum es that the data can
4351 * be produced by generating hints for the library if it is not already cached . 4570 * be produced by generating hints for the library if it is not already cached .
4352 * 4571 *
4353 * @param unitSource the source representing the Dart file 4572 * @param unitSource the source representing the Dart file
4354 * @param librarySource the source representing the library containing the Dar t file 4573 * @param librarySource the source representing the library containing the Dar t file
4355 * @param dartEntry the entry representing the Dart file 4574 * @param dartEntry the entry representing the Dart file
4356 * @param descriptor the descriptor representing the data to be returned 4575 * @param descriptor the descriptor representing the data to be returned
4357 * @return the requested data about the given source 4576 * @return the requested data about the given source
4358 * @throws AnalysisException if data could not be returned because the source could not be 4577 * @throws AnalysisException if data could not be returned because the source could not be
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
4551 } 4770 }
4552 // 4771 //
4553 // Look for a non-priority source that needs to be analyzed. 4772 // Look for a non-priority source that needs to be analyzed.
4554 // 4773 //
4555 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) { 4774 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4556 AnalysisTask task = getNextTaskAnalysisTask2(entry.getKey(), entry.getVa lue(), false, hintsEnabled); 4775 AnalysisTask task = getNextTaskAnalysisTask2(entry.getKey(), entry.getVa lue(), false, hintsEnabled);
4557 if (task != null) { 4776 if (task != null) {
4558 return task; 4777 return task;
4559 } 4778 }
4560 } 4779 }
4780 //
4781 // Look for HTML sources that should be resolved as Angular templates.
4782 //
4783 for (MapEntry<Source, SourceEntry> entry in _cache.entrySet()) {
4784 SourceEntry sourceEntry = entry.getValue();
4785 if (sourceEntry is DartEntry) {
4786 DartEntry dartEntry = sourceEntry;
4787 List<AngularElement> angularElements = dartEntry.getValue(DartEntry.AN GULAR_ELEMENTS);
4788 for (AngularElement angularElement in angularElements) {
4789 // prepare Angular component
4790 if (angularElement is! AngularComponentElement) {
4791 continue;
4792 }
4793 AngularComponentElement component = angularElement as AngularCompone ntElement;
4794 // prepare HTML template
4795 Source templateSource = component.templateSource;
4796 if (templateSource == null) {
4797 continue;
4798 }
4799 // prepare HTML template entry
4800 HtmlEntry htmlEntry = getReadableHtmlEntry(templateSource);
4801 if (htmlEntry == null) {
4802 continue;
4803 }
4804 // we need an entry with invalid Angular errors
4805 CacheState angularErrorsState = htmlEntry.getState(HtmlEntry.ANGULAR _ERRORS);
4806 if (angularErrorsState != CacheState.INVALID) {
4807 continue;
4808 }
4809 // do Angular component resolution
4810 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
4811 htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.IN_PROCESS);
4812 _cache.put(templateSource, htmlCopy);
4813 return new ResolveAngularComponentTemplateTask(this, templateSource, component, angularElements);
4814 }
4815 }
4816 }
4561 return null; 4817 return null;
4562 } 4818 }
4563 } 4819 }
4564 4820
4565 /** 4821 /**
4566 * Look at the given source to see whether a task needs to be performed relate d to it. Return the 4822 * Look at the given source to see whether a task needs to be performed relate d to it. Return the
4567 * task that should be performed, or `null` if there is no more work to be don e for the 4823 * task that should be performed, or `null` if there is no more work to be don e for the
4568 * source. 4824 * source.
4569 * 4825 *
4570 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. 4826 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock].
(...skipping 23 matching lines...) Expand all
4594 } 4850 }
4595 if (isPriority && parseErrorsState != CacheState.ERROR) { 4851 if (isPriority && parseErrorsState != CacheState.ERROR) {
4596 CompilationUnit parseUnit = dartEntry.anyParsedCompilationUnit; 4852 CompilationUnit parseUnit = dartEntry.anyParsedCompilationUnit;
4597 if (parseUnit == null) { 4853 if (parseUnit == null) {
4598 DartEntryImpl dartCopy = dartEntry.writableCopy; 4854 DartEntryImpl dartCopy = dartEntry.writableCopy;
4599 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS); 4855 dartCopy.setState(DartEntry.PARSED_UNIT, CacheState.IN_PROCESS);
4600 _cache.put(source, dartCopy); 4856 _cache.put(source, dartCopy);
4601 return new ParseDartTask(this, source); 4857 return new ParseDartTask(this, source);
4602 } 4858 }
4603 } 4859 }
4860 CacheState exportState = dartEntry.getState(DartEntry.EXPORTED_LIBRARIES);
4861 if (identical(exportState, CacheState.INVALID) || (isPriority && identical (exportState, CacheState.FLUSHED))) {
4862 DartEntryImpl dartCopy = dartEntry.writableCopy;
4863 dartCopy.setState(DartEntry.EXPORTED_LIBRARIES, CacheState.IN_PROCESS);
4864 _cache.put(source, dartCopy);
4865 return new ResolveDartDependenciesTask(this, source);
4866 }
4604 for (Source librarySource in getLibrariesContaining(source)) { 4867 for (Source librarySource in getLibrariesContaining(source)) {
4605 SourceEntry libraryEntry = _cache.get(librarySource); 4868 SourceEntry libraryEntry = _cache.get(librarySource);
4606 if (libraryEntry is DartEntry) { 4869 if (libraryEntry is DartEntry) {
4607 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT); 4870 CacheState elementState = libraryEntry.getState(DartEntry.ELEMENT);
4608 if (identical(elementState, CacheState.INVALID) || (isPriority && iden tical(elementState, CacheState.FLUSHED))) { 4871 if (identical(elementState, CacheState.INVALID) || (isPriority && iden tical(elementState, CacheState.FLUSHED))) {
4609 DartEntryImpl libraryCopy = libraryEntry.writableCopy; 4872 DartEntryImpl libraryCopy = libraryEntry.writableCopy;
4610 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS); 4873 libraryCopy.setState(DartEntry.ELEMENT, CacheState.IN_PROCESS);
4611 _cache.put(librarySource, libraryCopy); 4874 _cache.put(librarySource, libraryCopy);
4612 return new ResolveDartLibraryTask(this, source, librarySource); 4875 return new ResolveDartLibraryTask(this, source, librarySource);
4613 } 4876 }
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
4958 */ 5221 */
4959 void logInformation2(String message, Exception exception) { 5222 void logInformation2(String message, Exception exception) {
4960 if (exception == null) { 5223 if (exception == null) {
4961 AnalysisEngine.instance.logger.logInformation(message); 5224 AnalysisEngine.instance.logger.logInformation(message);
4962 } else { 5225 } else {
4963 AnalysisEngine.instance.logger.logInformation3(message, exception); 5226 AnalysisEngine.instance.logger.logInformation3(message, exception);
4964 } 5227 }
4965 } 5228 }
4966 5229
4967 /** 5230 /**
5231 * Updates [HtmlEntry]s that correspond to the previously known and new Angula r components.
5232 *
5233 * @param library the [Library] that was resolved
5234 * @param dartCopy the [DartEntryImpl] to record new Angular components
5235 */
5236 void recordAngularComponents(Library library, DartEntryImpl dartCopy) {
5237 // reset old Angular errors
5238 List<AngularElement> oldAngularElements = dartCopy.getValue(DartEntry.ANGULA R_ELEMENTS);
5239 if (oldAngularElements != null) {
5240 for (AngularElement angularElement in oldAngularElements) {
5241 if (angularElement is AngularComponentElement) {
5242 AngularComponentElement component = angularElement;
5243 Source templateSource = component.templateSource;
5244 if (templateSource != null) {
5245 HtmlEntry htmlEntry = getReadableHtmlEntry(templateSource);
5246 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
5247 htmlCopy.setValue(HtmlEntry.ANGULAR_ERRORS, AnalysisError.NO_ERRORS) ;
5248 _cache.put(templateSource, htmlCopy);
5249 // notify about (disappeared) HTML errors
5250 ChangeNoticeImpl notice = getNotice(templateSource);
5251 notice.setErrors(htmlCopy.allErrors, computeLineInfo(templateSource) );
5252 }
5253 }
5254 }
5255 }
5256 // invalidate new Angular errors
5257 List<AngularElement> newAngularElements = library.angularElements;
5258 for (AngularElement angularElement in newAngularElements) {
5259 if (angularElement is AngularComponentElement) {
5260 AngularComponentElement component = angularElement;
5261 Source templateSource = component.templateSource;
5262 if (templateSource != null) {
5263 HtmlEntry htmlEntry = getReadableHtmlEntry(templateSource);
5264 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
5265 htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.INVALID);
5266 _cache.put(templateSource, htmlCopy);
5267 }
5268 }
5269 }
5270 // remember Angular elements to resolve HTML templates later
5271 dartCopy.setValue(DartEntry.ANGULAR_ELEMENTS, newAngularElements);
5272 }
5273
5274 /**
4968 * Given a cache entry and a library element, record the library element and o ther information 5275 * Given a cache entry and a library element, record the library element and o ther information
4969 * gleaned from the element in the cache entry. 5276 * gleaned from the element in the cache entry.
4970 * 5277 *
4971 * @param dartCopy the cache entry in which data is to be recorded 5278 * @param dartCopy the cache entry in which data is to be recorded
4972 * @param library the library element used to record information 5279 * @param library the library element used to record information
4973 * @param htmlSource the source for the HTML library 5280 * @param htmlSource the source for the HTML library
4974 */ 5281 */
4975 void recordElementData(DartEntryImpl dartCopy, LibraryElement library, Source htmlSource) { 5282 void recordElementData(DartEntryImpl dartCopy, LibraryElement library, Source htmlSource) {
4976 dartCopy.setValue(DartEntry.ELEMENT, library); 5283 dartCopy.setValue(DartEntry.ELEMENT, library);
4977 dartCopy.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null); 5284 dartCopy.setValue(DartEntry.IS_LAUNCHABLE, library.entryPoint != null);
4978 dartCopy.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set <LibraryElement>())); 5285 dartCopy.setValue(DartEntry.IS_CLIENT, isClient(library, htmlSource, new Set <LibraryElement>()));
4979 List<Source> unitSources = new List<Source>(); 5286 List<Source> unitSources = new List<Source>();
4980 unitSources.add(library.definingCompilationUnit.source); 5287 unitSources.add(library.definingCompilationUnit.source);
5288 // TODO(brianwilkerson) Understand why we're doing this both here and in
5289 // ResolveDartDependenciesTask and whether we should also be capturing the i mported and exported
5290 // sources here.
4981 for (CompilationUnitElement part in library.parts) { 5291 for (CompilationUnitElement part in library.parts) {
4982 Source partSource = part.source; 5292 Source partSource = part.source;
4983 unitSources.add(partSource); 5293 unitSources.add(partSource);
4984 } 5294 }
4985 dartCopy.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources)); 5295 dartCopy.setValue(DartEntry.INCLUDED_PARTS, new List.from(unitSources));
4986 } 5296 }
4987 5297
4988 /** 5298 /**
4989 * Record the results produced by performing a [GenerateDartErrorsTask]. If th e results were 5299 * Record the results produced by performing a [GenerateDartErrorsTask]. If th e results were
4990 * computed from data that is now out-of-date, then the results will not be re corded. 5300 * computed from data that is now out-of-date, then the results will not be re corded.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
5213 if (thrownException == null) { 5523 if (thrownException == null) {
5214 LineInfo lineInfo = task.lineInfo; 5524 LineInfo lineInfo = task.lineInfo;
5215 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 5525 dartCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
5216 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) { 5526 if (task.hasPartOfDirective() && !task.hasLibraryDirective()) {
5217 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART); 5527 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.PART);
5218 } else { 5528 } else {
5219 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); 5529 dartCopy.setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY);
5220 } 5530 }
5221 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit); 5531 dartCopy.setValue(DartEntry.PARSED_UNIT, task.compilationUnit);
5222 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors); 5532 dartCopy.setValue(DartEntry.PARSE_ERRORS, task.errors);
5223 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
5224 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
5225 dartCopy.setValue(DartEntry.INCLUDED_PARTS, task.includedSources);
5226 ChangeNoticeImpl notice = getNotice(source); 5533 ChangeNoticeImpl notice = getNotice(source);
5227 notice.setErrors(dartEntry.allErrors, lineInfo); 5534 notice.setErrors(dartEntry.allErrors, lineInfo);
5228 // Verify that the incrementally parsed and resolved unit in the incre mental cache 5535 // Verify that the incrementally parsed and resolved unit in the incre mental cache
5229 // is structurally equivalent to the fully parsed unit 5536 // is structurally equivalent to the fully parsed unit
5230 _incrementalAnalysisCache = IncrementalAnalysisCache.verifyStructure(_ incrementalAnalysisCache, source, task.compilationUnit); 5537 _incrementalAnalysisCache = IncrementalAnalysisCache.verifyStructure(_ incrementalAnalysisCache, source, task.compilationUnit);
5231 } else { 5538 } else {
5232 dartCopy.recordParseError(); 5539 dartCopy.recordParseError();
5233 } 5540 }
5234 dartCopy.exception = thrownException; 5541 dartCopy.exception = thrownException;
5235 _cache.put(source, dartCopy); 5542 _cache.put(source, dartCopy);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
5290 // The source has changed without the context being notified. Simulate notification. 5597 // The source has changed without the context being notified. Simulate notification.
5291 sourceChanged(source); 5598 sourceChanged(source);
5292 htmlEntry = getReadableHtmlEntry(source); 5599 htmlEntry = getReadableHtmlEntry(source);
5293 if (htmlEntry == null) { 5600 if (htmlEntry == null) {
5294 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}"); 5601 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
5295 } 5602 }
5296 } 5603 }
5297 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy; 5604 HtmlEntryImpl htmlCopy = (sourceEntry as HtmlEntry).writableCopy;
5298 if (thrownException == null) { 5605 if (thrownException == null) {
5299 LineInfo lineInfo = task.lineInfo; 5606 LineInfo lineInfo = task.lineInfo;
5300 HtmlUnit unit = task.htmlUnit; 5607 ht.HtmlUnit unit = task.htmlUnit;
5301 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo); 5608 htmlCopy.setValue(SourceEntry.LINE_INFO, lineInfo);
5302 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit); 5609 htmlCopy.setValue(HtmlEntry.PARSED_UNIT, unit);
5303 htmlCopy.setValue(HtmlEntry.PARSE_ERRORS, task.errors); 5610 htmlCopy.setValue(HtmlEntry.PARSE_ERRORS, task.errors);
5304 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries); 5611 htmlCopy.setValue(HtmlEntry.REFERENCED_LIBRARIES, task.referencedLibra ries);
5305 ChangeNoticeImpl notice = getNotice(source); 5612 ChangeNoticeImpl notice = getNotice(source);
5306 notice.setErrors(htmlEntry.allErrors, lineInfo); 5613 notice.setErrors(htmlEntry.allErrors, lineInfo);
5307 } else { 5614 } else {
5308 htmlCopy.recordParseError(); 5615 htmlCopy.recordParseError();
5309 } 5616 }
5310 htmlCopy.exception = thrownException; 5617 htmlCopy.exception = thrownException;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5342 htmlEntry = htmlCopy; 5649 htmlEntry = htmlCopy;
5343 } 5650 }
5344 } 5651 }
5345 if (thrownException != null) { 5652 if (thrownException != null) {
5346 throw thrownException; 5653 throw thrownException;
5347 } 5654 }
5348 return htmlEntry; 5655 return htmlEntry;
5349 } 5656 }
5350 5657
5351 /** 5658 /**
5659 * Record the results produced by performing a [ResolveAngularComponentTemplat eTask]. If the
5660 * results were computed from data that is now out-of-date, then the results w ill not be recorded.
5661 *
5662 * @param task the task that was performed
5663 * @throws AnalysisException if the results could not be recorded
5664 */
5665 HtmlEntry recordResolveAngularComponentTemplateTaskResults(ResolveAngularCompo nentTemplateTask task) {
5666 Source source = task.source;
5667 AnalysisException thrownException = task.exception;
5668 HtmlEntry htmlEntry = null;
5669 {
5670 SourceEntry sourceEntry = _cache.get(source);
5671 if (sourceEntry is! HtmlEntry) {
5672 // This shouldn't be possible because we should never have performed the task if the source
5673 // didn't represent an HTML file, but check to be safe.
5674 throw new AnalysisException.con1("Internal error: attempting to resolve non-HTML file as an HTML file: ${source.fullName}");
5675 }
5676 htmlEntry = sourceEntry as HtmlEntry;
5677 _cache.accessed(source);
5678 int sourceTime = source.modificationStamp;
5679 int resultTime = task.modificationTime;
5680 if (sourceTime == resultTime) {
5681 if (htmlEntry.modificationTime != sourceTime) {
5682 // The source has changed without the context being notified. Simulate notification.
5683 sourceChanged(source);
5684 htmlEntry = getReadableHtmlEntry(source);
5685 if (htmlEntry == null) {
5686 throw new AnalysisException.con1("An HTML file became a non-HTML fil e: ${source.fullName}");
5687 }
5688 }
5689 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
5690 if (thrownException == null) {
5691 htmlCopy.setValue(HtmlEntry.ANGULAR_ERRORS, task.resolutionErrors);
5692 ChangeNoticeImpl notice = getNotice(source);
5693 notice.htmlUnit = task.resolvedUnit;
5694 notice.setErrors(htmlCopy.allErrors, htmlCopy.getValue(SourceEntry.LIN E_INFO));
5695 } else {
5696 htmlCopy.recordResolutionError();
5697 }
5698 htmlCopy.exception = thrownException;
5699 _cache.put(source, htmlCopy);
5700 htmlEntry = htmlCopy;
5701 } else {
5702 HtmlEntryImpl htmlCopy = htmlEntry.writableCopy;
5703 if (thrownException == null || resultTime >= 0) {
5704 //
5705 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
5706 // will be re-analyzed using the up-to-date sources.
5707 //
5708 if (identical(htmlCopy.getState(HtmlEntry.ANGULAR_ERRORS), CacheState. IN_PROCESS)) {
5709 htmlCopy.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.INVALID);
5710 }
5711 if (identical(htmlCopy.getState(HtmlEntry.ELEMENT), CacheState.IN_PROC ESS)) {
5712 htmlCopy.setState(HtmlEntry.ELEMENT, CacheState.INVALID);
5713 }
5714 if (identical(htmlCopy.getState(HtmlEntry.RESOLUTION_ERRORS), CacheSta te.IN_PROCESS)) {
5715 htmlCopy.setState(HtmlEntry.RESOLUTION_ERRORS, CacheState.INVALID);
5716 }
5717 } else {
5718 //
5719 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
5720 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
5721 // that we'll be able to do so without error.
5722 //
5723 htmlCopy.recordResolutionError();
5724 }
5725 htmlCopy.exception = thrownException;
5726 _cache.put(source, htmlCopy);
5727 htmlEntry = htmlCopy;
5728 }
5729 }
5730 if (thrownException != null) {
5731 throw thrownException;
5732 }
5733 return htmlEntry;
5734 }
5735
5736 /**
5737 * Record the results produced by performing a [ResolveDartDependenciesTask]. If the results
5738 * were computed from data that is now out-of-date, then the results will not be recorded.
5739 *
5740 * @param task the task that was performed
5741 * @return an entry containing the computed results
5742 * @throws AnalysisException if the results could not be recorded
5743 */
5744 DartEntry recordResolveDartDependenciesTaskResults(ResolveDartDependenciesTask task) {
5745 Source source = task.source;
5746 AnalysisException thrownException = task.exception;
5747 DartEntry dartEntry = null;
5748 {
5749 SourceEntry sourceEntry = _cache.get(source);
5750 if (sourceEntry is! DartEntry) {
5751 // This shouldn't be possible because we should never have performed the task if the source
5752 // didn't represent a Dart file, but check to be safe.
5753 throw new AnalysisException.con1("Internal error: attempting to resolve Dart dependencies in a non-Dart file: ${source.fullName}");
5754 }
5755 dartEntry = sourceEntry as DartEntry;
5756 _cache.accessed(source);
5757 int sourceTime = source.modificationStamp;
5758 int resultTime = task.modificationTime;
5759 if (sourceTime == resultTime) {
5760 if (dartEntry.modificationTime != sourceTime) {
5761 // The source has changed without the context being notified. Simulate notification.
5762 sourceChanged(source);
5763 dartEntry = getReadableDartEntry(source);
5764 if (dartEntry == null) {
5765 throw new AnalysisException.con1("A Dart file became a non-Dart file : ${source.fullName}");
5766 }
5767 }
5768 DartEntryImpl dartCopy = dartEntry.writableCopy;
5769 if (thrownException == null) {
5770 dartCopy.setValue(DartEntry.EXPORTED_LIBRARIES, task.exportedSources);
5771 dartCopy.setValue(DartEntry.IMPORTED_LIBRARIES, task.importedSources);
5772 dartCopy.setValue(DartEntry.INCLUDED_PARTS, task.includedSources);
5773 } else {
5774 dartCopy.recordDependencyError();
5775 }
5776 dartCopy.exception = thrownException;
5777 _cache.put(source, dartCopy);
5778 dartEntry = dartCopy;
5779 } else {
5780 logInformation2("Dependency resolution results discarded for ${debugging String(source)}; sourceTime = ${sourceTime}, resultTime = ${resultTime}, cacheTi me = ${dartEntry.modificationTime}", thrownException);
5781 DartEntryImpl dartCopy = dartEntry.writableCopy;
5782 if (thrownException == null || resultTime >= 0) {
5783 //
5784 // The analysis was performed on out-of-date sources. Mark the cache s o that the sources
5785 // will be re-analyzed using the up-to-date sources.
5786 //
5787 dartCopy.recordDependencyNotInProcess();
5788 } else {
5789 //
5790 // We could not determine whether the sources were up-to-date or out-o f-date. Mark the
5791 // cache so that we won't attempt to re-analyze the sources until ther e's a good chance
5792 // that we'll be able to do so without error.
5793 //
5794 dartCopy.setState(DartEntry.EXPORTED_LIBRARIES, CacheState.ERROR);
5795 dartCopy.setState(DartEntry.IMPORTED_LIBRARIES, CacheState.ERROR);
5796 dartCopy.setState(DartEntry.INCLUDED_PARTS, CacheState.ERROR);
5797 }
5798 dartCopy.exception = thrownException;
5799 _cache.put(source, dartCopy);
5800 dartEntry = dartCopy;
5801 }
5802 }
5803 if (thrownException != null) {
5804 throw thrownException;
5805 }
5806 return dartEntry;
5807 }
5808
5809 /**
5352 * Record the results produced by performing a [ResolveDartUnitTask]. If the r esults were 5810 * Record the results produced by performing a [ResolveDartUnitTask]. If the r esults were
5353 * computed from data that is now out-of-date, then the results will not be re corded. 5811 * computed from data that is now out-of-date, then the results will not be re corded.
5354 * 5812 *
5355 * @param task the task that was performed 5813 * @param task the task that was performed
5356 * @return an entry containing the computed results 5814 * @return an entry containing the computed results
5357 * @throws AnalysisException if the results could not be recorded 5815 * @throws AnalysisException if the results could not be recorded
5358 */ 5816 */
5359 SourceEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) { 5817 SourceEntry recordResolveDartUnitTaskResults(ResolveDartUnitTask task) {
5360 Source unitSource = task.source; 5818 Source unitSource = task.source;
5361 Source librarySource = task.librarySource; 5819 Source librarySource = task.librarySource;
5362 AnalysisException thrownException = task.exception; 5820 AnalysisException thrownException = task.exception;
5363 DartEntry dartEntry = null; 5821 DartEntry dartEntry = null;
5364 { 5822 {
5365 SourceEntry sourceEntry = _cache.get(unitSource); 5823 SourceEntry sourceEntry = _cache.get(unitSource);
5366 if (sourceEntry is! DartEntry) { 5824 if (sourceEntry is! DartEntry) {
5367 // This shouldn't be possible because we should never have performed the task if the source 5825 // This shouldn't be possible because we should never have performed the task if the source
5368 // didn't represent a Dart file, but check to be safe. 5826 // didn't represent a Dart file, but check to be safe.
5369 throw new AnalysisException.con1("Internal error: attempting to reolve n on-Dart file as a Dart file: ${unitSource.fullName}"); 5827 throw new AnalysisException.con1("Internal error: attempting to resolve non-Dart file as a Dart file: ${unitSource.fullName}");
5370 } 5828 }
5371 dartEntry = sourceEntry as DartEntry; 5829 dartEntry = sourceEntry as DartEntry;
5372 _cache.accessed(unitSource); 5830 _cache.accessed(unitSource);
5373 int sourceTime = unitSource.modificationStamp; 5831 int sourceTime = unitSource.modificationStamp;
5374 int resultTime = task.modificationTime; 5832 int resultTime = task.modificationTime;
5375 if (sourceTime == resultTime) { 5833 if (sourceTime == resultTime) {
5376 if (dartEntry.modificationTime != sourceTime) { 5834 if (dartEntry.modificationTime != sourceTime) {
5377 // The source has changed without the context being notified. Simulate notification. 5835 // The source has changed without the context being notified. Simulate notification.
5378 sourceChanged(unitSource); 5836 sourceChanged(unitSource);
5379 dartEntry = getReadableDartEntry(unitSource); 5837 dartEntry = getReadableDartEntry(unitSource);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5430 */ 5888 */
5431 SourceEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) { 5889 SourceEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) {
5432 Source source = task.source; 5890 Source source = task.source;
5433 AnalysisException thrownException = task.exception; 5891 AnalysisException thrownException = task.exception;
5434 HtmlEntry htmlEntry = null; 5892 HtmlEntry htmlEntry = null;
5435 { 5893 {
5436 SourceEntry sourceEntry = _cache.get(source); 5894 SourceEntry sourceEntry = _cache.get(source);
5437 if (sourceEntry is! HtmlEntry) { 5895 if (sourceEntry is! HtmlEntry) {
5438 // This shouldn't be possible because we should never have performed the task if the source 5896 // This shouldn't be possible because we should never have performed the task if the source
5439 // didn't represent an HTML file, but check to be safe. 5897 // didn't represent an HTML file, but check to be safe.
5440 throw new AnalysisException.con1("Internal error: attempting to reolve n on-HTML file as an HTML file: ${source.fullName}"); 5898 throw new AnalysisException.con1("Internal error: attempting to resolve non-HTML file as an HTML file: ${source.fullName}");
5441 } 5899 }
5442 htmlEntry = sourceEntry as HtmlEntry; 5900 htmlEntry = sourceEntry as HtmlEntry;
5443 _cache.accessed(source); 5901 _cache.accessed(source);
5444 int sourceTime = source.modificationStamp; 5902 int sourceTime = source.modificationStamp;
5445 int resultTime = task.modificationTime; 5903 int resultTime = task.modificationTime;
5446 if (sourceTime == resultTime) { 5904 if (sourceTime == resultTime) {
5447 if (htmlEntry.modificationTime != sourceTime) { 5905 if (htmlEntry.modificationTime != sourceTime) {
5448 // The source has changed without the context being notified. Simulate notification. 5906 // The source has changed without the context being notified. Simulate notification.
5449 sourceChanged(source); 5907 sourceChanged(source);
5450 htmlEntry = getReadableHtmlEntry(source); 5908 htmlEntry = getReadableHtmlEntry(source);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
5637 SourceEntry visitGenerateDartErrorsTask(GenerateDartErrorsTask task) => Analys isContextImpl_this.recordGenerateDartErrorsTask(task); 6095 SourceEntry visitGenerateDartErrorsTask(GenerateDartErrorsTask task) => Analys isContextImpl_this.recordGenerateDartErrorsTask(task);
5638 6096
5639 SourceEntry visitGenerateDartHintsTask(GenerateDartHintsTask task) => Analysis ContextImpl_this.recordGenerateDartHintsTask(task); 6097 SourceEntry visitGenerateDartHintsTask(GenerateDartHintsTask task) => Analysis ContextImpl_this.recordGenerateDartHintsTask(task);
5640 6098
5641 SourceEntry visitIncrementalAnalysisTask(IncrementalAnalysisTask task) => Anal ysisContextImpl_this.recordIncrementalAnalysisTaskResults(task); 6099 SourceEntry visitIncrementalAnalysisTask(IncrementalAnalysisTask task) => Anal ysisContextImpl_this.recordIncrementalAnalysisTaskResults(task);
5642 6100
5643 DartEntry visitParseDartTask(ParseDartTask task) => AnalysisContextImpl_this.r ecordParseDartTaskResults(task); 6101 DartEntry visitParseDartTask(ParseDartTask task) => AnalysisContextImpl_this.r ecordParseDartTaskResults(task);
5644 6102
5645 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => AnalysisContextImpl_this.r ecordParseHtmlTaskResults(task); 6103 HtmlEntry visitParseHtmlTask(ParseHtmlTask task) => AnalysisContextImpl_this.r ecordParseHtmlTaskResults(task);
5646 6104
6105 HtmlEntry visitResolveAngularComponentTemplateTask(ResolveAngularComponentTemp lateTask task) => AnalysisContextImpl_this.recordResolveAngularComponentTemplate TaskResults(task);
6106
6107 DartEntry visitResolveDartDependenciesTask(ResolveDartDependenciesTask task) = > AnalysisContextImpl_this.recordResolveDartDependenciesTaskResults(task);
6108
5647 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => Analysis ContextImpl_this.recordResolveDartLibraryTaskResults(task); 6109 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => Analysis ContextImpl_this.recordResolveDartLibraryTaskResults(task);
5648 6110
5649 SourceEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => AnalysisCont extImpl_this.recordResolveDartUnitTaskResults(task); 6111 SourceEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => AnalysisCont extImpl_this.recordResolveDartUnitTaskResults(task);
5650 6112
5651 SourceEntry visitResolveHtmlTask(ResolveHtmlTask task) => AnalysisContextImpl_ this.recordResolveHtmlTaskResults(task); 6113 SourceEntry visitResolveHtmlTask(ResolveHtmlTask task) => AnalysisContextImpl_ this.recordResolveHtmlTaskResults(task);
5652 } 6114 }
5653 6115
5654 class AnalysisContextImpl_ContextRetentionPolicy implements CacheRetentionPolicy { 6116 class AnalysisContextImpl_ContextRetentionPolicy implements CacheRetentionPolicy {
5655 final AnalysisContextImpl AnalysisContextImpl_this; 6117 final AnalysisContextImpl AnalysisContextImpl_this;
5656 6118
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
5773 /** 6235 /**
5774 * The fully resolved AST that changed as a result of the analysis, or `null` if the AST was 6236 * The fully resolved AST that changed as a result of the analysis, or `null` if the AST was
5775 * not changed. 6237 * not changed.
5776 */ 6238 */
5777 CompilationUnit compilationUnit; 6239 CompilationUnit compilationUnit;
5778 6240
5779 /** 6241 /**
5780 * The fully resolved HTML that changed as a result of the analysis, or `null` if the HTML 6242 * The fully resolved HTML that changed as a result of the analysis, or `null` if the HTML
5781 * was not changed. 6243 * was not changed.
5782 */ 6244 */
5783 HtmlUnit htmlUnit; 6245 ht.HtmlUnit htmlUnit;
5784 6246
5785 /** 6247 /**
5786 * The errors that changed as a result of the analysis, or `null` if errors we re not 6248 * The errors that changed as a result of the analysis, or `null` if errors we re not
5787 * changed. 6249 * changed.
5788 */ 6250 */
5789 List<AnalysisError> _errors; 6251 List<AnalysisError> _errors;
5790 6252
5791 /** 6253 /**
5792 * The line information associated with the source, or `null` if errors were n ot changed. 6254 * The line information associated with the source, or `null` if errors were n ot changed.
5793 */ 6255 */
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
6032 } 6494 }
6033 6495
6034 CompilationUnit parseCompilationUnit(Source source) { 6496 CompilationUnit parseCompilationUnit(Source source) {
6035 if (source.isInSystemLibrary) { 6497 if (source.isInSystemLibrary) {
6036 return _sdkAnalysisContext.parseCompilationUnit(source); 6498 return _sdkAnalysisContext.parseCompilationUnit(source);
6037 } else { 6499 } else {
6038 return super.parseCompilationUnit(source); 6500 return super.parseCompilationUnit(source);
6039 } 6501 }
6040 } 6502 }
6041 6503
6042 HtmlUnit parseHtmlUnit(Source source) { 6504 ht.HtmlUnit parseHtmlUnit(Source source) {
6043 if (source.isInSystemLibrary) { 6505 if (source.isInSystemLibrary) {
6044 return _sdkAnalysisContext.parseHtmlUnit(source); 6506 return _sdkAnalysisContext.parseHtmlUnit(source);
6045 } else { 6507 } else {
6046 return super.parseHtmlUnit(source); 6508 return super.parseHtmlUnit(source);
6047 } 6509 }
6048 } 6510 }
6049 6511
6050 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { 6512 void recordLibraryElements(Map<Source, LibraryElement> elementMap) {
6051 if (elementMap.isEmpty) { 6513 if (elementMap.isEmpty) {
6052 return; 6514 return;
(...skipping 19 matching lines...) Expand all
6072 } 6534 }
6073 6535
6074 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) { 6536 CompilationUnit resolveCompilationUnit2(Source unitSource, Source librarySourc e) {
6075 if (unitSource.isInSystemLibrary) { 6537 if (unitSource.isInSystemLibrary) {
6076 return _sdkAnalysisContext.resolveCompilationUnit2(unitSource, librarySour ce); 6538 return _sdkAnalysisContext.resolveCompilationUnit2(unitSource, librarySour ce);
6077 } else { 6539 } else {
6078 return super.resolveCompilationUnit2(unitSource, librarySource); 6540 return super.resolveCompilationUnit2(unitSource, librarySource);
6079 } 6541 }
6080 } 6542 }
6081 6543
6082 HtmlUnit resolveHtmlUnit(Source unitSource) { 6544 ht.HtmlUnit resolveHtmlUnit(Source unitSource) {
6083 if (unitSource.isInSystemLibrary) { 6545 if (unitSource.isInSystemLibrary) {
6084 return _sdkAnalysisContext.resolveHtmlUnit(unitSource); 6546 return _sdkAnalysisContext.resolveHtmlUnit(unitSource);
6085 } else { 6547 } else {
6086 return super.resolveHtmlUnit(unitSource); 6548 return super.resolveHtmlUnit(unitSource);
6087 } 6549 }
6088 } 6550 }
6089 6551
6090 void setChangedContents(Source source, String contents, int offset, int oldLen gth, int newLength) { 6552 void setChangedContents(Source source, String contents, int offset, int oldLen gth, int newLength) {
6091 if (source.isInSystemLibrary) { 6553 if (source.isInSystemLibrary) {
6092 _sdkAnalysisContext.setChangedContents(source, contents, offset, oldLength , newLength); 6554 _sdkAnalysisContext.setChangedContents(source, contents, offset, oldLength , newLength);
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
6593 List<Source> ret = _basis.getLibrariesDependingOn(librarySource); 7055 List<Source> ret = _basis.getLibrariesDependingOn(librarySource);
6594 if (ret != null) { 7056 if (ret != null) {
6595 instrumentation.metric2("Source-count", ret.length); 7057 instrumentation.metric2("Source-count", ret.length);
6596 } 7058 }
6597 return ret; 7059 return ret;
6598 } finally { 7060 } finally {
6599 instrumentation.log(); 7061 instrumentation.log();
6600 } 7062 }
6601 } 7063 }
6602 7064
7065 List<AngularElement> getLibraryAngularElements(Source source) {
7066 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLibraryAngularElements");
7067 try {
7068 instrumentation.metric3("contextId", _contextId);
7069 return _basis.getLibraryAngularElements(source);
7070 } finally {
7071 instrumentation.log();
7072 }
7073 }
7074
6603 LibraryElement getLibraryElement(Source source) { 7075 LibraryElement getLibraryElement(Source source) {
6604 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLibraryElement"); 7076 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getLibraryElement");
6605 try { 7077 try {
6606 instrumentation.metric3("contextId", _contextId); 7078 instrumentation.metric3("contextId", _contextId);
6607 return _basis.getLibraryElement(source); 7079 return _basis.getLibraryElement(source);
6608 } finally { 7080 } finally {
6609 instrumentation.log(); 7081 instrumentation.log();
6610 } 7082 }
6611 } 7083 }
6612 7084
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6653 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) { 7125 CompilationUnit getResolvedCompilationUnit2(Source unitSource, Source libraryS ource) {
6654 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getResolvedCompilationUnit"); 7126 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getResolvedCompilationUnit");
6655 try { 7127 try {
6656 instrumentation.metric3("contextId", _contextId); 7128 instrumentation.metric3("contextId", _contextId);
6657 return _basis.getResolvedCompilationUnit2(unitSource, librarySource); 7129 return _basis.getResolvedCompilationUnit2(unitSource, librarySource);
6658 } finally { 7130 } finally {
6659 instrumentation.log2(2); 7131 instrumentation.log2(2);
6660 } 7132 }
6661 } 7133 }
6662 7134
6663 HtmlUnit getResolvedHtmlUnit(Source htmlSource) { 7135 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) {
6664 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getResolvedHtmlUnit"); 7136 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- getResolvedHtmlUnit");
6665 try { 7137 try {
6666 instrumentation.metric3("contextId", _contextId); 7138 instrumentation.metric3("contextId", _contextId);
6667 return _basis.getResolvedHtmlUnit(htmlSource); 7139 return _basis.getResolvedHtmlUnit(htmlSource);
6668 } finally { 7140 } finally {
6669 instrumentation.log2(2); 7141 instrumentation.log2(2);
6670 } 7142 }
6671 } 7143 }
6672 7144
6673 SourceFactory get sourceFactory { 7145 SourceFactory get sourceFactory {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6725 instrumentation.metric3("contextId", _contextId); 7197 instrumentation.metric3("contextId", _contextId);
6726 return _basis.parseCompilationUnit(source); 7198 return _basis.parseCompilationUnit(source);
6727 } on AnalysisException catch (e) { 7199 } on AnalysisException catch (e) {
6728 recordAnalysisException(instrumentation, e); 7200 recordAnalysisException(instrumentation, e);
6729 throw e; 7201 throw e;
6730 } finally { 7202 } finally {
6731 instrumentation.log(); 7203 instrumentation.log();
6732 } 7204 }
6733 } 7205 }
6734 7206
6735 HtmlUnit parseHtmlUnit(Source source) { 7207 ht.HtmlUnit parseHtmlUnit(Source source) {
6736 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- parseHtmlUnit"); 7208 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- parseHtmlUnit");
6737 try { 7209 try {
6738 instrumentation.metric3("contextId", _contextId); 7210 instrumentation.metric3("contextId", _contextId);
6739 return _basis.parseHtmlUnit(source); 7211 return _basis.parseHtmlUnit(source);
6740 } on AnalysisException catch (e) { 7212 } on AnalysisException catch (e) {
6741 recordAnalysisException(instrumentation, e); 7213 recordAnalysisException(instrumentation, e);
6742 throw e; 7214 throw e;
6743 } finally { 7215 } finally {
6744 instrumentation.log(); 7216 instrumentation.log();
6745 } 7217 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
6782 instrumentation.metric3("contextId", _contextId); 7254 instrumentation.metric3("contextId", _contextId);
6783 return _basis.resolveCompilationUnit2(unitSource, librarySource); 7255 return _basis.resolveCompilationUnit2(unitSource, librarySource);
6784 } on AnalysisException catch (e) { 7256 } on AnalysisException catch (e) {
6785 recordAnalysisException(instrumentation, e); 7257 recordAnalysisException(instrumentation, e);
6786 throw e; 7258 throw e;
6787 } finally { 7259 } finally {
6788 instrumentation.log(); 7260 instrumentation.log();
6789 } 7261 }
6790 } 7262 }
6791 7263
6792 HtmlUnit resolveHtmlUnit(Source htmlSource) { 7264 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) {
6793 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- resolveHtmlUnit"); 7265 InstrumentationBuilder instrumentation = Instrumentation.builder2("Analysis- resolveHtmlUnit");
6794 try { 7266 try {
6795 instrumentation.metric3("contextId", _contextId); 7267 instrumentation.metric3("contextId", _contextId);
6796 return _basis.resolveHtmlUnit(htmlSource); 7268 return _basis.resolveHtmlUnit(htmlSource);
6797 } on AnalysisException catch (e) { 7269 } on AnalysisException catch (e) {
6798 recordAnalysisException(instrumentation, e); 7270 recordAnalysisException(instrumentation, e);
6799 throw e; 7271 throw e;
6800 } finally { 7272 } finally {
6801 instrumentation.log(); 7273 instrumentation.log();
6802 } 7274 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
7204 * @return the AST that was created from the source 7676 * @return the AST that was created from the source
7205 */ 7677 */
7206 CompilationUnit get compilationUnit => data; 7678 CompilationUnit get compilationUnit => data;
7207 } 7679 }
7208 7680
7209 /** 7681 /**
7210 * Instances of the class `ResolvableHtmlUnit` represent an HTML unit that is no t referenced 7682 * Instances of the class `ResolvableHtmlUnit` represent an HTML unit that is no t referenced
7211 * by any other objects and for which we have modification stamp information. It is used by the 7683 * by any other objects and for which we have modification stamp information. It is used by the
7212 * [ResolveHtmlTask] to resolve an HTML source. 7684 * [ResolveHtmlTask] to resolve an HTML source.
7213 */ 7685 */
7214 class ResolvableHtmlUnit extends TimestampedData<HtmlUnit> { 7686 class ResolvableHtmlUnit extends TimestampedData<ht.HtmlUnit> {
7215 /** 7687 /**
7216 * Initialize a newly created holder to hold the given values. 7688 * Initialize a newly created holder to hold the given values.
7217 * 7689 *
7218 * @param modificationTime the modification time of the source from which the AST was created 7690 * @param modificationTime the modification time of the source from which the AST was created
7219 * @param unit the AST that was created from the source 7691 * @param unit the AST that was created from the source
7220 */ 7692 */
7221 ResolvableHtmlUnit(int modificationTime, HtmlUnit unit) : super(modificationTi me, unit); 7693 ResolvableHtmlUnit(int modificationTime, ht.HtmlUnit unit) : super(modificatio nTime, unit);
7222 7694
7223 /** 7695 /**
7224 * Return the AST that was created from the source. 7696 * Return the AST that was created from the source.
7225 * 7697 *
7226 * @return the AST that was created from the source 7698 * @return the AST that was created from the source
7227 */ 7699 */
7228 HtmlUnit get compilationUnit => data; 7700 ht.HtmlUnit get compilationUnit => data;
7229 } 7701 }
7230 7702
7231 /** 7703 /**
7232 * Instances of the class `TimestampedData` represent analysis data for which we have a 7704 * Instances of the class `TimestampedData` represent analysis data for which we have a
7233 * modification time. 7705 * modification time.
7234 */ 7706 */
7235 class TimestampedData<E> { 7707 class TimestampedData<E> {
7236 /** 7708 /**
7237 * The modification time of the source from which the data was created. 7709 * The modification time of the source from which the data was created.
7238 */ 7710 */
7239 final int modificationTime; 7711 final int modificationTime;
7240 7712
7241 /** 7713 /**
7242 * The data that was created from the source. 7714 * The data that was created from the source.
7243 */ 7715 */
7244 final E data; 7716 final E data;
7245 7717
7246 /** 7718 /**
7247 * Initialize a newly created holder to hold the given values. 7719 * Initialize a newly created holder to hold the given values.
7248 * 7720 *
7249 * @param modificationTime the modification time of the source from which the data was created 7721 * @param modificationTime the modification time of the source from which the data was created
7250 * @param unit the data that was created from the source 7722 * @param unit the data that was created from the source
7251 */ 7723 */
7252 TimestampedData(this.modificationTime, this.data); 7724 TimestampedData(this.modificationTime, this.data);
7253 } 7725 }
7254 7726
7255 /** 7727 /**
7728 * Instances of the class [AngularHtmlUnitResolver] resolve Angular specific exp ressions.
7729 */
7730 class AngularHtmlUnitResolver extends ht.RecursiveXmlVisitor<Object> {
7731 static int _OPENING_DELIMITER_CHAR = 0x7B;
7732
7733 static int _CLOSING_DELIMITER_CHAR = 0x7D;
7734
7735 static String _OPENING_DELIMITER = "{{";
7736
7737 static String _CLOSING_DELIMITER = "}}";
7738
7739 static int _OPENING_DELIMITER_LENGTH = _OPENING_DELIMITER.length;
7740
7741 static int _CLOSING_DELIMITER_LENGTH = _CLOSING_DELIMITER.length;
7742
7743 static String _NG_APP = "ng-app";
7744
7745 /**
7746 * Checks if given [Element] is an artificial local variable and returns corre sponding
7747 * [AngularElement], or `null` otherwise.
7748 */
7749 static AngularElement getAngularElement(Element element) {
7750 // may be artificial local variable, replace with AngularElement
7751 if (element is LocalVariableElement) {
7752 LocalVariableElement local = element;
7753 List<ToolkitObjectElement> toolkitObjects = local.toolkitObjects;
7754 if (toolkitObjects.length == 1 && toolkitObjects[0] is AngularElement) {
7755 return toolkitObjects[0] as AngularElement;
7756 }
7757 }
7758 // not a special Element
7759 return null;
7760 }
7761
7762 /**
7763 * @return `true` if the given [HtmlUnit] has <code>ng-app</code> annotation.
7764 */
7765 static bool hasAngularAnnotation(ht.HtmlUnit htmlUnit) {
7766 try {
7767 htmlUnit.accept(new RecursiveXmlVisitor_AngularHtmlUnitResolver_hasAngular Annotation());
7768 } on AngularHtmlUnitResolver_FoundAppError catch (e) {
7769 return true;
7770 }
7771 return false;
7772 }
7773
7774 static SimpleIdentifier createIdentifier(String name, int offset) {
7775 StringToken token = createStringToken(name, offset);
7776 return new SimpleIdentifier(token);
7777 }
7778
7779 static StringToken createStringToken(String name, int offset) => new StringTok en(TokenType.IDENTIFIER, name, offset);
7780
7781 InternalAnalysisContext _context;
7782
7783 TypeProvider _typeProvider;
7784
7785 AnalysisErrorListener _errorListener;
7786
7787 Source _source;
7788
7789 LineInfo _lineInfo;
7790
7791 ht.HtmlUnit _unit;
7792
7793 List<AngularElement> _angularElements;
7794
7795 List<NgProcessor> _processors = [];
7796
7797 LibraryElementImpl _libraryElement;
7798
7799 CompilationUnitElementImpl _unitElement;
7800
7801 FunctionElementImpl _functionElement;
7802
7803 ResolverVisitor _resolver;
7804
7805 bool _isAngular = false;
7806
7807 List<LocalVariableElementImpl> _definedVariables = [];
7808
7809 Set<LibraryElement> _injectedLibraries = new Set();
7810
7811 Scope _topNameScope;
7812
7813 Scope _nameScope;
7814
7815 AngularHtmlUnitResolver(InternalAnalysisContext context, AnalysisErrorListener errorListener, Source source, LineInfo lineInfo, ht.HtmlUnit unit) {
7816 this._context = context;
7817 this._typeProvider = context.typeProvider;
7818 this._errorListener = errorListener;
7819 this._source = source;
7820 this._lineInfo = lineInfo;
7821 this._unit = unit;
7822 }
7823
7824 /**
7825 * Resolves [source] as an [AngularComponentElement] template file.
7826 *
7827 * @param angularElements the [AngularElement]s accessible in the component's library, not
7828 * `null`
7829 * @param component the [AngularComponentElement] to resolve template for, not `null`
7830 */
7831 void resolveComponentTemplate(List<AngularElement> angularElements, AngularCom ponentElement component) {
7832 _isAngular = true;
7833 resolveInternal(angularElements, component);
7834 }
7835
7836 /**
7837 * Resolves [source] as an entry-point HTML file, that references an external Dart script.
7838 */
7839 void resolveEntryPoint() {
7840 // check if Angular at all
7841 if (!hasAngularAnnotation(_unit)) {
7842 return;
7843 }
7844 // prepare accessible Angular elements
7845 List<AngularElement> angularElements;
7846 {
7847 // prepare external Dart script source
7848 Source dartSource = getDartSource(_unit);
7849 if (dartSource == null) {
7850 return;
7851 }
7852 // ensure resolved
7853 _context.resolveCompilationUnit2(dartSource, dartSource);
7854 // get cached Angular elements
7855 angularElements = _context.getLibraryAngularElements(dartSource);
7856 }
7857 // perform resolution
7858 resolveInternal(angularElements, null);
7859 }
7860
7861 Object visitXmlAttributeNode(ht.XmlAttributeNode node) {
7862 parseEmbeddedExpressions2(node);
7863 resolveExpressions(node.expressions);
7864 return super.visitXmlAttributeNode(node);
7865 }
7866
7867 Object visitXmlTagNode(ht.XmlTagNode node) {
7868 bool wasAngular = _isAngular;
7869 try {
7870 // new Angular context
7871 if (node.getAttribute(_NG_APP) != null) {
7872 _isAngular = true;
7873 visitModelDirectives(node);
7874 }
7875 // not Angular
7876 if (!_isAngular) {
7877 return super.visitXmlTagNode(node);
7878 }
7879 // process node in separate name scope
7880 _nameScope = _resolver.pushNameScope();
7881 try {
7882 parseEmbeddedExpressions3(node);
7883 // apply processors
7884 for (NgProcessor processor in _processors) {
7885 if (processor.canApply(node)) {
7886 processor.apply(this, node);
7887 }
7888 }
7889 // resolve expressions
7890 resolveExpressions(node.expressions);
7891 // process children
7892 return super.visitXmlTagNode(node);
7893 } finally {
7894 _resolver.popNameScope();
7895 }
7896 } finally {
7897 _isAngular = wasAngular;
7898 }
7899 }
7900
7901 /**
7902 * Creates new [LocalVariableElementImpl] with given type and identifier.
7903 *
7904 * @param type the [Type] of the variable
7905 * @param identifier the identifier to create variable for
7906 * @return the new [LocalVariableElementImpl]
7907 */
7908 LocalVariableElementImpl createLocalVariable(Type2 type, SimpleIdentifier iden tifier) {
7909 LocalVariableElementImpl variable = new LocalVariableElementImpl(identifier) ;
7910 _definedVariables.add(variable);
7911 variable.type = type;
7912 return variable;
7913 }
7914
7915 /**
7916 * Creates new [LocalVariableElementImpl] with given name and type.
7917 *
7918 * @param type the [Type] of the variable
7919 * @param name the name of the variable
7920 * @return the new [LocalVariableElementImpl]
7921 */
7922 LocalVariableElementImpl createLocalVariable2(Type2 type, String name) {
7923 SimpleIdentifier identifier = createIdentifier(name, 0);
7924 return createLocalVariable(type, identifier);
7925 }
7926
7927 /**
7928 * Declares the given [LocalVariableElementImpl] in the [topNameScope].
7929 */
7930 void defineTopVariable(LocalVariableElementImpl variable) {
7931 recordDefinedVariable(variable);
7932 _topNameScope.define(variable);
7933 recordTypeLibraryInjected(variable);
7934 }
7935
7936 /**
7937 * Declares the given [LocalVariableElementImpl] in the current [nameScope].
7938 */
7939 void defineVariable(LocalVariableElementImpl variable) {
7940 recordDefinedVariable(variable);
7941 _nameScope.define(variable);
7942 recordTypeLibraryInjected(variable);
7943 }
7944
7945 /**
7946 * @return the [AngularElement] with the given name, maybe `null`.
7947 */
7948 AngularElement findAngularElement(String name) {
7949 for (AngularElement element in _angularElements) {
7950 if (name == element.name) {
7951 return element;
7952 }
7953 }
7954 return null;
7955 }
7956
7957 /**
7958 * @return the [TypeProvider] of the [AnalysisContext].
7959 */
7960 TypeProvider get typeProvider => _typeProvider;
7961
7962 /**
7963 * Parses given [String] as an [Expression] at the given offset.
7964 */
7965 Expression parseExpression(String contents, int offset) => parseExpression2(co ntents, 0, contents.length, offset);
7966
7967 Expression parseExpression2(String contents, int startIndex, int endIndex, int offset) {
7968 Token token = scanDart(contents, startIndex, endIndex, offset);
7969 return parseExpression3(token);
7970 }
7971
7972 Expression parseExpression3(Token token) => ht.HtmlParser.parseEmbeddedExpress ion(_source, token, _errorListener);
7973
7974 /**
7975 * Reports given [ErrorCode] at the given [ASTNode].
7976 */
7977 void reportError(ASTNode node, ErrorCode errorCode, List<Object> arguments) {
7978 reportError7(node.offset, node.length, errorCode, arguments);
7979 }
7980
7981 /**
7982 * Reports given [ErrorCode] at the given position.
7983 */
7984 void reportError7(int offset, int length, ErrorCode errorCode, List<Object> ar guments) {
7985 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error Code, arguments));
7986 }
7987
7988 /**
7989 * Resolves given [ASTNode] using [resolver].
7990 */
7991 void resolveNode(ASTNode node) {
7992 node.accept(_resolver);
7993 }
7994
7995 Token scanDart(String contents, int startIndex, int endIndex, int offset) => h t.HtmlParser.scanDartSource(_source, _lineInfo, contents.substring(startIndex, e ndIndex), offset + startIndex, _errorListener);
7996
7997 /**
7998 * Puts into [libraryElement] an artificial [LibraryElementImpl] for this HTML
7999 * [Source].
8000 */
8001 void createLibraryElement() {
8002 // create CompilationUnitElementImpl
8003 String unitName = _source.shortName;
8004 _unitElement = new CompilationUnitElementImpl(unitName);
8005 _unitElement.source = _source;
8006 // create LibraryElementImpl
8007 _libraryElement = new LibraryElementImpl(_context, null);
8008 _libraryElement.definingCompilationUnit = _unitElement;
8009 // create FunctionElementImpl
8010 _functionElement = new FunctionElementImpl.con2(0);
8011 _unitElement.functions = <FunctionElement> [_functionElement];
8012 }
8013
8014 /**
8015 * Creates new [NgProcessor] for the given [AngularElement], maybe `null` if n ot
8016 * supported.
8017 */
8018 NgProcessor createProcessor(AngularElement element) {
8019 if (element is AngularComponentElement) {
8020 AngularComponentElement component = element;
8021 return new NgComponentElementProcessor(component);
8022 }
8023 if (element is AngularControllerElement) {
8024 AngularControllerElement controller = element;
8025 return new NgControllerElementProcessor(controller);
8026 }
8027 if (element is AngularDirectiveElement) {
8028 AngularDirectiveElement directive = element;
8029 return new NgDirectiveElementProcessor(directive);
8030 }
8031 return null;
8032 }
8033
8034 /**
8035 * Puts into [resolver] an [ResolverVisitor] to resolve [Expression]s in
8036 * [source].
8037 */
8038 void createResolver() {
8039 InheritanceManager inheritanceManager = new InheritanceManager(_libraryEleme nt);
8040 _resolver = new ResolverVisitor.con2(_libraryElement, _source, _typeProvider , inheritanceManager, _errorListener);
8041 _topNameScope = _resolver.pushNameScope();
8042 }
8043
8044 /**
8045 * Returns the external Dart script [Source] referenced by the given [HtmlUnit ].
8046 */
8047 Source getDartSource(ht.HtmlUnit unit) {
8048 for (HtmlScriptElement script in unit.element.scripts) {
8049 if (script is ExternalHtmlScriptElement) {
8050 Source scriptSource = script.scriptSource;
8051 if (scriptSource != null) {
8052 return scriptSource;
8053 }
8054 }
8055 }
8056 return null;
8057 }
8058
8059 /**
8060 * Parse the value of the given token for embedded expressions, and add any em bedded expressions
8061 * that are found to the given list of expressions.
8062 *
8063 * @param expressions the list to which embedded expressions are to be added
8064 * @param token the token whose value is to be parsed
8065 */
8066 void parseEmbeddedExpressions(List<ht.EmbeddedExpression> expressions, ht.Toke n token) {
8067 // prepare Token information
8068 String lexeme = token.lexeme;
8069 int offset = token.offset;
8070 // find expressions between {{ and }}
8071 int startIndex = StringUtilities.indexOf2(lexeme, 0, _OPENING_DELIMITER_CHAR , _OPENING_DELIMITER_CHAR);
8072 while (startIndex >= 0) {
8073 int endIndex = StringUtilities.indexOf2(lexeme, startIndex + _OPENING_DELI MITER_LENGTH, _CLOSING_DELIMITER_CHAR, _CLOSING_DELIMITER_CHAR);
8074 if (endIndex < 0) {
8075 // TODO(brianwilkerson) Should we report this error or will it be report ed by something else?
8076 return;
8077 } else if (startIndex + _OPENING_DELIMITER_LENGTH < endIndex) {
8078 startIndex += _OPENING_DELIMITER_LENGTH;
8079 Expression expression = parseExpression2(lexeme, startIndex, endIndex, o ffset);
8080 expressions.add(new ht.EmbeddedExpression(startIndex, expression, endInd ex));
8081 }
8082 startIndex = StringUtilities.indexOf2(lexeme, endIndex + _CLOSING_DELIMITE R_LENGTH, _OPENING_DELIMITER_CHAR, _OPENING_DELIMITER_CHAR);
8083 }
8084 }
8085
8086 void parseEmbeddedExpressions2(ht.XmlAttributeNode node) {
8087 List<ht.EmbeddedExpression> expressions = new List<ht.EmbeddedExpression>();
8088 parseEmbeddedExpressions(expressions, node.valueToken);
8089 if (!expressions.isEmpty) {
8090 node.expressions = new List.from(expressions);
8091 }
8092 }
8093
8094 void parseEmbeddedExpressions3(ht.XmlTagNode node) {
8095 List<ht.EmbeddedExpression> expressions = new List<ht.EmbeddedExpression>();
8096 ht.Token token = node.attributeEnd;
8097 ht.Token endToken = node.endToken;
8098 bool inChild = false;
8099 while (token != endToken) {
8100 for (ht.XmlTagNode child in node.tagNodes) {
8101 if (identical(token, child.beginToken)) {
8102 inChild = true;
8103 break;
8104 }
8105 if (identical(token, child.endToken)) {
8106 inChild = false;
8107 break;
8108 }
8109 }
8110 if (!inChild && identical(token.type, ht.TokenType.TEXT)) {
8111 parseEmbeddedExpressions(expressions, token);
8112 }
8113 token = token.next;
8114 }
8115 node.expressions = new List.from(expressions);
8116 }
8117
8118 void recordDefinedVariable(LocalVariableElementImpl variable) {
8119 _definedVariables.add(variable);
8120 _functionElement.localVariables = new List.from(_definedVariables);
8121 }
8122
8123 /**
8124 * When we inject variable, we give access to the library of its type.
8125 */
8126 void recordTypeLibraryInjected(LocalVariableElementImpl variable) {
8127 LibraryElement typeLibrary = variable.type.element.library;
8128 _injectedLibraries.add(typeLibrary);
8129 }
8130
8131 void resolveExpressions(List<ht.EmbeddedExpression> expressions) {
8132 for (ht.EmbeddedExpression embeddedExpression in expressions) {
8133 Expression expression = embeddedExpression.expression;
8134 resolveNode(expression);
8135 }
8136 }
8137
8138 /**
8139 * Resolves Angular specific expressions and elements in the [source].
8140 *
8141 * @param angularElements the [AngularElement]s accessible in the component's library, not
8142 * `null`
8143 * @param component the [AngularComponentElement] to resolve template for, may be
8144 * `null` if not a component template
8145 */
8146 void resolveInternal(List<AngularElement> angularElements, AngularComponentEle ment component) {
8147 this._angularElements = angularElements;
8148 // add built-in processors
8149 _processors.add(NgModelProcessor.INSTANCE);
8150 // _processors.add(NgRepeatProcessor.INSTANCE);
8151 // add accessible processors
8152 for (AngularElement angularElement in angularElements) {
8153 NgProcessor processor = createProcessor(angularElement);
8154 if (processor != null) {
8155 _processors.add(processor);
8156 }
8157 }
8158 // prepare Dart library
8159 createLibraryElement();
8160 _unit.compilationUnitElement = _libraryElement.definingCompilationUnit;
8161 // prepare Dart resolver
8162 createResolver();
8163 // may be resolving component template
8164 LocalVariableElementImpl componentVariable = null;
8165 if (component != null) {
8166 ClassElement componentClassElement = component.enclosingElement as ClassEl ement;
8167 InterfaceType componentType = componentClassElement.type;
8168 componentVariable = createLocalVariable2(componentType, component.name);
8169 defineTopVariable(componentVariable);
8170 componentVariable.toolkitObjects = <AngularElement> [component];
8171 }
8172 // run this HTML visitor
8173 _unit.accept(this);
8174 // simulate imports for injects
8175 {
8176 List<ImportElement> imports = [];
8177 for (LibraryElement injectedLibrary in _injectedLibraries) {
8178 ImportElementImpl importElement = new ImportElementImpl(-1);
8179 importElement.importedLibrary = injectedLibrary;
8180 imports.add(importElement);
8181 }
8182 _libraryElement.imports = new List.from(imports);
8183 }
8184 // push conditional errors
8185 for (ProxyConditionalAnalysisError conditionalCode in _resolver.proxyConditi onalAnalysisErrors) {
8186 _resolver.reportError(conditionalCode.analysisError);
8187 }
8188 }
8189
8190 /**
8191 * The "ng-model" directive is special, it contributes to the top-level name s cope. These models
8192 * can be used before actual "ng-model" attribute in HTML. So, we need to defi ne them once we
8193 * found [NG_APP] context.
8194 */
8195 void visitModelDirectives(ht.XmlTagNode appNode) {
8196 appNode.accept(new RecursiveXmlVisitor_AngularHtmlUnitResolver_visitModelDir ectives(this));
8197 }
8198 }
8199
8200 class AngularHtmlUnitResolver_FoundAppError extends Error {
8201 }
8202
8203 class RecursiveXmlVisitor_AngularHtmlUnitResolver_hasAngularAnnotation extends h t.RecursiveXmlVisitor<Object> {
8204 Object visitXmlTagNode(ht.XmlTagNode node) {
8205 if (node.getAttribute(AngularHtmlUnitResolver._NG_APP) != null) {
8206 throw new AngularHtmlUnitResolver_FoundAppError();
8207 }
8208 return super.visitXmlTagNode(node);
8209 }
8210 }
8211
8212 class RecursiveXmlVisitor_AngularHtmlUnitResolver_visitModelDirectives extends h t.RecursiveXmlVisitor<Object> {
8213 final AngularHtmlUnitResolver AngularHtmlUnitResolver_this;
8214
8215 RecursiveXmlVisitor_AngularHtmlUnitResolver_visitModelDirectives(this.AngularH tmlUnitResolver_this) : super();
8216
8217 Object visitXmlTagNode(ht.XmlTagNode node) {
8218 NgModelProcessor directive = NgModelProcessor.INSTANCE;
8219 if (directive.canApply(node)) {
8220 directive.applyTopDeclarations(AngularHtmlUnitResolver_this, node);
8221 }
8222 return super.visitXmlTagNode(node);
8223 }
8224 }
8225
8226 /**
8227 * Recursively visits [HtmlUnit] and every embedded [Expression].
8228 */
8229 abstract class ExpressionVisitor extends ht.RecursiveXmlVisitor<Object> {
8230 /**
8231 * Visits the given [Expression]s embedded into tag or attribute.
8232 *
8233 * @param expression the [Expression] to visit, not `null`
8234 */
8235 void visitExpression(Expression expression);
8236
8237 Object visitXmlAttributeNode(ht.XmlAttributeNode node) {
8238 visitExpressions(node.expressions);
8239 return super.visitXmlAttributeNode(node);
8240 }
8241
8242 Object visitXmlTagNode(ht.XmlTagNode node) {
8243 visitExpressions(node.expressions);
8244 return super.visitXmlTagNode(node);
8245 }
8246
8247 /**
8248 * Visits [Expression]s of the given [EmbeddedExpression]s.
8249 */
8250 void visitExpressions(List<ht.EmbeddedExpression> expressions) {
8251 for (ht.EmbeddedExpression embeddedExpression in expressions) {
8252 Expression expression = embeddedExpression.expression;
8253 visitExpression(expression);
8254 }
8255 }
8256 }
8257
8258 /**
8259 * [NgComponentElementProcessor] applies [AngularComponentElement] by parsing ma pped
8260 * attributes as expressions.
8261 */
8262 class NgComponentElementProcessor extends NgDirectiveProcessor {
8263 AngularComponentElement _element;
8264
8265 NgComponentElementProcessor(AngularComponentElement element) {
8266 this._element = element;
8267 }
8268
8269 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) {
8270 node.element = _element.selector;
8271 for (AngularPropertyElement property in _element.properties) {
8272 String name = property.name;
8273 ht.XmlAttributeNode attribute = node.getAttribute(name);
8274 if (attribute != null) {
8275 attribute.element = property;
8276 // resolve if binding
8277 if (property.propertyKind != AngularPropertyKind.ATTR) {
8278 Expression expression = parseExpression(resolver, attribute);
8279 resolver.resolveNode(expression);
8280 setExpression(attribute, expression);
8281 }
8282 }
8283 }
8284 }
8285
8286 bool canApply(ht.XmlTagNode node) => _element.selector.apply(node);
8287 }
8288
8289 /**
8290 * [NgControllerElementProcessor] applies [AngularControllerElement].
8291 */
8292 class NgControllerElementProcessor extends NgProcessor {
8293 AngularControllerElement _element;
8294
8295 NgControllerElementProcessor(AngularControllerElement element) {
8296 this._element = element;
8297 }
8298
8299 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) {
8300 InterfaceType type = (_element.enclosingElement as ClassElement).type;
8301 String name = _element.name;
8302 LocalVariableElementImpl variable = resolver.createLocalVariable2(type, name );
8303 resolver.defineVariable(variable);
8304 variable.toolkitObjects = <AngularElement> [_element];
8305 }
8306
8307 bool canApply(ht.XmlTagNode node) => _element.selector.apply(node);
8308 }
8309
8310 /**
8311 * [NgDirectiveElementProcessor] applies [AngularDirectiveElement] by parsing ma pped
8312 * attributes as expressions.
8313 */
8314 class NgDirectiveElementProcessor extends NgDirectiveProcessor {
8315 AngularDirectiveElement _element;
8316
8317 NgDirectiveElementProcessor(AngularDirectiveElement element) {
8318 this._element = element;
8319 }
8320
8321 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) {
8322 for (AngularPropertyElement property in _element.properties) {
8323 // prepare attribute name
8324 String name = property.name;
8325 if (name == ".") {
8326 AngularSelectorElement selector = _element.selector;
8327 if (selector is HasAttributeSelectorElementImpl) {
8328 name = selector.name;
8329 }
8330 }
8331 // resolve attribute expression
8332 ht.XmlAttributeNode attribute = node.getAttribute(name);
8333 if (attribute != null) {
8334 attribute.element = property;
8335 // resolve if binding
8336 if (property.propertyKind != AngularPropertyKind.ATTR) {
8337 Expression expression = parseExpression(resolver, attribute);
8338 resolver.resolveNode(expression);
8339 setExpression(attribute, expression);
8340 }
8341 }
8342 }
8343 }
8344
8345 bool canApply(ht.XmlTagNode node) => _element.selector.apply(node);
8346 }
8347
8348 /**
8349 * [NgDirectiveProcessor] describes any <code>NgDirective</code> annotation inst ance.
8350 */
8351 abstract class NgDirectiveProcessor extends NgProcessor {
8352 static ht.EmbeddedExpression newEmbeddedExpression(Expression e) => new ht.Emb eddedExpression(e.offset, e, e.end);
8353
8354 Expression parseExpression(AngularHtmlUnitResolver resolver, ht.XmlAttributeNo de attribute) {
8355 int offset = attribute.valueToken.offset + 1;
8356 String value = attribute.text;
8357 Token token = resolver.scanDart(value, 0, value.length, offset);
8358 return resolver.parseExpression3(token);
8359 }
8360
8361 /**
8362 * Sets single [Expression] for [XmlAttributeNode].
8363 */
8364 void setExpression(ht.XmlAttributeNode attribute, Expression expression) {
8365 attribute.expressions = <ht.EmbeddedExpression> [newEmbeddedExpression(expre ssion)];
8366 }
8367
8368 /**
8369 * Sets [Expression]s for [XmlAttributeNode].
8370 */
8371 void setExpressions(ht.XmlAttributeNode attribute, List<Expression> expression s) {
8372 List<ht.EmbeddedExpression> embExpressions = [];
8373 for (Expression expression in expressions) {
8374 embExpressions.add(newEmbeddedExpression(expression));
8375 }
8376 attribute.expressions = new List.from(embExpressions);
8377 }
8378 }
8379
8380 /**
8381 * [NgModelProcessor] describes built-in <code>NgModel</code> directive.
8382 */
8383 class NgModelProcessor extends NgDirectiveProcessor {
8384 static String _NG_MODEL = "ng-model";
8385
8386 static NgModelProcessor INSTANCE = new NgModelProcessor();
8387
8388 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) {
8389 ht.XmlAttributeNode attribute = node.getAttribute(_NG_MODEL);
8390 Expression expression = parseExpression(resolver, attribute);
8391 // identifiers have been already handled by "apply top"
8392 if (expression is SimpleIdentifier) {
8393 return;
8394 }
8395 // resolve
8396 resolver.resolveNode(expression);
8397 // remember expression
8398 setExpression(attribute, expression);
8399 }
8400
8401 bool canApply(ht.XmlTagNode node) => node.getAttribute(_NG_MODEL) != null;
8402
8403 /**
8404 * This method is used to define top-level [VariableElement]s for each "ng-mod el" with
8405 * simple identifier model.
8406 */
8407 void applyTopDeclarations(AngularHtmlUnitResolver resolver, ht.XmlTagNode node ) {
8408 ht.XmlAttributeNode attribute = node.getAttribute(_NG_MODEL);
8409 Expression expression = parseExpression(resolver, attribute);
8410 // if not identifier, then not a top-level model, delay until "apply"
8411 if (expression is! SimpleIdentifier) {
8412 return;
8413 }
8414 SimpleIdentifier identifier = expression as SimpleIdentifier;
8415 // define variable Element
8416 InterfaceType type = resolver.typeProvider.stringType;
8417 LocalVariableElementImpl element = resolver.createLocalVariable(type, identi fier);
8418 resolver.defineTopVariable(element);
8419 // remember expression
8420 identifier.staticElement = element;
8421 identifier.staticType = type;
8422 setExpression(attribute, identifier);
8423 }
8424 }
8425
8426 /**
8427 * [NgProcessor] is used to apply an Angular feature.
8428 */
8429 abstract class NgProcessor {
8430 /**
8431 * Applies this [NgProcessor] to the resolver.
8432 *
8433 * @param resolver the [AngularHtmlUnitResolver] to apply to, not `null`
8434 * @param node the [XmlTagNode] to apply within, not `null`
8435 */
8436 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node);
8437
8438 /**
8439 * Checks if this processor can be applied to the given [XmlTagNode].
8440 *
8441 * @param node the [XmlTagNode] to check
8442 * @return `true` if this processor can be applied, or `false` otherwise
8443 */
8444 bool canApply(ht.XmlTagNode node);
8445 }
8446
8447 /**
7256 * The abstract class `AnalysisTask` defines the behavior of objects used to per form an 8448 * The abstract class `AnalysisTask` defines the behavior of objects used to per form an
7257 * analysis task. 8449 * analysis task.
7258 */ 8450 */
7259 abstract class AnalysisTask { 8451 abstract class AnalysisTask {
7260 /** 8452 /**
7261 * The context in which the task is to be performed. 8453 * The context in which the task is to be performed.
7262 */ 8454 */
7263 final InternalAnalysisContext context; 8455 final InternalAnalysisContext context;
7264 8456
7265 /** 8457 /**
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
7387 /** 8579 /**
7388 * Visit a [ParseHtmlTask]. 8580 * Visit a [ParseHtmlTask].
7389 * 8581 *
7390 * @param task the task to be visited 8582 * @param task the task to be visited
7391 * @return the result of visiting the task 8583 * @return the result of visiting the task
7392 * @throws AnalysisException if the visitor throws an exception for some reaso n 8584 * @throws AnalysisException if the visitor throws an exception for some reaso n
7393 */ 8585 */
7394 E visitParseHtmlTask(ParseHtmlTask task); 8586 E visitParseHtmlTask(ParseHtmlTask task);
7395 8587
7396 /** 8588 /**
8589 * Visit a [ResolveAngularComponentTemplateTask].
8590 *
8591 * @param task the task to be visited
8592 * @return the result of visiting the task
8593 * @throws AnalysisException if the visitor throws an exception for some reaso n
8594 */
8595 E visitResolveAngularComponentTemplateTask(ResolveAngularComponentTemplateTask task);
8596
8597 /**
8598 * Visit a [ResolveDartDependenciesTask].
8599 *
8600 * @param task the task to be visited
8601 * @return the result of visiting the task
8602 * @throws AnalysisException if the visitor throws an exception for some reaso n
8603 */
8604 E visitResolveDartDependenciesTask(ResolveDartDependenciesTask task);
8605
8606 /**
7397 * Visit a [ResolveDartLibraryTask]. 8607 * Visit a [ResolveDartLibraryTask].
7398 * 8608 *
7399 * @param task the task to be visited 8609 * @param task the task to be visited
7400 * @return the result of visiting the task 8610 * @return the result of visiting the task
7401 * @throws AnalysisException if the visitor throws an exception for some reaso n 8611 * @throws AnalysisException if the visitor throws an exception for some reaso n
7402 */ 8612 */
7403 E visitResolveDartLibraryTask(ResolveDartLibraryTask task); 8613 E visitResolveDartLibraryTask(ResolveDartLibraryTask task);
7404 8614
7405 /** 8615 /**
7406 * Visit a [ResolveDartUnitTask]. 8616 * Visit a [ResolveDartUnitTask].
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
7721 * A flag indicating whether the source contains a 'part of' directive. 8931 * A flag indicating whether the source contains a 'part of' directive.
7722 */ 8932 */
7723 bool _hasPartOfDirective2 = false; 8933 bool _hasPartOfDirective2 = false;
7724 8934
7725 /** 8935 /**
7726 * A flag indicating whether the source contains a 'library' directive. 8936 * A flag indicating whether the source contains a 'library' directive.
7727 */ 8937 */
7728 bool _hasLibraryDirective2 = false; 8938 bool _hasLibraryDirective2 = false;
7729 8939
7730 /** 8940 /**
7731 * A set containing the sources referenced by 'export' directives.
7732 */
7733 Set<Source> _exportedSources = new Set<Source>();
7734
7735 /**
7736 * A set containing the sources referenced by 'import' directives.
7737 */
7738 Set<Source> _importedSources = new Set<Source>();
7739
7740 /**
7741 * A set containing the sources referenced by 'part' directives.
7742 */
7743 Set<Source> _includedSources = new Set<Source>();
7744
7745 /**
7746 * Initialize a newly created task to perform analysis within the given contex t. 8941 * Initialize a newly created task to perform analysis within the given contex t.
7747 * 8942 *
7748 * @param context the context in which the task is to be performed 8943 * @param context the context in which the task is to be performed
7749 * @param source the source to be parsed 8944 * @param source the source to be parsed
7750 */ 8945 */
7751 ParseDartTask(InternalAnalysisContext context, this.source) : super(context); 8946 ParseDartTask(InternalAnalysisContext context, this.source) : super(context);
7752 8947
7753 accept(AnalysisTaskVisitor visitor) => visitor.visitParseDartTask(this); 8948 accept(AnalysisTaskVisitor visitor) => visitor.visitParseDartTask(this);
7754 8949
7755 /** 8950 /**
7756 * Return the compilation unit that was produced by parsing the source, or `nu ll` if the 8951 * Return the compilation unit that was produced by parsing the source, or `nu ll` if the
7757 * task has not yet been performed or if an exception occurred. 8952 * task has not yet been performed or if an exception occurred.
7758 * 8953 *
7759 * @return the compilation unit that was produced by parsing the source 8954 * @return the compilation unit that was produced by parsing the source
7760 */ 8955 */
7761 CompilationUnit get compilationUnit => _unit; 8956 CompilationUnit get compilationUnit => _unit;
7762 8957
7763 /** 8958 /**
7764 * Return the errors that were produced by scanning and parsing the source, or `null` if the 8959 * Return the errors that were produced by scanning and parsing the source, or `null` if the
7765 * task has not yet been performed or if an exception occurred. 8960 * task has not yet been performed or if an exception occurred.
7766 * 8961 *
7767 * @return the errors that were produced by scanning and parsing the source 8962 * @return the errors that were produced by scanning and parsing the source
7768 */ 8963 */
7769 List<AnalysisError> get errors => _errors; 8964 List<AnalysisError> get errors => _errors;
7770 8965
7771 /** 8966 /**
7772 * Return an array containing the sources referenced by 'export' directives, o r an empty array if
7773 * the task has not yet been performed or if an exception occurred.
7774 *
7775 * @return an array containing the sources referenced by 'export' directives
7776 */
7777 List<Source> get exportedSources => toArray(_exportedSources);
7778
7779 /**
7780 * Return an array containing the sources referenced by 'import' directives, o r an empty array if
7781 * the task has not yet been performed or if an exception occurred.
7782 *
7783 * @return an array containing the sources referenced by 'import' directives
7784 */
7785 List<Source> get importedSources => toArray(_importedSources);
7786
7787 /**
7788 * Return an array containing the sources referenced by 'part' directives, or an empty array if
7789 * the task has not yet been performed or if an exception occurred.
7790 *
7791 * @return an array containing the sources referenced by 'part' directives
7792 */
7793 List<Source> get includedSources => toArray(_includedSources);
7794
7795 /**
7796 * Return the line information that was produced, or `null` if the task has no t yet been 8967 * Return the line information that was produced, or `null` if the task has no t yet been
7797 * performed or if an exception occurred. 8968 * performed or if an exception occurred.
7798 * 8969 *
7799 * @return the line information that was produced 8970 * @return the line information that was produced
7800 */ 8971 */
7801 LineInfo get lineInfo => _lineInfo; 8972 LineInfo get lineInfo => _lineInfo;
7802 8973
7803 /** 8974 /**
7804 * Return the time at which the contents of the source that was parsed were la st modified, or a 8975 * Return the time at which the contents of the source that was parsed were la st modified, or a
7805 * negative value if the task has not yet been performed or if an exception oc curred. 8976 * negative value if the task has not yet been performed or if an exception oc curred.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
7850 // 9021 //
7851 // Then parse the token stream. 9022 // Then parse the token stream.
7852 // 9023 //
7853 TimeCounter_TimeCounterHandle timeCounterParse = PerformanceStatistics.parse .start(); 9024 TimeCounter_TimeCounterHandle timeCounterParse = PerformanceStatistics.parse .start();
7854 try { 9025 try {
7855 Parser parser = new Parser(source, errorListener); 9026 Parser parser = new Parser(source, errorListener);
7856 parser.parseFunctionBodies = context.analysisOptions.analyzeFunctionBodies ; 9027 parser.parseFunctionBodies = context.analysisOptions.analyzeFunctionBodies ;
7857 _unit = parser.parseCompilationUnit(token[0]); 9028 _unit = parser.parseCompilationUnit(token[0]);
7858 _errors = errorListener.getErrors2(source); 9029 _errors = errorListener.getErrors2(source);
7859 for (Directive directive in _unit.directives) { 9030 for (Directive directive in _unit.directives) {
7860 if (directive is ExportDirective) { 9031 if (directive is LibraryDirective) {
7861 Source exportSource = resolveSource(source, directive);
7862 if (exportSource != null) {
7863 _exportedSources.add(exportSource);
7864 }
7865 } else if (directive is ImportDirective) {
7866 Source importSource = resolveSource(source, directive);
7867 if (importSource != null) {
7868 _importedSources.add(importSource);
7869 }
7870 } else if (directive is LibraryDirective) {
7871 _hasLibraryDirective2 = true; 9032 _hasLibraryDirective2 = true;
7872 } else if (directive is PartDirective) {
7873 Source partSource = resolveSource(source, directive);
7874 if (partSource != null) {
7875 _includedSources.add(partSource);
7876 }
7877 } else if (directive is PartOfDirective) { 9033 } else if (directive is PartOfDirective) {
7878 _hasPartOfDirective2 = true; 9034 _hasPartOfDirective2 = true;
7879 } 9035 }
7880 } 9036 }
7881 _unit.lineInfo = _lineInfo; 9037 _unit.lineInfo = _lineInfo;
7882 } finally { 9038 } finally {
7883 timeCounterParse.stop(); 9039 timeCounterParse.stop();
7884 } 9040 }
7885 } 9041 }
7886
7887 /**
7888 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
7889 * given library, or `null` if the URI is not valid.
7890 *
7891 * @param librarySource the source representing the library containing the dir ective
7892 * @param directive the directive which URI should be resolved
7893 * @return the result of resolving the URI against the URI of the library
7894 */
7895 Source resolveSource(Source librarySource, UriBasedDirective directive) {
7896 StringLiteral uriLiteral = directive.uri;
7897 if (uriLiteral is StringInterpolation) {
7898 return null;
7899 }
7900 String uriContent = uriLiteral.stringValue.trim();
7901 if (uriContent == null) {
7902 return null;
7903 }
7904 uriContent = Uri.encodeFull(uriContent);
7905 try {
7906 parseUriWithException(uriContent);
7907 return context.sourceFactory.resolveUri(librarySource, uriContent);
7908 } on URISyntaxException catch (exception) {
7909 return null;
7910 }
7911 }
7912
7913 /**
7914 * Efficiently convert the given set of sources to an array.
7915 *
7916 * @param sources the set to be converted
7917 * @return an array containing all of the sources in the given set
7918 */
7919 List<Source> toArray(Set<Source> sources) {
7920 int size = sources.length;
7921 if (size == 0) {
7922 return Source.EMPTY_ARRAY;
7923 }
7924 return new List.from(sources);
7925 }
7926 } 9042 }
7927 9043
7928 class Source_ContentReceiver_ParseDartTask_internalPerform implements Source_Con tentReceiver { 9044 class Source_ContentReceiver_ParseDartTask_internalPerform implements Source_Con tentReceiver {
7929 final ParseDartTask ParseDartTask_this; 9045 final ParseDartTask ParseDartTask_this;
7930 9046
7931 RecordingErrorListener errorListener; 9047 RecordingErrorListener errorListener;
7932 9048
7933 List<Token> token; 9049 List<Token> token;
7934 9050
7935 Source_ContentReceiver_ParseDartTask_internalPerform(this.ParseDartTask_this, this.errorListener, this.token); 9051 Source_ContentReceiver_ParseDartTask_internalPerform(this.ParseDartTask_this, this.errorListener, this.token);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7971 int _modificationTime = -1; 9087 int _modificationTime = -1;
7972 9088
7973 /** 9089 /**
7974 * The line information that was produced. 9090 * The line information that was produced.
7975 */ 9091 */
7976 LineInfo _lineInfo; 9092 LineInfo _lineInfo;
7977 9093
7978 /** 9094 /**
7979 * The HTML unit that was produced by parsing the source. 9095 * The HTML unit that was produced by parsing the source.
7980 */ 9096 */
7981 HtmlUnit _unit; 9097 ht.HtmlUnit _unit;
7982 9098
7983 /** 9099 /**
7984 * The errors that were produced by scanning and parsing the source. 9100 * The errors that were produced by scanning and parsing the source.
7985 */ 9101 */
7986 List<AnalysisError> _errors = AnalysisError.NO_ERRORS; 9102 List<AnalysisError> _errors = AnalysisError.NO_ERRORS;
7987 9103
7988 /** 9104 /**
7989 * An array containing the sources of the libraries that are referenced within the HTML. 9105 * An array containing the sources of the libraries that are referenced within the HTML.
7990 */ 9106 */
7991 List<Source> _referencedLibraries = Source.EMPTY_ARRAY; 9107 List<Source> _referencedLibraries = Source.EMPTY_ARRAY;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
8027 * 9143 *
8028 * @return the errors that were produced by scanning and parsing the source 9144 * @return the errors that were produced by scanning and parsing the source
8029 */ 9145 */
8030 List<AnalysisError> get errors => _errors; 9146 List<AnalysisError> get errors => _errors;
8031 9147
8032 /** 9148 /**
8033 * Return the HTML unit that was produced by parsing the source. 9149 * Return the HTML unit that was produced by parsing the source.
8034 * 9150 *
8035 * @return the HTML unit that was produced by parsing the source 9151 * @return the HTML unit that was produced by parsing the source
8036 */ 9152 */
8037 HtmlUnit get htmlUnit => _unit; 9153 ht.HtmlUnit get htmlUnit => _unit;
8038 9154
8039 /** 9155 /**
8040 * Return the line information that was produced, or `null` if the task has no t yet been 9156 * Return the line information that was produced, or `null` if the task has no t yet been
8041 * performed or if an exception occurred. 9157 * performed or if an exception occurred.
8042 * 9158 *
8043 * @return the line information that was produced 9159 * @return the line information that was produced
8044 */ 9160 */
8045 LineInfo get lineInfo => _lineInfo; 9161 LineInfo get lineInfo => _lineInfo;
8046 9162
8047 /** 9163 /**
(...skipping 12 matching lines...) Expand all
8060 List<Source> get referencedLibraries => _referencedLibraries; 9176 List<Source> get referencedLibraries => _referencedLibraries;
8061 9177
8062 String get taskDescription { 9178 String get taskDescription {
8063 if (source == null) { 9179 if (source == null) {
8064 return "parse as html null source"; 9180 return "parse as html null source";
8065 } 9181 }
8066 return "parse as html ${source.fullName}"; 9182 return "parse as html ${source.fullName}";
8067 } 9183 }
8068 9184
8069 void internalPerform() { 9185 void internalPerform() {
8070 HtmlScanner scanner = new HtmlScanner(source); 9186 ht.HtmlScanner scanner = new ht.HtmlScanner(source);
8071 try { 9187 try {
8072 source.getContents(scanner); 9188 source.getContents(scanner);
8073 } on JavaException catch (exception) { 9189 } on JavaException catch (exception) {
8074 throw new AnalysisException.con3(exception); 9190 throw new AnalysisException.con3(exception);
8075 } 9191 }
8076 HtmlScanResult scannerResult = scanner.result; 9192 ht.HtmlScanResult scannerResult = scanner.result;
8077 _modificationTime = scannerResult.modificationTime; 9193 _modificationTime = scannerResult.modificationTime;
8078 _lineInfo = new LineInfo(scannerResult.lineStarts); 9194 _lineInfo = new LineInfo(scannerResult.lineStarts);
8079 RecordingErrorListener errorListener = new RecordingErrorListener(); 9195 RecordingErrorListener errorListener = new RecordingErrorListener();
8080 HtmlParseResult result = new HtmlParser(source, errorListener).parse(scanner Result); 9196 ht.HtmlParseResult result = new ht.HtmlParser(source, errorListener).parse(s cannerResult);
8081 _unit = result.htmlUnit; 9197 _unit = result.htmlUnit;
8082 _errors = errorListener.getErrors2(source); 9198 _errors = errorListener.getErrors2(source);
8083 _referencedLibraries = librarySources; 9199 _referencedLibraries = librarySources;
8084 } 9200 }
8085 9201
8086 /** 9202 /**
8087 * Return the sources of libraries that are referenced in the specified HTML f ile. 9203 * Return the sources of libraries that are referenced in the specified HTML f ile.
8088 * 9204 *
8089 * @return the sources of libraries that are referenced in the HTML file 9205 * @return the sources of libraries that are referenced in the HTML file
8090 */ 9206 */
8091 List<Source> get librarySources { 9207 List<Source> get librarySources {
8092 List<Source> libraries = new List<Source>(); 9208 List<Source> libraries = new List<Source>();
8093 _unit.accept(new RecursiveXmlVisitor_ParseHtmlTask_getLibrarySources(this, l ibraries)); 9209 _unit.accept(new RecursiveXmlVisitor_ParseHtmlTask_getLibrarySources(this, l ibraries));
8094 if (libraries.isEmpty) { 9210 if (libraries.isEmpty) {
8095 return Source.EMPTY_ARRAY; 9211 return Source.EMPTY_ARRAY;
8096 } 9212 }
8097 return new List.from(libraries); 9213 return new List.from(libraries);
8098 } 9214 }
8099 } 9215 }
8100 9216
8101 class RecursiveXmlVisitor_ParseHtmlTask_getLibrarySources extends RecursiveXmlVi sitor<Object> { 9217 class RecursiveXmlVisitor_ParseHtmlTask_getLibrarySources extends ht.RecursiveXm lVisitor<Object> {
8102 final ParseHtmlTask ParseHtmlTask_this; 9218 final ParseHtmlTask ParseHtmlTask_this;
8103 9219
8104 List<Source> libraries; 9220 List<Source> libraries;
8105 9221
8106 RecursiveXmlVisitor_ParseHtmlTask_getLibrarySources(this.ParseHtmlTask_this, t his.libraries) : super(); 9222 RecursiveXmlVisitor_ParseHtmlTask_getLibrarySources(this.ParseHtmlTask_this, t his.libraries) : super();
8107 9223
8108 Object visitHtmlScriptTagNode(HtmlScriptTagNode node) { 9224 Object visitHtmlScriptTagNode(ht.HtmlScriptTagNode node) {
8109 XmlAttributeNode scriptAttribute = null; 9225 ht.XmlAttributeNode scriptAttribute = null;
8110 for (XmlAttributeNode attribute in node.attributes) { 9226 for (ht.XmlAttributeNode attribute in node.attributes) {
8111 if (javaStringEqualsIgnoreCase(attribute.name, ParseHtmlTask._ATTRIBUTE_SR C)) { 9227 if (javaStringEqualsIgnoreCase(attribute.name, ParseHtmlTask._ATTRIBUTE_SR C)) {
8112 scriptAttribute = attribute; 9228 scriptAttribute = attribute;
8113 } 9229 }
8114 } 9230 }
8115 if (scriptAttribute != null) { 9231 if (scriptAttribute != null) {
8116 try { 9232 try {
8117 Uri uri = new Uri(path: scriptAttribute.text); 9233 Uri uri = new Uri(path: scriptAttribute.text);
8118 String fileName = uri.path; 9234 String fileName = uri.path;
8119 Source librarySource = ParseHtmlTask_this.context.sourceFactory.resolveU ri(ParseHtmlTask_this.source, fileName); 9235 Source librarySource = ParseHtmlTask_this.context.sourceFactory.resolveU ri(ParseHtmlTask_this.source, fileName);
8120 if (librarySource != null && librarySource.exists()) { 9236 if (librarySource != null && librarySource.exists()) {
8121 libraries.add(librarySource); 9237 libraries.add(librarySource);
8122 } 9238 }
8123 } on URISyntaxException catch (e) { 9239 } on URISyntaxException catch (e) {
8124 } 9240 }
8125 } 9241 }
8126 return super.visitHtmlScriptTagNode(node); 9242 return super.visitHtmlScriptTagNode(node);
8127 } 9243 }
8128 } 9244 }
8129 9245
8130 /** 9246 /**
9247 * Instances of the class `ResolveAngularComponentTemplateTask` resolve HTML tem plate
9248 * referenced by [AngularComponentElement].
9249 */
9250 class ResolveAngularComponentTemplateTask extends AnalysisTask {
9251 /**
9252 * The [AngularComponentElement] to resolve template for.
9253 */
9254 AngularComponentElement _component;
9255
9256 /**
9257 * All Angular elements accessible in the component library.
9258 */
9259 List<AngularElement> _angularElements;
9260
9261 /**
9262 * The source to be resolved.
9263 */
9264 final Source source;
9265
9266 /**
9267 * The time at which the contents of the source were last modified.
9268 */
9269 int _modificationTime = -1;
9270
9271 /**
9272 * The [HtmlUnit] that was resolved by this task.
9273 */
9274 ht.HtmlUnit _resolvedUnit;
9275
9276 /**
9277 * The resolution errors that were discovered while resolving the source.
9278 */
9279 List<AnalysisError> _resolutionErrors = AnalysisError.NO_ERRORS;
9280
9281 /**
9282 * Initialize a newly created task to perform analysis within the given contex t.
9283 *
9284 * @param context the context in which the task is to be performed
9285 * @param source the source to be resolved
9286 * @param component the component that uses this HTML template, not `null`
9287 * @param angularElements all Angular elements accessible in the component lib rary
9288 */
9289 ResolveAngularComponentTemplateTask(InternalAnalysisContext context, this.sour ce, AngularComponentElement component, List<AngularElement> angularElements) : s uper(context) {
9290 this._component = component;
9291 this._angularElements = angularElements;
9292 }
9293
9294 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveAngularComponentTem plateTask(this);
9295
9296 /**
9297 * Return the time at which the contents of the source that was parsed were la st modified, or a
9298 * negative value if the task has not yet been performed or if an exception oc curred.
9299 *
9300 * @return the time at which the contents of the source that was parsed were l ast modified
9301 */
9302 int get modificationTime => _modificationTime;
9303
9304 List<AnalysisError> get resolutionErrors => _resolutionErrors;
9305
9306 /**
9307 * Return the [HtmlUnit] that was resolved by this task.
9308 *
9309 * @return the [HtmlUnit] that was resolved by this task
9310 */
9311 ht.HtmlUnit get resolvedUnit => _resolvedUnit;
9312
9313 String get taskDescription => "resolving Angular template ${source}";
9314
9315 void internalPerform() {
9316 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(so urce);
9317 ht.HtmlUnit unit = resolvableHtmlUnit.compilationUnit;
9318 if (unit == null) {
9319 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit");
9320 }
9321 _modificationTime = resolvableHtmlUnit.modificationTime;
9322 // prepare for resolution
9323 RecordingErrorListener errorListener = new RecordingErrorListener();
9324 LineInfo lineInfo = context.getLineInfo(source);
9325 // do resolve
9326 AngularHtmlUnitResolver resolver = new AngularHtmlUnitResolver(context, erro rListener, source, lineInfo, unit);
9327 resolver.resolveComponentTemplate(_angularElements, _component);
9328 // remember errors
9329 _resolutionErrors = errorListener.getErrors2(source);
9330 // remember resolved unit
9331 _resolvedUnit = unit;
9332 }
9333 }
9334
9335 /**
9336 * Instances of the class `ResolveDartDependenciesTask` resolve the import, expo rt, and part
9337 * directives in a single source.
9338 */
9339 class ResolveDartDependenciesTask extends AnalysisTask {
9340 /**
9341 * The source containing the directives to be resolved.
9342 */
9343 final Source source;
9344
9345 /**
9346 * The time at which the contents of the source were last modified.
9347 */
9348 int _modificationTime = -1;
9349
9350 /**
9351 * A set containing the sources referenced by 'export' directives.
9352 */
9353 Set<Source> _exportedSources = new Set<Source>();
9354
9355 /**
9356 * A set containing the sources referenced by 'import' directives.
9357 */
9358 Set<Source> _importedSources = new Set<Source>();
9359
9360 /**
9361 * A set containing the sources referenced by 'part' directives.
9362 */
9363 Set<Source> _includedSources = new Set<Source>();
9364
9365 /**
9366 * Initialize a newly created task to perform analysis within the given contex t.
9367 *
9368 * @param context the context in which the task is to be performed
9369 * @param source the source to be parsed
9370 */
9371 ResolveDartDependenciesTask(InternalAnalysisContext context, this.source) : su per(context);
9372
9373 accept(AnalysisTaskVisitor visitor) => visitor.visitResolveDartDependenciesTas k(this);
9374
9375 /**
9376 * Return an array containing the sources referenced by 'export' directives, o r an empty array if
9377 * the task has not yet been performed or if an exception occurred.
9378 *
9379 * @return an array containing the sources referenced by 'export' directives
9380 */
9381 List<Source> get exportedSources => toArray(_exportedSources);
9382
9383 /**
9384 * Return an array containing the sources referenced by 'import' directives, o r an empty array if
9385 * the task has not yet been performed or if an exception occurred.
9386 *
9387 * @return an array containing the sources referenced by 'import' directives
9388 */
9389 List<Source> get importedSources => toArray(_importedSources);
9390
9391 /**
9392 * Return an array containing the sources referenced by 'part' directives, or an empty array if
9393 * the task has not yet been performed or if an exception occurred.
9394 *
9395 * @return an array containing the sources referenced by 'part' directives
9396 */
9397 List<Source> get includedSources => toArray(_includedSources);
9398
9399 /**
9400 * Return the time at which the contents of the source that was parsed were la st modified, or a
9401 * negative value if the task has not yet been performed or if an exception oc curred.
9402 *
9403 * @return the time at which the contents of the source that was parsed were l ast modified
9404 */
9405 int get modificationTime => _modificationTime;
9406
9407 String get taskDescription {
9408 if (source == null) {
9409 return "resolve dart dependencies null source";
9410 }
9411 return "resolve dart dependencies ${source.fullName}";
9412 }
9413
9414 void internalPerform() {
9415 ResolvableCompilationUnit unit = context.computeResolvableCompilationUnit(so urce);
9416 _modificationTime = unit.modificationTime;
9417 //
9418 // Then parse the token stream.
9419 //
9420 TimeCounter_TimeCounterHandle timeCounterParse = PerformanceStatistics.parse .start();
9421 try {
9422 for (Directive directive in unit.compilationUnit.directives) {
9423 if (directive is ExportDirective) {
9424 Source exportSource = resolveSource(source, directive);
9425 if (exportSource != null) {
9426 _exportedSources.add(exportSource);
9427 }
9428 } else if (directive is ImportDirective) {
9429 Source importSource = resolveSource(source, directive);
9430 if (importSource != null) {
9431 _importedSources.add(importSource);
9432 }
9433 } else if (directive is PartDirective) {
9434 Source partSource = resolveSource(source, directive);
9435 if (partSource != null) {
9436 _includedSources.add(partSource);
9437 }
9438 }
9439 }
9440 } finally {
9441 timeCounterParse.stop();
9442 }
9443 }
9444
9445 /**
9446 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
9447 * given library, or `null` if the URI is not valid.
9448 *
9449 * @param librarySource the source representing the library containing the dir ective
9450 * @param directive the directive which URI should be resolved
9451 * @return the result of resolving the URI against the URI of the library
9452 */
9453 Source resolveSource(Source librarySource, UriBasedDirective directive) {
9454 StringLiteral uriLiteral = directive.uri;
9455 if (uriLiteral is StringInterpolation) {
9456 return null;
9457 }
9458 String uriContent = uriLiteral.stringValue.trim();
9459 if (uriContent == null) {
9460 return null;
9461 }
9462 uriContent = Uri.encodeFull(uriContent);
9463 try {
9464 parseUriWithException(uriContent);
9465 return context.sourceFactory.resolveUri(librarySource, uriContent);
9466 } on URISyntaxException catch (exception) {
9467 return null;
9468 }
9469 }
9470
9471 /**
9472 * Efficiently convert the given set of sources to an array.
9473 *
9474 * @param sources the set to be converted
9475 * @return an array containing all of the sources in the given set
9476 */
9477 List<Source> toArray(Set<Source> sources) {
9478 int size = sources.length;
9479 if (size == 0) {
9480 return Source.EMPTY_ARRAY;
9481 }
9482 return new List.from(sources);
9483 }
9484 }
9485
9486 /**
8131 * Instances of the class `ResolveDartLibraryTask` parse a specific Dart library . 9487 * Instances of the class `ResolveDartLibraryTask` parse a specific Dart library .
8132 */ 9488 */
8133 class ResolveDartLibraryTask extends AnalysisTask { 9489 class ResolveDartLibraryTask extends AnalysisTask {
8134 /** 9490 /**
8135 * The source representing the file whose compilation unit is to be returned. 9491 * The source representing the file whose compilation unit is to be returned.
8136 */ 9492 */
8137 final Source unitSource; 9493 final Source unitSource;
8138 9494
8139 /** 9495 /**
8140 * The source representing the library to be resolved. 9496 * The source representing the library to be resolved.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
8327 final Source source; 9683 final Source source;
8328 9684
8329 /** 9685 /**
8330 * The time at which the contents of the source were last modified. 9686 * The time at which the contents of the source were last modified.
8331 */ 9687 */
8332 int _modificationTime = -1; 9688 int _modificationTime = -1;
8333 9689
8334 /** 9690 /**
8335 * The [HtmlUnit] that was resolved by this task. 9691 * The [HtmlUnit] that was resolved by this task.
8336 */ 9692 */
8337 HtmlUnit _resolvedUnit; 9693 ht.HtmlUnit _resolvedUnit;
8338 9694
8339 /** 9695 /**
8340 * The element produced by resolving the source. 9696 * The element produced by resolving the source.
8341 */ 9697 */
8342 HtmlElement _element = null; 9698 HtmlElement _element = null;
8343 9699
8344 /** 9700 /**
8345 * The resolution errors that were discovered while resolving the source. 9701 * The resolution errors that were discovered while resolving the source.
8346 */ 9702 */
8347 List<AnalysisError> _resolutionErrors = AnalysisError.NO_ERRORS; 9703 List<AnalysisError> _resolutionErrors = AnalysisError.NO_ERRORS;
(...skipping 18 matching lines...) Expand all
8366 */ 9722 */
8367 int get modificationTime => _modificationTime; 9723 int get modificationTime => _modificationTime;
8368 9724
8369 List<AnalysisError> get resolutionErrors => _resolutionErrors; 9725 List<AnalysisError> get resolutionErrors => _resolutionErrors;
8370 9726
8371 /** 9727 /**
8372 * Return the [HtmlUnit] that was resolved by this task. 9728 * Return the [HtmlUnit] that was resolved by this task.
8373 * 9729 *
8374 * @return the [HtmlUnit] that was resolved by this task 9730 * @return the [HtmlUnit] that was resolved by this task
8375 */ 9731 */
8376 HtmlUnit get resolvedUnit => _resolvedUnit; 9732 ht.HtmlUnit get resolvedUnit => _resolvedUnit;
8377 9733
8378 String get taskDescription { 9734 String get taskDescription {
8379 if (source == null) { 9735 if (source == null) {
8380 return "resolve as html null source"; 9736 return "resolve as html null source";
8381 } 9737 }
8382 return "resolve as html ${source.fullName}"; 9738 return "resolve as html ${source.fullName}";
8383 } 9739 }
8384 9740
8385 void internalPerform() { 9741 void internalPerform() {
8386 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(so urce); 9742 ResolvableHtmlUnit resolvableHtmlUnit = context.computeResolvableHtmlUnit(so urce);
8387 HtmlUnit unit = resolvableHtmlUnit.compilationUnit; 9743 ht.HtmlUnit unit = resolvableHtmlUnit.compilationUnit;
8388 if (unit == null) { 9744 if (unit == null) {
8389 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit"); 9745 throw new AnalysisException.con1("Internal error: computeResolvableHtmlUni t returned a value without a parsed HTML unit");
8390 } 9746 }
8391 _modificationTime = resolvableHtmlUnit.modificationTime; 9747 _modificationTime = resolvableHtmlUnit.modificationTime;
8392 // build standard HTML element 9748 // build standard HTML element
8393 HtmlUnitBuilder builder = new HtmlUnitBuilder(context); 9749 HtmlUnitBuilder builder = new HtmlUnitBuilder(context);
8394 _element = builder.buildHtmlElement2(source, _modificationTime, unit); 9750 _element = builder.buildHtmlElement2(source, _modificationTime, unit);
8395 // resolve toolkit-specific features 9751 // resolve toolkit-specific features
8396 LineInfo lineInfo = context.getLineInfo(source); 9752 LineInfo lineInfo = context.getLineInfo(source);
8397 // new AngularHtmlUnitResolver(context, builder.errorListener, source, lineIn fo).resolve(unit); 9753 new AngularHtmlUnitResolver(context, builder.errorListener, source, lineInfo , unit).resolveEntryPoint();
8398 // record all resolution errors 9754 // record all resolution errors
8399 _resolutionErrors = builder.errorListener.getErrors2(source); 9755 _resolutionErrors = builder.errorListener.getErrors2(source);
8400 // remember resolved unit 9756 // remember resolved unit
8401 _resolvedUnit = unit; 9757 _resolvedUnit = unit;
8402 } 9758 }
8403 } 9759 }
8404 9760
8405 /** 9761 /**
8406 * The interface `Logger` defines the behavior of objects that can be used to re ceive 9762 * The interface `Logger` defines the behavior of objects that can be used to re ceive
8407 * information about errors within the analysis engine. Implementations usually write this 9763 * information about errors within the analysis engine. Implementations usually write this
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
8464 9820
8465 void logError3(Exception exception) { 9821 void logError3(Exception exception) {
8466 } 9822 }
8467 9823
8468 void logInformation(String message) { 9824 void logInformation(String message) {
8469 } 9825 }
8470 9826
8471 void logInformation3(String message, Exception exception) { 9827 void logInformation3(String message, Exception exception) {
8472 } 9828 }
8473 } 9829 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698