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 library engine; | 5 library engine; |
Brian Wilkerson
2015/08/24 21:43:09
If there are any non-formatting changes in this fi
| |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:math' as math; | 9 import 'dart:math' as math; |
10 | 10 |
11 import 'package:analyzer/src/cancelable_future.dart'; | 11 import 'package:analyzer/src/cancelable_future.dart'; |
12 import 'package:analyzer/src/context/cache.dart' as cache; | 12 import 'package:analyzer/src/context/cache.dart' as cache; |
13 import 'package:analyzer/src/context/context.dart' as newContext; | 13 import 'package:analyzer/src/context/context.dart' as newContext; |
14 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; | 14 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; |
15 import 'package:analyzer/src/plugin/command_line_plugin.dart'; | 15 import 'package:analyzer/src/plugin/command_line_plugin.dart'; |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 /** | 1082 /** |
1083 * A factory to override how [LibraryResolver] is created. | 1083 * A factory to override how [LibraryResolver] is created. |
1084 */ | 1084 */ |
1085 LibraryResolverFactory libraryResolverFactory; | 1085 LibraryResolverFactory libraryResolverFactory; |
1086 | 1086 |
1087 /** | 1087 /** |
1088 * Initialize a newly created analysis context. | 1088 * Initialize a newly created analysis context. |
1089 */ | 1089 */ |
1090 AnalysisContextImpl() { | 1090 AnalysisContextImpl() { |
1091 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); | 1091 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); |
1092 _privatePartition = new UniversalCachePartition(this, | 1092 _privatePartition = new UniversalCachePartition( |
1093 this, | |
1093 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, | 1094 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, |
1094 new AnalysisContextImpl_ContextRetentionPolicy(this)); | 1095 new AnalysisContextImpl_ContextRetentionPolicy(this)); |
1095 _cache = createCacheFromSourceFactory(null); | 1096 _cache = createCacheFromSourceFactory(null); |
1096 _onSourcesChangedController = | 1097 _onSourcesChangedController = |
1097 new StreamController<SourcesChangedEvent>.broadcast(); | 1098 new StreamController<SourcesChangedEvent>.broadcast(); |
1098 _implicitAnalysisEventsController = | 1099 _implicitAnalysisEventsController = |
1099 new StreamController<ImplicitAnalysisEvent>.broadcast(); | 1100 new StreamController<ImplicitAnalysisEvent>.broadcast(); |
1100 } | 1101 } |
1101 | 1102 |
1102 @override | 1103 @override |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1641 List<AnalysisError> errors = new List<AnalysisError>(); | 1642 List<AnalysisError> errors = new List<AnalysisError>(); |
1642 try { | 1643 try { |
1643 DartEntry dartEntry = sourceEntry; | 1644 DartEntry dartEntry = sourceEntry; |
1644 ListUtilities.addAll( | 1645 ListUtilities.addAll( |
1645 errors, _getDartScanData(source, dartEntry, DartEntry.SCAN_ERRORS)); | 1646 errors, _getDartScanData(source, dartEntry, DartEntry.SCAN_ERRORS)); |
1646 dartEntry = _getReadableDartEntry(source); | 1647 dartEntry = _getReadableDartEntry(source); |
1647 ListUtilities.addAll(errors, | 1648 ListUtilities.addAll(errors, |
1648 _getDartParseData(source, dartEntry, DartEntry.PARSE_ERRORS)); | 1649 _getDartParseData(source, dartEntry, DartEntry.PARSE_ERRORS)); |
1649 dartEntry = _getReadableDartEntry(source); | 1650 dartEntry = _getReadableDartEntry(source); |
1650 if (dartEntry.getValue(DartEntry.SOURCE_KIND) == SourceKind.LIBRARY) { | 1651 if (dartEntry.getValue(DartEntry.SOURCE_KIND) == SourceKind.LIBRARY) { |
1651 ListUtilities.addAll(errors, _getDartResolutionData( | 1652 ListUtilities.addAll( |
1652 source, source, dartEntry, DartEntry.RESOLUTION_ERRORS)); | 1653 errors, |
1654 _getDartResolutionData( | |
1655 source, source, dartEntry, DartEntry.RESOLUTION_ERRORS)); | |
1653 dartEntry = _getReadableDartEntry(source); | 1656 dartEntry = _getReadableDartEntry(source); |
1654 ListUtilities.addAll(errors, _getDartVerificationData( | 1657 ListUtilities.addAll( |
1655 source, source, dartEntry, DartEntry.VERIFICATION_ERRORS)); | 1658 errors, |
1659 _getDartVerificationData( | |
1660 source, source, dartEntry, DartEntry.VERIFICATION_ERRORS)); | |
1656 if (enableHints) { | 1661 if (enableHints) { |
1657 dartEntry = _getReadableDartEntry(source); | 1662 dartEntry = _getReadableDartEntry(source); |
1658 ListUtilities.addAll(errors, | 1663 ListUtilities.addAll(errors, |
1659 _getDartHintData(source, source, dartEntry, DartEntry.HINTS)); | 1664 _getDartHintData(source, source, dartEntry, DartEntry.HINTS)); |
1660 } | 1665 } |
1661 if (enableLints) { | 1666 if (enableLints) { |
1662 dartEntry = _getReadableDartEntry(source); | 1667 dartEntry = _getReadableDartEntry(source); |
1663 ListUtilities.addAll(errors, | 1668 ListUtilities.addAll(errors, |
1664 _getDartLintData(source, source, dartEntry, DartEntry.LINTS)); | 1669 _getDartLintData(source, source, dartEntry, DartEntry.LINTS)); |
1665 } | 1670 } |
1666 } else { | 1671 } else { |
1667 List<Source> libraries = getLibrariesContaining(source); | 1672 List<Source> libraries = getLibrariesContaining(source); |
1668 for (Source librarySource in libraries) { | 1673 for (Source librarySource in libraries) { |
1669 ListUtilities.addAll(errors, _getDartResolutionData( | 1674 ListUtilities.addAll( |
1670 source, librarySource, dartEntry, DartEntry.RESOLUTION_ERRORS)); | 1675 errors, |
1676 _getDartResolutionData(source, librarySource, dartEntry, | |
1677 DartEntry.RESOLUTION_ERRORS)); | |
1671 dartEntry = _getReadableDartEntry(source); | 1678 dartEntry = _getReadableDartEntry(source); |
1672 ListUtilities.addAll(errors, _getDartVerificationData(source, | 1679 ListUtilities.addAll( |
1673 librarySource, dartEntry, DartEntry.VERIFICATION_ERRORS)); | 1680 errors, |
1681 _getDartVerificationData(source, librarySource, dartEntry, | |
1682 DartEntry.VERIFICATION_ERRORS)); | |
1674 if (enableHints) { | 1683 if (enableHints) { |
1675 dartEntry = _getReadableDartEntry(source); | 1684 dartEntry = _getReadableDartEntry(source); |
1676 ListUtilities.addAll(errors, _getDartHintData( | 1685 ListUtilities.addAll( |
1677 source, librarySource, dartEntry, DartEntry.HINTS)); | 1686 errors, |
1687 _getDartHintData( | |
1688 source, librarySource, dartEntry, DartEntry.HINTS)); | |
1678 } | 1689 } |
1679 if (enableLints) { | 1690 if (enableLints) { |
1680 dartEntry = _getReadableDartEntry(source); | 1691 dartEntry = _getReadableDartEntry(source); |
1681 ListUtilities.addAll(errors, _getDartLintData( | 1692 ListUtilities.addAll( |
1682 source, librarySource, dartEntry, DartEntry.LINTS)); | 1693 errors, |
1694 _getDartLintData( | |
1695 source, librarySource, dartEntry, DartEntry.LINTS)); | |
1683 } | 1696 } |
1684 } | 1697 } |
1685 } | 1698 } |
1686 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { | 1699 } on ObsoleteSourceAnalysisException catch (exception, stackTrace) { |
1687 AnalysisEngine.instance.logger.logInformation( | 1700 AnalysisEngine.instance.logger.logInformation( |
1688 "Could not compute errors", | 1701 "Could not compute errors", |
1689 new CaughtException(exception, stackTrace)); | 1702 new CaughtException(exception, stackTrace)); |
1690 } | 1703 } |
1691 if (errors.isEmpty) { | 1704 if (errors.isEmpty) { |
1692 return AnalysisError.NO_ERRORS; | 1705 return AnalysisError.NO_ERRORS; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1768 throw new AnalysisException( | 1781 throw new AnalysisException( |
1769 "Internal error: computeResolvableCompilationUnit could not parse ${so urce.fullName}", | 1782 "Internal error: computeResolvableCompilationUnit could not parse ${so urce.fullName}", |
1770 new CaughtException(dartEntry.exception, null)); | 1783 new CaughtException(dartEntry.exception, null)); |
1771 } | 1784 } |
1772 return unit; | 1785 return unit; |
1773 } | 1786 } |
1774 | 1787 |
1775 @override | 1788 @override |
1776 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( | 1789 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( |
1777 Source unitSource, Source librarySource) { | 1790 Source unitSource, Source librarySource) { |
1778 return new _AnalysisFutureHelper<CompilationUnit>(this).computeAsync( | 1791 return new _AnalysisFutureHelper<CompilationUnit>(this) |
1779 unitSource, (SourceEntry sourceEntry) { | 1792 .computeAsync(unitSource, (SourceEntry sourceEntry) { |
1780 if (sourceEntry is DartEntry) { | 1793 if (sourceEntry is DartEntry) { |
1781 if (sourceEntry.getStateInLibrary( | 1794 if (sourceEntry.getStateInLibrary( |
1782 DartEntry.RESOLVED_UNIT, librarySource) == | 1795 DartEntry.RESOLVED_UNIT, librarySource) == |
1783 CacheState.ERROR) { | 1796 CacheState.ERROR) { |
1784 throw sourceEntry.exception; | 1797 throw sourceEntry.exception; |
1785 } | 1798 } |
1786 return sourceEntry.getValueInLibrary( | 1799 return sourceEntry.getValueInLibrary( |
1787 DartEntry.RESOLVED_UNIT, librarySource); | 1800 DartEntry.RESOLVED_UNIT, librarySource); |
1788 } | 1801 } |
1789 throw new AnalysisNotScheduledError(); | 1802 throw new AnalysisNotScheduledError(); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2110 Namespace namespace = null; | 2123 Namespace namespace = null; |
2111 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { | 2124 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { |
2112 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); | 2125 namespace = dartEntry.getValue(DartEntry.PUBLIC_NAMESPACE); |
2113 } | 2126 } |
2114 if (namespace == null) { | 2127 if (namespace == null) { |
2115 NamespaceBuilder builder = new NamespaceBuilder(); | 2128 NamespaceBuilder builder = new NamespaceBuilder(); |
2116 namespace = builder.createPublicNamespaceForLibrary(library); | 2129 namespace = builder.createPublicNamespaceForLibrary(library); |
2117 if (dartEntry == null) { | 2130 if (dartEntry == null) { |
2118 AnalysisEngine.instance.logger.logError( | 2131 AnalysisEngine.instance.logger.logError( |
2119 "Could not compute the public namespace for ${library.source.fullNam e}", | 2132 "Could not compute the public namespace for ${library.source.fullNam e}", |
2120 new CaughtException(new AnalysisException( | 2133 new CaughtException( |
2134 new AnalysisException( | |
2121 "A Dart file became a non-Dart file: ${source.fullName}"), | 2135 "A Dart file became a non-Dart file: ${source.fullName}"), |
2122 null)); | 2136 null)); |
2123 return null; | 2137 return null; |
2124 } | 2138 } |
2125 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { | 2139 if (identical(dartEntry.getValue(DartEntry.ELEMENT), library)) { |
2126 dartEntry.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); | 2140 dartEntry.setValue(DartEntry.PUBLIC_NAMESPACE, namespace); |
2127 } | 2141 } |
2128 } | 2142 } |
2129 return namespace; | 2143 return namespace; |
2130 } | 2144 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2305 } | 2319 } |
2306 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { | 2320 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { |
2307 int getStart = JavaSystem.currentTimeMillis(); | 2321 int getStart = JavaSystem.currentTimeMillis(); |
2308 AnalysisTask task = PerformanceStatistics.nextTask | 2322 AnalysisTask task = PerformanceStatistics.nextTask |
2309 .makeCurrentWhile(() => nextAnalysisTask); | 2323 .makeCurrentWhile(() => nextAnalysisTask); |
2310 int getEnd = JavaSystem.currentTimeMillis(); | 2324 int getEnd = JavaSystem.currentTimeMillis(); |
2311 if (task == null) { | 2325 if (task == null) { |
2312 _validateLastIncrementalResolutionResult(); | 2326 _validateLastIncrementalResolutionResult(); |
2313 if (_performAnalysisTaskStopwatch != null) { | 2327 if (_performAnalysisTaskStopwatch != null) { |
2314 AnalysisEngine.instance.instrumentationService.logPerformance( | 2328 AnalysisEngine.instance.instrumentationService.logPerformance( |
2315 AnalysisPerformanceKind.FULL, _performAnalysisTaskStopwatch, | 2329 AnalysisPerformanceKind.FULL, |
2330 _performAnalysisTaskStopwatch, | |
2316 'context_id=$_id'); | 2331 'context_id=$_id'); |
2317 _performAnalysisTaskStopwatch = null; | 2332 _performAnalysisTaskStopwatch = null; |
2318 } | 2333 } |
2319 return new AnalysisResult( | 2334 return new AnalysisResult( |
2320 _getChangeNotices(true), getEnd - getStart, null, -1); | 2335 _getChangeNotices(true), getEnd - getStart, null, -1); |
2321 } | 2336 } |
2322 if (_performAnalysisTaskStopwatch == null) { | 2337 if (_performAnalysisTaskStopwatch == null) { |
2323 _performAnalysisTaskStopwatch = new Stopwatch()..start(); | 2338 _performAnalysisTaskStopwatch = new Stopwatch()..start(); |
2324 } | 2339 } |
2325 String taskDescription = task.toString(); | 2340 String taskDescription = task.toString(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2559 CompilationUnit resolveCompilationUnit( | 2574 CompilationUnit resolveCompilationUnit( |
2560 Source unitSource, LibraryElement library) { | 2575 Source unitSource, LibraryElement library) { |
2561 if (library == null) { | 2576 if (library == null) { |
2562 return null; | 2577 return null; |
2563 } | 2578 } |
2564 return resolveCompilationUnit2(unitSource, library.source); | 2579 return resolveCompilationUnit2(unitSource, library.source); |
2565 } | 2580 } |
2566 | 2581 |
2567 @override | 2582 @override |
2568 CompilationUnit resolveCompilationUnit2( | 2583 CompilationUnit resolveCompilationUnit2( |
2569 Source unitSource, Source librarySource) => _getDartResolutionData2( | 2584 Source unitSource, Source librarySource) => |
2585 _getDartResolutionData2( | |
2570 unitSource, librarySource, DartEntry.RESOLVED_UNIT, null); | 2586 unitSource, librarySource, DartEntry.RESOLVED_UNIT, null); |
2571 | 2587 |
2572 @override | 2588 @override |
2573 @deprecated | 2589 @deprecated |
2574 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { | 2590 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { |
2575 computeHtmlElement(htmlSource); | 2591 computeHtmlElement(htmlSource); |
2576 return parseHtmlUnit(htmlSource); | 2592 return parseHtmlUnit(htmlSource); |
2577 } | 2593 } |
2578 | 2594 |
2579 @override | 2595 @override |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2883 // | 2899 // |
2884 // Check to see whether we already have the information being requested. | 2900 // Check to see whether we already have the information being requested. |
2885 // | 2901 // |
2886 CacheState state = dartEntry.getState(descriptor); | 2902 CacheState state = dartEntry.getState(descriptor); |
2887 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2903 while (state != CacheState.ERROR && state != CacheState.VALID) { |
2888 // | 2904 // |
2889 // If not, compute the information. Unless the modification date of the | 2905 // If not, compute the information. Unless the modification date of the |
2890 // source continues to change, this loop will eventually terminate. | 2906 // source continues to change, this loop will eventually terminate. |
2891 // | 2907 // |
2892 dartEntry = _cacheDartScanData(source, dartEntry, DartEntry.TOKEN_STREAM); | 2908 dartEntry = _cacheDartScanData(source, dartEntry, DartEntry.TOKEN_STREAM); |
2893 dartEntry = new ParseDartTask(this, source, | 2909 dartEntry = new ParseDartTask( |
2910 this, | |
2911 source, | |
2894 dartEntry.getValue(DartEntry.TOKEN_STREAM), | 2912 dartEntry.getValue(DartEntry.TOKEN_STREAM), |
2895 dartEntry.getValue(SourceEntry.LINE_INFO)) | 2913 dartEntry.getValue(SourceEntry.LINE_INFO)) |
2896 .perform(_resultRecorder) as DartEntry; | 2914 .perform(_resultRecorder) as DartEntry; |
2897 state = dartEntry.getState(descriptor); | 2915 state = dartEntry.getState(descriptor); |
2898 } | 2916 } |
2899 return dartEntry; | 2917 return dartEntry; |
2900 } | 2918 } |
2901 | 2919 |
2902 /** | 2920 /** |
2903 * Given a source for a Dart file and the library that contains it, return a | 2921 * Given a source for a Dart file and the library that contains it, return a |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2947 // Check to see whether we already have the information being requested. | 2965 // Check to see whether we already have the information being requested. |
2948 // | 2966 // |
2949 CacheState state = dartEntry.getState(descriptor); | 2967 CacheState state = dartEntry.getState(descriptor); |
2950 while (state != CacheState.ERROR && state != CacheState.VALID) { | 2968 while (state != CacheState.ERROR && state != CacheState.VALID) { |
2951 // | 2969 // |
2952 // If not, compute the information. Unless the modification date of the | 2970 // If not, compute the information. Unless the modification date of the |
2953 // source continues to change, this loop will eventually terminate. | 2971 // source continues to change, this loop will eventually terminate. |
2954 // | 2972 // |
2955 try { | 2973 try { |
2956 if (dartEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { | 2974 if (dartEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { |
2957 dartEntry = new GetContentTask(this, source) | 2975 dartEntry = new GetContentTask(this, source).perform(_resultRecorder) |
2958 .perform(_resultRecorder) as DartEntry; | 2976 as DartEntry; |
2959 } | 2977 } |
2960 dartEntry = new ScanDartTask( | 2978 dartEntry = new ScanDartTask( |
2961 this, source, dartEntry.getValue(SourceEntry.CONTENT)) | 2979 this, source, dartEntry.getValue(SourceEntry.CONTENT)) |
2962 .perform(_resultRecorder) as DartEntry; | 2980 .perform(_resultRecorder) as DartEntry; |
2963 } on AnalysisException catch (exception) { | 2981 } on AnalysisException catch (exception) { |
2964 throw exception; | 2982 throw exception; |
2965 } catch (exception, stackTrace) { | 2983 } catch (exception, stackTrace) { |
2966 throw new AnalysisException( | 2984 throw new AnalysisException( |
2967 "Exception", new CaughtException(exception, stackTrace)); | 2985 "Exception", new CaughtException(exception, stackTrace)); |
2968 } | 2986 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3024 // Check to see whether we already have the information being requested. | 3042 // Check to see whether we already have the information being requested. |
3025 // | 3043 // |
3026 CacheState state = htmlEntry.getState(descriptor); | 3044 CacheState state = htmlEntry.getState(descriptor); |
3027 while (state != CacheState.ERROR && state != CacheState.VALID) { | 3045 while (state != CacheState.ERROR && state != CacheState.VALID) { |
3028 // | 3046 // |
3029 // If not, compute the information. Unless the modification date of the | 3047 // If not, compute the information. Unless the modification date of the |
3030 // source continues to change, this loop will eventually terminate. | 3048 // source continues to change, this loop will eventually terminate. |
3031 // | 3049 // |
3032 try { | 3050 try { |
3033 if (htmlEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { | 3051 if (htmlEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { |
3034 htmlEntry = new GetContentTask(this, source) | 3052 htmlEntry = new GetContentTask(this, source).perform(_resultRecorder) |
3035 .perform(_resultRecorder) as HtmlEntry; | 3053 as HtmlEntry; |
3036 } | 3054 } |
3037 htmlEntry = new ParseHtmlTask( | 3055 htmlEntry = new ParseHtmlTask( |
3038 this, source, htmlEntry.getValue(SourceEntry.CONTENT)) | 3056 this, source, htmlEntry.getValue(SourceEntry.CONTENT)) |
3039 .perform(_resultRecorder) as HtmlEntry; | 3057 .perform(_resultRecorder) as HtmlEntry; |
3040 } on AnalysisException catch (exception) { | 3058 } on AnalysisException catch (exception) { |
3041 throw exception; | 3059 throw exception; |
3042 } catch (exception, stackTrace) { | 3060 } catch (exception, stackTrace) { |
3043 throw new AnalysisException( | 3061 throw new AnalysisException( |
3044 "Exception", new CaughtException(exception, stackTrace)); | 3062 "Exception", new CaughtException(exception, stackTrace)); |
3045 } | 3063 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3161 * event where as this method does not. | 3179 * event where as this method does not. |
3162 */ | 3180 */ |
3163 bool _contentRangeChanged(Source source, String contents, int offset, | 3181 bool _contentRangeChanged(Source source, String contents, int offset, |
3164 int oldLength, int newLength) { | 3182 int oldLength, int newLength) { |
3165 bool changed = false; | 3183 bool changed = false; |
3166 String originalContents = _contentCache.setContents(source, contents); | 3184 String originalContents = _contentCache.setContents(source, contents); |
3167 if (contents != null) { | 3185 if (contents != null) { |
3168 if (contents != originalContents) { | 3186 if (contents != originalContents) { |
3169 if (_options.incremental) { | 3187 if (_options.incremental) { |
3170 _incrementalAnalysisCache = IncrementalAnalysisCache.update( | 3188 _incrementalAnalysisCache = IncrementalAnalysisCache.update( |
3171 _incrementalAnalysisCache, source, originalContents, contents, | 3189 _incrementalAnalysisCache, |
3172 offset, oldLength, newLength, _getReadableSourceEntry(source)); | 3190 source, |
3191 originalContents, | |
3192 contents, | |
3193 offset, | |
3194 oldLength, | |
3195 newLength, | |
3196 _getReadableSourceEntry(source)); | |
3173 } | 3197 } |
3174 _sourceChanged(source); | 3198 _sourceChanged(source); |
3175 changed = true; | 3199 changed = true; |
3176 SourceEntry sourceEntry = _cache.get(source); | 3200 SourceEntry sourceEntry = _cache.get(source); |
3177 if (sourceEntry != null) { | 3201 if (sourceEntry != null) { |
3178 sourceEntry.modificationTime = | 3202 sourceEntry.modificationTime = |
3179 _contentCache.getModificationStamp(source); | 3203 _contentCache.getModificationStamp(source); |
3180 sourceEntry.setValue(SourceEntry.CONTENT, contents); | 3204 sourceEntry.setValue(SourceEntry.CONTENT, contents); |
3181 } | 3205 } |
3182 } | 3206 } |
(...skipping 27 matching lines...) Expand all Loading... | |
3210 AnalysisContextImpl_TaskData _createGenerateDartErrorsTask(Source unitSource, | 3234 AnalysisContextImpl_TaskData _createGenerateDartErrorsTask(Source unitSource, |
3211 DartEntry unitEntry, Source librarySource, DartEntry libraryEntry) { | 3235 DartEntry unitEntry, Source librarySource, DartEntry libraryEntry) { |
3212 if (unitEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) != | 3236 if (unitEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) != |
3213 CacheState.VALID || | 3237 CacheState.VALID || |
3214 libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { | 3238 libraryEntry.getState(DartEntry.ELEMENT) != CacheState.VALID) { |
3215 return _createResolveDartLibraryTask(librarySource, libraryEntry); | 3239 return _createResolveDartLibraryTask(librarySource, libraryEntry); |
3216 } | 3240 } |
3217 CompilationUnit unit = | 3241 CompilationUnit unit = |
3218 unitEntry.getValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource); | 3242 unitEntry.getValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource); |
3219 if (unit == null) { | 3243 if (unit == null) { |
3220 CaughtException exception = new CaughtException(new AnalysisException( | 3244 CaughtException exception = new CaughtException( |
3245 new AnalysisException( | |
3221 "Entry has VALID state for RESOLVED_UNIT but null value for ${unit Source.fullName} in ${librarySource.fullName}"), | 3246 "Entry has VALID state for RESOLVED_UNIT but null value for ${unit Source.fullName} in ${librarySource.fullName}"), |
3222 null); | 3247 null); |
3223 AnalysisEngine.instance.logger.logInformation( | 3248 AnalysisEngine.instance.logger |
3224 exception.toString(), exception); | 3249 .logInformation(exception.toString(), exception); |
3225 unitEntry.recordResolutionError(exception); | 3250 unitEntry.recordResolutionError(exception); |
3226 return new AnalysisContextImpl_TaskData(null, false); | 3251 return new AnalysisContextImpl_TaskData(null, false); |
3227 } | 3252 } |
3228 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); | 3253 LibraryElement libraryElement = libraryEntry.getValue(DartEntry.ELEMENT); |
3229 return new AnalysisContextImpl_TaskData( | 3254 return new AnalysisContextImpl_TaskData( |
3230 new GenerateDartErrorsTask(this, unitSource, unit, libraryElement), | 3255 new GenerateDartErrorsTask(this, unitSource, unit, libraryElement), |
3231 false); | 3256 false); |
3232 } | 3257 } |
3233 | 3258 |
3234 /** | 3259 /** |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3312 * Create a [ParseDartTask] for the given [source]. | 3337 * Create a [ParseDartTask] for the given [source]. |
3313 */ | 3338 */ |
3314 AnalysisContextImpl_TaskData _createParseDartTask( | 3339 AnalysisContextImpl_TaskData _createParseDartTask( |
3315 Source source, DartEntry dartEntry) { | 3340 Source source, DartEntry dartEntry) { |
3316 if (dartEntry.getState(DartEntry.TOKEN_STREAM) != CacheState.VALID || | 3341 if (dartEntry.getState(DartEntry.TOKEN_STREAM) != CacheState.VALID || |
3317 dartEntry.getState(SourceEntry.LINE_INFO) != CacheState.VALID) { | 3342 dartEntry.getState(SourceEntry.LINE_INFO) != CacheState.VALID) { |
3318 return _createScanDartTask(source, dartEntry); | 3343 return _createScanDartTask(source, dartEntry); |
3319 } | 3344 } |
3320 Token tokenStream = dartEntry.getValue(DartEntry.TOKEN_STREAM); | 3345 Token tokenStream = dartEntry.getValue(DartEntry.TOKEN_STREAM); |
3321 dartEntry.setState(DartEntry.TOKEN_STREAM, CacheState.FLUSHED); | 3346 dartEntry.setState(DartEntry.TOKEN_STREAM, CacheState.FLUSHED); |
3322 return new AnalysisContextImpl_TaskData(new ParseDartTask(this, source, | 3347 return new AnalysisContextImpl_TaskData( |
3323 tokenStream, dartEntry.getValue(SourceEntry.LINE_INFO)), false); | 3348 new ParseDartTask(this, source, tokenStream, |
3349 dartEntry.getValue(SourceEntry.LINE_INFO)), | |
3350 false); | |
3324 } | 3351 } |
3325 | 3352 |
3326 /** | 3353 /** |
3327 * Create a [ParseHtmlTask] for the given [source]. | 3354 * Create a [ParseHtmlTask] for the given [source]. |
3328 */ | 3355 */ |
3329 AnalysisContextImpl_TaskData _createParseHtmlTask( | 3356 AnalysisContextImpl_TaskData _createParseHtmlTask( |
3330 Source source, HtmlEntry htmlEntry) { | 3357 Source source, HtmlEntry htmlEntry) { |
3331 if (htmlEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { | 3358 if (htmlEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { |
3332 return _createGetContentTask(source, htmlEntry); | 3359 return _createGetContentTask(source, htmlEntry); |
3333 } | 3360 } |
(...skipping 12 matching lines...) Expand all Loading... | |
3346 try { | 3373 try { |
3347 AnalysisContextImpl_CycleBuilder builder = | 3374 AnalysisContextImpl_CycleBuilder builder = |
3348 new AnalysisContextImpl_CycleBuilder(this); | 3375 new AnalysisContextImpl_CycleBuilder(this); |
3349 PerformanceStatistics.cycles.makeCurrentWhile(() { | 3376 PerformanceStatistics.cycles.makeCurrentWhile(() { |
3350 builder.computeCycleContaining(source); | 3377 builder.computeCycleContaining(source); |
3351 }); | 3378 }); |
3352 AnalysisContextImpl_TaskData taskData = builder.taskData; | 3379 AnalysisContextImpl_TaskData taskData = builder.taskData; |
3353 if (taskData != null) { | 3380 if (taskData != null) { |
3354 return taskData; | 3381 return taskData; |
3355 } | 3382 } |
3356 return new AnalysisContextImpl_TaskData(new ResolveDartLibraryCycleTask( | 3383 return new AnalysisContextImpl_TaskData( |
3357 this, source, source, builder.librariesInCycle), false); | 3384 new ResolveDartLibraryCycleTask( |
3385 this, source, source, builder.librariesInCycle), | |
3386 false); | |
3358 } on AnalysisException catch (exception, stackTrace) { | 3387 } on AnalysisException catch (exception, stackTrace) { |
3359 dartEntry | 3388 dartEntry |
3360 .recordResolutionError(new CaughtException(exception, stackTrace)); | 3389 .recordResolutionError(new CaughtException(exception, stackTrace)); |
3361 AnalysisEngine.instance.logger.logError( | 3390 AnalysisEngine.instance.logger.logError( |
3362 "Internal error trying to create a ResolveDartLibraryTask", | 3391 "Internal error trying to create a ResolveDartLibraryTask", |
3363 new CaughtException(exception, stackTrace)); | 3392 new CaughtException(exception, stackTrace)); |
3364 } | 3393 } |
3365 return new AnalysisContextImpl_TaskData(null, false); | 3394 return new AnalysisContextImpl_TaskData(null, false); |
3366 } | 3395 } |
3367 | 3396 |
3368 /** | 3397 /** |
3369 * Create a [ResolveHtmlTask] for the given [source], marking the resolved | 3398 * Create a [ResolveHtmlTask] for the given [source], marking the resolved |
3370 * unit as being in-process. | 3399 * unit as being in-process. |
3371 */ | 3400 */ |
3372 AnalysisContextImpl_TaskData _createResolveHtmlTask( | 3401 AnalysisContextImpl_TaskData _createResolveHtmlTask( |
3373 Source source, HtmlEntry htmlEntry) { | 3402 Source source, HtmlEntry htmlEntry) { |
3374 if (htmlEntry.getState(HtmlEntry.PARSED_UNIT) != CacheState.VALID) { | 3403 if (htmlEntry.getState(HtmlEntry.PARSED_UNIT) != CacheState.VALID) { |
3375 return _createParseHtmlTask(source, htmlEntry); | 3404 return _createParseHtmlTask(source, htmlEntry); |
3376 } | 3405 } |
3377 return new AnalysisContextImpl_TaskData(new ResolveHtmlTask(this, source, | 3406 return new AnalysisContextImpl_TaskData( |
3378 htmlEntry.modificationTime, | 3407 new ResolveHtmlTask(this, source, htmlEntry.modificationTime, |
3379 htmlEntry.getValue(HtmlEntry.PARSED_UNIT)), false); | 3408 htmlEntry.getValue(HtmlEntry.PARSED_UNIT)), |
3409 false); | |
3380 } | 3410 } |
3381 | 3411 |
3382 /** | 3412 /** |
3383 * Create a [ScanDartTask] for the given [source], marking the scan errors as | 3413 * Create a [ScanDartTask] for the given [source], marking the scan errors as |
3384 * being in-process. | 3414 * being in-process. |
3385 */ | 3415 */ |
3386 AnalysisContextImpl_TaskData _createScanDartTask( | 3416 AnalysisContextImpl_TaskData _createScanDartTask( |
3387 Source source, DartEntry dartEntry) { | 3417 Source source, DartEntry dartEntry) { |
3388 if (dartEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { | 3418 if (dartEntry.getState(SourceEntry.CONTENT) != CacheState.VALID) { |
3389 return _createGetContentTask(source, dartEntry); | 3419 return _createGetContentTask(source, dartEntry); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3713 _accessedAst(source); | 3743 _accessedAst(source); |
3714 } | 3744 } |
3715 return htmlEntry.getValue(descriptor); | 3745 return htmlEntry.getValue(descriptor); |
3716 } | 3746 } |
3717 | 3747 |
3718 /** | 3748 /** |
3719 * Look at the given [source] to see whether a task needs to be performed | 3749 * Look at the given [source] to see whether a task needs to be performed |
3720 * related to it. Return the task that should be performed, or `null` if there | 3750 * related to it. Return the task that should be performed, or `null` if there |
3721 * is no more work to be done for the source. | 3751 * is no more work to be done for the source. |
3722 */ | 3752 */ |
3723 AnalysisContextImpl_TaskData _getNextAnalysisTaskForSource(Source source, | 3753 AnalysisContextImpl_TaskData _getNextAnalysisTaskForSource( |
3724 SourceEntry sourceEntry, bool isPriority, bool hintsEnabled, | 3754 Source source, |
3755 SourceEntry sourceEntry, | |
3756 bool isPriority, | |
3757 bool hintsEnabled, | |
3725 bool lintsEnabled) { | 3758 bool lintsEnabled) { |
3726 // Refuse to generate tasks for html based files that are above 1500 KB | 3759 // Refuse to generate tasks for html based files that are above 1500 KB |
3727 if (_isTooBigHtmlSourceEntry(source, sourceEntry)) { | 3760 if (_isTooBigHtmlSourceEntry(source, sourceEntry)) { |
3728 // TODO (jwren) we still need to report an error of some kind back to the | 3761 // TODO (jwren) we still need to report an error of some kind back to the |
3729 // client. | 3762 // client. |
3730 return new AnalysisContextImpl_TaskData(null, false); | 3763 return new AnalysisContextImpl_TaskData(null, false); |
3731 } | 3764 } |
3732 if (sourceEntry == null) { | 3765 if (sourceEntry == null) { |
3733 return new AnalysisContextImpl_TaskData(null, false); | 3766 return new AnalysisContextImpl_TaskData(null, false); |
3734 } | 3767 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3904 * the library defined by the given [librarySource], or `null` if the | 3937 * the library defined by the given [librarySource], or `null` if the |
3905 * information is not cached. | 3938 * information is not cached. |
3906 */ | 3939 */ |
3907 TimestampedData<CompilationUnit> _getResolvedUnit( | 3940 TimestampedData<CompilationUnit> _getResolvedUnit( |
3908 CompilationUnitElement element, Source librarySource) { | 3941 CompilationUnitElement element, Source librarySource) { |
3909 SourceEntry sourceEntry = _cache.get(element.source); | 3942 SourceEntry sourceEntry = _cache.get(element.source); |
3910 if (sourceEntry is DartEntry) { | 3943 if (sourceEntry is DartEntry) { |
3911 DartEntry dartEntry = sourceEntry; | 3944 DartEntry dartEntry = sourceEntry; |
3912 if (dartEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) == | 3945 if (dartEntry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource) == |
3913 CacheState.VALID) { | 3946 CacheState.VALID) { |
3914 return new TimestampedData<CompilationUnit>(dartEntry.modificationTime, | 3947 return new TimestampedData<CompilationUnit>( |
3948 dartEntry.modificationTime, | |
3915 dartEntry.getValueInLibrary( | 3949 dartEntry.getValueInLibrary( |
3916 DartEntry.RESOLVED_UNIT, librarySource)); | 3950 DartEntry.RESOLVED_UNIT, librarySource)); |
3917 } | 3951 } |
3918 } | 3952 } |
3919 return null; | 3953 return null; |
3920 } | 3954 } |
3921 | 3955 |
3922 /** | 3956 /** |
3923 * Return a list containing all of the sources known to this context that have | 3957 * Return a list containing all of the sources known to this context that have |
3924 * the given [kind]. | 3958 * the given [kind]. |
3925 */ | 3959 */ |
3926 List<Source> _getSources(SourceKind kind) { | 3960 List<Source> _getSources(SourceKind kind) { |
3927 List<Source> sources = new List<Source>(); | 3961 List<Source> sources = new List<Source>(); |
3928 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); | 3962 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); |
3929 while (iterator.moveNext()) { | 3963 while (iterator.moveNext()) { |
3930 if (iterator.value.kind == kind) { | 3964 if (iterator.value.kind == kind) { |
3931 sources.add(iterator.key); | 3965 sources.add(iterator.key); |
3932 } | 3966 } |
3933 } | 3967 } |
3934 return sources; | 3968 return sources; |
3935 } | 3969 } |
3936 | 3970 |
3937 /** | 3971 /** |
3938 * Look at the given [source] to see whether a task needs to be performed | 3972 * Look at the given [source] to see whether a task needs to be performed |
3939 * related to it. If so, add the source to the set of sources that need to be | 3973 * related to it. If so, add the source to the set of sources that need to be |
3940 * processed. This method duplicates, and must therefore be kept in sync with, | 3974 * processed. This method duplicates, and must therefore be kept in sync with, |
3941 * [_getNextAnalysisTaskForSource]. This method is intended to be used for | 3975 * [_getNextAnalysisTaskForSource]. This method is intended to be used for |
3942 * testing purposes only. | 3976 * testing purposes only. |
3943 */ | 3977 */ |
3944 void _getSourcesNeedingProcessing(Source source, SourceEntry sourceEntry, | 3978 void _getSourcesNeedingProcessing( |
3945 bool isPriority, bool hintsEnabled, bool lintsEnabled, | 3979 Source source, |
3980 SourceEntry sourceEntry, | |
3981 bool isPriority, | |
3982 bool hintsEnabled, | |
3983 bool lintsEnabled, | |
3946 HashSet<Source> sources) { | 3984 HashSet<Source> sources) { |
3947 if (sourceEntry is DartEntry) { | 3985 if (sourceEntry is DartEntry) { |
3948 DartEntry dartEntry = sourceEntry; | 3986 DartEntry dartEntry = sourceEntry; |
3949 CacheState scanErrorsState = dartEntry.getState(DartEntry.SCAN_ERRORS); | 3987 CacheState scanErrorsState = dartEntry.getState(DartEntry.SCAN_ERRORS); |
3950 if (scanErrorsState == CacheState.INVALID || | 3988 if (scanErrorsState == CacheState.INVALID || |
3951 (isPriority && scanErrorsState == CacheState.FLUSHED)) { | 3989 (isPriority && scanErrorsState == CacheState.FLUSHED)) { |
3952 sources.add(source); | 3990 sources.add(source); |
3953 return; | 3991 return; |
3954 } | 3992 } |
3955 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERRORS); | 3993 CacheState parseErrorsState = dartEntry.getState(DartEntry.PARSE_ERRORS); |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4789 } | 4827 } |
4790 // prepare the existing unit | 4828 // prepare the existing unit |
4791 CompilationUnit oldUnit = | 4829 CompilationUnit oldUnit = |
4792 getResolvedCompilationUnit2(unitSource, librarySource); | 4830 getResolvedCompilationUnit2(unitSource, librarySource); |
4793 if (oldUnit == null) { | 4831 if (oldUnit == null) { |
4794 return false; | 4832 return false; |
4795 } | 4833 } |
4796 // do resolution | 4834 // do resolution |
4797 Stopwatch perfCounter = new Stopwatch()..start(); | 4835 Stopwatch perfCounter = new Stopwatch()..start(); |
4798 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( | 4836 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( |
4799 typeProvider, unitSource, getReadableSourceEntryOrNull(unitSource), | 4837 typeProvider, |
4800 null, null, oldUnit, analysisOptions.incrementalApi, analysisOptions); | 4838 unitSource, |
4839 getReadableSourceEntryOrNull(unitSource), | |
4840 null, | |
4841 null, | |
4842 oldUnit, | |
4843 analysisOptions.incrementalApi, | |
4844 analysisOptions); | |
4801 bool success = resolver.resolve(newCode); | 4845 bool success = resolver.resolve(newCode); |
4802 AnalysisEngine.instance.instrumentationService.logPerformance( | 4846 AnalysisEngine.instance.instrumentationService.logPerformance( |
4803 AnalysisPerformanceKind.INCREMENTAL, perfCounter, | 4847 AnalysisPerformanceKind.INCREMENTAL, |
4848 perfCounter, | |
4804 'success=$success,context_id=$_id,code_length=${newCode.length}'); | 4849 'success=$success,context_id=$_id,code_length=${newCode.length}'); |
4805 if (!success) { | 4850 if (!success) { |
4806 return false; | 4851 return false; |
4807 } | 4852 } |
4808 // if validation, remember the result, but throw it away | 4853 // if validation, remember the result, but throw it away |
4809 if (analysisOptions.incrementalValidation) { | 4854 if (analysisOptions.incrementalValidation) { |
4810 incrementalResolutionValidation_lastUnitSource = oldUnit.element.source; | 4855 incrementalResolutionValidation_lastUnitSource = oldUnit.element.source; |
4811 incrementalResolutionValidation_lastLibrarySource = | 4856 incrementalResolutionValidation_lastLibrarySource = |
4812 oldUnit.element.library.source; | 4857 oldUnit.element.library.source; |
4813 incrementalResolutionValidation_lastUnit = oldUnit; | 4858 incrementalResolutionValidation_lastUnit = oldUnit; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5013 _librariesInCycle = _dependencyGraph.findCycleContaining(targetLibrary); | 5058 _librariesInCycle = _dependencyGraph.findCycleContaining(targetLibrary); |
5014 // | 5059 // |
5015 // Ensure that all of the data needed to resolve them has been computed. | 5060 // Ensure that all of the data needed to resolve them has been computed. |
5016 // | 5061 // |
5017 _ensureImportsAndExports(); | 5062 _ensureImportsAndExports(); |
5018 if (_taskData != null) { | 5063 if (_taskData != null) { |
5019 // At least one imported library needs to be resolved before the target | 5064 // At least one imported library needs to be resolved before the target |
5020 // library. | 5065 // library. |
5021 AnalysisTask task = _taskData.task; | 5066 AnalysisTask task = _taskData.task; |
5022 if (task is ResolveDartLibraryTask) { | 5067 if (task is ResolveDartLibraryTask) { |
5023 AnalysisContextImpl_this._workManager.addFirst( | 5068 AnalysisContextImpl_this._workManager |
5024 task.librarySource, SourcePriority.LIBRARY); | 5069 .addFirst(task.librarySource, SourcePriority.LIBRARY); |
5025 } | 5070 } |
5026 return; | 5071 return; |
5027 } | 5072 } |
5028 _computePartsInCycle(librarySource); | 5073 _computePartsInCycle(librarySource); |
5029 if (_taskData != null) { | 5074 if (_taskData != null) { |
5030 // At least one part needs to be parsed. | 5075 // At least one part needs to be parsed. |
5031 return; | 5076 return; |
5032 } | 5077 } |
5033 // All of the AST's necessary to perform a resolution of the library cycle | 5078 // All of the AST's necessary to perform a resolution of the library cycle |
5034 // have been gathered, so it is no longer necessary to retain them in the | 5079 // have been gathered, so it is no longer necessary to retain them in the |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5242 * Ensure that the given [library] has an element model built for it. If | 5287 * Ensure that the given [library] has an element model built for it. If |
5243 * another task needs to be executed first in order to build the element | 5288 * another task needs to be executed first in order to build the element |
5244 * model, that task is placed in [taskData]. | 5289 * model, that task is placed in [taskData]. |
5245 */ | 5290 */ |
5246 void _ensureElementModel(ResolvableLibrary library) { | 5291 void _ensureElementModel(ResolvableLibrary library) { |
5247 Source librarySource = library.librarySource; | 5292 Source librarySource = library.librarySource; |
5248 DartEntry libraryEntry = | 5293 DartEntry libraryEntry = |
5249 AnalysisContextImpl_this._getReadableDartEntry(librarySource); | 5294 AnalysisContextImpl_this._getReadableDartEntry(librarySource); |
5250 if (libraryEntry != null && | 5295 if (libraryEntry != null && |
5251 libraryEntry.getState(DartEntry.PARSED_UNIT) != CacheState.ERROR) { | 5296 libraryEntry.getState(DartEntry.PARSED_UNIT) != CacheState.ERROR) { |
5252 AnalysisContextImpl_this._workManager.addFirst( | 5297 AnalysisContextImpl_this._workManager |
5253 librarySource, SourcePriority.LIBRARY); | 5298 .addFirst(librarySource, SourcePriority.LIBRARY); |
5254 if (_taskData == null) { | 5299 if (_taskData == null) { |
5255 _taskData = AnalysisContextImpl_this._createResolveDartLibraryTask( | 5300 _taskData = AnalysisContextImpl_this._createResolveDartLibraryTask( |
5256 librarySource, libraryEntry); | 5301 librarySource, libraryEntry); |
5257 } | 5302 } |
5258 } | 5303 } |
5259 } | 5304 } |
5260 | 5305 |
5261 /** | 5306 /** |
5262 * Ensure that all of the libraries that are exported by the given [library] | 5307 * Ensure that all of the libraries that are exported by the given [library] |
5263 * (but are not themselves in the cycle) have element models built for them. | 5308 * (but are not themselves in the cycle) have element models built for them. |
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6560 * Perform this analysis task, ensuring that all exceptions are wrapped in an | 6605 * Perform this analysis task, ensuring that all exceptions are wrapped in an |
6561 * [AnalysisException]. Throws an [AnalysisException] if any exception occurs | 6606 * [AnalysisException]. Throws an [AnalysisException] if any exception occurs |
6562 * while performing the task | 6607 * while performing the task |
6563 */ | 6608 */ |
6564 void _safelyPerform() { | 6609 void _safelyPerform() { |
6565 try { | 6610 try { |
6566 String contextName = context.name; | 6611 String contextName = context.name; |
6567 if (contextName == null) { | 6612 if (contextName == null) { |
6568 contextName = 'unnamed'; | 6613 contextName = 'unnamed'; |
6569 } | 6614 } |
6570 AnalysisEngine.instance.instrumentationService.logAnalysisTask( | 6615 AnalysisEngine.instance.instrumentationService |
6571 contextName, taskDescription); | 6616 .logAnalysisTask(contextName, taskDescription); |
6572 internalPerform(); | 6617 internalPerform(); |
6573 } on AnalysisException { | 6618 } on AnalysisException { |
6574 rethrow; | 6619 rethrow; |
6575 } catch (exception, stackTrace) { | 6620 } catch (exception, stackTrace) { |
6576 throw new AnalysisException( | 6621 throw new AnalysisException( |
6577 exception.toString(), new CaughtException(exception, stackTrace)); | 6622 exception.toString(), new CaughtException(exception, stackTrace)); |
6578 } | 6623 } |
6579 } | 6624 } |
6580 } | 6625 } |
6581 | 6626 |
(...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8395 // | 8440 // |
8396 // TODO(paulberry): as a temporary workaround for issue 21572, | 8441 // TODO(paulberry): as a temporary workaround for issue 21572, |
8397 // ConstantVerifier is being run right after ConstantValueComputer, so we | 8442 // ConstantVerifier is being run right after ConstantValueComputer, so we |
8398 // don't need to run it here. Once issue 21572 is fixed, re-enable the | 8443 // don't need to run it here. Once issue 21572 is fixed, re-enable the |
8399 // call to ConstantVerifier. | 8444 // call to ConstantVerifier. |
8400 // ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, libraryElement, typeProvider); | 8445 // ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, libraryElement, typeProvider); |
8401 // _unit.accept(constantVerifier); | 8446 // _unit.accept(constantVerifier); |
8402 // | 8447 // |
8403 // Use the ErrorVerifier to compute the rest of the errors. | 8448 // Use the ErrorVerifier to compute the rest of the errors. |
8404 // | 8449 // |
8405 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, | 8450 ErrorVerifier errorVerifier = new ErrorVerifier( |
8406 libraryElement, typeProvider, new InheritanceManager(libraryElement), | 8451 errorReporter, |
8452 libraryElement, | |
8453 typeProvider, | |
8454 new InheritanceManager(libraryElement), | |
8407 context.analysisOptions.enableSuperMixins); | 8455 context.analysisOptions.enableSuperMixins); |
8408 _unit.accept(errorVerifier); | 8456 _unit.accept(errorVerifier); |
8409 _errors = errorListener.getErrorsForSource(source); | 8457 _errors = errorListener.getErrorsForSource(source); |
8410 }); | 8458 }); |
8411 } | 8459 } |
8412 | 8460 |
8413 /** | 8461 /** |
8414 * Check each directive in the given compilation unit to see if the referenced source exists and | 8462 * Check each directive in the given compilation unit to see if the referenced source exists and |
8415 * report an error if it does not. | 8463 * report an error if it does not. |
8416 * | 8464 * |
(...skipping 14 matching lines...) Expand all Loading... | |
8431 | 8479 |
8432 /** | 8480 /** |
8433 * Check the given directive to see if the referenced source exists and report an error if it does | 8481 * Check the given directive to see if the referenced source exists and report an error if it does |
8434 * not. | 8482 * not. |
8435 * | 8483 * |
8436 * @param context the context in which the library exists | 8484 * @param context the context in which the library exists |
8437 * @param librarySource the source representing the library containing the dir ective | 8485 * @param librarySource the source representing the library containing the dir ective |
8438 * @param directive the directive to be verified | 8486 * @param directive the directive to be verified |
8439 * @param errorListener the error listener to which errors should be reported | 8487 * @param errorListener the error listener to which errors should be reported |
8440 */ | 8488 */ |
8441 static void validateReferencedSource(AnalysisContext context, | 8489 static void validateReferencedSource( |
8442 Source librarySource, UriBasedDirective directive, | 8490 AnalysisContext context, |
8491 Source librarySource, | |
8492 UriBasedDirective directive, | |
8443 AnalysisErrorListener errorListener) { | 8493 AnalysisErrorListener errorListener) { |
8444 Source source = directive.source; | 8494 Source source = directive.source; |
8445 if (source != null) { | 8495 if (source != null) { |
8446 if (context.exists(source)) { | 8496 if (context.exists(source)) { |
8447 return; | 8497 return; |
8448 } | 8498 } |
8449 } else { | 8499 } else { |
8450 // Don't report errors already reported by ParseDartTask.resolveDirective | 8500 // Don't report errors already reported by ParseDartTask.resolveDirective |
8451 if (directive.validate() != null) { | 8501 if (directive.validate() != null) { |
8452 return; | 8502 return; |
8453 } | 8503 } |
8454 } | 8504 } |
8455 StringLiteral uriLiteral = directive.uri; | 8505 StringLiteral uriLiteral = directive.uri; |
8456 errorListener.onError(new AnalysisError(librarySource, uriLiteral.offset, | 8506 errorListener.onError(new AnalysisError( |
8457 uriLiteral.length, CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 8507 librarySource, |
8508 uriLiteral.offset, | |
8509 uriLiteral.length, | |
8510 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | |
8458 [directive.uriContent])); | 8511 [directive.uriContent])); |
8459 } | 8512 } |
8460 } | 8513 } |
8461 | 8514 |
8462 /** | 8515 /** |
8463 * Instances of the class `GenerateDartHintsTask` generate hints for a single Da rt library. | 8516 * Instances of the class `GenerateDartHintsTask` generate hints for a single Da rt library. |
8464 */ | 8517 */ |
8465 class GenerateDartHintsTask extends AnalysisTask { | 8518 class GenerateDartHintsTask extends AnalysisTask { |
8466 /** | 8519 /** |
8467 * The compilation units that comprise the library, with the defining compilat ion unit appearing | 8520 * The compilation units that comprise the library, with the defining compilat ion unit appearing |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8539 _hintMap = new HashMap<Source, List<AnalysisError>>(); | 8592 _hintMap = new HashMap<Source, List<AnalysisError>>(); |
8540 for (int i = 0; i < unitCount; i++) { | 8593 for (int i = 0; i < unitCount; i++) { |
8541 Source source = _units[i].data.element.source; | 8594 Source source = _units[i].data.element.source; |
8542 _hintMap[source] = errorListener.getErrorsForSource(source); | 8595 _hintMap[source] = errorListener.getErrorsForSource(source); |
8543 } | 8596 } |
8544 } | 8597 } |
8545 } | 8598 } |
8546 | 8599 |
8547 /// Generates lint feedback for a single Dart library. | 8600 /// Generates lint feedback for a single Dart library. |
8548 class GenerateDartLintsTask extends AnalysisTask { | 8601 class GenerateDartLintsTask extends AnalysisTask { |
8549 | |
8550 ///The compilation units that comprise the library, with the defining | 8602 ///The compilation units that comprise the library, with the defining |
8551 ///compilation unit appearing first in the list. | 8603 ///compilation unit appearing first in the list. |
8552 final List<TimestampedData<CompilationUnit>> _units; | 8604 final List<TimestampedData<CompilationUnit>> _units; |
8553 | 8605 |
8554 /// The element model for the library being analyzed. | 8606 /// The element model for the library being analyzed. |
8555 final LibraryElement libraryElement; | 8607 final LibraryElement libraryElement; |
8556 | 8608 |
8557 /// A mapping of analyzed sources to their associated lint warnings. | 8609 /// A mapping of analyzed sources to their associated lint warnings. |
8558 /// May be [null] if the task has not been performed or if analysis did not | 8610 /// May be [null] if the task has not been performed or if analysis did not |
8559 /// complete normally. | 8611 /// complete normally. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8669 @override | 8721 @override |
8670 accept(AnalysisTaskVisitor visitor) => visitor.visitGetContentTask(this); | 8722 accept(AnalysisTaskVisitor visitor) => visitor.visitGetContentTask(this); |
8671 | 8723 |
8672 @override | 8724 @override |
8673 void internalPerform() { | 8725 void internalPerform() { |
8674 _complete = true; | 8726 _complete = true; |
8675 try { | 8727 try { |
8676 TimestampedData<String> data = context.getContents(source); | 8728 TimestampedData<String> data = context.getContents(source); |
8677 _content = data.data; | 8729 _content = data.data; |
8678 _modificationTime = data.modificationTime; | 8730 _modificationTime = data.modificationTime; |
8679 AnalysisEngine.instance.instrumentationService.logFileRead( | 8731 AnalysisEngine.instance.instrumentationService |
8680 source.fullName, _modificationTime, _content); | 8732 .logFileRead(source.fullName, _modificationTime, _content); |
8681 } catch (exception, stackTrace) { | 8733 } catch (exception, stackTrace) { |
8682 errors.add(new AnalysisError( | 8734 errors.add(new AnalysisError( |
8683 source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [exception])); | 8735 source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, [exception])); |
8684 throw new AnalysisException("Could not get contents of $source", | 8736 throw new AnalysisException("Could not get contents of $source", |
8685 new CaughtException(exception, stackTrace)); | 8737 new CaughtException(exception, stackTrace)); |
8686 } | 8738 } |
8687 } | 8739 } |
8688 } | 8740 } |
8689 | 8741 |
8690 /** | 8742 /** |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8955 final CompilationUnit resolvedUnit; | 9007 final CompilationUnit resolvedUnit; |
8956 | 9008 |
8957 String _newContents; | 9009 String _newContents; |
8958 | 9010 |
8959 int _offset = 0; | 9011 int _offset = 0; |
8960 | 9012 |
8961 int _oldLength = 0; | 9013 int _oldLength = 0; |
8962 | 9014 |
8963 int _newLength = 0; | 9015 int _newLength = 0; |
8964 | 9016 |
8965 IncrementalAnalysisCache(this.librarySource, this.source, this.resolvedUnit, | 9017 IncrementalAnalysisCache( |
8966 this.oldContents, this._newContents, this._offset, this._oldLength, | 9018 this.librarySource, |
9019 this.source, | |
9020 this.resolvedUnit, | |
9021 this.oldContents, | |
9022 this._newContents, | |
9023 this._offset, | |
9024 this._oldLength, | |
8967 this._newLength); | 9025 this._newLength); |
8968 | 9026 |
8969 /** | 9027 /** |
8970 * Determine if the cache contains source changes that need to be analyzed | 9028 * Determine if the cache contains source changes that need to be analyzed |
8971 * | 9029 * |
8972 * @return `true` if the cache contains changes to be analyzed, else `false` | 9030 * @return `true` if the cache contains changes to be analyzed, else `false` |
8973 */ | 9031 */ |
8974 bool get hasWork => _oldLength > 0 || _newLength > 0; | 9032 bool get hasWork => _oldLength > 0 || _newLength > 0; |
8975 | 9033 |
8976 /** | 9034 /** |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9041 * @param source the source being updated (not `null`) | 9099 * @param source the source being updated (not `null`) |
9042 * @param oldContents the original source contents prior to this update (may b e `null`) | 9100 * @param oldContents the original source contents prior to this update (may b e `null`) |
9043 * @param newContents the new contents after this incremental change (not `nul l`) | 9101 * @param newContents the new contents after this incremental change (not `nul l`) |
9044 * @param offset the offset at which the change occurred | 9102 * @param offset the offset at which the change occurred |
9045 * @param oldLength the length of the text being replaced | 9103 * @param oldLength the length of the text being replaced |
9046 * @param newLength the length of the replacement text | 9104 * @param newLength the length of the replacement text |
9047 * @param sourceEntry the cached entry for the given source or `null` if none | 9105 * @param sourceEntry the cached entry for the given source or `null` if none |
9048 * @return the cache used for incremental analysis or `null` if incremental an alysis cannot | 9106 * @return the cache used for incremental analysis or `null` if incremental an alysis cannot |
9049 * be performed | 9107 * be performed |
9050 */ | 9108 */ |
9051 static IncrementalAnalysisCache update(IncrementalAnalysisCache cache, | 9109 static IncrementalAnalysisCache update( |
9052 Source source, String oldContents, String newContents, int offset, | 9110 IncrementalAnalysisCache cache, |
9053 int oldLength, int newLength, SourceEntry sourceEntry) { | 9111 Source source, |
9112 String oldContents, | |
9113 String newContents, | |
9114 int offset, | |
9115 int oldLength, | |
9116 int newLength, | |
9117 SourceEntry sourceEntry) { | |
9054 // Determine the cache resolved unit | 9118 // Determine the cache resolved unit |
9055 Source librarySource = null; | 9119 Source librarySource = null; |
9056 CompilationUnit unit = null; | 9120 CompilationUnit unit = null; |
9057 if (sourceEntry is DartEntry) { | 9121 if (sourceEntry is DartEntry) { |
9058 DartEntry dartEntry = sourceEntry; | 9122 DartEntry dartEntry = sourceEntry; |
9059 List<Source> librarySources = dartEntry.librariesContaining; | 9123 List<Source> librarySources = dartEntry.librariesContaining; |
9060 if (librarySources.length == 1) { | 9124 if (librarySources.length == 1) { |
9061 librarySource = librarySources[0]; | 9125 librarySource = librarySources[0]; |
9062 if (librarySource != null) { | 9126 if (librarySource != null) { |
9063 unit = dartEntry.getValueInLibrary( | 9127 unit = dartEntry.getValueInLibrary( |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9469 class ObsoleteSourceAnalysisException extends AnalysisException { | 9533 class ObsoleteSourceAnalysisException extends AnalysisException { |
9470 /** | 9534 /** |
9471 * The source that was removed while it was being analyzed. | 9535 * The source that was removed while it was being analyzed. |
9472 */ | 9536 */ |
9473 Source _source; | 9537 Source _source; |
9474 | 9538 |
9475 /** | 9539 /** |
9476 * Initialize a newly created exception to represent the removal of the given | 9540 * Initialize a newly created exception to represent the removal of the given |
9477 * [source]. | 9541 * [source]. |
9478 */ | 9542 */ |
9479 ObsoleteSourceAnalysisException(Source source) : super( | 9543 ObsoleteSourceAnalysisException(Source source) |
9480 "The source '${source.fullName}' was removed while it was being analyz ed") { | 9544 : super( |
9545 "The source '${source.fullName}' was removed while it was being anal yzed") { | |
9481 this._source = source; | 9546 this._source = source; |
9482 } | 9547 } |
9483 | 9548 |
9484 /** | 9549 /** |
9485 * Return the source that was removed while it was being analyzed. | 9550 * Return the source that was removed while it was being analyzed. |
9486 */ | 9551 */ |
9487 Source get source => _source; | 9552 Source get source => _source; |
9488 } | 9553 } |
9489 | 9554 |
9490 /** | 9555 /** |
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10827 new InheritanceManager(_libraryElement); | 10892 new InheritanceManager(_libraryElement); |
10828 ResolverVisitor resolverVisitor = new ResolverVisitor( | 10893 ResolverVisitor resolverVisitor = new ResolverVisitor( |
10829 _libraryElement, source, typeProvider, errorListener, | 10894 _libraryElement, source, typeProvider, errorListener, |
10830 inheritanceManager: inheritanceManager); | 10895 inheritanceManager: inheritanceManager); |
10831 unit.accept(resolverVisitor); | 10896 unit.accept(resolverVisitor); |
10832 // | 10897 // |
10833 // Perform additional error checking. | 10898 // Perform additional error checking. |
10834 // | 10899 // |
10835 PerformanceStatistics.errors.makeCurrentWhile(() { | 10900 PerformanceStatistics.errors.makeCurrentWhile(() { |
10836 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 10901 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
10837 ErrorVerifier errorVerifier = new ErrorVerifier(errorReporter, | 10902 ErrorVerifier errorVerifier = new ErrorVerifier( |
10838 _libraryElement, typeProvider, inheritanceManager, | 10903 errorReporter, |
10904 _libraryElement, | |
10905 typeProvider, | |
10906 inheritanceManager, | |
10839 context.analysisOptions.enableSuperMixins); | 10907 context.analysisOptions.enableSuperMixins); |
10840 unit.accept(errorVerifier); | 10908 unit.accept(errorVerifier); |
10841 // TODO(paulberry): as a temporary workaround for issue 21572, | 10909 // TODO(paulberry): as a temporary workaround for issue 21572, |
10842 // ConstantVerifier is being run right after ConstantValueComputer, so we | 10910 // ConstantVerifier is being run right after ConstantValueComputer, so we |
10843 // don't need to run it here. Once issue 21572 is fixed, re-enable the | 10911 // don't need to run it here. Once issue 21572 is fixed, re-enable the |
10844 // call to ConstantVerifier. | 10912 // call to ConstantVerifier. |
10845 // ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _libraryElement, typeProvider); | 10913 // ConstantVerifier constantVerifier = new ConstantVerifier(errorReporter, _libraryElement, typeProvider); |
10846 // unit.accept(constantVerifier); | 10914 // unit.accept(constantVerifier); |
10847 }); | 10915 }); |
10848 // | 10916 // |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11923 PendingFuture pendingFuture = | 11991 PendingFuture pendingFuture = |
11924 new PendingFuture<T>(_context, source, computeValue); | 11992 new PendingFuture<T>(_context, source, computeValue); |
11925 if (!pendingFuture.evaluate(sourceEntry)) { | 11993 if (!pendingFuture.evaluate(sourceEntry)) { |
11926 _context._pendingFutureSources | 11994 _context._pendingFutureSources |
11927 .putIfAbsent(source, () => <PendingFuture>[]) | 11995 .putIfAbsent(source, () => <PendingFuture>[]) |
11928 .add(pendingFuture); | 11996 .add(pendingFuture); |
11929 } | 11997 } |
11930 return pendingFuture.future; | 11998 return pendingFuture.future; |
11931 } | 11999 } |
11932 } | 12000 } |
OLD | NEW |