| OLD | NEW |
| 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 "dart:math" as math; | 10 import "dart:math" as math; |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 * This method should be used rather than the method [Source.exists] because c
ontexts can | 573 * This method should be used rather than the method [Source.exists] because c
ontexts can |
| 574 * have local overrides of the content of a source that the source is not awar
e of and a source | 574 * have local overrides of the content of a source that the source is not awar
e of and a source |
| 575 * with local content is considered to exist even if there is no file on disk. | 575 * with local content is considered to exist even if there is no file on disk. |
| 576 * | 576 * |
| 577 * @param source the source whose modification stamp is to be returned | 577 * @param source the source whose modification stamp is to be returned |
| 578 * @return `true` if the source exists | 578 * @return `true` if the source exists |
| 579 */ | 579 */ |
| 580 bool exists(Source source); | 580 bool exists(Source source); |
| 581 | 581 |
| 582 /** | 582 /** |
| 583 * Return the Angular application that contains the HTML file defined by the g
iven source, or | |
| 584 * `null` if the source does not represent an HTML file, the Angular applicati
on containing | |
| 585 * the file has not yet been resolved, or the analysis of the HTML file failed
for some reason. | |
| 586 * | |
| 587 * @param htmlSource the source defining the HTML file | |
| 588 * @return the Angular application that contains the HTML file defined by the
given source | |
| 589 */ | |
| 590 AngularApplication getAngularApplicationWithHtml(Source htmlSource); | |
| 591 | |
| 592 /** | |
| 593 * Return the element model corresponding to the compilation unit defined by t
he given source in | 583 * Return the element model corresponding to the compilation unit defined by t
he given source in |
| 594 * the library defined by the given source, or `null` if the element model doe
s not | 584 * the library defined by the given source, or `null` if the element model doe
s not |
| 595 * currently exist or if the library cannot be analyzed for some reason. | 585 * currently exist or if the library cannot be analyzed for some reason. |
| 596 * | 586 * |
| 597 * @param unitSource the source of the compilation unit | 587 * @param unitSource the source of the compilation unit |
| 598 * @param librarySource the source of the defining compilation unit of the lib
rary containing the | 588 * @param librarySource the source of the defining compilation unit of the lib
rary containing the |
| 599 * compilation unit | 589 * compilation unit |
| 600 * @return the element model corresponding to the compilation unit defined by
the given source | 590 * @return the element model corresponding to the compilation unit defined by
the given source |
| 601 */ | 591 */ |
| 602 CompilationUnitElement getCompilationUnitElement(Source unitSource, | 592 CompilationUnitElement getCompilationUnitElement(Source unitSource, |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 * [cacheLock] before accessing this field. | 1008 * [cacheLock] before accessing this field. |
| 1019 */ | 1009 */ |
| 1020 IncrementalAnalysisCache _incrementalAnalysisCache; | 1010 IncrementalAnalysisCache _incrementalAnalysisCache; |
| 1021 | 1011 |
| 1022 /** | 1012 /** |
| 1023 * The object used to manage the list of sources that need to be analyzed. | 1013 * The object used to manage the list of sources that need to be analyzed. |
| 1024 */ | 1014 */ |
| 1025 WorkManager _workManager = new WorkManager(); | 1015 WorkManager _workManager = new WorkManager(); |
| 1026 | 1016 |
| 1027 /** | 1017 /** |
| 1028 * The set of [AngularApplication] in this context. | |
| 1029 */ | |
| 1030 Set<AngularApplication> _angularApplications = new Set(); | |
| 1031 | |
| 1032 /** | |
| 1033 * The controller for sending [SourcesChangedEvent]s. | 1018 * The controller for sending [SourcesChangedEvent]s. |
| 1034 */ | 1019 */ |
| 1035 StreamController<SourcesChangedEvent> _onSourcesChangedController; | 1020 StreamController<SourcesChangedEvent> _onSourcesChangedController; |
| 1036 | 1021 |
| 1037 /** | 1022 /** |
| 1038 * The listeners that are to be notified when various analysis results are pro
duced in this | 1023 * The listeners that are to be notified when various analysis results are pro
duced in this |
| 1039 * context. | 1024 * context. |
| 1040 */ | 1025 */ |
| 1041 List<AnalysisListener> _listeners = new List<AnalysisListener>(); | 1026 List<AnalysisListener> _listeners = new List<AnalysisListener>(); |
| 1042 | 1027 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1053 _onSourcesChangedController = | 1038 _onSourcesChangedController = |
| 1054 new StreamController<SourcesChangedEvent>.broadcast(); | 1039 new StreamController<SourcesChangedEvent>.broadcast(); |
| 1055 } | 1040 } |
| 1056 | 1041 |
| 1057 @override | 1042 @override |
| 1058 AnalysisOptions get analysisOptions => _options; | 1043 AnalysisOptions get analysisOptions => _options; |
| 1059 | 1044 |
| 1060 @override | 1045 @override |
| 1061 void set analysisOptions(AnalysisOptions options) { | 1046 void set analysisOptions(AnalysisOptions options) { |
| 1062 bool needsRecompute = | 1047 bool needsRecompute = |
| 1063 this._options.analyzeAngular != options.analyzeAngular || | |
| 1064 this._options.analyzeFunctionBodies != options.analyzeFunctionBodies || | 1048 this._options.analyzeFunctionBodies != options.analyzeFunctionBodies || |
| 1065 this._options.generateSdkErrors != options.generateSdkErrors || | 1049 this._options.generateSdkErrors != options.generateSdkErrors || |
| 1066 this._options.enableDeferredLoading != options.enableDeferredLoading || | 1050 this._options.enableDeferredLoading != options.enableDeferredLoading || |
| 1067 this._options.enableEnum != options.enableEnum || | 1051 this._options.enableEnum != options.enableEnum || |
| 1068 this._options.dart2jsHint != options.dart2jsHint || | 1052 this._options.dart2jsHint != options.dart2jsHint || |
| 1069 (this._options.hint && !options.hint) || | 1053 (this._options.hint && !options.hint) || |
| 1070 this._options.preserveComments != options.preserveComments; | 1054 this._options.preserveComments != options.preserveComments; |
| 1071 int cacheSize = options.cacheSize; | 1055 int cacheSize = options.cacheSize; |
| 1072 if (this._options.cacheSize != cacheSize) { | 1056 if (this._options.cacheSize != cacheSize) { |
| 1073 this._options.cacheSize = cacheSize; | 1057 this._options.cacheSize = cacheSize; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1084 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize); | 1068 List<Source> newPriorityOrder = new List<Source>(maxPriorityOrderSize); |
| 1085 JavaSystem.arraycopy( | 1069 JavaSystem.arraycopy( |
| 1086 _priorityOrder, | 1070 _priorityOrder, |
| 1087 0, | 1071 0, |
| 1088 newPriorityOrder, | 1072 newPriorityOrder, |
| 1089 0, | 1073 0, |
| 1090 maxPriorityOrderSize); | 1074 maxPriorityOrderSize); |
| 1091 _priorityOrder = newPriorityOrder; | 1075 _priorityOrder = newPriorityOrder; |
| 1092 } | 1076 } |
| 1093 } | 1077 } |
| 1094 this._options.analyzeAngular = options.analyzeAngular; | |
| 1095 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies; | 1078 this._options.analyzeFunctionBodies = options.analyzeFunctionBodies; |
| 1096 this._options.generateSdkErrors = options.generateSdkErrors; | 1079 this._options.generateSdkErrors = options.generateSdkErrors; |
| 1097 this._options.enableDeferredLoading = options.enableDeferredLoading; | 1080 this._options.enableDeferredLoading = options.enableDeferredLoading; |
| 1098 this._options.enableEnum = options.enableEnum; | 1081 this._options.enableEnum = options.enableEnum; |
| 1099 this._options.dart2jsHint = options.dart2jsHint; | 1082 this._options.dart2jsHint = options.dart2jsHint; |
| 1100 this._options.hint = options.hint; | 1083 this._options.hint = options.hint; |
| 1101 this._options.incremental = options.incremental; | 1084 this._options.incremental = options.incremental; |
| 1102 this._options.incrementalApi = options.incrementalApi; | 1085 this._options.incrementalApi = options.incrementalApi; |
| 1103 this._options.incrementalValidation = options.incrementalValidation; | 1086 this._options.incrementalValidation = options.incrementalValidation; |
| 1104 this._options.preserveComments = options.preserveComments; | 1087 this._options.preserveComments = options.preserveComments; |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 } | 1796 } |
| 1814 } | 1797 } |
| 1815 } | 1798 } |
| 1816 } on _ElementByIdFinderException catch (e) { | 1799 } on _ElementByIdFinderException catch (e) { |
| 1817 return finder.result; | 1800 return finder.result; |
| 1818 } | 1801 } |
| 1819 return null; | 1802 return null; |
| 1820 } | 1803 } |
| 1821 | 1804 |
| 1822 @override | 1805 @override |
| 1823 AngularApplication getAngularApplicationWithHtml(Source htmlSource) { | |
| 1824 SourceEntry sourceEntry = getReadableSourceEntryOrNull(htmlSource); | |
| 1825 if (sourceEntry is HtmlEntry) { | |
| 1826 HtmlEntry htmlEntry = sourceEntry; | |
| 1827 AngularApplication application = | |
| 1828 htmlEntry.getValue(HtmlEntry.ANGULAR_APPLICATION); | |
| 1829 if (application != null) { | |
| 1830 return application; | |
| 1831 } | |
| 1832 return htmlEntry.getValue(HtmlEntry.ANGULAR_ENTRY); | |
| 1833 } | |
| 1834 return null; | |
| 1835 } | |
| 1836 | |
| 1837 @override | |
| 1838 CompilationUnitElement getCompilationUnitElement(Source unitSource, | 1806 CompilationUnitElement getCompilationUnitElement(Source unitSource, |
| 1839 Source librarySource) { | 1807 Source librarySource) { |
| 1840 LibraryElement libraryElement = getLibraryElement(librarySource); | 1808 LibraryElement libraryElement = getLibraryElement(librarySource); |
| 1841 if (libraryElement != null) { | 1809 if (libraryElement != null) { |
| 1842 // try defining unit | 1810 // try defining unit |
| 1843 CompilationUnitElement definingUnit = | 1811 CompilationUnitElement definingUnit = |
| 1844 libraryElement.definingCompilationUnit; | 1812 libraryElement.definingCompilationUnit; |
| 1845 if (definingUnit.source == unitSource) { | 1813 if (definingUnit.source == unitSource) { |
| 1846 return definingUnit; | 1814 return definingUnit; |
| 1847 } | 1815 } |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2212 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); | 2180 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); |
| 2213 elementMap.forEach((Source librarySource, LibraryElement library) { | 2181 elementMap.forEach((Source librarySource, LibraryElement library) { |
| 2214 // | 2182 // |
| 2215 // Cache the element in the library's info. | 2183 // Cache the element in the library's info. |
| 2216 // | 2184 // |
| 2217 DartEntry dartEntry = _getReadableDartEntry(librarySource); | 2185 DartEntry dartEntry = _getReadableDartEntry(librarySource); |
| 2218 if (dartEntry != null) { | 2186 if (dartEntry != null) { |
| 2219 _recordElementData(dartEntry, library, library.source, htmlSource); | 2187 _recordElementData(dartEntry, library, library.source, htmlSource); |
| 2220 dartEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); | 2188 dartEntry.setState(SourceEntry.CONTENT, CacheState.FLUSHED); |
| 2221 dartEntry.setValue(SourceEntry.LINE_INFO, new LineInfo(<int>[0])); | 2189 dartEntry.setValue(SourceEntry.LINE_INFO, new LineInfo(<int>[0])); |
| 2222 dartEntry.setValue(DartEntry.ANGULAR_ERRORS, AnalysisError.NO_ERRORS); | |
| 2223 // DartEntry.ELEMENT - set in recordElementData | 2190 // DartEntry.ELEMENT - set in recordElementData |
| 2224 dartEntry.setValue(DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY); | 2191 dartEntry.setValue(DartEntry.EXPORTED_LIBRARIES, Source.EMPTY_ARRAY); |
| 2225 dartEntry.setValue(DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY); | 2192 dartEntry.setValue(DartEntry.IMPORTED_LIBRARIES, Source.EMPTY_ARRAY); |
| 2226 dartEntry.setValue(DartEntry.INCLUDED_PARTS, Source.EMPTY_ARRAY); | 2193 dartEntry.setValue(DartEntry.INCLUDED_PARTS, Source.EMPTY_ARRAY); |
| 2227 // DartEntry.IS_CLIENT - set in recordElementData | 2194 // DartEntry.IS_CLIENT - set in recordElementData |
| 2228 // DartEntry.IS_LAUNCHABLE - set in recordElementData | 2195 // DartEntry.IS_LAUNCHABLE - set in recordElementData |
| 2229 dartEntry.setValue(DartEntry.PARSE_ERRORS, AnalysisError.NO_ERRORS); | 2196 dartEntry.setValue(DartEntry.PARSE_ERRORS, AnalysisError.NO_ERRORS); |
| 2230 dartEntry.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); | 2197 dartEntry.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
| 2231 dartEntry.setState(DartEntry.PUBLIC_NAMESPACE, CacheState.FLUSHED); | 2198 dartEntry.setState(DartEntry.PUBLIC_NAMESPACE, CacheState.FLUSHED); |
| 2232 dartEntry.setValue(DartEntry.SCAN_ERRORS, AnalysisError.NO_ERRORS); | 2199 dartEntry.setValue(DartEntry.SCAN_ERRORS, AnalysisError.NO_ERRORS); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2483 // The source kind is always valid, so the state isn't interesting. | 2450 // The source kind is always valid, so the state isn't interesting. |
| 2484 continue; | 2451 continue; |
| 2485 } else if (descriptor == DartEntry.CONTAINING_LIBRARIES) { | 2452 } else if (descriptor == DartEntry.CONTAINING_LIBRARIES) { |
| 2486 // The list of containing libraries is always valid, so the state | 2453 // The list of containing libraries is always valid, so the state |
| 2487 // isn't interesting. | 2454 // isn't interesting. |
| 2488 continue; | 2455 continue; |
| 2489 } else if (descriptor == DartEntry.PUBLIC_NAMESPACE) { | 2456 } else if (descriptor == DartEntry.PUBLIC_NAMESPACE) { |
| 2490 // The public namespace isn't computed by performAnalysisTask() | 2457 // The public namespace isn't computed by performAnalysisTask() |
| 2491 // and therefore isn't interesting. | 2458 // and therefore isn't interesting. |
| 2492 continue; | 2459 continue; |
| 2493 } else if (descriptor == HtmlEntry.ANGULAR_APPLICATION || | 2460 } else if (descriptor == HtmlEntry.POLYMER_BUILD_ERRORS || |
| 2494 descriptor == HtmlEntry.ANGULAR_COMPONENT || | |
| 2495 descriptor == HtmlEntry.ANGULAR_ENTRY || | |
| 2496 descriptor == HtmlEntry.ANGULAR_ERRORS || | |
| 2497 descriptor == HtmlEntry.POLYMER_BUILD_ERRORS || | |
| 2498 descriptor == HtmlEntry.POLYMER_RESOLUTION_ERRORS) { | 2461 descriptor == HtmlEntry.POLYMER_RESOLUTION_ERRORS) { |
| 2499 // These values are not currently being computed, so their state is | 2462 // These values are not currently being computed, so their state is |
| 2500 // not interesting. | 2463 // not interesting. |
| 2501 continue; | 2464 continue; |
| 2502 } else if (descriptor == HtmlEntry.HINTS) { | 2465 } else if (descriptor == HtmlEntry.HINTS) { |
| 2503 // We are not currently recording any hints related to HTML. | 2466 // We are not currently recording any hints related to HTML. |
| 2504 continue; | 2467 continue; |
| 2505 } | 2468 } |
| 2506 callback( | 2469 callback( |
| 2507 source, | 2470 source, |
| 2508 sourceEntry, | 2471 sourceEntry, |
| 2509 descriptor, | 2472 descriptor, |
| 2510 sourceEntry.getState(descriptor)); | 2473 sourceEntry.getState(descriptor)); |
| 2511 } | 2474 } |
| 2512 if (sourceEntry is DartEntry) { | 2475 if (sourceEntry is DartEntry) { |
| 2513 // get library-specific values | 2476 // get library-specific values |
| 2514 List<Source> librarySources = getLibrariesContaining(source); | 2477 List<Source> librarySources = getLibrariesContaining(source); |
| 2515 for (Source librarySource in librarySources) { | 2478 for (Source librarySource in librarySources) { |
| 2516 for (DataDescriptor descriptor in sourceEntry.libraryDescriptors) { | 2479 for (DataDescriptor descriptor in sourceEntry.libraryDescriptors) { |
| 2517 if (descriptor == DartEntry.ANGULAR_ERRORS || | 2480 if (descriptor == DartEntry.BUILT_ELEMENT || |
| 2518 descriptor == DartEntry.BUILT_ELEMENT || | |
| 2519 descriptor == DartEntry.BUILT_UNIT) { | 2481 descriptor == DartEntry.BUILT_UNIT) { |
| 2520 // These values are not currently being computed, so their state | 2482 // These values are not currently being computed, so their state |
| 2521 // is not interesting. | 2483 // is not interesting. |
| 2522 continue; | 2484 continue; |
| 2523 } else if (source.isInSystemLibrary && | 2485 } else if (source.isInSystemLibrary && |
| 2524 !_generateSdkErrors && | 2486 !_generateSdkErrors && |
| 2525 (descriptor == DartEntry.VERIFICATION_ERRORS || | 2487 (descriptor == DartEntry.VERIFICATION_ERRORS || |
| 2526 descriptor == DartEntry.HINTS)) { | 2488 descriptor == DartEntry.HINTS)) { |
| 2527 continue; | 2489 continue; |
| 2528 } else if (!hintsEnabled && descriptor == DartEntry.HINTS) { | 2490 } else if (!hintsEnabled && descriptor == DartEntry.HINTS) { |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3268 return new AnalysisContextImpl_TaskData( | 3230 return new AnalysisContextImpl_TaskData( |
| 3269 new PolymerResolveHtmlTask( | 3231 new PolymerResolveHtmlTask( |
| 3270 this, | 3232 this, |
| 3271 source, | 3233 source, |
| 3272 htmlEntry.getValue(SourceEntry.LINE_INFO), | 3234 htmlEntry.getValue(SourceEntry.LINE_INFO), |
| 3273 htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT)), | 3235 htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT)), |
| 3274 false); | 3236 false); |
| 3275 } | 3237 } |
| 3276 | 3238 |
| 3277 /** | 3239 /** |
| 3278 * Create a [ResolveAngularComponentTemplateTask] for the given source, markin
g the angular | |
| 3279 * errors as being in-process. | |
| 3280 * | |
| 3281 * @param source the source whose content is to be resolved | |
| 3282 * @param htmlEntry the entry for the source | |
| 3283 * @return task data representing the created task | |
| 3284 */ | |
| 3285 AnalysisContextImpl_TaskData | |
| 3286 _createResolveAngularComponentTemplateTask(Source source, HtmlEntry htmlEn
try) { | |
| 3287 if (htmlEntry.getState(HtmlEntry.RESOLVED_UNIT) != CacheState.VALID) { | |
| 3288 return _createResolveHtmlTask(source, htmlEntry); | |
| 3289 } | |
| 3290 AngularApplication application = | |
| 3291 htmlEntry.getValue(HtmlEntry.ANGULAR_APPLICATION); | |
| 3292 AngularComponentElement component = | |
| 3293 htmlEntry.getValue(HtmlEntry.ANGULAR_COMPONENT); | |
| 3294 htmlEntry.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.IN_PROCESS); | |
| 3295 return new AnalysisContextImpl_TaskData( | |
| 3296 new ResolveAngularComponentTemplateTask( | |
| 3297 this, | |
| 3298 source, | |
| 3299 htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT), | |
| 3300 component, | |
| 3301 application), | |
| 3302 false); | |
| 3303 } | |
| 3304 | |
| 3305 /** | |
| 3306 * Create a [ResolveAngularEntryHtmlTask] for the given source, marking the an
gular entry as | |
| 3307 * being in-process. | |
| 3308 * | |
| 3309 * @param source the source whose content is to be resolved | |
| 3310 * @param htmlEntry the entry for the source | |
| 3311 * @return task data representing the created task | |
| 3312 */ | |
| 3313 AnalysisContextImpl_TaskData _createResolveAngularEntryHtmlTask(Source source, | |
| 3314 HtmlEntry htmlEntry) { | |
| 3315 if (htmlEntry.getState(HtmlEntry.RESOLVED_UNIT) != CacheState.VALID) { | |
| 3316 return _createResolveHtmlTask(source, htmlEntry); | |
| 3317 } | |
| 3318 htmlEntry.setState(HtmlEntry.ANGULAR_ENTRY, CacheState.IN_PROCESS); | |
| 3319 return new AnalysisContextImpl_TaskData( | |
| 3320 new ResolveAngularEntryHtmlTask( | |
| 3321 this, | |
| 3322 source, | |
| 3323 htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT)), | |
| 3324 false); | |
| 3325 } | |
| 3326 | |
| 3327 /** | |
| 3328 * Create a [ResolveDartLibraryTask] for the given source, marking ? as being
in-process. | 3240 * Create a [ResolveDartLibraryTask] for the given source, marking ? as being
in-process. |
| 3329 * | 3241 * |
| 3330 * @param source the source whose content is to be resolved | 3242 * @param source the source whose content is to be resolved |
| 3331 * @param dartEntry the entry for the source | 3243 * @param dartEntry the entry for the source |
| 3332 * @return task data representing the created task | 3244 * @return task data representing the created task |
| 3333 */ | 3245 */ |
| 3334 AnalysisContextImpl_TaskData _createResolveDartLibraryTask(Source source, | 3246 AnalysisContextImpl_TaskData _createResolveDartLibraryTask(Source source, |
| 3335 DartEntry dartEntry) { | 3247 DartEntry dartEntry) { |
| 3336 try { | 3248 try { |
| 3337 AnalysisContextImpl_CycleBuilder builder = | 3249 AnalysisContextImpl_CycleBuilder builder = |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3875 return _createParseHtmlTask(source, htmlEntry); | 3787 return _createParseHtmlTask(source, htmlEntry); |
| 3876 } | 3788 } |
| 3877 } | 3789 } |
| 3878 CacheState resolvedUnitState = | 3790 CacheState resolvedUnitState = |
| 3879 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); | 3791 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); |
| 3880 if (resolvedUnitState == CacheState.INVALID || | 3792 if (resolvedUnitState == CacheState.INVALID || |
| 3881 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { | 3793 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { |
| 3882 return _createResolveHtmlTask(source, htmlEntry); | 3794 return _createResolveHtmlTask(source, htmlEntry); |
| 3883 } | 3795 } |
| 3884 // | 3796 // |
| 3885 // Angular support | |
| 3886 // | |
| 3887 if (_options.analyzeAngular) { | |
| 3888 // Try to resolve the HTML as an Angular entry point. | |
| 3889 CacheState angularEntryState = | |
| 3890 htmlEntry.getState(HtmlEntry.ANGULAR_ENTRY); | |
| 3891 if (angularEntryState == CacheState.INVALID || | |
| 3892 (isPriority && angularEntryState == CacheState.FLUSHED)) { | |
| 3893 return _createResolveAngularEntryHtmlTask(source, htmlEntry); | |
| 3894 } | |
| 3895 // Try to resolve the HTML as an Angular application part. | |
| 3896 CacheState angularErrorsState = | |
| 3897 htmlEntry.getState(HtmlEntry.ANGULAR_ERRORS); | |
| 3898 if (angularErrorsState == CacheState.INVALID || | |
| 3899 (isPriority && angularErrorsState == CacheState.FLUSHED)) { | |
| 3900 return _createResolveAngularComponentTemplateTask(source, htmlEntry); | |
| 3901 } | |
| 3902 } | |
| 3903 // | |
| 3904 // Polymer support | 3797 // Polymer support |
| 3905 // | 3798 // |
| 3906 if (_options.analyzePolymer) { | 3799 if (_options.analyzePolymer) { |
| 3907 // Build elements. | 3800 // Build elements. |
| 3908 CacheState polymerBuildErrorsState = | 3801 CacheState polymerBuildErrorsState = |
| 3909 htmlEntry.getState(HtmlEntry.POLYMER_BUILD_ERRORS); | 3802 htmlEntry.getState(HtmlEntry.POLYMER_BUILD_ERRORS); |
| 3910 if (polymerBuildErrorsState == CacheState.INVALID || | 3803 if (polymerBuildErrorsState == CacheState.INVALID || |
| 3911 (isPriority && polymerBuildErrorsState == CacheState.FLUSHED)) { | 3804 (isPriority && polymerBuildErrorsState == CacheState.FLUSHED)) { |
| 3912 return _createPolymerBuildHtmlTask(source, htmlEntry); | 3805 return _createPolymerBuildHtmlTask(source, htmlEntry); |
| 3913 } | 3806 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4121 sources.add(source); | 4014 sources.add(source); |
| 4122 return; | 4015 return; |
| 4123 } | 4016 } |
| 4124 CacheState resolvedUnitState = | 4017 CacheState resolvedUnitState = |
| 4125 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); | 4018 htmlEntry.getState(HtmlEntry.RESOLVED_UNIT); |
| 4126 if (resolvedUnitState == CacheState.INVALID || | 4019 if (resolvedUnitState == CacheState.INVALID || |
| 4127 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { | 4020 (isPriority && resolvedUnitState == CacheState.FLUSHED)) { |
| 4128 sources.add(source); | 4021 sources.add(source); |
| 4129 return; | 4022 return; |
| 4130 } | 4023 } |
| 4131 // Angular | |
| 4132 if (_options.analyzeAngular) { | |
| 4133 CacheState angularErrorsState = | |
| 4134 htmlEntry.getState(HtmlEntry.ANGULAR_ERRORS); | |
| 4135 if (angularErrorsState == CacheState.INVALID || | |
| 4136 (isPriority && angularErrorsState == CacheState.FLUSHED)) { | |
| 4137 AngularApplication entryInfo = | |
| 4138 htmlEntry.getValue(HtmlEntry.ANGULAR_ENTRY); | |
| 4139 if (entryInfo != null) { | |
| 4140 sources.add(source); | |
| 4141 return; | |
| 4142 } | |
| 4143 AngularApplication applicationInfo = | |
| 4144 htmlEntry.getValue(HtmlEntry.ANGULAR_APPLICATION); | |
| 4145 if (applicationInfo != null) { | |
| 4146 AngularComponentElement component = | |
| 4147 htmlEntry.getValue(HtmlEntry.ANGULAR_COMPONENT); | |
| 4148 if (component != null) { | |
| 4149 sources.add(source); | |
| 4150 return; | |
| 4151 } | |
| 4152 } | |
| 4153 } | |
| 4154 } | |
| 4155 // Polymer | 4024 // Polymer |
| 4156 if (_options.analyzePolymer) { | 4025 if (_options.analyzePolymer) { |
| 4157 // Elements building. | 4026 // Elements building. |
| 4158 CacheState polymerBuildErrorsState = | 4027 CacheState polymerBuildErrorsState = |
| 4159 htmlEntry.getState(HtmlEntry.POLYMER_BUILD_ERRORS); | 4028 htmlEntry.getState(HtmlEntry.POLYMER_BUILD_ERRORS); |
| 4160 if (polymerBuildErrorsState == CacheState.INVALID || | 4029 if (polymerBuildErrorsState == CacheState.INVALID || |
| 4161 (isPriority && polymerBuildErrorsState == CacheState.FLUSHED)) { | 4030 (isPriority && polymerBuildErrorsState == CacheState.FLUSHED)) { |
| 4162 sources.add(source); | 4031 sources.add(source); |
| 4163 } | 4032 } |
| 4164 // Resolution. | 4033 // Resolution. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4197 oldPartMap[source] = dartEntry.getValue(DartEntry.INCLUDED_PARTS); | 4066 oldPartMap[source] = dartEntry.getValue(DartEntry.INCLUDED_PARTS); |
| 4198 dartEntry.invalidateAllResolutionInformation(invalidateUris); | 4067 dartEntry.invalidateAllResolutionInformation(invalidateUris); |
| 4199 iterator.value = dartEntry; | 4068 iterator.value = dartEntry; |
| 4200 _workManager.add(source, _computePriority(dartEntry)); | 4069 _workManager.add(source, _computePriority(dartEntry)); |
| 4201 } | 4070 } |
| 4202 } | 4071 } |
| 4203 _removeFromPartsUsingMap(oldPartMap); | 4072 _removeFromPartsUsingMap(oldPartMap); |
| 4204 } | 4073 } |
| 4205 | 4074 |
| 4206 /** | 4075 /** |
| 4207 * In response to a change to Angular entry point [HtmlElement], invalidate an
y results that | |
| 4208 * depend on it. | |
| 4209 * | |
| 4210 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | |
| 4211 * | |
| 4212 * <b>Note:</b> Any cache entries that were accessed before this method was in
voked must be | |
| 4213 * re-accessed after this method returns. | |
| 4214 * | |
| 4215 * @param entryCopy the [HtmlEntry] of the (maybe) Angular entry point being i
nvalidated | |
| 4216 */ | |
| 4217 void _invalidateAngularResolution(HtmlEntry entryCopy) { | |
| 4218 AngularApplication application = | |
| 4219 entryCopy.getValue(HtmlEntry.ANGULAR_ENTRY); | |
| 4220 if (application == null) { | |
| 4221 return; | |
| 4222 } | |
| 4223 _angularApplications.remove(application); | |
| 4224 // invalidate Entry | |
| 4225 entryCopy.setState(HtmlEntry.ANGULAR_ENTRY, CacheState.INVALID); | |
| 4226 // reset HTML sources | |
| 4227 List<AngularElement> oldAngularElements = application.elements; | |
| 4228 for (AngularElement angularElement in oldAngularElements) { | |
| 4229 if (angularElement is AngularHasTemplateElement) { | |
| 4230 AngularHasTemplateElement hasTemplate = angularElement; | |
| 4231 Source templateSource = hasTemplate.templateSource; | |
| 4232 if (templateSource != null) { | |
| 4233 HtmlEntry htmlEntry = _getReadableHtmlEntry(templateSource); | |
| 4234 htmlEntry.setValue(HtmlEntry.ANGULAR_APPLICATION, null); | |
| 4235 htmlEntry.setValue(HtmlEntry.ANGULAR_COMPONENT, null); | |
| 4236 htmlEntry.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.INVALID); | |
| 4237 _workManager.add(templateSource, SourcePriority.HTML); | |
| 4238 } | |
| 4239 } | |
| 4240 } | |
| 4241 // reset Dart sources | |
| 4242 List<Source> oldElementSources = application.elementSources; | |
| 4243 for (Source elementSource in oldElementSources) { | |
| 4244 DartEntry dartEntry = _getReadableDartEntry(elementSource); | |
| 4245 dartEntry.setValue(DartEntry.ANGULAR_ERRORS, AnalysisError.NO_ERRORS); | |
| 4246 // notify about (disappeared) Angular errors | |
| 4247 ChangeNoticeImpl notice = _getNotice(elementSource); | |
| 4248 notice.setErrors( | |
| 4249 dartEntry.allErrors, | |
| 4250 dartEntry.getValue(SourceEntry.LINE_INFO)); | |
| 4251 } | |
| 4252 } | |
| 4253 | |
| 4254 /** | |
| 4255 * In response to a change to at least one of the compilation units in the giv
en library, | 4076 * In response to a change to at least one of the compilation units in the giv
en library, |
| 4256 * invalidate any results that are dependent on the result of resolving that l
ibrary. | 4077 * invalidate any results that are dependent on the result of resolving that l
ibrary. |
| 4257 * | 4078 * |
| 4258 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | 4079 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. |
| 4259 * | 4080 * |
| 4260 * <b>Note:</b> Any cache entries that were accessed before this method was in
voked must be | 4081 * <b>Note:</b> Any cache entries that were accessed before this method was in
voked must be |
| 4261 * re-accessed after this method returns. | 4082 * re-accessed after this method returns. |
| 4262 * | 4083 * |
| 4263 * @param librarySource the source of the library being invalidated | 4084 * @param librarySource the source of the library being invalidated |
| 4264 */ | 4085 */ |
| 4265 void _invalidateLibraryResolution(Source librarySource) { | 4086 void _invalidateLibraryResolution(Source librarySource) { |
| 4266 // TODO(brianwilkerson) This could be optimized. There's no need to flush | 4087 // TODO(brianwilkerson) This could be optimized. There's no need to flush |
| 4267 // all of these entries if the public namespace hasn't changed, which will | 4088 // all of these entries if the public namespace hasn't changed, which will |
| 4268 // be a fairly common case. The question is whether we can afford the time | 4089 // be a fairly common case. The question is whether we can afford the time |
| 4269 // to compute the namespace to look for differences. | 4090 // to compute the namespace to look for differences. |
| 4270 DartEntry libraryEntry = _getReadableDartEntry(librarySource); | 4091 DartEntry libraryEntry = _getReadableDartEntry(librarySource); |
| 4271 if (libraryEntry != null) { | 4092 if (libraryEntry != null) { |
| 4272 List<Source> includedParts = | 4093 List<Source> includedParts = |
| 4273 libraryEntry.getValue(DartEntry.INCLUDED_PARTS); | 4094 libraryEntry.getValue(DartEntry.INCLUDED_PARTS); |
| 4274 libraryEntry.invalidateAllResolutionInformation(false); | 4095 libraryEntry.invalidateAllResolutionInformation(false); |
| 4275 _workManager.add(librarySource, SourcePriority.LIBRARY); | 4096 _workManager.add(librarySource, SourcePriority.LIBRARY); |
| 4276 for (Source partSource in includedParts) { | 4097 for (Source partSource in includedParts) { |
| 4277 SourceEntry partEntry = _cache.get(partSource); | 4098 SourceEntry partEntry = _cache.get(partSource); |
| 4278 if (partEntry is DartEntry) { | 4099 if (partEntry is DartEntry) { |
| 4279 partEntry.invalidateAllResolutionInformation(false); | 4100 partEntry.invalidateAllResolutionInformation(false); |
| 4280 } | 4101 } |
| 4281 } | 4102 } |
| 4282 } | 4103 } |
| 4283 // invalidate Angular applications | |
| 4284 List<AngularApplication> angularApplicationsCopy = <AngularApplication>[]; | |
| 4285 for (AngularApplication application in angularApplicationsCopy) { | |
| 4286 if (application.dependsOn(librarySource)) { | |
| 4287 Source entryPointSource = application.entryPoint; | |
| 4288 HtmlEntry htmlEntry = _getReadableHtmlEntry(entryPointSource); | |
| 4289 _invalidateAngularResolution(htmlEntry); | |
| 4290 _workManager.add(entryPointSource, SourcePriority.HTML); | |
| 4291 } | |
| 4292 } | |
| 4293 } | 4104 } |
| 4294 | 4105 |
| 4295 /** | 4106 /** |
| 4296 * Return `true` if this library is, or depends on, dart:html. | 4107 * Return `true` if this library is, or depends on, dart:html. |
| 4297 * | 4108 * |
| 4298 * @param library the library being tested | 4109 * @param library the library being tested |
| 4299 * @param visitedLibraries a collection of the libraries that have been visite
d, used to prevent | 4110 * @param visitedLibraries a collection of the libraries that have been visite
d, used to prevent |
| 4300 * infinite recursion | 4111 * infinite recursion |
| 4301 * @return `true` if this library is, or depends on, dart:html | 4112 * @return `true` if this library is, or depends on, dart:html |
| 4302 */ | 4113 */ |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4434 // * @param unit the result of resolving the source | 4245 // * @param unit the result of resolving the source |
| 4435 // */ | 4246 // */ |
| 4436 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) { | 4247 // void _notifyResolvedHtml(Source source, ht.HtmlUnit unit) { |
| 4437 // int count = _listeners.length; | 4248 // int count = _listeners.length; |
| 4438 // for (int i = 0; i < count; i++) { | 4249 // for (int i = 0; i < count; i++) { |
| 4439 // _listeners[i].resolvedHtml(this, source, unit); | 4250 // _listeners[i].resolvedHtml(this, source, unit); |
| 4440 // } | 4251 // } |
| 4441 // } | 4252 // } |
| 4442 | 4253 |
| 4443 /** | 4254 /** |
| 4444 * Updates [HtmlEntry]s that correspond to the previously known and new Angula
r application | |
| 4445 * information. | |
| 4446 */ | |
| 4447 void _recordAngularEntryPoint(HtmlEntry entry, | |
| 4448 ResolveAngularEntryHtmlTask task) { | |
| 4449 AngularApplication application = task.application; | |
| 4450 if (application != null) { | |
| 4451 _angularApplications.add(application); | |
| 4452 // if this is an entry point, then we already resolved it | |
| 4453 entry.setValue(HtmlEntry.ANGULAR_ERRORS, task.entryErrors); | |
| 4454 // schedule HTML templates analysis | |
| 4455 List<AngularElement> newAngularElements = application.elements; | |
| 4456 for (AngularElement angularElement in newAngularElements) { | |
| 4457 if (angularElement is AngularHasTemplateElement) { | |
| 4458 AngularHasTemplateElement hasTemplate = angularElement; | |
| 4459 Source templateSource = hasTemplate.templateSource; | |
| 4460 if (templateSource != null) { | |
| 4461 HtmlEntry htmlEntry = _getReadableHtmlEntry(templateSource); | |
| 4462 htmlEntry.setValue(HtmlEntry.ANGULAR_APPLICATION, application); | |
| 4463 if (hasTemplate is AngularComponentElement) { | |
| 4464 AngularComponentElement component = hasTemplate; | |
| 4465 htmlEntry.setValue(HtmlEntry.ANGULAR_COMPONENT, component); | |
| 4466 } | |
| 4467 htmlEntry.setState(HtmlEntry.ANGULAR_ERRORS, CacheState.INVALID); | |
| 4468 _workManager.add(templateSource, SourcePriority.HTML); | |
| 4469 } | |
| 4470 } | |
| 4471 } | |
| 4472 // update Dart sources errors | |
| 4473 List<Source> newElementSources = application.elementSources; | |
| 4474 for (Source elementSource in newElementSources) { | |
| 4475 DartEntry dartEntry = _getReadableDartEntry(elementSource); | |
| 4476 dartEntry.setValue( | |
| 4477 DartEntry.ANGULAR_ERRORS, | |
| 4478 task.getErrors(elementSource)); | |
| 4479 // notify about Dart errors | |
| 4480 ChangeNoticeImpl notice = _getNotice(elementSource); | |
| 4481 notice.setErrors(dartEntry.allErrors, computeLineInfo(elementSource)); | |
| 4482 } | |
| 4483 } | |
| 4484 // remember Angular entry point | |
| 4485 entry.setValue(HtmlEntry.ANGULAR_ENTRY, application); | |
| 4486 } | |
| 4487 | |
| 4488 /** | |
| 4489 * Record the results produced by performing a [task] and return the cache | 4255 * Record the results produced by performing a [task] and return the cache |
| 4490 * entry associated with the results. | 4256 * entry associated with the results. |
| 4491 */ | 4257 */ |
| 4492 DartEntry _recordBuildUnitElementTask(BuildUnitElementTask task) { | 4258 DartEntry _recordBuildUnitElementTask(BuildUnitElementTask task) { |
| 4493 Source source = task.source; | 4259 Source source = task.source; |
| 4494 Source library = task.library; | 4260 Source library = task.library; |
| 4495 DartEntry dartEntry = _cache.get(source); | 4261 DartEntry dartEntry = _cache.get(source); |
| 4496 CaughtException thrownException = task.exception; | 4262 CaughtException thrownException = task.exception; |
| 4497 if (thrownException != null) { | 4263 if (thrownException != null) { |
| 4498 dartEntry.recordBuildElementErrorInLibrary(library, thrownException); | 4264 dartEntry.recordBuildElementErrorInLibrary(library, thrownException); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4762 ChangeNoticeImpl notice = _getNotice(source); | 4528 ChangeNoticeImpl notice = _getNotice(source); |
| 4763 LineInfo lineInfo = htmlEntry.getValue(SourceEntry.LINE_INFO); | 4529 LineInfo lineInfo = htmlEntry.getValue(SourceEntry.LINE_INFO); |
| 4764 notice.setErrors(htmlEntry.allErrors, lineInfo); | 4530 notice.setErrors(htmlEntry.allErrors, lineInfo); |
| 4765 return htmlEntry; | 4531 return htmlEntry; |
| 4766 } | 4532 } |
| 4767 | 4533 |
| 4768 /** | 4534 /** |
| 4769 * Record the results produced by performing a [task] and return the cache | 4535 * Record the results produced by performing a [task] and return the cache |
| 4770 * entry associated with the results. | 4536 * entry associated with the results. |
| 4771 */ | 4537 */ |
| 4772 HtmlEntry | |
| 4773 _recordResolveAngularComponentTemplateTaskResults(ResolveAngularComponentT
emplateTask task) { | |
| 4774 Source source = task.source; | |
| 4775 HtmlEntry htmlEntry = _cache.get(source); | |
| 4776 CaughtException thrownException = task.exception; | |
| 4777 if (thrownException != null) { | |
| 4778 htmlEntry.recordResolutionError(thrownException); | |
| 4779 throw new AnalysisException('<rethrow>', thrownException); | |
| 4780 } | |
| 4781 htmlEntry.setValue(HtmlEntry.ANGULAR_ERRORS, task.resolutionErrors); | |
| 4782 // notify about errors | |
| 4783 ChangeNoticeImpl notice = _getNotice(source); | |
| 4784 notice.htmlUnit = task.resolvedUnit; | |
| 4785 LineInfo lineInfo = htmlEntry.getValue(SourceEntry.LINE_INFO); | |
| 4786 notice.setErrors(htmlEntry.allErrors, lineInfo); | |
| 4787 return htmlEntry; | |
| 4788 } | |
| 4789 | |
| 4790 /** | |
| 4791 * Record the results produced by performing a [task] and return the cache | |
| 4792 * entry associated with the results. | |
| 4793 */ | |
| 4794 HtmlEntry | |
| 4795 _recordResolveAngularEntryHtmlTaskResults(ResolveAngularEntryHtmlTask task
) { | |
| 4796 Source source = task.source; | |
| 4797 HtmlEntry htmlEntry = _cache.get(source); | |
| 4798 CaughtException thrownException = task.exception; | |
| 4799 if (thrownException != null) { | |
| 4800 htmlEntry.recordResolutionError(thrownException); | |
| 4801 throw new AnalysisException('<rethrow>', thrownException); | |
| 4802 } | |
| 4803 htmlEntry.setValue(HtmlEntry.RESOLVED_UNIT, task.resolvedUnit); | |
| 4804 _recordAngularEntryPoint(htmlEntry, task); | |
| 4805 _cache.storedAst(source); | |
| 4806 ChangeNoticeImpl notice = _getNotice(source); | |
| 4807 notice.htmlUnit = task.resolvedUnit; | |
| 4808 LineInfo lineInfo = htmlEntry.getValue(SourceEntry.LINE_INFO); | |
| 4809 notice.setErrors(htmlEntry.allErrors, lineInfo); | |
| 4810 return htmlEntry; | |
| 4811 } | |
| 4812 | |
| 4813 /** | |
| 4814 * Record the results produced by performing a [task] and return the cache | |
| 4815 * entry associated with the results. | |
| 4816 */ | |
| 4817 DartEntry _recordResolveDartUnitTaskResults(ResolveDartUnitTask task) { | 4538 DartEntry _recordResolveDartUnitTaskResults(ResolveDartUnitTask task) { |
| 4818 Source unitSource = task.source; | 4539 Source unitSource = task.source; |
| 4819 DartEntry dartEntry = _cache.get(unitSource); | 4540 DartEntry dartEntry = _cache.get(unitSource); |
| 4820 Source librarySource = task.librarySource; | 4541 Source librarySource = task.librarySource; |
| 4821 CaughtException thrownException = task.exception; | 4542 CaughtException thrownException = task.exception; |
| 4822 if (thrownException != null) { | 4543 if (thrownException != null) { |
| 4823 dartEntry.recordResolutionErrorInLibrary(librarySource, thrownException); | 4544 dartEntry.recordResolutionErrorInLibrary(librarySource, thrownException); |
| 4824 _cache.removedAst(unitSource); | 4545 _cache.removedAst(unitSource); |
| 4825 throw new AnalysisException('<rethrow>', thrownException); | 4546 throw new AnalysisException('<rethrow>', thrownException); |
| 4826 } | 4547 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4983 if (sourceEntry == null || | 4704 if (sourceEntry == null || |
| 4984 sourceEntry.modificationTime == getModificationStamp(source)) { | 4705 sourceEntry.modificationTime == getModificationStamp(source)) { |
| 4985 // Either we have removed this source, in which case we don't care that | 4706 // Either we have removed this source, in which case we don't care that |
| 4986 // it is changed, or we have already invalidated the cache and don't need | 4707 // it is changed, or we have already invalidated the cache and don't need |
| 4987 // to invalidate it again. | 4708 // to invalidate it again. |
| 4988 return; | 4709 return; |
| 4989 } | 4710 } |
| 4990 if (sourceEntry is HtmlEntry) { | 4711 if (sourceEntry is HtmlEntry) { |
| 4991 HtmlEntry htmlEntry = sourceEntry; | 4712 HtmlEntry htmlEntry = sourceEntry; |
| 4992 htmlEntry.modificationTime = getModificationStamp(source); | 4713 htmlEntry.modificationTime = getModificationStamp(source); |
| 4993 _invalidateAngularResolution(htmlEntry); | |
| 4994 htmlEntry.invalidateAllInformation(); | 4714 htmlEntry.invalidateAllInformation(); |
| 4995 _cache.removedAst(source); | 4715 _cache.removedAst(source); |
| 4996 _workManager.add(source, SourcePriority.HTML); | 4716 _workManager.add(source, SourcePriority.HTML); |
| 4997 } else if (sourceEntry is DartEntry) { | 4717 } else if (sourceEntry is DartEntry) { |
| 4998 List<Source> containingLibraries = getLibrariesContaining(source); | 4718 List<Source> containingLibraries = getLibrariesContaining(source); |
| 4999 HashSet<Source> librariesToInvalidate = new HashSet<Source>(); | 4719 HashSet<Source> librariesToInvalidate = new HashSet<Source>(); |
| 5000 for (Source containingLibrary in containingLibraries) { | 4720 for (Source containingLibrary in containingLibraries) { |
| 5001 _computeAllLibrariesDependingOn( | 4721 _computeAllLibrariesDependingOn( |
| 5002 containingLibrary, | 4722 containingLibrary, |
| 5003 librariesToInvalidate); | 4723 librariesToInvalidate); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5016 | 4736 |
| 5017 /** | 4737 /** |
| 5018 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | 4738 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. |
| 5019 * | 4739 * |
| 5020 * @param source the source that has been deleted | 4740 * @param source the source that has been deleted |
| 5021 */ | 4741 */ |
| 5022 void _sourceDeleted(Source source) { | 4742 void _sourceDeleted(Source source) { |
| 5023 SourceEntry sourceEntry = _cache.get(source); | 4743 SourceEntry sourceEntry = _cache.get(source); |
| 5024 if (sourceEntry is HtmlEntry) { | 4744 if (sourceEntry is HtmlEntry) { |
| 5025 HtmlEntry htmlEntry = sourceEntry; | 4745 HtmlEntry htmlEntry = sourceEntry; |
| 5026 _invalidateAngularResolution(htmlEntry); | |
| 5027 htmlEntry.recordContentError( | 4746 htmlEntry.recordContentError( |
| 5028 new CaughtException( | 4747 new CaughtException( |
| 5029 new AnalysisException("This source was marked as being deleted"), | 4748 new AnalysisException("This source was marked as being deleted"), |
| 5030 null)); | 4749 null)); |
| 5031 } else if (sourceEntry is DartEntry) { | 4750 } else if (sourceEntry is DartEntry) { |
| 5032 DartEntry dartEntry = sourceEntry; | 4751 DartEntry dartEntry = sourceEntry; |
| 5033 HashSet<Source> libraries = new HashSet<Source>(); | 4752 HashSet<Source> libraries = new HashSet<Source>(); |
| 5034 for (Source librarySource in getLibrariesContaining(source)) { | 4753 for (Source librarySource in getLibrariesContaining(source)) { |
| 5035 libraries.add(librarySource); | 4754 libraries.add(librarySource); |
| 5036 for (Source dependentLibrary in getLibrariesDependingOn( | 4755 for (Source dependentLibrary in getLibrariesDependingOn( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5051 } | 4770 } |
| 5052 | 4771 |
| 5053 /** | 4772 /** |
| 5054 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. | 4773 * <b>Note:</b> This method must only be invoked while we are synchronized on
[cacheLock]. |
| 5055 * | 4774 * |
| 5056 * @param source the source that has been removed | 4775 * @param source the source that has been removed |
| 5057 */ | 4776 */ |
| 5058 void _sourceRemoved(Source source) { | 4777 void _sourceRemoved(Source source) { |
| 5059 SourceEntry sourceEntry = _cache.get(source); | 4778 SourceEntry sourceEntry = _cache.get(source); |
| 5060 if (sourceEntry is HtmlEntry) { | 4779 if (sourceEntry is HtmlEntry) { |
| 5061 _invalidateAngularResolution(sourceEntry); | |
| 5062 } else if (sourceEntry is DartEntry) { | 4780 } else if (sourceEntry is DartEntry) { |
| 5063 HashSet<Source> libraries = new HashSet<Source>(); | 4781 HashSet<Source> libraries = new HashSet<Source>(); |
| 5064 for (Source librarySource in getLibrariesContaining(source)) { | 4782 for (Source librarySource in getLibrariesContaining(source)) { |
| 5065 libraries.add(librarySource); | 4783 libraries.add(librarySource); |
| 5066 for (Source dependentLibrary in getLibrariesDependingOn( | 4784 for (Source dependentLibrary in getLibrariesDependingOn( |
| 5067 librarySource)) { | 4785 librarySource)) { |
| 5068 libraries.add(dependentLibrary); | 4786 libraries.add(dependentLibrary); |
| 5069 } | 4787 } |
| 5070 } | 4788 } |
| 5071 for (Source librarySource in libraries) { | 4789 for (Source librarySource in libraries) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5211 | 4929 |
| 5212 @override | 4930 @override |
| 5213 HtmlEntry visitPolymerBuildHtmlTask(PolymerBuildHtmlTask task) => | 4931 HtmlEntry visitPolymerBuildHtmlTask(PolymerBuildHtmlTask task) => |
| 5214 AnalysisContextImpl_this._recordPolymerBuildHtmlTaskResults(task); | 4932 AnalysisContextImpl_this._recordPolymerBuildHtmlTaskResults(task); |
| 5215 | 4933 |
| 5216 @override | 4934 @override |
| 5217 HtmlEntry visitPolymerResolveHtmlTask(PolymerResolveHtmlTask task) => | 4935 HtmlEntry visitPolymerResolveHtmlTask(PolymerResolveHtmlTask task) => |
| 5218 AnalysisContextImpl_this._recordPolymerResolveHtmlTaskResults(task); | 4936 AnalysisContextImpl_this._recordPolymerResolveHtmlTaskResults(task); |
| 5219 | 4937 |
| 5220 @override | 4938 @override |
| 5221 HtmlEntry | |
| 5222 visitResolveAngularComponentTemplateTask(ResolveAngularComponentTemplateTa
sk task) => | |
| 5223 AnalysisContextImpl_this._recordResolveAngularComponentTemplateTaskResults
( | |
| 5224 task); | |
| 5225 | |
| 5226 @override | |
| 5227 HtmlEntry | |
| 5228 visitResolveAngularEntryHtmlTask(ResolveAngularEntryHtmlTask task) => | |
| 5229 AnalysisContextImpl_this._recordResolveAngularEntryHtmlTaskResults(task); | |
| 5230 | |
| 5231 @override | |
| 5232 DartEntry | 4939 DartEntry |
| 5233 visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task) => | 4940 visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task) => |
| 5234 AnalysisContextImpl_this.recordResolveDartLibraryCycleTaskResults(task); | 4941 AnalysisContextImpl_this.recordResolveDartLibraryCycleTaskResults(task); |
| 5235 | 4942 |
| 5236 @override | 4943 @override |
| 5237 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => | 4944 DartEntry visitResolveDartLibraryTask(ResolveDartLibraryTask task) => |
| 5238 AnalysisContextImpl_this.recordResolveDartLibraryTaskResults(task); | 4945 AnalysisContextImpl_this.recordResolveDartLibraryTaskResults(task); |
| 5239 | 4946 |
| 5240 @override | 4947 @override |
| 5241 DartEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => | 4948 DartEntry visitResolveDartUnitTask(ResolveDartUnitTask task) => |
| (...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6449 */ | 6156 */ |
| 6450 class AnalysisNotScheduledError implements Exception { | 6157 class AnalysisNotScheduledError implements Exception { |
| 6451 } | 6158 } |
| 6452 | 6159 |
| 6453 /** | 6160 /** |
| 6454 * The interface `AnalysisOptions` defines the behavior of objects that provide
access to a | 6161 * The interface `AnalysisOptions` defines the behavior of objects that provide
access to a |
| 6455 * set of analysis options used to control the behavior of an analysis context. | 6162 * set of analysis options used to control the behavior of an analysis context. |
| 6456 */ | 6163 */ |
| 6457 abstract class AnalysisOptions { | 6164 abstract class AnalysisOptions { |
| 6458 /** | 6165 /** |
| 6459 * Return `true` if analysis is to analyze Angular. | |
| 6460 * | |
| 6461 * @return `true` if analysis is to analyze Angular | |
| 6462 */ | |
| 6463 bool get analyzeAngular; | |
| 6464 | |
| 6465 /** | |
| 6466 * Return `true` if analysis is to parse and analyze function bodies. | 6166 * Return `true` if analysis is to parse and analyze function bodies. |
| 6467 * | 6167 * |
| 6468 * @return `true` if analysis is to parse and analyzer function bodies | 6168 * @return `true` if analysis is to parse and analyzer function bodies |
| 6469 */ | 6169 */ |
| 6470 bool get analyzeFunctionBodies; | 6170 bool get analyzeFunctionBodies; |
| 6471 | 6171 |
| 6472 /** | 6172 /** |
| 6473 * Return `true` if analysis is to analyze Polymer. | 6173 * Return `true` if analysis is to analyze Polymer. |
| 6474 * | 6174 * |
| 6475 * @return `true` if analysis is to analyze Polymer | 6175 * @return `true` if analysis is to analyze Polymer |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6567 * The default value for enabling deferred loading. | 6267 * The default value for enabling deferred loading. |
| 6568 */ | 6268 */ |
| 6569 static bool DEFAULT_ENABLE_DEFERRED_LOADING = true; | 6269 static bool DEFAULT_ENABLE_DEFERRED_LOADING = true; |
| 6570 | 6270 |
| 6571 /** | 6271 /** |
| 6572 * The default value for enabling enum support. | 6272 * The default value for enabling enum support. |
| 6573 */ | 6273 */ |
| 6574 static bool DEFAULT_ENABLE_ENUM = false; | 6274 static bool DEFAULT_ENABLE_ENUM = false; |
| 6575 | 6275 |
| 6576 /** | 6276 /** |
| 6577 * A flag indicating whether analysis is to analyze Angular. | |
| 6578 */ | |
| 6579 bool analyzeAngular = true; | |
| 6580 | |
| 6581 /** | |
| 6582 * A flag indicating whether analysis is to parse and analyze function bodies. | 6277 * A flag indicating whether analysis is to parse and analyze function bodies. |
| 6583 */ | 6278 */ |
| 6584 bool analyzeFunctionBodies = true; | 6279 bool analyzeFunctionBodies = true; |
| 6585 | 6280 |
| 6586 /** | 6281 /** |
| 6587 * A flag indicating whether analysis is to analyze Polymer. | 6282 * A flag indicating whether analysis is to analyze Polymer. |
| 6588 */ | 6283 */ |
| 6589 bool analyzePolymer = true; | 6284 bool analyzePolymer = true; |
| 6590 | 6285 |
| 6591 /** | 6286 /** |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6656 */ | 6351 */ |
| 6657 AnalysisOptionsImpl(); | 6352 AnalysisOptionsImpl(); |
| 6658 | 6353 |
| 6659 /** | 6354 /** |
| 6660 * Initialize a newly created set of analysis options to have the same values
as those in the | 6355 * Initialize a newly created set of analysis options to have the same values
as those in the |
| 6661 * given set of analysis options. | 6356 * given set of analysis options. |
| 6662 * | 6357 * |
| 6663 * @param options the analysis options whose values are being copied | 6358 * @param options the analysis options whose values are being copied |
| 6664 */ | 6359 */ |
| 6665 AnalysisOptionsImpl.con1(AnalysisOptions options) { | 6360 AnalysisOptionsImpl.con1(AnalysisOptions options) { |
| 6666 analyzeAngular = options.analyzeAngular; | |
| 6667 analyzeFunctionBodies = options.analyzeFunctionBodies; | 6361 analyzeFunctionBodies = options.analyzeFunctionBodies; |
| 6668 analyzePolymer = options.analyzePolymer; | 6362 analyzePolymer = options.analyzePolymer; |
| 6669 cacheSize = options.cacheSize; | 6363 cacheSize = options.cacheSize; |
| 6670 dart2jsHint = options.dart2jsHint; | 6364 dart2jsHint = options.dart2jsHint; |
| 6671 enableDeferredLoading = options.enableDeferredLoading; | 6365 enableDeferredLoading = options.enableDeferredLoading; |
| 6672 enableEnum = options.enableEnum; | 6366 enableEnum = options.enableEnum; |
| 6673 _generateSdkErrors = options.generateSdkErrors; | 6367 _generateSdkErrors = options.generateSdkErrors; |
| 6674 hint = options.hint; | 6368 hint = options.hint; |
| 6675 incremental = options.incremental; | 6369 incremental = options.incremental; |
| 6676 incrementalApi = options.incrementalApi; | 6370 incrementalApi = options.incrementalApi; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6898 /** | 6592 /** |
| 6899 * Visit the given [task], returning the result of the visit. This method will | 6593 * Visit the given [task], returning the result of the visit. This method will |
| 6900 * throw an AnalysisException if the visitor throws an exception. | 6594 * throw an AnalysisException if the visitor throws an exception. |
| 6901 */ | 6595 */ |
| 6902 E visitPolymerResolveHtmlTask(PolymerResolveHtmlTask task); | 6596 E visitPolymerResolveHtmlTask(PolymerResolveHtmlTask task); |
| 6903 | 6597 |
| 6904 /** | 6598 /** |
| 6905 * Visit the given [task], returning the result of the visit. This method will | 6599 * Visit the given [task], returning the result of the visit. This method will |
| 6906 * throw an AnalysisException if the visitor throws an exception. | 6600 * throw an AnalysisException if the visitor throws an exception. |
| 6907 */ | 6601 */ |
| 6908 E | |
| 6909 visitResolveAngularComponentTemplateTask(ResolveAngularComponentTemplateTa
sk task); | |
| 6910 | |
| 6911 /** | |
| 6912 * Visit the given [task], returning the result of the visit. This method will | |
| 6913 * throw an AnalysisException if the visitor throws an exception. | |
| 6914 */ | |
| 6915 E visitResolveAngularEntryHtmlTask(ResolveAngularEntryHtmlTask task); | |
| 6916 | |
| 6917 /** | |
| 6918 * Visit the given [task], returning the result of the visit. This method will | |
| 6919 * throw an AnalysisException if the visitor throws an exception. | |
| 6920 */ | |
| 6921 E visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task); | 6602 E visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task); |
| 6922 | 6603 |
| 6923 /** | 6604 /** |
| 6924 * Visit the given [task], returning the result of the visit. This method will | 6605 * Visit the given [task], returning the result of the visit. This method will |
| 6925 * throw an AnalysisException if the visitor throws an exception. | 6606 * throw an AnalysisException if the visitor throws an exception. |
| 6926 */ | 6607 */ |
| 6927 E visitResolveDartLibraryTask(ResolveDartLibraryTask task); | 6608 E visitResolveDartLibraryTask(ResolveDartLibraryTask task); |
| 6928 | 6609 |
| 6929 /** | 6610 /** |
| 6930 * Visit the given [task], returning the result of the visit. This method will | 6611 * Visit the given [task], returning the result of the visit. This method will |
| 6931 * throw an AnalysisException if the visitor throws an exception. | 6612 * throw an AnalysisException if the visitor throws an exception. |
| 6932 */ | 6613 */ |
| 6933 E visitResolveDartUnitTask(ResolveDartUnitTask task); | 6614 E visitResolveDartUnitTask(ResolveDartUnitTask task); |
| 6934 | 6615 |
| 6935 /** | 6616 /** |
| 6936 * Visit the given [task], returning the result of the visit. This method will | 6617 * Visit the given [task], returning the result of the visit. This method will |
| 6937 * throw an AnalysisException if the visitor throws an exception. | 6618 * throw an AnalysisException if the visitor throws an exception. |
| 6938 */ | 6619 */ |
| 6939 E visitResolveHtmlTask(ResolveHtmlTask task); | 6620 E visitResolveHtmlTask(ResolveHtmlTask task); |
| 6940 | 6621 |
| 6941 /** | 6622 /** |
| 6942 * Visit the given [task], returning the result of the visit. This method will | 6623 * Visit the given [task], returning the result of the visit. This method will |
| 6943 * throw an AnalysisException if the visitor throws an exception. | 6624 * throw an AnalysisException if the visitor throws an exception. |
| 6944 */ | 6625 */ |
| 6945 E visitScanDartTask(ScanDartTask task); | 6626 E visitScanDartTask(ScanDartTask task); |
| 6946 } | 6627 } |
| 6947 | 6628 |
| 6948 /** | 6629 /** |
| 6949 * An [Expression] with optional [AngularFormatterNode]s. | |
| 6950 */ | |
| 6951 class AngularExpression { | |
| 6952 /** | |
| 6953 * The [Expression] to apply formatters to. | |
| 6954 */ | |
| 6955 final Expression expression; | |
| 6956 | |
| 6957 /** | |
| 6958 * The formatters to apply. | |
| 6959 */ | |
| 6960 final List<AngularFormatterNode> formatters; | |
| 6961 | |
| 6962 AngularExpression(this.expression, this.formatters); | |
| 6963 | |
| 6964 /** | |
| 6965 * Return the offset of the character immediately following the last character
of this node's | |
| 6966 * source range. This is equivalent to `node.getOffset() + node.getLength()`. | |
| 6967 * | |
| 6968 * @return the offset of the character just past the node's source range | |
| 6969 */ | |
| 6970 int get end { | |
| 6971 if (formatters.isEmpty) { | |
| 6972 return expression.end; | |
| 6973 } | |
| 6974 AngularFormatterNode lastFormatter = formatters[formatters.length - 1]; | |
| 6975 List<AngularFormatterArgument> formatterArguments = lastFormatter.arguments; | |
| 6976 if (formatterArguments.isEmpty) { | |
| 6977 return lastFormatter.name.end; | |
| 6978 } | |
| 6979 return formatterArguments[formatterArguments.length - 1].expression.end; | |
| 6980 } | |
| 6981 | |
| 6982 /** | |
| 6983 * Return Dart [Expression]s this Angular expression consists of. | |
| 6984 */ | |
| 6985 List<Expression> get expressions { | |
| 6986 List<Expression> expressions = <Expression>[]; | |
| 6987 expressions.add(expression); | |
| 6988 for (AngularFormatterNode formatter in formatters) { | |
| 6989 expressions.add(formatter.name); | |
| 6990 for (AngularFormatterArgument formatterArgument in formatter.arguments) { | |
| 6991 expressions.addAll(formatterArgument.subExpressions); | |
| 6992 expressions.add(formatterArgument.expression); | |
| 6993 } | |
| 6994 } | |
| 6995 return expressions; | |
| 6996 } | |
| 6997 | |
| 6998 /** | |
| 6999 * Return the number of characters in the expression's source range. | |
| 7000 */ | |
| 7001 int get length => end - offset; | |
| 7002 | |
| 7003 /** | |
| 7004 * Return the offset of the first character in the expression's source range. | |
| 7005 */ | |
| 7006 int get offset => expression.offset; | |
| 7007 } | |
| 7008 | |
| 7009 /** | |
| 7010 * Angular formatter argument. | |
| 7011 */ | |
| 7012 class AngularFormatterArgument { | |
| 7013 /** | |
| 7014 * The [TokenType.COLON] token. | |
| 7015 */ | |
| 7016 final Token token; | |
| 7017 | |
| 7018 /** | |
| 7019 * The argument expression. | |
| 7020 */ | |
| 7021 final Expression expression; | |
| 7022 | |
| 7023 /** | |
| 7024 * The optional sub-[Expression]s. | |
| 7025 */ | |
| 7026 List<Expression> subExpressions = Expression.EMPTY_ARRAY; | |
| 7027 | |
| 7028 AngularFormatterArgument(this.token, this.expression); | |
| 7029 } | |
| 7030 | |
| 7031 /** | |
| 7032 * Angular formatter node. | |
| 7033 */ | |
| 7034 class AngularFormatterNode { | |
| 7035 /** | |
| 7036 * The [TokenType.BAR] token. | |
| 7037 */ | |
| 7038 final Token token; | |
| 7039 | |
| 7040 /** | |
| 7041 * The name of the formatter. | |
| 7042 */ | |
| 7043 final SimpleIdentifier name; | |
| 7044 | |
| 7045 /** | |
| 7046 * The arguments for this formatter. | |
| 7047 */ | |
| 7048 final List<AngularFormatterArgument> arguments; | |
| 7049 | |
| 7050 AngularFormatterNode(this.token, this.name, this.arguments); | |
| 7051 } | |
| 7052 | |
| 7053 /** | |
| 7054 * Instances of the class [AngularHtmlUnitResolver] resolve Angular specific exp
ressions. | |
| 7055 */ | |
| 7056 class AngularHtmlUnitResolver extends ht.RecursiveXmlVisitor<Object> { | |
| 7057 static String _NG_APP = "ng-app"; | |
| 7058 | |
| 7059 final InternalAnalysisContext _context; | |
| 7060 | |
| 7061 TypeProvider _typeProvider; | |
| 7062 | |
| 7063 AngularHtmlUnitResolver_FilteringAnalysisErrorListener _errorListener; | |
| 7064 | |
| 7065 final Source _source; | |
| 7066 | |
| 7067 final LineInfo _lineInfo; | |
| 7068 | |
| 7069 final ht.HtmlUnit _unit; | |
| 7070 | |
| 7071 // List<AngularElement> _angularElements; | |
| 7072 | |
| 7073 List<NgProcessor> _processors = <NgProcessor>[]; | |
| 7074 | |
| 7075 LibraryElementImpl _libraryElement; | |
| 7076 | |
| 7077 CompilationUnitElementImpl _unitElement; | |
| 7078 | |
| 7079 FunctionElementImpl _functionElement; | |
| 7080 | |
| 7081 ResolverVisitor _resolver; | |
| 7082 | |
| 7083 bool _isAngular = false; | |
| 7084 | |
| 7085 List<LocalVariableElementImpl> _definedVariables = <LocalVariableElementImpl>[ | |
| 7086 ]; | |
| 7087 | |
| 7088 Set<LibraryElement> _injectedLibraries = new Set(); | |
| 7089 | |
| 7090 Scope _topNameScope; | |
| 7091 | |
| 7092 Scope _nameScope; | |
| 7093 | |
| 7094 AngularHtmlUnitResolver(this._context, AnalysisErrorListener errorListener, | |
| 7095 this._source, this._lineInfo, this._unit) { | |
| 7096 this._typeProvider = _context.typeProvider; | |
| 7097 this._errorListener = | |
| 7098 new AngularHtmlUnitResolver_FilteringAnalysisErrorListener(errorListener
); | |
| 7099 } | |
| 7100 | |
| 7101 /** | |
| 7102 * @return the [TypeProvider] of the [AnalysisContext]. | |
| 7103 */ | |
| 7104 TypeProvider get typeProvider => _typeProvider; | |
| 7105 | |
| 7106 /** | |
| 7107 * The [AngularApplication] for the Web application with this entry point, may
be | |
| 7108 * `null` if not an entry point. | |
| 7109 */ | |
| 7110 AngularApplication calculateAngularApplication() { | |
| 7111 // check if Angular at all | |
| 7112 if (!hasAngularAnnotation(_unit)) { | |
| 7113 return null; | |
| 7114 } | |
| 7115 // prepare resolved Dart unit | |
| 7116 CompilationUnit dartUnit = _getDartUnit(_context, _unit); | |
| 7117 if (dartUnit == null) { | |
| 7118 return null; | |
| 7119 } | |
| 7120 // prepare accessible Angular elements | |
| 7121 LibraryElement libraryElement = dartUnit.element.library; | |
| 7122 Set<LibraryElement> libraries = new Set(); | |
| 7123 List<AngularElement> angularElements = | |
| 7124 _getAngularElements(libraries, libraryElement); | |
| 7125 // resolve AngularComponentElement template URIs | |
| 7126 // TODO(scheglov) resolve to HtmlElement to allow F3 ? | |
| 7127 Set<Source> angularElementsSources = new Set(); | |
| 7128 for (AngularElement angularElement in angularElements) { | |
| 7129 if (angularElement is AngularHasTemplateElement) { | |
| 7130 AngularHasTemplateElement hasTemplate = angularElement; | |
| 7131 angularElementsSources.add(angularElement.source); | |
| 7132 String templateUri = hasTemplate.templateUri; | |
| 7133 if (templateUri == null) { | |
| 7134 continue; | |
| 7135 } | |
| 7136 try { | |
| 7137 Source templateSource = _context.sourceFactory.forUri2( | |
| 7138 _source.resolveRelativeUri(parseUriWithException(templateUri))); | |
| 7139 if (!_context.exists(templateSource)) { | |
| 7140 templateSource = | |
| 7141 _context.sourceFactory.resolveUri(_source, "package:$templateUri
"); | |
| 7142 if (!_context.exists(templateSource)) { | |
| 7143 _errorListener.onError( | |
| 7144 new AnalysisError.con2( | |
| 7145 angularElement.source, | |
| 7146 hasTemplate.templateUriOffset, | |
| 7147 templateUri.length, | |
| 7148 AngularCode.URI_DOES_NOT_EXIST, | |
| 7149 [templateUri])); | |
| 7150 continue; | |
| 7151 } | |
| 7152 } | |
| 7153 if (!AnalysisEngine.isHtmlFileName(templateUri)) { | |
| 7154 continue; | |
| 7155 } | |
| 7156 if (hasTemplate is AngularComponentElementImpl) { | |
| 7157 hasTemplate.templateSource = templateSource; | |
| 7158 } | |
| 7159 if (hasTemplate is AngularViewElementImpl) { | |
| 7160 hasTemplate.templateSource = templateSource; | |
| 7161 } | |
| 7162 } on URISyntaxException catch (exception) { | |
| 7163 _errorListener.onError( | |
| 7164 new AnalysisError.con2( | |
| 7165 angularElement.source, | |
| 7166 hasTemplate.templateUriOffset, | |
| 7167 templateUri.length, | |
| 7168 AngularCode.INVALID_URI, | |
| 7169 [templateUri])); | |
| 7170 } | |
| 7171 } | |
| 7172 } | |
| 7173 // create AngularApplication | |
| 7174 AngularApplication application = new AngularApplication( | |
| 7175 _source, | |
| 7176 _getLibrarySources(libraries), | |
| 7177 angularElements, | |
| 7178 new List.from(angularElementsSources)); | |
| 7179 // set AngularApplication for each AngularElement | |
| 7180 for (AngularElement angularElement in angularElements) { | |
| 7181 (angularElement as AngularElementImpl).application = application; | |
| 7182 } | |
| 7183 // done | |
| 7184 return application; | |
| 7185 } | |
| 7186 | |
| 7187 /** | |
| 7188 * Resolves [source] as an [AngularComponentElement] template file. | |
| 7189 * | |
| 7190 * @param application the Angular application we are resolving for | |
| 7191 * @param component the [AngularComponentElement] to resolve template for, not
`null` | |
| 7192 */ | |
| 7193 void resolveComponentTemplate(AngularApplication application, | |
| 7194 AngularComponentElement component) { | |
| 7195 _isAngular = true; | |
| 7196 _resolveInternal(application.elements, component); | |
| 7197 } | |
| 7198 | |
| 7199 /** | |
| 7200 * Resolves [source] as an Angular application entry point. | |
| 7201 */ | |
| 7202 void resolveEntryPoint(AngularApplication application) { | |
| 7203 _resolveInternal(application.elements, null); | |
| 7204 } | |
| 7205 | |
| 7206 @override | |
| 7207 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { | |
| 7208 _parseEmbeddedExpressionsInAttribute(node); | |
| 7209 _resolveExpressions(node.expressions); | |
| 7210 return super.visitXmlAttributeNode(node); | |
| 7211 } | |
| 7212 | |
| 7213 @override | |
| 7214 Object visitXmlTagNode(ht.XmlTagNode node) { | |
| 7215 bool wasAngular = _isAngular; | |
| 7216 try { | |
| 7217 // new Angular context | |
| 7218 if (node.getAttribute(_NG_APP) != null) { | |
| 7219 _isAngular = true; | |
| 7220 _visitModelDirectives(node); | |
| 7221 } | |
| 7222 // not Angular | |
| 7223 if (!_isAngular) { | |
| 7224 return super.visitXmlTagNode(node); | |
| 7225 } | |
| 7226 // process node in separate name scope | |
| 7227 _pushNameScope(); | |
| 7228 try { | |
| 7229 _parseEmbeddedExpressionsInTag(node); | |
| 7230 // apply processors | |
| 7231 for (NgProcessor processor in _processors) { | |
| 7232 if (processor.canApply(node)) { | |
| 7233 processor.apply(this, node); | |
| 7234 } | |
| 7235 } | |
| 7236 // resolve expressions | |
| 7237 _resolveExpressions(node.expressions); | |
| 7238 // process children | |
| 7239 return super.visitXmlTagNode(node); | |
| 7240 } finally { | |
| 7241 _popNameScope(); | |
| 7242 } | |
| 7243 } finally { | |
| 7244 _isAngular = wasAngular; | |
| 7245 } | |
| 7246 } | |
| 7247 | |
| 7248 /** | |
| 7249 * Puts into [libraryElement] an artificial [LibraryElementImpl] for this HTML | |
| 7250 * [Source]. | |
| 7251 */ | |
| 7252 void _createLibraryElement() { | |
| 7253 // create CompilationUnitElementImpl | |
| 7254 String unitName = _source.shortName; | |
| 7255 _unitElement = new CompilationUnitElementImpl(unitName); | |
| 7256 _unitElement.source = _source; | |
| 7257 // create LibraryElementImpl | |
| 7258 _libraryElement = | |
| 7259 new LibraryElementImpl.forNode(_context.getContextFor(_source), null); | |
| 7260 _libraryElement.definingCompilationUnit = _unitElement; | |
| 7261 _libraryElement.angularHtml = true; | |
| 7262 _injectedLibraries.add(_libraryElement); | |
| 7263 // create FunctionElementImpl | |
| 7264 _functionElement = new FunctionElementImpl.forOffset(0); | |
| 7265 _unitElement.functions = <FunctionElement>[_functionElement]; | |
| 7266 } | |
| 7267 | |
| 7268 /** | |
| 7269 * Creates new [LocalVariableElementImpl] with given type and identifier. | |
| 7270 * | |
| 7271 * @param type the [Type] of the variable | |
| 7272 * @param identifier the identifier to create variable for | |
| 7273 * @return the new [LocalVariableElementImpl] | |
| 7274 */ | |
| 7275 LocalVariableElementImpl _createLocalVariableFromIdentifier(DartType type, | |
| 7276 SimpleIdentifier identifier) { | |
| 7277 LocalVariableElementImpl variable = | |
| 7278 new LocalVariableElementImpl.forNode(identifier); | |
| 7279 _definedVariables.add(variable); | |
| 7280 variable.type = type; | |
| 7281 return variable; | |
| 7282 } | |
| 7283 | |
| 7284 /** | |
| 7285 * Creates new [LocalVariableElementImpl] with given name and type. | |
| 7286 * | |
| 7287 * @param type the [Type] of the variable | |
| 7288 * @param name the name of the variable | |
| 7289 * @return the new [LocalVariableElementImpl] | |
| 7290 */ | |
| 7291 LocalVariableElementImpl _createLocalVariableWithName(DartType type, | |
| 7292 String name) { | |
| 7293 SimpleIdentifier identifier = _createIdentifier(name, 0); | |
| 7294 return _createLocalVariableFromIdentifier(type, identifier); | |
| 7295 } | |
| 7296 | |
| 7297 /** | |
| 7298 * Creates new [NgProcessor] for the given [AngularElement], maybe `null` if n
ot | |
| 7299 * supported. | |
| 7300 */ | |
| 7301 NgProcessor _createProcessor(AngularElement element) { | |
| 7302 if (element is AngularComponentElement) { | |
| 7303 AngularComponentElement component = element; | |
| 7304 return new NgComponentElementProcessor(component); | |
| 7305 } | |
| 7306 if (element is AngularControllerElement) { | |
| 7307 AngularControllerElement controller = element; | |
| 7308 return new NgControllerElementProcessor(controller); | |
| 7309 } | |
| 7310 if (element is AngularDecoratorElement) { | |
| 7311 AngularDecoratorElement directive = element; | |
| 7312 return new NgDecoratorElementProcessor(directive); | |
| 7313 } | |
| 7314 return null; | |
| 7315 } | |
| 7316 | |
| 7317 /** | |
| 7318 * Puts into [resolver] an [ResolverVisitor] to resolve [Expression]s in | |
| 7319 * [source]. | |
| 7320 */ | |
| 7321 void _createResolver() { | |
| 7322 InheritanceManager inheritanceManager = | |
| 7323 new InheritanceManager(_libraryElement); | |
| 7324 _resolver = new ResolverVisitor.con2( | |
| 7325 _libraryElement, | |
| 7326 _source, | |
| 7327 _typeProvider, | |
| 7328 inheritanceManager, | |
| 7329 _errorListener); | |
| 7330 _topNameScope = _resolver.pushNameScope(); | |
| 7331 // add Scope variables - no type, no location, just to avoid warnings | |
| 7332 { | |
| 7333 DartType type = _typeProvider.dynamicType; | |
| 7334 _topNameScope.define(_createLocalVariableWithName(type, "\$id")); | |
| 7335 _topNameScope.define(_createLocalVariableWithName(type, "\$parent")); | |
| 7336 _topNameScope.define(_createLocalVariableWithName(type, "\$root")); | |
| 7337 } | |
| 7338 } | |
| 7339 | |
| 7340 /** | |
| 7341 * Declares the given [LocalVariableElementImpl] in the [topNameScope]. | |
| 7342 */ | |
| 7343 void _defineTopVariable(LocalVariableElementImpl variable) { | |
| 7344 _recordDefinedVariable(variable); | |
| 7345 _topNameScope.define(variable); | |
| 7346 _recordTypeLibraryInjected(variable); | |
| 7347 } | |
| 7348 | |
| 7349 /** | |
| 7350 * Defines variable for the given [AngularElement] with type of the enclosing | |
| 7351 * [ClassElement]. | |
| 7352 */ | |
| 7353 void _defineTopVariable_forClassElement(AngularElement element) { | |
| 7354 ClassElement classElement = element.enclosingElement as ClassElement; | |
| 7355 InterfaceType type = classElement.type; | |
| 7356 LocalVariableElementImpl variable = | |
| 7357 _createLocalVariableWithName(type, element.name); | |
| 7358 _defineTopVariable(variable); | |
| 7359 variable.toolkitObjects = <AngularElement>[element]; | |
| 7360 } | |
| 7361 | |
| 7362 /** | |
| 7363 * Defines variable for the given [AngularScopePropertyElement]. | |
| 7364 */ | |
| 7365 void | |
| 7366 _defineTopVariable_forScopeProperty(AngularScopePropertyElement element) { | |
| 7367 DartType type = element.type; | |
| 7368 LocalVariableElementImpl variable = | |
| 7369 _createLocalVariableWithName(type, element.name); | |
| 7370 _defineTopVariable(variable); | |
| 7371 variable.toolkitObjects = <AngularElement>[element]; | |
| 7372 } | |
| 7373 | |
| 7374 /** | |
| 7375 * Declares the given [LocalVariableElementImpl] in the current [nameScope]. | |
| 7376 */ | |
| 7377 void _defineVariable(LocalVariableElementImpl variable) { | |
| 7378 _recordDefinedVariable(variable); | |
| 7379 _nameScope.define(variable); | |
| 7380 _recordTypeLibraryInjected(variable); | |
| 7381 } | |
| 7382 | |
| 7383 // /** | |
| 7384 // * @return the [AngularElement] with the given name, maybe `null`. | |
| 7385 // */ | |
| 7386 // AngularElement _findAngularElement(String name) { | |
| 7387 // for (AngularElement element in _angularElements) { | |
| 7388 // if (name == element.name) { | |
| 7389 // return element; | |
| 7390 // } | |
| 7391 // } | |
| 7392 // return null; | |
| 7393 // } | |
| 7394 | |
| 7395 /** | |
| 7396 * Parses given [String] as an [AngularExpression] at the given offset. | |
| 7397 */ | |
| 7398 AngularExpression _parseAngularExpression(String contents, int startIndex, | |
| 7399 int endIndex, int offset) { | |
| 7400 Token token = _scanDart(contents, startIndex, endIndex, offset); | |
| 7401 return _parseAngularExpressionInToken(token); | |
| 7402 } | |
| 7403 | |
| 7404 AngularExpression _parseAngularExpressionInToken(Token token) { | |
| 7405 List<Token> tokens = _splitAtBar(token); | |
| 7406 Expression mainExpression = _parseDartExpressionInToken(tokens[0]); | |
| 7407 // parse formatters | |
| 7408 List<AngularFormatterNode> formatters = <AngularFormatterNode>[]; | |
| 7409 for (int i = 1; i < tokens.length; i++) { | |
| 7410 Token formatterToken = tokens[i]; | |
| 7411 Token barToken = formatterToken; | |
| 7412 formatterToken = formatterToken.next; | |
| 7413 // parse name | |
| 7414 Expression nameExpression = _parseDartExpressionInToken(formatterToken); | |
| 7415 if (nameExpression is! SimpleIdentifier) { | |
| 7416 _reportErrorForNode(AngularCode.INVALID_FORMATTER_NAME, nameExpression); | |
| 7417 continue; | |
| 7418 } | |
| 7419 SimpleIdentifier name = nameExpression as SimpleIdentifier; | |
| 7420 formatterToken = name.endToken.next; | |
| 7421 // parse arguments | |
| 7422 List<AngularFormatterArgument> arguments = <AngularFormatterArgument>[]; | |
| 7423 while (formatterToken.type != TokenType.EOF) { | |
| 7424 // skip ":" | |
| 7425 Token colonToken = formatterToken; | |
| 7426 if (colonToken.type == TokenType.COLON) { | |
| 7427 formatterToken = formatterToken.next; | |
| 7428 } else { | |
| 7429 _reportErrorForToken(AngularCode.MISSING_FORMATTER_COLON, colonToken); | |
| 7430 break; | |
| 7431 } | |
| 7432 // parse argument | |
| 7433 Expression argument = _parseDartExpressionInToken(formatterToken); | |
| 7434 arguments.add(new AngularFormatterArgument(colonToken, argument)); | |
| 7435 // next token | |
| 7436 formatterToken = argument.endToken.next; | |
| 7437 } | |
| 7438 formatters.add(new AngularFormatterNode(barToken, name, arguments)); | |
| 7439 } | |
| 7440 // done | |
| 7441 return new AngularExpression(mainExpression, formatters); | |
| 7442 } | |
| 7443 | |
| 7444 // /** | |
| 7445 // * Parses given [String] as an [Expression] at the given offset. | |
| 7446 // */ | |
| 7447 // Expression _parseDartExpression(String contents, int startIndex, int endInde
x, | |
| 7448 // int offset) { | |
| 7449 // Token token = _scanDart(contents, startIndex, endIndex, offset); | |
| 7450 // return _parseDartExpressionInToken(token); | |
| 7451 // } | |
| 7452 | |
| 7453 Expression _parseDartExpressionInToken(Token token) { | |
| 7454 Parser parser = new Parser(_source, _errorListener); | |
| 7455 return parser.parseExpression(token); | |
| 7456 } | |
| 7457 | |
| 7458 /** | |
| 7459 * Parse the value of the given token for embedded expressions, and add any em
bedded expressions | |
| 7460 * that are found to the given list of expressions. | |
| 7461 * | |
| 7462 * @param expressions the list to which embedded expressions are to be added | |
| 7463 * @param token the token whose value is to be parsed | |
| 7464 */ | |
| 7465 void | |
| 7466 _parseEmbeddedExpressions(List<AngularMoustacheXmlExpression> expressions, | |
| 7467 ht.Token token) { | |
| 7468 // prepare Token information | |
| 7469 String lexeme = token.lexeme; | |
| 7470 int offset = token.offset; | |
| 7471 // find expressions between {{ and }} | |
| 7472 int startIndex = StringUtilities.indexOf2( | |
| 7473 lexeme, | |
| 7474 0, | |
| 7475 AngularMoustacheXmlExpression.OPENING_DELIMITER_CHAR, | |
| 7476 AngularMoustacheXmlExpression.OPENING_DELIMITER_CHAR); | |
| 7477 while (startIndex >= 0) { | |
| 7478 int endIndex = StringUtilities.indexOf2( | |
| 7479 lexeme, | |
| 7480 startIndex + AngularMoustacheXmlExpression.OPENING_DELIMITER_LENGTH, | |
| 7481 AngularMoustacheXmlExpression.CLOSING_DELIMITER_CHAR, | |
| 7482 AngularMoustacheXmlExpression.CLOSING_DELIMITER_CHAR); | |
| 7483 if (endIndex < 0) { | |
| 7484 // TODO(brianwilkerson) Should we report this error or will it be | |
| 7485 // reported by something else? | |
| 7486 return; | |
| 7487 } else if (startIndex + | |
| 7488 AngularMoustacheXmlExpression.OPENING_DELIMITER_LENGTH < | |
| 7489 endIndex) { | |
| 7490 startIndex += AngularMoustacheXmlExpression.OPENING_DELIMITER_LENGTH; | |
| 7491 AngularExpression expression = | |
| 7492 _parseAngularExpression(lexeme, startIndex, endIndex, offset); | |
| 7493 expressions.add( | |
| 7494 new AngularMoustacheXmlExpression(startIndex, endIndex, expression))
; | |
| 7495 } | |
| 7496 startIndex = StringUtilities.indexOf2( | |
| 7497 lexeme, | |
| 7498 endIndex + AngularMoustacheXmlExpression.CLOSING_DELIMITER_LENGTH, | |
| 7499 AngularMoustacheXmlExpression.OPENING_DELIMITER_CHAR, | |
| 7500 AngularMoustacheXmlExpression.OPENING_DELIMITER_CHAR); | |
| 7501 } | |
| 7502 } | |
| 7503 | |
| 7504 void _parseEmbeddedExpressionsInAttribute(ht.XmlAttributeNode node) { | |
| 7505 List<AngularMoustacheXmlExpression> expressions = | |
| 7506 <AngularMoustacheXmlExpression>[ | |
| 7507 ]; | |
| 7508 _parseEmbeddedExpressions(expressions, node.valueToken); | |
| 7509 if (!expressions.isEmpty) { | |
| 7510 node.expressions = expressions; | |
| 7511 } | |
| 7512 } | |
| 7513 | |
| 7514 void _parseEmbeddedExpressionsInTag(ht.XmlTagNode node) { | |
| 7515 List<AngularMoustacheXmlExpression> expressions = | |
| 7516 <AngularMoustacheXmlExpression>[ | |
| 7517 ]; | |
| 7518 ht.Token token = node.attributeEnd; | |
| 7519 ht.Token endToken = node.endToken; | |
| 7520 bool inChild = false; | |
| 7521 while (!identical(token, endToken)) { | |
| 7522 for (ht.XmlTagNode child in node.tagNodes) { | |
| 7523 if (identical(token, child.beginToken)) { | |
| 7524 inChild = true; | |
| 7525 break; | |
| 7526 } | |
| 7527 if (identical(token, child.endToken)) { | |
| 7528 inChild = false; | |
| 7529 break; | |
| 7530 } | |
| 7531 } | |
| 7532 if (!inChild && token.type == ht.TokenType.TEXT) { | |
| 7533 _parseEmbeddedExpressions(expressions, token); | |
| 7534 } | |
| 7535 token = token.next; | |
| 7536 } | |
| 7537 node.expressions = expressions; | |
| 7538 } | |
| 7539 | |
| 7540 void _popNameScope() { | |
| 7541 _nameScope = _resolver.popNameScope(); | |
| 7542 } | |
| 7543 | |
| 7544 void _pushNameScope() { | |
| 7545 _nameScope = _resolver.pushNameScope(); | |
| 7546 } | |
| 7547 | |
| 7548 void _recordDefinedVariable(LocalVariableElementImpl variable) { | |
| 7549 _definedVariables.add(variable); | |
| 7550 _functionElement.localVariables = new List.from(_definedVariables); | |
| 7551 } | |
| 7552 | |
| 7553 /** | |
| 7554 * When we inject variable, we give access to the library of its type. | |
| 7555 */ | |
| 7556 void _recordTypeLibraryInjected(LocalVariableElementImpl variable) { | |
| 7557 LibraryElement typeLibrary = variable.type.element.library; | |
| 7558 _injectedLibraries.add(typeLibrary); | |
| 7559 } | |
| 7560 | |
| 7561 /** | |
| 7562 * Reports given [ErrorCode] at the given [AstNode]. | |
| 7563 */ | |
| 7564 void _reportErrorForNode(ErrorCode errorCode, AstNode node, | |
| 7565 [List<Object> arguments]) { | |
| 7566 _reportErrorForOffset(errorCode, node.offset, node.length, arguments); | |
| 7567 } | |
| 7568 | |
| 7569 /** | |
| 7570 * Reports given [ErrorCode] at the given position. | |
| 7571 */ | |
| 7572 void _reportErrorForOffset(ErrorCode errorCode, int offset, int length, | |
| 7573 [List<Object> arguments]) { | |
| 7574 _errorListener.onError( | |
| 7575 new AnalysisError.con2(_source, offset, length, errorCode, arguments)); | |
| 7576 } | |
| 7577 | |
| 7578 /** | |
| 7579 * Reports given [ErrorCode] at the given [Token]. | |
| 7580 */ | |
| 7581 void _reportErrorForToken(ErrorCode errorCode, Token token, | |
| 7582 [List<Object> arguments]) { | |
| 7583 _reportErrorForOffset(errorCode, token.offset, token.length, arguments); | |
| 7584 } | |
| 7585 | |
| 7586 void _resolveExpression(AngularExpression angularExpression) { | |
| 7587 List<Expression> dartExpressions = angularExpression.expressions; | |
| 7588 for (Expression dartExpression in dartExpressions) { | |
| 7589 _resolveNode(dartExpression); | |
| 7590 } | |
| 7591 } | |
| 7592 | |
| 7593 void _resolveExpressions(List<ht.XmlExpression> expressions) { | |
| 7594 for (ht.XmlExpression xmlExpression in expressions) { | |
| 7595 if (xmlExpression is AngularXmlExpression) { | |
| 7596 AngularXmlExpression angularXmlExpression = xmlExpression; | |
| 7597 _resolveXmlExpression(angularXmlExpression); | |
| 7598 } | |
| 7599 } | |
| 7600 } | |
| 7601 | |
| 7602 /** | |
| 7603 * Resolves Angular specific expressions and elements in the [source]. | |
| 7604 * | |
| 7605 * @param angularElements the [AngularElement]s accessible in the component's
library, not | |
| 7606 * `null` | |
| 7607 * @param component the [AngularComponentElement] to resolve template for, may
be | |
| 7608 * `null` if not a component template | |
| 7609 */ | |
| 7610 void _resolveInternal(List<AngularElement> angularElements, | |
| 7611 AngularComponentElement component) { | |
| 7612 // this._angularElements = angularElements; | |
| 7613 // add built-in processors | |
| 7614 _processors.add(NgModelProcessor.INSTANCE); | |
| 7615 // _processors.add(NgRepeatProcessor.INSTANCE); | |
| 7616 // add element's libraries | |
| 7617 for (AngularElement angularElement in angularElements) { | |
| 7618 _injectedLibraries.add(angularElement.library); | |
| 7619 } | |
| 7620 // prepare Dart library | |
| 7621 _createLibraryElement(); | |
| 7622 (_unit.element as HtmlElementImpl).angularCompilationUnit = _unitElement; | |
| 7623 // prepare Dart resolver | |
| 7624 _createResolver(); | |
| 7625 // maybe resolving component template | |
| 7626 if (component != null) { | |
| 7627 _defineTopVariable_forClassElement(component); | |
| 7628 for (AngularScopePropertyElement scopeProperty in | |
| 7629 component.scopeProperties) { | |
| 7630 _defineTopVariable_forScopeProperty(scopeProperty); | |
| 7631 } | |
| 7632 } | |
| 7633 // add processors | |
| 7634 for (AngularElement angularElement in angularElements) { | |
| 7635 NgProcessor processor = _createProcessor(angularElement); | |
| 7636 if (processor != null) { | |
| 7637 _processors.add(processor); | |
| 7638 } | |
| 7639 } | |
| 7640 // define formatters | |
| 7641 for (AngularElement angularElement in angularElements) { | |
| 7642 if (angularElement is AngularFormatterElement) { | |
| 7643 _defineTopVariable_forClassElement(angularElement); | |
| 7644 } | |
| 7645 } | |
| 7646 // run this HTML visitor | |
| 7647 _unit.accept(this); | |
| 7648 // simulate imports for injects | |
| 7649 { | |
| 7650 List<ImportElement> imports = <ImportElement>[]; | |
| 7651 for (LibraryElement injectedLibrary in _injectedLibraries) { | |
| 7652 ImportElementImpl importElement = new ImportElementImpl(-1); | |
| 7653 importElement.importedLibrary = injectedLibrary; | |
| 7654 imports.add(importElement); | |
| 7655 } | |
| 7656 _libraryElement.imports = imports; | |
| 7657 } | |
| 7658 } | |
| 7659 | |
| 7660 /** | |
| 7661 * Resolves given [AstNode] using [resolver]. | |
| 7662 */ | |
| 7663 void _resolveNode(AstNode node) { | |
| 7664 node.accept(_resolver); | |
| 7665 } | |
| 7666 | |
| 7667 void _resolveXmlExpression(AngularXmlExpression angularXmlExpression) { | |
| 7668 AngularExpression angularExpression = angularXmlExpression.expression; | |
| 7669 _resolveExpression(angularExpression); | |
| 7670 } | |
| 7671 | |
| 7672 Token _scanDart(String contents, int startIndex, int endIndex, int offset) => | |
| 7673 ht.HtmlParser.scanDartSource( | |
| 7674 _source, | |
| 7675 _lineInfo, | |
| 7676 contents.substring(startIndex, endIndex), | |
| 7677 offset + startIndex, | |
| 7678 _errorListener); | |
| 7679 | |
| 7680 List<Token> _splitAtBar(Token token) { | |
| 7681 List<Token> tokens = <Token>[]; | |
| 7682 tokens.add(token); | |
| 7683 while (token.type != TokenType.EOF) { | |
| 7684 if (token.type == TokenType.BAR) { | |
| 7685 tokens.add(token); | |
| 7686 Token eofToken = new Token(TokenType.EOF, 0); | |
| 7687 token.previous.setNext(eofToken); | |
| 7688 } | |
| 7689 token = token.next; | |
| 7690 } | |
| 7691 return tokens; | |
| 7692 } | |
| 7693 | |
| 7694 /** | |
| 7695 * The "ng-model" directive is special, it contributes to the top-level name s
cope. These models | |
| 7696 * can be used before actual "ng-model" attribute in HTML. So, we need to defi
ne them once we | |
| 7697 * found [NG_APP] context. | |
| 7698 */ | |
| 7699 void _visitModelDirectives(ht.XmlTagNode appNode) { | |
| 7700 appNode.accept(new _AngularHtmlUnitResolver_visitModelDirectives(this)); | |
| 7701 } | |
| 7702 | |
| 7703 /** | |
| 7704 * Checks if given [Element] is an artificial local variable and returns corre
sponding | |
| 7705 * [AngularElement], or `null` otherwise. | |
| 7706 */ | |
| 7707 static AngularElement getAngularElement(Element element) { | |
| 7708 // may be artificial local variable, replace with AngularElement | |
| 7709 if (element is LocalVariableElement) { | |
| 7710 LocalVariableElement local = element; | |
| 7711 List<ToolkitObjectElement> toolkitObjects = local.toolkitObjects; | |
| 7712 if (toolkitObjects.length == 1 && toolkitObjects[0] is AngularElement) { | |
| 7713 return toolkitObjects[0] as AngularElement; | |
| 7714 } | |
| 7715 } | |
| 7716 // not a special Element | |
| 7717 return null; | |
| 7718 } | |
| 7719 | |
| 7720 /** | |
| 7721 * @return `true` if the given [HtmlUnit] has <code>ng-app</code> annotation. | |
| 7722 */ | |
| 7723 static bool hasAngularAnnotation(ht.HtmlUnit htmlUnit) { | |
| 7724 try { | |
| 7725 htmlUnit.accept( | |
| 7726 new RecursiveXmlVisitor_AngularHtmlUnitResolver_hasAngularAnnotation()
); | |
| 7727 } on AngularHtmlUnitResolver_FoundAppError catch (e) { | |
| 7728 return true; | |
| 7729 } | |
| 7730 return false; | |
| 7731 } | |
| 7732 | |
| 7733 /** | |
| 7734 * Adds [AngularElement] declared by the given top-level [Element]. | |
| 7735 * | |
| 7736 * @param angularElements the list to fill with top-level [AngularElement]s | |
| 7737 * @param classElement the [ClassElement] to get [AngularElement]s from | |
| 7738 */ | |
| 7739 static void _addAngularElementsFromClass(Set<AngularElement> angularElements, | |
| 7740 ClassElement classElement) { | |
| 7741 for (ToolkitObjectElement toolkitObject in classElement.toolkitObjects) { | |
| 7742 if (toolkitObject is AngularElement) { | |
| 7743 angularElements.add(toolkitObject); | |
| 7744 } | |
| 7745 } | |
| 7746 } | |
| 7747 | |
| 7748 /** | |
| 7749 * Returns the array of all top-level Angular elements that could be used in t
his library. | |
| 7750 * | |
| 7751 * @param libraryElement the [LibraryElement] to analyze | |
| 7752 * @return the array of all top-level Angular elements that could be used in t
his library | |
| 7753 */ | |
| 7754 static void | |
| 7755 _addAngularElementsFromLibrary(Set<AngularElement> angularElements, | |
| 7756 LibraryElement library, Set<LibraryElement> visited) { | |
| 7757 if (library == null) { | |
| 7758 return; | |
| 7759 } | |
| 7760 if (!visited.add(library)) { | |
| 7761 return; | |
| 7762 } | |
| 7763 // add Angular elements from current library | |
| 7764 for (CompilationUnitElement unit in library.units) { | |
| 7765 angularElements.addAll(unit.angularViews); | |
| 7766 for (ClassElement type in unit.types) { | |
| 7767 _addAngularElementsFromClass(angularElements, type); | |
| 7768 } | |
| 7769 } | |
| 7770 // handle imports | |
| 7771 for (ImportElement importElement in library.imports) { | |
| 7772 LibraryElement importedLibrary = importElement.importedLibrary; | |
| 7773 _addAngularElementsFromLibrary(angularElements, importedLibrary, visited); | |
| 7774 } | |
| 7775 } | |
| 7776 | |
| 7777 static SimpleIdentifier _createIdentifier(String name, int offset) { | |
| 7778 StringToken token = _createStringToken(name, offset); | |
| 7779 return new SimpleIdentifier(token); | |
| 7780 } | |
| 7781 | |
| 7782 static StringToken _createStringToken(String name, int offset) => | |
| 7783 new StringToken(TokenType.IDENTIFIER, name, offset); | |
| 7784 | |
| 7785 /** | |
| 7786 * Returns the array of all top-level Angular elements that could be used in t
his library. | |
| 7787 * | |
| 7788 * @param libraryElement the [LibraryElement] to analyze | |
| 7789 * @return the array of all top-level Angular elements that could be used in t
his library | |
| 7790 */ | |
| 7791 static List<AngularElement> _getAngularElements(Set<LibraryElement> libraries, | |
| 7792 LibraryElement libraryElement) { | |
| 7793 Set<AngularElement> angularElements = new Set(); | |
| 7794 _addAngularElementsFromLibrary(angularElements, libraryElement, libraries); | |
| 7795 return new List.from(angularElements); | |
| 7796 } | |
| 7797 | |
| 7798 /** | |
| 7799 * Returns the external Dart [CompilationUnit] referenced by the given [HtmlUn
it]. | |
| 7800 */ | |
| 7801 static CompilationUnit _getDartUnit(AnalysisContext context, | |
| 7802 ht.HtmlUnit unit) { | |
| 7803 for (HtmlScriptElement script in unit.element.scripts) { | |
| 7804 if (script is ExternalHtmlScriptElement) { | |
| 7805 Source scriptSource = script.scriptSource; | |
| 7806 if (scriptSource != null) { | |
| 7807 return context.resolveCompilationUnit2(scriptSource, scriptSource); | |
| 7808 } | |
| 7809 } | |
| 7810 } | |
| 7811 return null; | |
| 7812 } | |
| 7813 | |
| 7814 static Set<Source> _getLibrarySources(Set<LibraryElement> libraries) { | |
| 7815 Set<Source> sources = new Set(); | |
| 7816 for (LibraryElement library in libraries) { | |
| 7817 sources.add(library.source); | |
| 7818 } | |
| 7819 return sources; | |
| 7820 } | |
| 7821 } | |
| 7822 | |
| 7823 class AngularHtmlUnitResolver_FilteringAnalysisErrorListener implements | |
| 7824 AnalysisErrorListener { | |
| 7825 final AnalysisErrorListener _listener; | |
| 7826 | |
| 7827 AngularHtmlUnitResolver_FilteringAnalysisErrorListener(this._listener); | |
| 7828 | |
| 7829 @override | |
| 7830 void onError(AnalysisError error) { | |
| 7831 ErrorCode errorCode = error.errorCode; | |
| 7832 if (identical(errorCode, StaticWarningCode.UNDEFINED_GETTER) || | |
| 7833 identical(errorCode, StaticWarningCode.UNDEFINED_IDENTIFIER) || | |
| 7834 identical(errorCode, StaticTypeWarningCode.UNDEFINED_GETTER)) { | |
| 7835 return; | |
| 7836 } | |
| 7837 _listener.onError(error); | |
| 7838 } | |
| 7839 } | |
| 7840 | |
| 7841 class AngularHtmlUnitResolver_FoundAppError extends Error { | |
| 7842 } | |
| 7843 | |
| 7844 /** | |
| 7845 * Implementation of [AngularXmlExpression] for an [AngularExpression] enclosed
between | |
| 7846 * <code>{{</code> and <code>}}</code>. | |
| 7847 */ | |
| 7848 class AngularMoustacheXmlExpression extends AngularXmlExpression { | |
| 7849 static int OPENING_DELIMITER_CHAR = 0x7B; | |
| 7850 | |
| 7851 static int CLOSING_DELIMITER_CHAR = 0x7D; | |
| 7852 | |
| 7853 static String OPENING_DELIMITER = "{{"; | |
| 7854 | |
| 7855 static String CLOSING_DELIMITER = "}}"; | |
| 7856 | |
| 7857 static int OPENING_DELIMITER_LENGTH = OPENING_DELIMITER.length; | |
| 7858 | |
| 7859 static int CLOSING_DELIMITER_LENGTH = CLOSING_DELIMITER.length; | |
| 7860 | |
| 7861 /** | |
| 7862 * The offset of the first character of the opening delimiter. | |
| 7863 */ | |
| 7864 final int _openingOffset; | |
| 7865 | |
| 7866 /** | |
| 7867 * The offset of the first character of the closing delimiter. | |
| 7868 */ | |
| 7869 final int _closingOffset; | |
| 7870 | |
| 7871 AngularMoustacheXmlExpression(this._openingOffset, this._closingOffset, | |
| 7872 AngularExpression expression) | |
| 7873 : super(expression); | |
| 7874 | |
| 7875 @override | |
| 7876 int get end => _closingOffset + CLOSING_DELIMITER_LENGTH; | |
| 7877 | |
| 7878 @override | |
| 7879 int get length => _closingOffset + CLOSING_DELIMITER_LENGTH - _openingOffset; | |
| 7880 | |
| 7881 @override | |
| 7882 int get offset => _openingOffset; | |
| 7883 } | |
| 7884 | |
| 7885 /** | |
| 7886 * Implementation of [AngularXmlExpression] for an [AngularExpression] embedded
without | |
| 7887 * any wrapping characters. | |
| 7888 */ | |
| 7889 class AngularRawXmlExpression extends AngularXmlExpression { | |
| 7890 AngularRawXmlExpression(AngularExpression expression) : super(expression); | |
| 7891 | |
| 7892 @override | |
| 7893 int get end => expression.end; | |
| 7894 | |
| 7895 @override | |
| 7896 int get length => expression.length; | |
| 7897 | |
| 7898 @override | |
| 7899 int get offset => expression.offset; | |
| 7900 } | |
| 7901 | |
| 7902 /** | |
| 7903 * Abstract Angular specific [XmlExpression]. | |
| 7904 */ | |
| 7905 abstract class AngularXmlExpression extends ht.XmlExpression { | |
| 7906 /** | |
| 7907 * The expression that is enclosed between the delimiters. | |
| 7908 */ | |
| 7909 final AngularExpression expression; | |
| 7910 | |
| 7911 AngularXmlExpression(this.expression); | |
| 7912 | |
| 7913 @override | |
| 7914 ht.XmlExpression_Reference getReference(int offset) { | |
| 7915 // main expression | |
| 7916 ht.XmlExpression_Reference reference = | |
| 7917 _getReferenceAtNode(expression.expression, offset); | |
| 7918 if (reference != null) { | |
| 7919 return reference; | |
| 7920 } | |
| 7921 // formatters | |
| 7922 for (AngularFormatterNode formatter in expression.formatters) { | |
| 7923 // formatter name | |
| 7924 reference = _getReferenceAtNode(formatter.name, offset); | |
| 7925 if (reference != null) { | |
| 7926 return reference; | |
| 7927 } | |
| 7928 // formatter arguments | |
| 7929 for (AngularFormatterArgument formatterArgument in formatter.arguments) { | |
| 7930 reference = _getReferenceAtNode(formatterArgument.expression, offset); | |
| 7931 if (reference != null) { | |
| 7932 return reference; | |
| 7933 } | |
| 7934 } | |
| 7935 } | |
| 7936 return null; | |
| 7937 } | |
| 7938 | |
| 7939 /** | |
| 7940 * If the given [AstNode] has an [Element] at the given offset, then returns | |
| 7941 * [Reference] with this [Element]. | |
| 7942 */ | |
| 7943 ht.XmlExpression_Reference _getReferenceAtNode(AstNode root, int offset) { | |
| 7944 AstNode node = new NodeLocator.con1(offset).searchWithin(root); | |
| 7945 if (node != null) { | |
| 7946 Element element = ElementLocator.locate(node); | |
| 7947 return new ht.XmlExpression_Reference(element, node.offset, node.length); | |
| 7948 } | |
| 7949 return null; | |
| 7950 } | |
| 7951 } | |
| 7952 | |
| 7953 /** | |
| 7954 * A `CachedResult` is a single analysis result that is stored in a | 6630 * A `CachedResult` is a single analysis result that is stored in a |
| 7955 * [SourceEntry]. | 6631 * [SourceEntry]. |
| 7956 */ | 6632 */ |
| 7957 class CachedResult<E> { | 6633 class CachedResult<E> { |
| 7958 /** | 6634 /** |
| 7959 * The state of the cached value. | 6635 * The state of the cached value. |
| 7960 */ | 6636 */ |
| 7961 CacheState state; | 6637 CacheState state; |
| 7962 | 6638 |
| 7963 /** | 6639 /** |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8729 this.entry = entry; | 7405 this.entry = entry; |
| 8730 } | 7406 } |
| 8731 } | 7407 } |
| 8732 | 7408 |
| 8733 /** | 7409 /** |
| 8734 * A `DartEntry` maintains the information cached by an analysis context about | 7410 * A `DartEntry` maintains the information cached by an analysis context about |
| 8735 * an individual Dart file. | 7411 * an individual Dart file. |
| 8736 */ | 7412 */ |
| 8737 class DartEntry extends SourceEntry { | 7413 class DartEntry extends SourceEntry { |
| 8738 /** | 7414 /** |
| 8739 * The data descriptor representing the errors reported during Angular | |
| 8740 * resolution. | |
| 8741 */ | |
| 8742 static final DataDescriptor<List<AnalysisError>> ANGULAR_ERRORS = | |
| 8743 new DataDescriptor<List<AnalysisError>>( | |
| 8744 "DartEntry.ANGULAR_ERRORS", | |
| 8745 AnalysisError.NO_ERRORS); | |
| 8746 | |
| 8747 /** | |
| 8748 * The data descriptor representing the element model representing a single | 7415 * The data descriptor representing the element model representing a single |
| 8749 * compilation unit. This model is incomplete and should not be used except as | 7416 * compilation unit. This model is incomplete and should not be used except as |
| 8750 * input to another task. | 7417 * input to another task. |
| 8751 */ | 7418 */ |
| 8752 static final DataDescriptor<List<AnalysisError>> BUILT_ELEMENT = | 7419 static final DataDescriptor<List<AnalysisError>> BUILT_ELEMENT = |
| 8753 new DataDescriptor<List<AnalysisError>>("DartEntry.BUILT_ELEMENT"); | 7420 new DataDescriptor<List<AnalysisError>>("DartEntry.BUILT_ELEMENT"); |
| 8754 | 7421 |
| 8755 /** | 7422 /** |
| 8756 * The data descriptor representing the AST structure after the element model | 7423 * The data descriptor representing the AST structure after the element model |
| 8757 * has been built (and declarations are resolved) but before other resolution | 7424 * has been built (and declarations are resolved) but before other resolution |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8920 List<AnalysisError> errors = new List<AnalysisError>(); | 7587 List<AnalysisError> errors = new List<AnalysisError>(); |
| 8921 errors.addAll(getValue(SCAN_ERRORS)); | 7588 errors.addAll(getValue(SCAN_ERRORS)); |
| 8922 errors.addAll(getValue(PARSE_ERRORS)); | 7589 errors.addAll(getValue(PARSE_ERRORS)); |
| 8923 ResolutionState state = _resolutionState; | 7590 ResolutionState state = _resolutionState; |
| 8924 while (state != null) { | 7591 while (state != null) { |
| 8925 errors.addAll(state.getValue(RESOLUTION_ERRORS)); | 7592 errors.addAll(state.getValue(RESOLUTION_ERRORS)); |
| 8926 errors.addAll(state.getValue(VERIFICATION_ERRORS)); | 7593 errors.addAll(state.getValue(VERIFICATION_ERRORS)); |
| 8927 errors.addAll(state.getValue(HINTS)); | 7594 errors.addAll(state.getValue(HINTS)); |
| 8928 state = state._nextState; | 7595 state = state._nextState; |
| 8929 } | 7596 } |
| 8930 errors.addAll(getValue(ANGULAR_ERRORS)); | |
| 8931 if (errors.length == 0) { | 7597 if (errors.length == 0) { |
| 8932 return AnalysisError.NO_ERRORS; | 7598 return AnalysisError.NO_ERRORS; |
| 8933 } | 7599 } |
| 8934 return errors; | 7600 return errors; |
| 8935 } | 7601 } |
| 8936 | 7602 |
| 8937 /** | 7603 /** |
| 8938 * Return a valid parsed compilation unit, either an unresolved AST structure | 7604 * Return a valid parsed compilation unit, either an unresolved AST structure |
| 8939 * or the result of resolving the AST structure in the context of some library
, | 7605 * or the result of resolving the AST structure in the context of some library
, |
| 8940 * or `null` if there is no parsed compilation unit available. | 7606 * or `null` if there is no parsed compilation unit available. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9067 } | 7733 } |
| 9068 return result; | 7734 return result; |
| 9069 } | 7735 } |
| 9070 | 7736 |
| 9071 /** | 7737 /** |
| 9072 * Get a list of all the library-dependent descriptors for which values may | 7738 * Get a list of all the library-dependent descriptors for which values may |
| 9073 * be stored in this SourceEntry. | 7739 * be stored in this SourceEntry. |
| 9074 */ | 7740 */ |
| 9075 List<DataDescriptor> get libraryDescriptors { | 7741 List<DataDescriptor> get libraryDescriptors { |
| 9076 return <DataDescriptor>[ | 7742 return <DataDescriptor>[ |
| 9077 DartEntry.ANGULAR_ERRORS, | |
| 9078 DartEntry.BUILT_ELEMENT, | 7743 DartEntry.BUILT_ELEMENT, |
| 9079 DartEntry.BUILT_UNIT, | 7744 DartEntry.BUILT_UNIT, |
| 9080 DartEntry.RESOLUTION_ERRORS, | 7745 DartEntry.RESOLUTION_ERRORS, |
| 9081 DartEntry.RESOLVED_UNIT, | 7746 DartEntry.RESOLVED_UNIT, |
| 9082 DartEntry.VERIFICATION_ERRORS, | 7747 DartEntry.VERIFICATION_ERRORS, |
| 9083 DartEntry.HINTS]; | 7748 DartEntry.HINTS]; |
| 9084 } | 7749 } |
| 9085 | 7750 |
| 9086 /** | 7751 /** |
| 9087 * A compilation unit that has not been accessed by any other client and can | 7752 * A compilation unit that has not been accessed by any other client and can |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9445 state._nextState = newState; | 8110 state._nextState = newState; |
| 9446 return newState; | 8111 return newState; |
| 9447 } | 8112 } |
| 9448 state = state._nextState; | 8113 state = state._nextState; |
| 9449 } | 8114 } |
| 9450 return state; | 8115 return state; |
| 9451 } | 8116 } |
| 9452 | 8117 |
| 9453 @override | 8118 @override |
| 9454 bool _isValidDescriptor(DataDescriptor descriptor) { | 8119 bool _isValidDescriptor(DataDescriptor descriptor) { |
| 9455 return descriptor == ANGULAR_ERRORS || | 8120 return descriptor == CONTAINING_LIBRARIES || |
| 9456 descriptor == CONTAINING_LIBRARIES || | |
| 9457 descriptor == ELEMENT || | 8121 descriptor == ELEMENT || |
| 9458 descriptor == EXPORTED_LIBRARIES || | 8122 descriptor == EXPORTED_LIBRARIES || |
| 9459 descriptor == IMPORTED_LIBRARIES || | 8123 descriptor == IMPORTED_LIBRARIES || |
| 9460 descriptor == INCLUDED_PARTS || | 8124 descriptor == INCLUDED_PARTS || |
| 9461 descriptor == IS_CLIENT || | 8125 descriptor == IS_CLIENT || |
| 9462 descriptor == IS_LAUNCHABLE || | 8126 descriptor == IS_LAUNCHABLE || |
| 9463 descriptor == PARSED_UNIT || | 8127 descriptor == PARSED_UNIT || |
| 9464 descriptor == PARSE_ERRORS || | 8128 descriptor == PARSE_ERRORS || |
| 9465 descriptor == PUBLIC_NAMESPACE || | 8129 descriptor == PUBLIC_NAMESPACE || |
| 9466 descriptor == SCAN_ERRORS || | 8130 descriptor == SCAN_ERRORS || |
| 9467 descriptor == SOURCE_KIND || | 8131 descriptor == SOURCE_KIND || |
| 9468 descriptor == TOKEN_STREAM || | 8132 descriptor == TOKEN_STREAM || |
| 9469 super._isValidDescriptor(descriptor); | 8133 super._isValidDescriptor(descriptor); |
| 9470 } | 8134 } |
| 9471 | 8135 |
| 9472 /** | 8136 /** |
| 9473 * Return `true` if the [descriptor] is valid for this entry when the data is | 8137 * Return `true` if the [descriptor] is valid for this entry when the data is |
| 9474 * relative to a library. | 8138 * relative to a library. |
| 9475 */ | 8139 */ |
| 9476 bool _isValidLibraryDescriptor(DataDescriptor descriptor) { | 8140 bool _isValidLibraryDescriptor(DataDescriptor descriptor) { |
| 9477 return descriptor == ANGULAR_ERRORS || | 8141 return descriptor == BUILT_ELEMENT || |
| 9478 descriptor == BUILT_ELEMENT || | |
| 9479 descriptor == BUILT_UNIT || | 8142 descriptor == BUILT_UNIT || |
| 9480 descriptor == HINTS || | 8143 descriptor == HINTS || |
| 9481 descriptor == RESOLUTION_ERRORS || | 8144 descriptor == RESOLUTION_ERRORS || |
| 9482 descriptor == RESOLVED_UNIT || | 8145 descriptor == RESOLVED_UNIT || |
| 9483 descriptor == VERIFICATION_ERRORS; | 8146 descriptor == VERIFICATION_ERRORS; |
| 9484 } | 8147 } |
| 9485 | 8148 |
| 9486 @override | 8149 @override |
| 9487 bool _writeDiffOn(StringBuffer buffer, SourceEntry oldEntry) { | 8150 bool _writeDiffOn(StringBuffer buffer, SourceEntry oldEntry) { |
| 9488 bool needsSeparator = super._writeDiffOn(buffer, oldEntry); | 8151 bool needsSeparator = super._writeDiffOn(buffer, oldEntry); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9632 _writeStateOn(buffer, "sourceKind", SOURCE_KIND); | 8295 _writeStateOn(buffer, "sourceKind", SOURCE_KIND); |
| 9633 _writeStateOn(buffer, "parsedUnit", PARSED_UNIT); | 8296 _writeStateOn(buffer, "parsedUnit", PARSED_UNIT); |
| 9634 _writeStateOn(buffer, "parseErrors", PARSE_ERRORS); | 8297 _writeStateOn(buffer, "parseErrors", PARSE_ERRORS); |
| 9635 _writeStateOn(buffer, "exportedLibraries", EXPORTED_LIBRARIES); | 8298 _writeStateOn(buffer, "exportedLibraries", EXPORTED_LIBRARIES); |
| 9636 _writeStateOn(buffer, "importedLibraries", IMPORTED_LIBRARIES); | 8299 _writeStateOn(buffer, "importedLibraries", IMPORTED_LIBRARIES); |
| 9637 _writeStateOn(buffer, "includedParts", INCLUDED_PARTS); | 8300 _writeStateOn(buffer, "includedParts", INCLUDED_PARTS); |
| 9638 _writeStateOn(buffer, "element", ELEMENT); | 8301 _writeStateOn(buffer, "element", ELEMENT); |
| 9639 _writeStateOn(buffer, "publicNamespace", PUBLIC_NAMESPACE); | 8302 _writeStateOn(buffer, "publicNamespace", PUBLIC_NAMESPACE); |
| 9640 _writeStateOn(buffer, "clientServer", IS_CLIENT); | 8303 _writeStateOn(buffer, "clientServer", IS_CLIENT); |
| 9641 _writeStateOn(buffer, "launchable", IS_LAUNCHABLE); | 8304 _writeStateOn(buffer, "launchable", IS_LAUNCHABLE); |
| 9642 _writeStateOn(buffer, "angularErrors", ANGULAR_ERRORS); | |
| 9643 _resolutionState._writeOn(buffer); | 8305 _resolutionState._writeOn(buffer); |
| 9644 } | 8306 } |
| 9645 } | 8307 } |
| 9646 | 8308 |
| 9647 /** | 8309 /** |
| 9648 * Instances of the class `DataDescriptor` are immutable constants representing
data that can | 8310 * Instances of the class `DataDescriptor` are immutable constants representing
data that can |
| 9649 * be stored in the cache. | 8311 * be stored in the cache. |
| 9650 */ | 8312 */ |
| 9651 class DataDescriptor<E> { | 8313 class DataDescriptor<E> { |
| 9652 /** | 8314 /** |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9697 if (sourceEntry is DartEntry) { | 8359 if (sourceEntry is DartEntry) { |
| 9698 DartEntry dartEntry = sourceEntry; | 8360 DartEntry dartEntry = sourceEntry; |
| 9699 if (astIsNeeded(dartEntry)) { | 8361 if (astIsNeeded(dartEntry)) { |
| 9700 return RetentionPriority.MEDIUM; | 8362 return RetentionPriority.MEDIUM; |
| 9701 } | 8363 } |
| 9702 } | 8364 } |
| 9703 return RetentionPriority.LOW; | 8365 return RetentionPriority.LOW; |
| 9704 } | 8366 } |
| 9705 } | 8367 } |
| 9706 | 8368 |
| 9707 | |
| 9708 /** | |
| 9709 * Recursively visits [HtmlUnit] and every embedded [Expression]. | |
| 9710 */ | |
| 9711 abstract class ExpressionVisitor extends ht.RecursiveXmlVisitor<Object> { | |
| 9712 /** | |
| 9713 * Visits the given [Expression]s embedded into tag or attribute. | |
| 9714 * | |
| 9715 * @param expression the [Expression] to visit, not `null` | |
| 9716 */ | |
| 9717 void visitExpression(Expression expression); | |
| 9718 | |
| 9719 @override | |
| 9720 Object visitXmlAttributeNode(ht.XmlAttributeNode node) { | |
| 9721 _visitExpressions(node.expressions); | |
| 9722 return super.visitXmlAttributeNode(node); | |
| 9723 } | |
| 9724 | |
| 9725 @override | |
| 9726 Object visitXmlTagNode(ht.XmlTagNode node) { | |
| 9727 _visitExpressions(node.expressions); | |
| 9728 return super.visitXmlTagNode(node); | |
| 9729 } | |
| 9730 | |
| 9731 /** | |
| 9732 * Visits [Expression]s of the given [XmlExpression]s. | |
| 9733 */ | |
| 9734 void _visitExpressions(List<ht.XmlExpression> expressions) { | |
| 9735 for (ht.XmlExpression xmlExpression in expressions) { | |
| 9736 if (xmlExpression is AngularXmlExpression) { | |
| 9737 AngularXmlExpression angularXmlExpression = xmlExpression; | |
| 9738 List<Expression> dartExpressions = | |
| 9739 angularXmlExpression.expression.expressions; | |
| 9740 for (Expression dartExpression in dartExpressions) { | |
| 9741 visitExpression(dartExpression); | |
| 9742 } | |
| 9743 } | |
| 9744 if (xmlExpression is ht.RawXmlExpression) { | |
| 9745 ht.RawXmlExpression rawXmlExpression = xmlExpression; | |
| 9746 visitExpression(rawXmlExpression.expression); | |
| 9747 } | |
| 9748 } | |
| 9749 } | |
| 9750 } | |
| 9751 | |
| 9752 /** | 8369 /** |
| 9753 * Instances of the class `GenerateDartErrorsTask` generate errors and warnings
for a single | 8370 * Instances of the class `GenerateDartErrorsTask` generate errors and warnings
for a single |
| 9754 * Dart source. | 8371 * Dart source. |
| 9755 */ | 8372 */ |
| 9756 class GenerateDartErrorsTask extends AnalysisTask { | 8373 class GenerateDartErrorsTask extends AnalysisTask { |
| 9757 /** | 8374 /** |
| 9758 * The source for which errors and warnings are to be produced. | 8375 * The source for which errors and warnings are to be produced. |
| 9759 */ | 8376 */ |
| 9760 final Source source; | 8377 final Source source; |
| 9761 | 8378 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10065 } | 8682 } |
| 10066 } | 8683 } |
| 10067 } | 8684 } |
| 10068 | 8685 |
| 10069 /** | 8686 /** |
| 10070 * An `HtmlEntry` maintains the information cached by an analysis context about | 8687 * An `HtmlEntry` maintains the information cached by an analysis context about |
| 10071 * an individual HTML file. | 8688 * an individual HTML file. |
| 10072 */ | 8689 */ |
| 10073 class HtmlEntry extends SourceEntry { | 8690 class HtmlEntry extends SourceEntry { |
| 10074 /** | 8691 /** |
| 10075 * The data descriptor representing the information about an Angular | |
| 10076 * application this source is used in. | |
| 10077 */ | |
| 10078 static final DataDescriptor<AngularApplication> ANGULAR_APPLICATION = | |
| 10079 new DataDescriptor<AngularApplication>("HtmlEntry.ANGULAR_APPLICATION"); | |
| 10080 | |
| 10081 /** | |
| 10082 * The data descriptor representing the information about an Angular component | |
| 10083 * this source is used as template for. | |
| 10084 */ | |
| 10085 static final DataDescriptor<AngularComponentElement> ANGULAR_COMPONENT = | |
| 10086 new DataDescriptor<AngularComponentElement>("HtmlEntry.ANGULAR_COMPONENT")
; | |
| 10087 | |
| 10088 /** | |
| 10089 * The data descriptor representing the information about an Angular | |
| 10090 * application for which this source is an entry point. | |
| 10091 */ | |
| 10092 static final DataDescriptor<AngularApplication> ANGULAR_ENTRY = | |
| 10093 new DataDescriptor<AngularApplication>("HtmlEntry.ANGULAR_ENTRY"); | |
| 10094 | |
| 10095 /** | |
| 10096 * The data descriptor representing the errors reported during Angular | |
| 10097 * resolution. | |
| 10098 */ | |
| 10099 static final DataDescriptor<List<AnalysisError>> ANGULAR_ERRORS = | |
| 10100 new DataDescriptor<List<AnalysisError>>( | |
| 10101 "HtmlEntry.ANGULAR_ERRORS", | |
| 10102 AnalysisError.NO_ERRORS); | |
| 10103 | |
| 10104 /** | |
| 10105 * The data descriptor representing the HTML element. | 8692 * The data descriptor representing the HTML element. |
| 10106 */ | 8693 */ |
| 10107 static final DataDescriptor<HtmlElement> ELEMENT = | 8694 static final DataDescriptor<HtmlElement> ELEMENT = |
| 10108 new DataDescriptor<HtmlElement>("HtmlEntry.ELEMENT"); | 8695 new DataDescriptor<HtmlElement>("HtmlEntry.ELEMENT"); |
| 10109 | 8696 |
| 10110 /** | 8697 /** |
| 10111 * The data descriptor representing the hints resulting from auditing the | 8698 * The data descriptor representing the hints resulting from auditing the |
| 10112 * source. | 8699 * source. |
| 10113 */ | 8700 */ |
| 10114 static final DataDescriptor<List<AnalysisError>> HINTS = | 8701 static final DataDescriptor<List<AnalysisError>> HINTS = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10173 AnalysisError.NO_ERRORS); | 8760 AnalysisError.NO_ERRORS); |
| 10174 | 8761 |
| 10175 /** | 8762 /** |
| 10176 * Return all of the errors associated with the HTML file that are currently | 8763 * Return all of the errors associated with the HTML file that are currently |
| 10177 * cached. | 8764 * cached. |
| 10178 */ | 8765 */ |
| 10179 List<AnalysisError> get allErrors { | 8766 List<AnalysisError> get allErrors { |
| 10180 List<AnalysisError> errors = new List<AnalysisError>(); | 8767 List<AnalysisError> errors = new List<AnalysisError>(); |
| 10181 errors.addAll(getValue(PARSE_ERRORS)); | 8768 errors.addAll(getValue(PARSE_ERRORS)); |
| 10182 errors.addAll(getValue(RESOLUTION_ERRORS)); | 8769 errors.addAll(getValue(RESOLUTION_ERRORS)); |
| 10183 errors.addAll(getValue(ANGULAR_ERRORS)); | |
| 10184 errors.addAll(getValue(HINTS)); | 8770 errors.addAll(getValue(HINTS)); |
| 10185 errors.addAll(getValue(POLYMER_BUILD_ERRORS)); | 8771 errors.addAll(getValue(POLYMER_BUILD_ERRORS)); |
| 10186 errors.addAll(getValue(POLYMER_RESOLUTION_ERRORS)); | 8772 errors.addAll(getValue(POLYMER_RESOLUTION_ERRORS)); |
| 10187 if (errors.length == 0) { | 8773 if (errors.length == 0) { |
| 10188 return AnalysisError.NO_ERRORS; | 8774 return AnalysisError.NO_ERRORS; |
| 10189 } | 8775 } |
| 10190 return errors; | 8776 return errors; |
| 10191 } | 8777 } |
| 10192 | 8778 |
| 10193 /** | 8779 /** |
| 10194 * Return a valid parsed unit, either an unresolved AST structure or the | 8780 * Return a valid parsed unit, either an unresolved AST structure or the |
| 10195 * result of resolving the AST structure, or `null` if there is no parsed unit | 8781 * result of resolving the AST structure, or `null` if there is no parsed unit |
| 10196 * available. | 8782 * available. |
| 10197 */ | 8783 */ |
| 10198 ht.HtmlUnit get anyParsedUnit { | 8784 ht.HtmlUnit get anyParsedUnit { |
| 10199 if (getState(PARSED_UNIT) == CacheState.VALID) { | 8785 if (getState(PARSED_UNIT) == CacheState.VALID) { |
| 10200 return getValue(PARSED_UNIT); | 8786 return getValue(PARSED_UNIT); |
| 10201 } | 8787 } |
| 10202 if (getState(RESOLVED_UNIT) == CacheState.VALID) { | 8788 if (getState(RESOLVED_UNIT) == CacheState.VALID) { |
| 10203 return getValue(RESOLVED_UNIT); | 8789 return getValue(RESOLVED_UNIT); |
| 10204 } | 8790 } |
| 10205 return null; | 8791 return null; |
| 10206 } | 8792 } |
| 10207 | 8793 |
| 10208 @override | 8794 @override |
| 10209 List<DataDescriptor> get descriptors { | 8795 List<DataDescriptor> get descriptors { |
| 10210 List<DataDescriptor> result = super.descriptors; | 8796 List<DataDescriptor> result = super.descriptors; |
| 10211 result.addAll( | 8797 result.addAll( |
| 10212 [ | 8798 [ |
| 10213 HtmlEntry.ANGULAR_APPLICATION, | |
| 10214 HtmlEntry.ANGULAR_COMPONENT, | |
| 10215 HtmlEntry.ANGULAR_ENTRY, | |
| 10216 HtmlEntry.ANGULAR_ERRORS, | |
| 10217 HtmlEntry.ELEMENT, | 8799 HtmlEntry.ELEMENT, |
| 10218 HtmlEntry.PARSE_ERRORS, | 8800 HtmlEntry.PARSE_ERRORS, |
| 10219 HtmlEntry.PARSED_UNIT, | 8801 HtmlEntry.PARSED_UNIT, |
| 10220 HtmlEntry.POLYMER_BUILD_ERRORS, | 8802 HtmlEntry.POLYMER_BUILD_ERRORS, |
| 10221 HtmlEntry.POLYMER_RESOLUTION_ERRORS, | 8803 HtmlEntry.POLYMER_RESOLUTION_ERRORS, |
| 10222 HtmlEntry.RESOLUTION_ERRORS, | 8804 HtmlEntry.RESOLUTION_ERRORS, |
| 10223 HtmlEntry.RESOLVED_UNIT, | 8805 HtmlEntry.RESOLVED_UNIT, |
| 10224 HtmlEntry.HINTS]); | 8806 HtmlEntry.HINTS]); |
| 10225 return result; | 8807 return result; |
| 10226 } | 8808 } |
| 10227 | 8809 |
| 10228 @override | 8810 @override |
| 10229 SourceKind get kind => SourceKind.HTML; | 8811 SourceKind get kind => SourceKind.HTML; |
| 10230 | 8812 |
| 10231 /** | 8813 /** |
| 10232 * Flush any AST structures being maintained by this entry. | 8814 * Flush any AST structures being maintained by this entry. |
| 10233 */ | 8815 */ |
| 10234 void flushAstStructures() { | 8816 void flushAstStructures() { |
| 10235 _flush(PARSED_UNIT); | 8817 _flush(PARSED_UNIT); |
| 10236 _flush(RESOLVED_UNIT); | 8818 _flush(RESOLVED_UNIT); |
| 10237 _flush(ANGULAR_ENTRY); | |
| 10238 _flush(ANGULAR_ERRORS); | |
| 10239 } | 8819 } |
| 10240 | 8820 |
| 10241 @override | 8821 @override |
| 10242 void invalidateAllInformation() { | 8822 void invalidateAllInformation() { |
| 10243 super.invalidateAllInformation(); | 8823 super.invalidateAllInformation(); |
| 10244 setState(PARSE_ERRORS, CacheState.INVALID); | 8824 setState(PARSE_ERRORS, CacheState.INVALID); |
| 10245 setState(PARSED_UNIT, CacheState.INVALID); | 8825 setState(PARSED_UNIT, CacheState.INVALID); |
| 10246 setState(RESOLVED_UNIT, CacheState.INVALID); | 8826 setState(RESOLVED_UNIT, CacheState.INVALID); |
| 10247 invalidateAllResolutionInformation(true); | 8827 invalidateAllResolutionInformation(true); |
| 10248 } | 8828 } |
| 10249 | 8829 |
| 10250 /** | 8830 /** |
| 10251 * Invalidate all of the resolution information associated with the HTML file. | 8831 * Invalidate all of the resolution information associated with the HTML file. |
| 10252 * If [invalidateUris] is `true`, the cached results of converting URIs to | 8832 * If [invalidateUris] is `true`, the cached results of converting URIs to |
| 10253 * source files should also be invalidated. | 8833 * source files should also be invalidated. |
| 10254 */ | 8834 */ |
| 10255 void invalidateAllResolutionInformation(bool invalidateUris) { | 8835 void invalidateAllResolutionInformation(bool invalidateUris) { |
| 10256 setState(ANGULAR_ENTRY, CacheState.INVALID); | |
| 10257 setState(ANGULAR_ERRORS, CacheState.INVALID); | |
| 10258 setState(POLYMER_BUILD_ERRORS, CacheState.INVALID); | 8836 setState(POLYMER_BUILD_ERRORS, CacheState.INVALID); |
| 10259 setState(POLYMER_RESOLUTION_ERRORS, CacheState.INVALID); | 8837 setState(POLYMER_RESOLUTION_ERRORS, CacheState.INVALID); |
| 10260 setState(ELEMENT, CacheState.INVALID); | 8838 setState(ELEMENT, CacheState.INVALID); |
| 10261 setState(RESOLUTION_ERRORS, CacheState.INVALID); | 8839 setState(RESOLUTION_ERRORS, CacheState.INVALID); |
| 10262 setState(HINTS, CacheState.INVALID); | 8840 setState(HINTS, CacheState.INVALID); |
| 10263 if (invalidateUris) { | 8841 if (invalidateUris) { |
| 10264 setState(REFERENCED_LIBRARIES, CacheState.INVALID); | 8842 setState(REFERENCED_LIBRARIES, CacheState.INVALID); |
| 10265 } | 8843 } |
| 10266 } | 8844 } |
| 10267 | 8845 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 10284 setState(REFERENCED_LIBRARIES, CacheState.ERROR); | 8862 setState(REFERENCED_LIBRARIES, CacheState.ERROR); |
| 10285 recordResolutionError(exception); | 8863 recordResolutionError(exception); |
| 10286 } | 8864 } |
| 10287 | 8865 |
| 10288 /** | 8866 /** |
| 10289 * Record that an [exception] was encountered while attempting to resolve the | 8867 * Record that an [exception] was encountered while attempting to resolve the |
| 10290 * source associated with this entry. | 8868 * source associated with this entry. |
| 10291 */ | 8869 */ |
| 10292 void recordResolutionError(CaughtException exception) { | 8870 void recordResolutionError(CaughtException exception) { |
| 10293 this.exception = exception; | 8871 this.exception = exception; |
| 10294 setState(ANGULAR_ERRORS, CacheState.ERROR); | |
| 10295 setState(RESOLVED_UNIT, CacheState.ERROR); | 8872 setState(RESOLVED_UNIT, CacheState.ERROR); |
| 10296 setState(ELEMENT, CacheState.ERROR); | 8873 setState(ELEMENT, CacheState.ERROR); |
| 10297 setState(RESOLUTION_ERRORS, CacheState.ERROR); | 8874 setState(RESOLUTION_ERRORS, CacheState.ERROR); |
| 10298 setState(HINTS, CacheState.ERROR); | 8875 setState(HINTS, CacheState.ERROR); |
| 10299 setState(POLYMER_BUILD_ERRORS, CacheState.ERROR); | 8876 setState(POLYMER_BUILD_ERRORS, CacheState.ERROR); |
| 10300 setState(POLYMER_RESOLUTION_ERRORS, CacheState.ERROR); | 8877 setState(POLYMER_RESOLUTION_ERRORS, CacheState.ERROR); |
| 10301 } | 8878 } |
| 10302 | 8879 |
| 10303 @override | 8880 @override |
| 10304 bool _isValidDescriptor(DataDescriptor descriptor) { | 8881 bool _isValidDescriptor(DataDescriptor descriptor) { |
| 10305 return descriptor == ANGULAR_APPLICATION || | 8882 return descriptor == ELEMENT || |
| 10306 descriptor == ANGULAR_COMPONENT || | |
| 10307 descriptor == ANGULAR_ENTRY || | |
| 10308 descriptor == ANGULAR_ERRORS || | |
| 10309 descriptor == ELEMENT || | |
| 10310 descriptor == HINTS || | 8883 descriptor == HINTS || |
| 10311 descriptor == PARSED_UNIT || | 8884 descriptor == PARSED_UNIT || |
| 10312 descriptor == PARSE_ERRORS || | 8885 descriptor == PARSE_ERRORS || |
| 10313 descriptor == POLYMER_BUILD_ERRORS || | 8886 descriptor == POLYMER_BUILD_ERRORS || |
| 10314 descriptor == POLYMER_RESOLUTION_ERRORS || | 8887 descriptor == POLYMER_RESOLUTION_ERRORS || |
| 10315 descriptor == REFERENCED_LIBRARIES || | 8888 descriptor == REFERENCED_LIBRARIES || |
| 10316 descriptor == RESOLUTION_ERRORS || | 8889 descriptor == RESOLUTION_ERRORS || |
| 10317 descriptor == RESOLVED_UNIT || | 8890 descriptor == RESOLVED_UNIT || |
| 10318 super._isValidDescriptor(descriptor); | 8891 super._isValidDescriptor(descriptor); |
| 10319 } | 8892 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10361 oldEntry); | 8934 oldEntry); |
| 10362 needsSeparator = _writeStateDiffOn( | 8935 needsSeparator = _writeStateDiffOn( |
| 10363 buffer, | 8936 buffer, |
| 10364 needsSeparator, | 8937 needsSeparator, |
| 10365 "element", | 8938 "element", |
| 10366 HtmlEntry.ELEMENT, | 8939 HtmlEntry.ELEMENT, |
| 10367 oldEntry); | 8940 oldEntry); |
| 10368 needsSeparator = _writeStateDiffOn( | 8941 needsSeparator = _writeStateDiffOn( |
| 10369 buffer, | 8942 buffer, |
| 10370 needsSeparator, | 8943 needsSeparator, |
| 10371 "angularApplicationState", | |
| 10372 HtmlEntry.ANGULAR_APPLICATION, | |
| 10373 oldEntry); | |
| 10374 needsSeparator = _writeStateDiffOn( | |
| 10375 buffer, | |
| 10376 needsSeparator, | |
| 10377 "angularComponent", | |
| 10378 HtmlEntry.ANGULAR_COMPONENT, | |
| 10379 oldEntry); | |
| 10380 needsSeparator = _writeStateDiffOn( | |
| 10381 buffer, | |
| 10382 needsSeparator, | |
| 10383 "angularEntry", | |
| 10384 HtmlEntry.ANGULAR_ENTRY, | |
| 10385 oldEntry); | |
| 10386 needsSeparator = _writeStateDiffOn( | |
| 10387 buffer, | |
| 10388 needsSeparator, | |
| 10389 "angularErrors", | |
| 10390 HtmlEntry.ANGULAR_ERRORS, | |
| 10391 oldEntry); | |
| 10392 needsSeparator = _writeStateDiffOn( | |
| 10393 buffer, | |
| 10394 needsSeparator, | |
| 10395 "polymerBuildErrors", | 8944 "polymerBuildErrors", |
| 10396 HtmlEntry.POLYMER_BUILD_ERRORS, | 8945 HtmlEntry.POLYMER_BUILD_ERRORS, |
| 10397 oldEntry); | 8946 oldEntry); |
| 10398 needsSeparator = _writeStateDiffOn( | 8947 needsSeparator = _writeStateDiffOn( |
| 10399 buffer, | 8948 buffer, |
| 10400 needsSeparator, | 8949 needsSeparator, |
| 10401 "polymerResolutionErrors", | 8950 "polymerResolutionErrors", |
| 10402 HtmlEntry.POLYMER_RESOLUTION_ERRORS, | 8951 HtmlEntry.POLYMER_RESOLUTION_ERRORS, |
| 10403 oldEntry); | 8952 oldEntry); |
| 10404 return needsSeparator; | 8953 return needsSeparator; |
| 10405 } | 8954 } |
| 10406 | 8955 |
| 10407 @override | 8956 @override |
| 10408 void _writeOn(StringBuffer buffer) { | 8957 void _writeOn(StringBuffer buffer) { |
| 10409 buffer.write("Html: "); | 8958 buffer.write("Html: "); |
| 10410 super._writeOn(buffer); | 8959 super._writeOn(buffer); |
| 10411 _writeStateOn(buffer, "parseErrors", PARSE_ERRORS); | 8960 _writeStateOn(buffer, "parseErrors", PARSE_ERRORS); |
| 10412 _writeStateOn(buffer, "parsedUnit", PARSED_UNIT); | 8961 _writeStateOn(buffer, "parsedUnit", PARSED_UNIT); |
| 10413 _writeStateOn(buffer, "resolvedUnit", RESOLVED_UNIT); | 8962 _writeStateOn(buffer, "resolvedUnit", RESOLVED_UNIT); |
| 10414 _writeStateOn(buffer, "resolutionErrors", RESOLUTION_ERRORS); | 8963 _writeStateOn(buffer, "resolutionErrors", RESOLUTION_ERRORS); |
| 10415 _writeStateOn(buffer, "referencedLibraries", REFERENCED_LIBRARIES); | 8964 _writeStateOn(buffer, "referencedLibraries", REFERENCED_LIBRARIES); |
| 10416 _writeStateOn(buffer, "element", ELEMENT); | 8965 _writeStateOn(buffer, "element", ELEMENT); |
| 10417 _writeStateOn(buffer, "angularApplication", ANGULAR_APPLICATION); | |
| 10418 _writeStateOn(buffer, "angularComponent", ANGULAR_COMPONENT); | |
| 10419 _writeStateOn(buffer, "angularEntry", ANGULAR_ENTRY); | |
| 10420 _writeStateOn(buffer, "angularErrors", ANGULAR_ERRORS); | |
| 10421 _writeStateOn(buffer, "polymerBuildErrors", POLYMER_BUILD_ERRORS); | 8966 _writeStateOn(buffer, "polymerBuildErrors", POLYMER_BUILD_ERRORS); |
| 10422 _writeStateOn(buffer, "polymerResolutionErrors", POLYMER_RESOLUTION_ERRORS); | 8967 _writeStateOn(buffer, "polymerResolutionErrors", POLYMER_RESOLUTION_ERRORS); |
| 10423 } | 8968 } |
| 10424 } | 8969 } |
| 10425 | 8970 |
| 10426 /** | 8971 /** |
| 10427 * Instances of the class `IncrementalAnalysisCache` hold information used to pe
rform | 8972 * Instances of the class `IncrementalAnalysisCache` hold information used to pe
rform |
| 10428 * incremental analysis. | 8973 * incremental analysis. |
| 10429 * | 8974 * |
| 10430 * See [AnalysisContextImpl.setChangedContents]. | 8975 * See [AnalysisContextImpl.setChangedContents]. |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10876 * Log the given exception as one representing an informational message. | 9421 * Log the given exception as one representing an informational message. |
| 10877 * | 9422 * |
| 10878 * @param message an explanation of why the error occurred or what it means | 9423 * @param message an explanation of why the error occurred or what it means |
| 10879 * @param exception the exception being logged | 9424 * @param exception the exception being logged |
| 10880 */ | 9425 */ |
| 10881 @deprecated | 9426 @deprecated |
| 10882 void logInformation2(String message, Object exception); | 9427 void logInformation2(String message, Object exception); |
| 10883 } | 9428 } |
| 10884 | 9429 |
| 10885 /** | 9430 /** |
| 10886 * [NgComponentElementProcessor] applies [AngularComponentElement] by parsing ma
pped | |
| 10887 * attributes as expressions. | |
| 10888 */ | |
| 10889 class NgComponentElementProcessor extends NgDirectiveProcessor { | |
| 10890 final AngularComponentElement _element; | |
| 10891 | |
| 10892 NgComponentElementProcessor(this._element); | |
| 10893 | |
| 10894 @override | |
| 10895 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) { | |
| 10896 node.element = _element.selector; | |
| 10897 for (AngularPropertyElement property in _element.properties) { | |
| 10898 String name = property.name; | |
| 10899 ht.XmlAttributeNode attribute = node.getAttribute(name); | |
| 10900 if (attribute != null) { | |
| 10901 attribute.element = property; | |
| 10902 // resolve if binding | |
| 10903 if (property.propertyKind != AngularPropertyKind.ATTR) { | |
| 10904 AngularExpression expression = | |
| 10905 parseAngularExpression(resolver, attribute); | |
| 10906 resolver._resolveExpression(expression); | |
| 10907 setAngularExpression(attribute, expression); | |
| 10908 } | |
| 10909 } | |
| 10910 } | |
| 10911 } | |
| 10912 | |
| 10913 @override | |
| 10914 bool canApply(ht.XmlTagNode node) => _element.selector.apply(node); | |
| 10915 } | |
| 10916 | |
| 10917 /** | |
| 10918 * [NgControllerElementProcessor] applies [AngularControllerElement]. | |
| 10919 */ | |
| 10920 class NgControllerElementProcessor extends NgProcessor { | |
| 10921 final AngularControllerElement _element; | |
| 10922 | |
| 10923 NgControllerElementProcessor(this._element); | |
| 10924 | |
| 10925 @override | |
| 10926 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) { | |
| 10927 InterfaceType type = (_element.enclosingElement as ClassElement).type; | |
| 10928 String name = _element.name; | |
| 10929 LocalVariableElementImpl variable = | |
| 10930 resolver._createLocalVariableWithName(type, name); | |
| 10931 resolver._defineVariable(variable); | |
| 10932 variable.toolkitObjects = <AngularElement>[_element]; | |
| 10933 } | |
| 10934 | |
| 10935 @override | |
| 10936 bool canApply(ht.XmlTagNode node) => _element.selector.apply(node); | |
| 10937 } | |
| 10938 | |
| 10939 /** | |
| 10940 * [NgDecoratorElementProcessor] applies [AngularDecoratorElement] by parsing ma
pped | |
| 10941 * attributes as expressions. | |
| 10942 */ | |
| 10943 class NgDecoratorElementProcessor extends NgDirectiveProcessor { | |
| 10944 final AngularDecoratorElement _element; | |
| 10945 | |
| 10946 NgDecoratorElementProcessor(this._element); | |
| 10947 | |
| 10948 @override | |
| 10949 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) { | |
| 10950 String selectorAttributeName = null; | |
| 10951 { | |
| 10952 AngularSelectorElement selector = _element.selector; | |
| 10953 if (selector is HasAttributeSelectorElementImpl) { | |
| 10954 selectorAttributeName = selector.name; | |
| 10955 // resolve attribute expression | |
| 10956 ht.XmlAttributeNode attribute = | |
| 10957 node.getAttribute(selectorAttributeName); | |
| 10958 if (attribute != null) { | |
| 10959 attribute.element = selector; | |
| 10960 } | |
| 10961 } | |
| 10962 } | |
| 10963 // | |
| 10964 for (AngularPropertyElement property in _element.properties) { | |
| 10965 // prepare attribute name | |
| 10966 String name = property.name; | |
| 10967 if (name == ".") { | |
| 10968 name = selectorAttributeName; | |
| 10969 } | |
| 10970 // prepare attribute | |
| 10971 ht.XmlAttributeNode attribute = node.getAttribute(name); | |
| 10972 if (attribute == null) { | |
| 10973 continue; | |
| 10974 } | |
| 10975 // if not resolved as the selector, resolve as a property | |
| 10976 if (name != selectorAttributeName) { | |
| 10977 attribute.element = property; | |
| 10978 } | |
| 10979 // skip if attribute has no value | |
| 10980 if (!NgDirectiveProcessor.hasValue(attribute)) { | |
| 10981 continue; | |
| 10982 } | |
| 10983 // resolve if binding | |
| 10984 if (property.propertyKind != AngularPropertyKind.ATTR) { | |
| 10985 resolver._pushNameScope(); | |
| 10986 try { | |
| 10987 _onNgEventDirective(resolver); | |
| 10988 AngularExpression expression = | |
| 10989 parseAngularExpression(resolver, attribute); | |
| 10990 resolver._resolveExpression(expression); | |
| 10991 setAngularExpression(attribute, expression); | |
| 10992 } finally { | |
| 10993 resolver._popNameScope(); | |
| 10994 } | |
| 10995 } | |
| 10996 } | |
| 10997 } | |
| 10998 | |
| 10999 @override | |
| 11000 bool canApply(ht.XmlTagNode node) => _element.selector.apply(node); | |
| 11001 | |
| 11002 /** | |
| 11003 * Support for <code>$event</code> variable in <code>NgEventDirective</code>. | |
| 11004 */ | |
| 11005 void _onNgEventDirective(AngularHtmlUnitResolver resolver) { | |
| 11006 if (_element.isClass("NgEventDirective")) { | |
| 11007 DartType dynamicType = resolver.typeProvider.dynamicType; | |
| 11008 resolver._defineVariable( | |
| 11009 resolver._createLocalVariableWithName(dynamicType, "\$event")); | |
| 11010 } | |
| 11011 } | |
| 11012 } | |
| 11013 | |
| 11014 /** | |
| 11015 * [NgDirectiveProcessor] describes any <code>Directive</code> annotation instan
ce. | |
| 11016 */ | |
| 11017 abstract class NgDirectiveProcessor extends NgProcessor { | |
| 11018 AngularExpression parseAngularExpression(AngularHtmlUnitResolver resolver, | |
| 11019 ht.XmlAttributeNode attribute) { | |
| 11020 Token token = _scanAttribute(resolver, attribute); | |
| 11021 return resolver._parseAngularExpressionInToken(token); | |
| 11022 } | |
| 11023 | |
| 11024 Expression parseDartExpression(AngularHtmlUnitResolver resolver, | |
| 11025 ht.XmlAttributeNode attribute) { | |
| 11026 Token token = _scanAttribute(resolver, attribute); | |
| 11027 return resolver._parseDartExpressionInToken(token); | |
| 11028 } | |
| 11029 | |
| 11030 /** | |
| 11031 * Sets single [AngularExpression] for [XmlAttributeNode]. | |
| 11032 */ | |
| 11033 void setAngularExpression(ht.XmlAttributeNode attribute, | |
| 11034 AngularExpression expression) { | |
| 11035 _setExpression(attribute, newAngularRawXmlExpression(expression)); | |
| 11036 } | |
| 11037 | |
| 11038 /** | |
| 11039 * Sets single [Expression] for [XmlAttributeNode]. | |
| 11040 */ | |
| 11041 void setExpression(ht.XmlAttributeNode attribute, Expression expression) { | |
| 11042 _setExpression(attribute, newRawXmlExpression(expression)); | |
| 11043 } | |
| 11044 | |
| 11045 void setExpressions(ht.XmlAttributeNode attribute, | |
| 11046 List<ht.XmlExpression> xmlExpressions) { | |
| 11047 attribute.expressions = new List.from(xmlExpressions); | |
| 11048 } | |
| 11049 | |
| 11050 Token _scanAttribute(AngularHtmlUnitResolver resolver, | |
| 11051 ht.XmlAttributeNode attribute) { | |
| 11052 int offset = attribute.valueToken.offset + 1; | |
| 11053 String value = attribute.text; | |
| 11054 return resolver._scanDart(value, 0, value.length, offset); | |
| 11055 } | |
| 11056 | |
| 11057 void _setExpression(ht.XmlAttributeNode attribute, | |
| 11058 ht.XmlExpression xmlExpression) { | |
| 11059 attribute.expressions = <ht.XmlExpression>[xmlExpression]; | |
| 11060 } | |
| 11061 | |
| 11062 static bool hasValue(ht.XmlAttributeNode attribute) { | |
| 11063 ht.Token valueToken = attribute.valueToken; | |
| 11064 return valueToken != null && !valueToken.isSynthetic; | |
| 11065 } | |
| 11066 | |
| 11067 static AngularRawXmlExpression | |
| 11068 newAngularRawXmlExpression(AngularExpression e) => | |
| 11069 new AngularRawXmlExpression(e); | |
| 11070 | |
| 11071 static ht.RawXmlExpression newRawXmlExpression(Expression e) => | |
| 11072 new ht.RawXmlExpression(e); | |
| 11073 } | |
| 11074 | |
| 11075 /** | |
| 11076 * [NgModelProcessor] describes built-in <code>NgModel</code> directive. | |
| 11077 */ | |
| 11078 class NgModelProcessor extends NgDirectiveProcessor { | |
| 11079 static String _NG_MODEL = "ng-model"; | |
| 11080 | |
| 11081 static NgModelProcessor INSTANCE = new NgModelProcessor(); | |
| 11082 | |
| 11083 @override | |
| 11084 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node) { | |
| 11085 ht.XmlAttributeNode attribute = node.getAttribute(_NG_MODEL); | |
| 11086 Expression expression = parseDartExpression(resolver, attribute); | |
| 11087 // identifiers have been already handled by "apply top" | |
| 11088 if (expression is SimpleIdentifier) { | |
| 11089 return; | |
| 11090 } | |
| 11091 // resolve | |
| 11092 resolver._resolveNode(expression); | |
| 11093 // remember expression | |
| 11094 setExpression(attribute, expression); | |
| 11095 } | |
| 11096 | |
| 11097 @override | |
| 11098 bool canApply(ht.XmlTagNode node) => node.getAttribute(_NG_MODEL) != null; | |
| 11099 | |
| 11100 /** | |
| 11101 * This method is used to define top-level [VariableElement]s for each "ng-mod
el" with | |
| 11102 * simple identifier model. | |
| 11103 */ | |
| 11104 void _applyTopDeclarations(AngularHtmlUnitResolver resolver, | |
| 11105 ht.XmlTagNode node) { | |
| 11106 ht.XmlAttributeNode attribute = node.getAttribute(_NG_MODEL); | |
| 11107 Expression expression = parseDartExpression(resolver, attribute); | |
| 11108 // if not identifier, then not a top-level model, delay until "apply" | |
| 11109 if (expression is! SimpleIdentifier) { | |
| 11110 return; | |
| 11111 } | |
| 11112 SimpleIdentifier identifier = expression as SimpleIdentifier; | |
| 11113 // define variable Element | |
| 11114 InterfaceType type = resolver.typeProvider.stringType; | |
| 11115 LocalVariableElementImpl element = | |
| 11116 resolver._createLocalVariableFromIdentifier(type, identifier); | |
| 11117 resolver._defineTopVariable(element); | |
| 11118 // remember expression | |
| 11119 identifier.staticElement = element; | |
| 11120 identifier.staticType = type; | |
| 11121 setExpression(attribute, identifier); | |
| 11122 } | |
| 11123 } | |
| 11124 | |
| 11125 /** | |
| 11126 * [NgProcessor] is used to apply an Angular feature. | |
| 11127 */ | |
| 11128 abstract class NgProcessor { | |
| 11129 /** | |
| 11130 * Applies this [NgProcessor] to the resolver. | |
| 11131 * | |
| 11132 * @param resolver the [AngularHtmlUnitResolver] to apply to, not `null` | |
| 11133 * @param node the [XmlTagNode] to apply within, not `null` | |
| 11134 */ | |
| 11135 void apply(AngularHtmlUnitResolver resolver, ht.XmlTagNode node); | |
| 11136 | |
| 11137 /** | |
| 11138 * Checks if this processor can be applied to the given [XmlTagNode]. | |
| 11139 * | |
| 11140 * @param node the [XmlTagNode] to check | |
| 11141 * @return `true` if this processor can be applied, or `false` otherwise | |
| 11142 */ | |
| 11143 bool canApply(ht.XmlTagNode node); | |
| 11144 } | |
| 11145 | |
| 11146 /** | |
| 11147 * An implementation of [Logger] that does nothing. | 9431 * An implementation of [Logger] that does nothing. |
| 11148 */ | 9432 */ |
| 11149 class NullLogger implements Logger { | 9433 class NullLogger implements Logger { |
| 11150 @override | 9434 @override |
| 11151 void logError(String message, [CaughtException exception]) { | 9435 void logError(String message, [CaughtException exception]) { |
| 11152 } | 9436 } |
| 11153 | 9437 |
| 11154 @override | 9438 @override |
| 11155 void logError2(String message, Object exception) { | 9439 void logError2(String message, Object exception) { |
| 11156 } | 9440 } |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11771 * The [TimeCounter] for time spent in parsing. | 10055 * The [TimeCounter] for time spent in parsing. |
| 11772 */ | 10056 */ |
| 11773 static TimeCounter parse = new TimeCounter(); | 10057 static TimeCounter parse = new TimeCounter(); |
| 11774 | 10058 |
| 11775 /** | 10059 /** |
| 11776 * The [TimeCounter] for time spent in resolving. | 10060 * The [TimeCounter] for time spent in resolving. |
| 11777 */ | 10061 */ |
| 11778 static TimeCounter resolve = new TimeCounter(); | 10062 static TimeCounter resolve = new TimeCounter(); |
| 11779 | 10063 |
| 11780 /** | 10064 /** |
| 11781 * The [TimeCounter] for time spent in Angular analysis. | |
| 11782 */ | |
| 11783 static TimeCounter angular = new TimeCounter(); | |
| 11784 | |
| 11785 /** | |
| 11786 * The [TimeCounter] for time spent in Polymer analysis. | 10065 * The [TimeCounter] for time spent in Polymer analysis. |
| 11787 */ | 10066 */ |
| 11788 static TimeCounter polymer = new TimeCounter(); | 10067 static TimeCounter polymer = new TimeCounter(); |
| 11789 | 10068 |
| 11790 /** | 10069 /** |
| 11791 * The [TimeCounter] for time spent in error verifier. | 10070 * The [TimeCounter] for time spent in error verifier. |
| 11792 */ | 10071 */ |
| 11793 static TimeCounter errors = new TimeCounter(); | 10072 static TimeCounter errors = new TimeCounter(); |
| 11794 | 10073 |
| 11795 /** | 10074 /** |
| 11796 * The [TimeCounter] for time spent in hints generator. | 10075 * The [TimeCounter] for time spent in hints generator. |
| 11797 */ | 10076 */ |
| 11798 static TimeCounter hints = new TimeCounter(); | 10077 static TimeCounter hints = new TimeCounter(); |
| 11799 | 10078 |
| 11800 /** | 10079 /** |
| 11801 * Reset all of the time counters to zero. | 10080 * Reset all of the time counters to zero. |
| 11802 */ | 10081 */ |
| 11803 static void reset() { | 10082 static void reset() { |
| 11804 io = new TimeCounter(); | 10083 io = new TimeCounter(); |
| 11805 scan = new TimeCounter(); | 10084 scan = new TimeCounter(); |
| 11806 parse = new TimeCounter(); | 10085 parse = new TimeCounter(); |
| 11807 resolve = new TimeCounter(); | 10086 resolve = new TimeCounter(); |
| 11808 angular = new TimeCounter(); | |
| 11809 polymer = new TimeCounter(); | 10087 polymer = new TimeCounter(); |
| 11810 errors = new TimeCounter(); | 10088 errors = new TimeCounter(); |
| 11811 hints = new TimeCounter(); | 10089 hints = new TimeCounter(); |
| 11812 } | 10090 } |
| 11813 } | 10091 } |
| 11814 | 10092 |
| 11815 /** | 10093 /** |
| 11816 * Instances of the class `PolymerBuildHtmlTask` build Polymer specific elements
. | 10094 * Instances of the class `PolymerBuildHtmlTask` build Polymer specific elements
. |
| 11817 */ | 10095 */ |
| 11818 class PolymerBuildHtmlTask extends AnalysisTask { | 10096 class PolymerBuildHtmlTask extends AnalysisTask { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11873 class PolymerHtmlUnitBuilder extends ht.RecursiveXmlVisitor<Object> { | 10151 class PolymerHtmlUnitBuilder extends ht.RecursiveXmlVisitor<Object> { |
| 11874 /** | 10152 /** |
| 11875 * These names are forbidden to use as a custom tag name. | 10153 * These names are forbidden to use as a custom tag name. |
| 11876 * | 10154 * |
| 11877 * http://w3c.github.io/webcomponents/spec/custom/#concepts | 10155 * http://w3c.github.io/webcomponents/spec/custom/#concepts |
| 11878 */ | 10156 */ |
| 11879 static Set<String> _FORBIDDEN_TAG_NAMES = new Set(); | 10157 static Set<String> _FORBIDDEN_TAG_NAMES = new Set(); |
| 11880 | 10158 |
| 11881 final InternalAnalysisContext _context; | 10159 final InternalAnalysisContext _context; |
| 11882 | 10160 |
| 11883 TypeProvider _typeProvider; | |
| 11884 | |
| 11885 final AnalysisErrorListener _errorListener; | 10161 final AnalysisErrorListener _errorListener; |
| 11886 | 10162 |
| 11887 final Source _source; | 10163 final Source _source; |
| 11888 | 10164 |
| 11889 final LineInfo _lineInfo; | 10165 final LineInfo _lineInfo; |
| 11890 | 10166 |
| 11891 final ht.HtmlUnit _unit; | 10167 final ht.HtmlUnit _unit; |
| 11892 | 10168 |
| 11893 List<PolymerTagHtmlElement> _tagHtmlElements = <PolymerTagHtmlElement>[]; | 10169 List<PolymerTagHtmlElement> _tagHtmlElements = <PolymerTagHtmlElement>[]; |
| 11894 | 10170 |
| 11895 ht.XmlTagNode _elementNode; | 10171 ht.XmlTagNode _elementNode; |
| 11896 | 10172 |
| 11897 String _elementName; | 10173 String _elementName; |
| 11898 | 10174 |
| 11899 PolymerTagHtmlElementImpl _htmlElement; | 10175 PolymerTagHtmlElementImpl _htmlElement; |
| 11900 | 10176 |
| 11901 PolymerTagDartElementImpl _dartElement; | 10177 PolymerTagDartElementImpl _dartElement; |
| 11902 | 10178 |
| 11903 PolymerHtmlUnitBuilder(this._context, this._errorListener, this._source, | 10179 PolymerHtmlUnitBuilder(this._context, this._errorListener, this._source, |
| 11904 this._lineInfo, this._unit) { | 10180 this._lineInfo, this._unit); |
| 11905 this._typeProvider = _context.typeProvider; | |
| 11906 } | |
| 11907 | 10181 |
| 11908 /** | 10182 /** |
| 11909 * Returns the only [LibraryElement] referenced by a direct `script` child. Ma
ybe | 10183 * Returns the only [LibraryElement] referenced by a direct `script` child. Ma
ybe |
| 11910 * `null` if none. | 10184 * `null` if none. |
| 11911 */ | 10185 */ |
| 11912 LibraryElement get dartUnitElement { | 10186 LibraryElement get dartUnitElement { |
| 11913 // TODO(scheglov) Maybe check if more than one "script". | 10187 // TODO(scheglov) Maybe check if more than one "script". |
| 11914 for (ht.XmlTagNode child in _elementNode.tagNodes) { | 10188 for (ht.XmlTagNode child in _elementNode.tagNodes) { |
| 11915 if (child is ht.HtmlScriptTagNode) { | 10189 if (child is ht.HtmlScriptTagNode) { |
| 11916 HtmlScriptElement scriptElement = child.scriptElement; | 10190 HtmlScriptElement scriptElement = child.scriptElement; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12242 | 10516 |
| 12243 /** | 10517 /** |
| 12244 * Instances of the class [PolymerHtmlUnitResolver] resolve Polymer specific | 10518 * Instances of the class [PolymerHtmlUnitResolver] resolve Polymer specific |
| 12245 * [XmlTagNode]s and expressions. | 10519 * [XmlTagNode]s and expressions. |
| 12246 * | 10520 * |
| 12247 * TODO(scheglov) implement it | 10521 * TODO(scheglov) implement it |
| 12248 */ | 10522 */ |
| 12249 class PolymerHtmlUnitResolver extends ht.RecursiveXmlVisitor<Object> { | 10523 class PolymerHtmlUnitResolver extends ht.RecursiveXmlVisitor<Object> { |
| 12250 final InternalAnalysisContext _context; | 10524 final InternalAnalysisContext _context; |
| 12251 | 10525 |
| 12252 TypeProvider _typeProvider; | |
| 12253 | |
| 12254 final AnalysisErrorListener _errorListener; | 10526 final AnalysisErrorListener _errorListener; |
| 12255 | 10527 |
| 12256 final Source _source; | 10528 final Source _source; |
| 12257 | 10529 |
| 12258 final LineInfo _lineInfo; | 10530 final LineInfo _lineInfo; |
| 12259 | 10531 |
| 12260 final ht.HtmlUnit _unit; | 10532 final ht.HtmlUnit _unit; |
| 12261 | 10533 |
| 12262 PolymerHtmlUnitResolver(this._context, this._errorListener, this._source, | 10534 PolymerHtmlUnitResolver(this._context, this._errorListener, this._source, |
| 12263 this._lineInfo, this._unit) { | 10535 this._lineInfo, this._unit); |
| 12264 this._typeProvider = _context.typeProvider; | |
| 12265 } | |
| 12266 | 10536 |
| 12267 /** | 10537 /** |
| 12268 * Resolves Polymer specific features. | 10538 * Resolves Polymer specific features. |
| 12269 */ | 10539 */ |
| 12270 void resolveUnit() { | 10540 void resolveUnit() { |
| 12271 // TODO(scheglov) implement it | 10541 // TODO(scheglov) implement it |
| 12272 // unit.accept(this); | 10542 // unit.accept(this); |
| 12273 } | 10543 } |
| 12274 | 10544 |
| 12275 @override | 10545 @override |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12398 Source source = error.source; | 10668 Source source = error.source; |
| 12399 HashSet<AnalysisError> errorsForSource = _errors[source]; | 10669 HashSet<AnalysisError> errorsForSource = _errors[source]; |
| 12400 if (_errors[source] == null) { | 10670 if (_errors[source] == null) { |
| 12401 errorsForSource = new HashSet<AnalysisError>(); | 10671 errorsForSource = new HashSet<AnalysisError>(); |
| 12402 _errors[source] = errorsForSource; | 10672 _errors[source] = errorsForSource; |
| 12403 } | 10673 } |
| 12404 errorsForSource.add(error); | 10674 errorsForSource.add(error); |
| 12405 } | 10675 } |
| 12406 } | 10676 } |
| 12407 | 10677 |
| 12408 class RecursiveXmlVisitor_AngularHtmlUnitResolver_hasAngularAnnotation extends | |
| 12409 ht.RecursiveXmlVisitor<Object> { | |
| 12410 @override | |
| 12411 Object visitXmlTagNode(ht.XmlTagNode node) { | |
| 12412 if (node.getAttribute(AngularHtmlUnitResolver._NG_APP) != null) { | |
| 12413 throw new AngularHtmlUnitResolver_FoundAppError(); | |
| 12414 } | |
| 12415 return super.visitXmlTagNode(node); | |
| 12416 } | |
| 12417 } | |
| 12418 | |
| 12419 class RecursiveXmlVisitor_ParseHtmlTask_internalPerform extends | 10678 class RecursiveXmlVisitor_ParseHtmlTask_internalPerform extends |
| 12420 ht.RecursiveXmlVisitor<Object> { | 10679 ht.RecursiveXmlVisitor<Object> { |
| 12421 final ParseHtmlTask ParseHtmlTask_this; | 10680 final ParseHtmlTask ParseHtmlTask_this; |
| 12422 | 10681 |
| 12423 RecordingErrorListener errorListener; | 10682 RecordingErrorListener errorListener; |
| 12424 | 10683 |
| 12425 RecursiveXmlVisitor_ParseHtmlTask_internalPerform(this.ParseHtmlTask_this, | 10684 RecursiveXmlVisitor_ParseHtmlTask_internalPerform(this.ParseHtmlTask_this, |
| 12426 this.errorListener) | 10685 this.errorListener) |
| 12427 : super(); | 10686 : super(); |
| 12428 | 10687 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12692 } | 10951 } |
| 12693 | 10952 |
| 12694 /** | 10953 /** |
| 12695 * Record that an exception occurred while attempting to resolve the source | 10954 * Record that an exception occurred while attempting to resolve the source |
| 12696 * associated with this state. | 10955 * associated with this state. |
| 12697 */ | 10956 */ |
| 12698 void recordResolutionError() { | 10957 void recordResolutionError() { |
| 12699 setState(DartEntry.RESOLVED_UNIT, CacheState.ERROR); | 10958 setState(DartEntry.RESOLVED_UNIT, CacheState.ERROR); |
| 12700 setState(DartEntry.RESOLUTION_ERRORS, CacheState.ERROR); | 10959 setState(DartEntry.RESOLUTION_ERRORS, CacheState.ERROR); |
| 12701 recordVerificationError(); | 10960 recordVerificationError(); |
| 12702 setState(DartEntry.ANGULAR_ERRORS, CacheState.ERROR); | |
| 12703 } | 10961 } |
| 12704 | 10962 |
| 12705 /** | 10963 /** |
| 12706 * Record that an exception occurred while attempting to scan or parse the | 10964 * Record that an exception occurred while attempting to scan or parse the |
| 12707 * source associated with this entry. This will set the state of all | 10965 * source associated with this entry. This will set the state of all |
| 12708 * resolution-based information as being in error. | 10966 * resolution-based information as being in error. |
| 12709 */ | 10967 */ |
| 12710 void recordResolutionErrorsInAllLibraries() { | 10968 void recordResolutionErrorsInAllLibraries() { |
| 12711 recordBuildElementError(); | 10969 recordBuildElementError(); |
| 12712 if (_nextState != null) { | 10970 if (_nextState != null) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12882 /** | 11140 /** |
| 12883 * Initialize a newly created holder to hold the given values. | 11141 * Initialize a newly created holder to hold the given values. |
| 12884 * | 11142 * |
| 12885 * @param source the source of the compilation unit | 11143 * @param source the source of the compilation unit |
| 12886 * @param unit the AST that was created from the source | 11144 * @param unit the AST that was created from the source |
| 12887 */ | 11145 */ |
| 12888 ResolvableCompilationUnit(this.source, this.compilationUnit); | 11146 ResolvableCompilationUnit(this.source, this.compilationUnit); |
| 12889 } | 11147 } |
| 12890 | 11148 |
| 12891 /** | 11149 /** |
| 12892 * Instances of the class `ResolveAngularComponentTemplateTask` resolve HTML tem
plate | |
| 12893 * referenced by [AngularComponentElement]. | |
| 12894 */ | |
| 12895 class ResolveAngularComponentTemplateTask extends AnalysisTask { | |
| 12896 /** | |
| 12897 * The source to be resolved. | |
| 12898 */ | |
| 12899 final Source source; | |
| 12900 | |
| 12901 /** | |
| 12902 * The HTML unit to be resolved. | |
| 12903 */ | |
| 12904 final ht.HtmlUnit _unit; | |
| 12905 | |
| 12906 /** | |
| 12907 * The [AngularComponentElement] to resolve template for. | |
| 12908 */ | |
| 12909 final AngularComponentElement _component; | |
| 12910 | |
| 12911 /** | |
| 12912 * The Angular application to resolve in context of. | |
| 12913 */ | |
| 12914 final AngularApplication _application; | |
| 12915 | |
| 12916 /** | |
| 12917 * The [HtmlUnit] that was resolved by this task. | |
| 12918 */ | |
| 12919 ht.HtmlUnit _resolvedUnit; | |
| 12920 | |
| 12921 /** | |
| 12922 * The resolution errors that were discovered while resolving the source. | |
| 12923 */ | |
| 12924 List<AnalysisError> _resolutionErrors = AnalysisError.NO_ERRORS; | |
| 12925 | |
| 12926 /** | |
| 12927 * Initialize a newly created task to perform analysis within the given contex
t. | |
| 12928 * | |
| 12929 * @param context the context in which the task is to be performed | |
| 12930 * @param source the source to be resolved | |
| 12931 * @param unit the HTML unit to be resolved | |
| 12932 * @param component the component that uses this HTML template, not `null` | |
| 12933 * @param application the Angular application to resolve in context of | |
| 12934 */ | |
| 12935 ResolveAngularComponentTemplateTask(InternalAnalysisContext context, | |
| 12936 this.source, this._unit, this._component, this._application) | |
| 12937 : super(context); | |
| 12938 | |
| 12939 List<AnalysisError> get resolutionErrors => _resolutionErrors; | |
| 12940 | |
| 12941 /** | |
| 12942 * Return the [HtmlUnit] that was resolved by this task. | |
| 12943 * | |
| 12944 * @return the [HtmlUnit] that was resolved by this task | |
| 12945 */ | |
| 12946 ht.HtmlUnit get resolvedUnit => _resolvedUnit; | |
| 12947 | |
| 12948 @override | |
| 12949 String get taskDescription => "resolve as Angular template $source"; | |
| 12950 | |
| 12951 @override | |
| 12952 accept(AnalysisTaskVisitor visitor) => | |
| 12953 visitor.visitResolveAngularComponentTemplateTask(this); | |
| 12954 | |
| 12955 @override | |
| 12956 void internalPerform() { | |
| 12957 // | |
| 12958 // Prepare for resolution. | |
| 12959 // | |
| 12960 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 12961 LineInfo lineInfo = context.getLineInfo(source); | |
| 12962 // | |
| 12963 // Perform resolution. | |
| 12964 // | |
| 12965 if (_application != null) { | |
| 12966 AngularHtmlUnitResolver resolver = | |
| 12967 new AngularHtmlUnitResolver(context, errorListener, source, lineInfo,
_unit); | |
| 12968 resolver.resolveComponentTemplate(_application, _component); | |
| 12969 _resolvedUnit = _unit; | |
| 12970 } | |
| 12971 // | |
| 12972 // Remember the errors. | |
| 12973 // | |
| 12974 _resolutionErrors = errorListener.getErrorsForSource(source); | |
| 12975 } | |
| 12976 } | |
| 12977 | |
| 12978 /** | |
| 12979 * Instances of the class `ResolveAngularEntryHtmlTask` resolve a specific HTML
file as an | |
| 12980 * Angular entry point. | |
| 12981 */ | |
| 12982 class ResolveAngularEntryHtmlTask extends AnalysisTask { | |
| 12983 /** | |
| 12984 * The source to be resolved. | |
| 12985 */ | |
| 12986 final Source source; | |
| 12987 | |
| 12988 /** | |
| 12989 * The HTML unit to be resolved. | |
| 12990 */ | |
| 12991 final ht.HtmlUnit _unit; | |
| 12992 | |
| 12993 /** | |
| 12994 * The listener to record errors. | |
| 12995 */ | |
| 12996 RecordingErrorListener _errorListener = new RecordingErrorListener(); | |
| 12997 | |
| 12998 /** | |
| 12999 * The [HtmlUnit] that was resolved by this task. | |
| 13000 */ | |
| 13001 ht.HtmlUnit _resolvedUnit; | |
| 13002 | |
| 13003 /** | |
| 13004 * The element produced by resolving the source. | |
| 13005 */ | |
| 13006 HtmlElement _element = null; | |
| 13007 | |
| 13008 /** | |
| 13009 * The Angular application to resolve in context of. | |
| 13010 */ | |
| 13011 AngularApplication _application; | |
| 13012 | |
| 13013 /** | |
| 13014 * Initialize a newly created task to perform analysis within the given contex
t. | |
| 13015 * | |
| 13016 * @param context the context in which the task is to be performed | |
| 13017 * @param source the source to be resolved | |
| 13018 * @param unit the HTML unit to be resolved | |
| 13019 */ | |
| 13020 ResolveAngularEntryHtmlTask(InternalAnalysisContext context, this.source, | |
| 13021 this._unit) | |
| 13022 : super(context); | |
| 13023 | |
| 13024 /** | |
| 13025 * Returns the [AngularApplication] for the Web application with this Angular
entry point, | |
| 13026 * maybe `null` if not an Angular entry point. | |
| 13027 */ | |
| 13028 AngularApplication get application => _application; | |
| 13029 | |
| 13030 HtmlElement get element => _element; | |
| 13031 | |
| 13032 /** | |
| 13033 * The resolution errors that were discovered while resolving the source. | |
| 13034 */ | |
| 13035 List<AnalysisError> get entryErrors => | |
| 13036 _errorListener.getErrorsForSource(source); | |
| 13037 | |
| 13038 /** | |
| 13039 * Return the [HtmlUnit] that was resolved by this task. | |
| 13040 * | |
| 13041 * @return the [HtmlUnit] that was resolved by this task | |
| 13042 */ | |
| 13043 ht.HtmlUnit get resolvedUnit => _resolvedUnit; | |
| 13044 | |
| 13045 @override | |
| 13046 String get taskDescription { | |
| 13047 if (source == null) { | |
| 13048 return "resolve as Angular entry point null source"; | |
| 13049 } | |
| 13050 return "resolve as Angular entry point ${source.fullName}"; | |
| 13051 } | |
| 13052 | |
| 13053 @override | |
| 13054 accept(AnalysisTaskVisitor visitor) => | |
| 13055 visitor.visitResolveAngularEntryHtmlTask(this); | |
| 13056 | |
| 13057 /** | |
| 13058 * Returns [AnalysisError]s recorded for the given [Source]. | |
| 13059 */ | |
| 13060 List<AnalysisError> getErrors(Source source) => | |
| 13061 _errorListener.getErrorsForSource(source); | |
| 13062 | |
| 13063 @override | |
| 13064 void internalPerform() { | |
| 13065 // | |
| 13066 // Prepare for resolution. | |
| 13067 // | |
| 13068 LineInfo lineInfo = context.getLineInfo(source); | |
| 13069 // | |
| 13070 // Try to resolve as an Angular entry point. | |
| 13071 // | |
| 13072 _application = new AngularHtmlUnitResolver( | |
| 13073 context, | |
| 13074 _errorListener, | |
| 13075 source, | |
| 13076 lineInfo, | |
| 13077 _unit).calculateAngularApplication(); | |
| 13078 // | |
| 13079 // Perform resolution. | |
| 13080 // | |
| 13081 if (_application != null) { | |
| 13082 new AngularHtmlUnitResolver( | |
| 13083 context, | |
| 13084 _errorListener, | |
| 13085 source, | |
| 13086 lineInfo, | |
| 13087 _unit).resolveEntryPoint(_application); | |
| 13088 } | |
| 13089 // | |
| 13090 // Remember the resolved unit. | |
| 13091 // | |
| 13092 _resolvedUnit = _unit; | |
| 13093 } | |
| 13094 } | |
| 13095 | |
| 13096 /** | |
| 13097 * Instances of the class `ResolveDartLibraryTask` resolve a specific Dart libra
ry. | 11150 * Instances of the class `ResolveDartLibraryTask` resolve a specific Dart libra
ry. |
| 13098 */ | 11151 */ |
| 13099 class ResolveDartLibraryCycleTask extends AnalysisTask { | 11152 class ResolveDartLibraryCycleTask extends AnalysisTask { |
| 13100 /** | 11153 /** |
| 13101 * The source representing the file whose compilation unit is to be returned.
TODO(brianwilkerson) | 11154 * The source representing the file whose compilation unit is to be returned.
TODO(brianwilkerson) |
| 13102 * This should probably be removed, but is being left in for now to ease the t
ransition. | 11155 * This should probably be removed, but is being left in for now to ease the t
ransition. |
| 13103 */ | 11156 */ |
| 13104 final Source unitSource; | 11157 final Source unitSource; |
| 13105 | 11158 |
| 13106 /** | 11159 /** |
| (...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14383 new PendingFuture<T>(_context, source, computeValue); | 12436 new PendingFuture<T>(_context, source, computeValue); |
| 14384 if (!pendingFuture.evaluate(sourceEntry)) { | 12437 if (!pendingFuture.evaluate(sourceEntry)) { |
| 14385 _context._pendingFutureSources.putIfAbsent( | 12438 _context._pendingFutureSources.putIfAbsent( |
| 14386 source, | 12439 source, |
| 14387 () => <PendingFuture>[]).add(pendingFuture); | 12440 () => <PendingFuture>[]).add(pendingFuture); |
| 14388 } | 12441 } |
| 14389 return pendingFuture.future; | 12442 return pendingFuture.future; |
| 14390 } | 12443 } |
| 14391 } | 12444 } |
| 14392 | 12445 |
| 14393 class _AngularHtmlUnitResolver_visitModelDirectives extends | |
| 14394 ht.RecursiveXmlVisitor<Object> { | |
| 14395 final AngularHtmlUnitResolver resolver; | |
| 14396 | |
| 14397 _AngularHtmlUnitResolver_visitModelDirectives(this.resolver) | |
| 14398 : super(); | |
| 14399 | |
| 14400 @override | |
| 14401 Object visitXmlTagNode(ht.XmlTagNode node) { | |
| 14402 NgModelProcessor directive = NgModelProcessor.INSTANCE; | |
| 14403 if (directive.canApply(node)) { | |
| 14404 directive._applyTopDeclarations(resolver, node); | |
| 14405 } | |
| 14406 return super.visitXmlTagNode(node); | |
| 14407 } | |
| 14408 } | |
| 14409 | |
| 14410 class _ElementByIdFinder extends GeneralizingElementVisitor { | 12446 class _ElementByIdFinder extends GeneralizingElementVisitor { |
| 14411 final int _id; | 12447 final int _id; |
| 14412 Element result; | 12448 Element result; |
| 14413 | 12449 |
| 14414 _ElementByIdFinder(this._id); | 12450 _ElementByIdFinder(this._id); |
| 14415 | 12451 |
| 14416 @override | 12452 @override |
| 14417 visitElement(Element element) { | 12453 visitElement(Element element) { |
| 14418 if (element.id == _id) { | 12454 if (element.id == _id) { |
| 14419 result = element; | 12455 result = element; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 14435 | 12471 |
| 14436 @override | 12472 @override |
| 14437 Object visitPolymerTagDartElement(PolymerTagDartElement element) { | 12473 Object visitPolymerTagDartElement(PolymerTagDartElement element) { |
| 14438 if (element.name == PolymerHtmlUnitBuilder_this._elementName) { | 12474 if (element.name == PolymerHtmlUnitBuilder_this._elementName) { |
| 14439 throw new PolymerHtmlUnitBuilder_FoundTagDartElementError( | 12475 throw new PolymerHtmlUnitBuilder_FoundTagDartElementError( |
| 14440 element as PolymerTagDartElementImpl); | 12476 element as PolymerTagDartElementImpl); |
| 14441 } | 12477 } |
| 14442 return null; | 12478 return null; |
| 14443 } | 12479 } |
| 14444 } | 12480 } |
| OLD | NEW |