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

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

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

Powered by Google App Engine
This is Rietveld 408576698