Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine; | 8 library engine; |
| 9 | 9 |
| 10 import "dart:math" as math; | 10 import "dart:math" as math; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 import 'incremental_scanner.dart'; | 26 import 'incremental_scanner.dart'; |
| 27 import 'java_core.dart'; | 27 import 'java_core.dart'; |
| 28 import 'java_engine.dart'; | 28 import 'java_engine.dart'; |
| 29 import 'parser.dart' show Parser, IncrementalParser; | 29 import 'parser.dart' show Parser, IncrementalParser; |
| 30 import 'resolver.dart'; | 30 import 'resolver.dart'; |
| 31 import 'scanner.dart'; | 31 import 'scanner.dart'; |
| 32 import 'sdk.dart' show DartSdk; | 32 import 'sdk.dart' show DartSdk; |
| 33 import 'source.dart'; | 33 import 'source.dart'; |
| 34 import 'utilities_collection.dart'; | 34 import 'utilities_collection.dart'; |
| 35 import 'utilities_general.dart'; | 35 import 'utilities_general.dart'; |
| 36 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; | |
| 36 | 37 |
| 37 /** | 38 /** |
| 38 * Type of callback functions used by PendingFuture. Functions of this type | 39 * Type of callback functions used by PendingFuture. Functions of this type |
| 39 * should perform a computation based on the data in [sourceEntry] and return | 40 * should perform a computation based on the data in [sourceEntry] and return |
| 40 * it. If the computation can't be performed yet because more analysis is | 41 * it. If the computation can't be performed yet because more analysis is |
| 41 * needed, null should be returned. | 42 * needed, null should be returned. |
| 42 * | 43 * |
| 43 * The function may also throw an exception, in which case the corresponding | 44 * The function may also throw an exception, in which case the corresponding |
| 44 * future will be completed with failure. | 45 * future will be completed with failure. |
| 45 * | 46 * |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 */ | 1035 */ |
| 1035 StreamController<SourcesChangedEvent> _onSourcesChangedController; | 1036 StreamController<SourcesChangedEvent> _onSourcesChangedController; |
| 1036 | 1037 |
| 1037 /** | 1038 /** |
| 1038 * The listeners that are to be notified when various analysis results are pro duced in this | 1039 * The listeners that are to be notified when various analysis results are pro duced in this |
| 1039 * context. | 1040 * context. |
| 1040 */ | 1041 */ |
| 1041 List<AnalysisListener> _listeners = new List<AnalysisListener>(); | 1042 List<AnalysisListener> _listeners = new List<AnalysisListener>(); |
| 1042 | 1043 |
| 1043 /** | 1044 /** |
| 1045 * The most recently incrementally resolved [Source]. | |
| 1046 * Is null when it was already validated, or the most recent change was | |
| 1047 * not incrementally resolved. | |
| 1048 */ | |
| 1049 Source incrementalResolutionValidation_lastUnitSource; | |
| 1050 | |
| 1051 /** | |
| 1052 * The most recently incrementally resolved library [Source]. | |
| 1053 * Is null when it was already validated, or the most recent change was | |
| 1054 * not incrementally resolved. | |
| 1055 */ | |
| 1056 Source incrementalResolutionValidation_lastLibrarySource; | |
| 1057 | |
| 1058 /** | |
| 1059 * The result of incremental resolution result of | |
| 1060 * [incrementalResolutionValidation_lastSource]. | |
| 1061 */ | |
| 1062 CompilationUnit incrementalResolutionValidation_lastUnit; | |
| 1063 | |
| 1064 /** | |
| 1044 * Initialize a newly created analysis context. | 1065 * Initialize a newly created analysis context. |
| 1045 */ | 1066 */ |
| 1046 AnalysisContextImpl() { | 1067 AnalysisContextImpl() { |
| 1047 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); | 1068 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); |
| 1048 _privatePartition = new UniversalCachePartition( | 1069 _privatePartition = new UniversalCachePartition( |
| 1049 this, | 1070 this, |
| 1050 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, | 1071 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, |
| 1051 new AnalysisContextImpl_ContextRetentionPolicy(this)); | 1072 new AnalysisContextImpl_ContextRetentionPolicy(this)); |
| 1052 _cache = createCacheFromSourceFactory(null); | 1073 _cache = createCacheFromSourceFactory(null); |
| 1053 _onSourcesChangedController = | 1074 _onSourcesChangedController = |
| (...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2153 if (_TRACE_PERFORM_TASK) { | 2174 if (_TRACE_PERFORM_TASK) { |
| 2154 print("----------------------------------------"); | 2175 print("----------------------------------------"); |
| 2155 } | 2176 } |
| 2156 int getStart = JavaSystem.currentTimeMillis(); | 2177 int getStart = JavaSystem.currentTimeMillis(); |
| 2157 AnalysisTask task = nextAnalysisTask; | 2178 AnalysisTask task = nextAnalysisTask; |
| 2158 int getEnd = JavaSystem.currentTimeMillis(); | 2179 int getEnd = JavaSystem.currentTimeMillis(); |
| 2159 if (task == null && _validateCacheConsistency()) { | 2180 if (task == null && _validateCacheConsistency()) { |
| 2160 task = nextAnalysisTask; | 2181 task = nextAnalysisTask; |
| 2161 } | 2182 } |
| 2162 if (task == null) { | 2183 if (task == null) { |
| 2184 _validateLastIncrementalResolutionResult(); | |
| 2163 return new AnalysisResult( | 2185 return new AnalysisResult( |
| 2164 _getChangeNotices(true), | 2186 _getChangeNotices(true), |
| 2165 getEnd - getStart, | 2187 getEnd - getStart, |
| 2166 null, | 2188 null, |
| 2167 -1); | 2189 -1); |
| 2168 } | 2190 } |
| 2169 String taskDescription = task.toString(); | 2191 String taskDescription = task.toString(); |
| 2170 _notifyAboutToPerformTask(taskDescription); | 2192 _notifyAboutToPerformTask(taskDescription); |
| 2171 if (_TRACE_PERFORM_TASK) { | 2193 if (_TRACE_PERFORM_TASK) { |
| 2172 print(taskDescription); | 2194 print(taskDescription); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 2202 // } | 2224 // } |
| 2203 _notifyErrors(source, notice.errors, notice.lineInfo); | 2225 _notifyErrors(source, notice.errors, notice.lineInfo); |
| 2204 } | 2226 } |
| 2205 return new AnalysisResult( | 2227 return new AnalysisResult( |
| 2206 notices, | 2228 notices, |
| 2207 getEnd - getStart, | 2229 getEnd - getStart, |
| 2208 task.runtimeType.toString(), | 2230 task.runtimeType.toString(), |
| 2209 performEnd - performStart); | 2231 performEnd - performStart); |
| 2210 } | 2232 } |
| 2211 | 2233 |
| 2234 void _validateLastIncrementalResolutionResult() { | |
| 2235 if (incrementalResolutionValidation_lastUnitSource == null || | |
| 2236 incrementalResolutionValidation_lastLibrarySource == null || | |
| 2237 incrementalResolutionValidation_lastUnit == null) { | |
| 2238 return; | |
| 2239 } | |
| 2240 CompilationUnit fullUnit = getResolvedCompilationUnit2( | |
| 2241 incrementalResolutionValidation_lastUnitSource, | |
| 2242 incrementalResolutionValidation_lastLibrarySource); | |
| 2243 if (fullUnit != null) { | |
| 2244 try { | |
| 2245 assertSameResolution(incrementalResolutionValidation_lastUnit, fullUnit) ; | |
|
danrubel
2015/01/07 22:32:48
Should this be asserting valid types?
scheglov
2015/01/07 23:24:11
We should, but we cannot.
See my message about Ele
| |
| 2246 } on IncrementalResolutionMismatch catch (mismatch, stack) { | |
| 2247 String failure = mismatch.message; | |
| 2248 String message = 'Incremental resolution mismatch:\n$failure\nat\n$stack '; | |
| 2249 AnalysisEngine.instance.instrumentationService.logError(message); | |
| 2250 } | |
| 2251 } | |
| 2252 incrementalResolutionValidation_lastUnitSource = null; | |
| 2253 incrementalResolutionValidation_lastLibrarySource = null; | |
| 2254 incrementalResolutionValidation_lastUnit = null; | |
| 2255 } | |
| 2256 | |
| 2212 @override | 2257 @override |
| 2213 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | 2258 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 2214 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); | 2259 Source htmlSource = _sourceFactory.forUri(DartSdk.DART_HTML); |
| 2215 elementMap.forEach((Source librarySource, LibraryElement library) { | 2260 elementMap.forEach((Source librarySource, LibraryElement library) { |
| 2216 // | 2261 // |
| 2217 // Cache the element in the library's info. | 2262 // Cache the element in the library's info. |
| 2218 // | 2263 // |
| 2219 DartEntry dartEntry = _getReadableDartEntry(librarySource); | 2264 DartEntry dartEntry = _getReadableDartEntry(librarySource); |
| 2220 if (dartEntry != null) { | 2265 if (dartEntry != null) { |
| 2221 _recordElementData(dartEntry, library, library.source, htmlSource); | 2266 _recordElementData(dartEntry, library, library.source, htmlSource); |
| (...skipping 2854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5076 } | 5121 } |
| 5077 _cache.remove(source); | 5122 _cache.remove(source); |
| 5078 _workManager.remove(source); | 5123 _workManager.remove(source); |
| 5079 _removeFromPriorityOrder(source); | 5124 _removeFromPriorityOrder(source); |
| 5080 } | 5125 } |
| 5081 | 5126 |
| 5082 /** | 5127 /** |
| 5083 * TODO(scheglov) A hackish, limited incremental resolution implementation. | 5128 * TODO(scheglov) A hackish, limited incremental resolution implementation. |
| 5084 */ | 5129 */ |
| 5085 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) { | 5130 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) { |
| 5131 incrementalResolutionValidation_lastUnitSource = null; | |
| 5132 incrementalResolutionValidation_lastLibrarySource = null; | |
| 5133 incrementalResolutionValidation_lastUnit = null; | |
| 5134 // prepare the entry | |
| 5086 DartEntry dartEntry = _cache.get(unitSource); | 5135 DartEntry dartEntry = _cache.get(unitSource); |
| 5087 if (dartEntry == null) { | 5136 if (dartEntry == null) { |
| 5088 return false; | 5137 return false; |
| 5089 } | 5138 } |
| 5090 // prepare the (only) library | 5139 // prepare the (only) library |
| 5091 List<Source> librarySources = getLibrariesContaining(unitSource); | 5140 List<Source> librarySources = getLibrariesContaining(unitSource); |
| 5092 if (librarySources.length != 1) { | 5141 if (librarySources.length != 1) { |
| 5093 return false; | 5142 return false; |
| 5094 } | 5143 } |
| 5095 // prepare the existing unit | 5144 // prepare the existing unit |
| 5096 Source librarySource = librarySources[0]; | 5145 Source librarySource = librarySources[0]; |
| 5097 CompilationUnit oldUnit = | 5146 CompilationUnit oldUnit = |
| 5098 getResolvedCompilationUnit2(unitSource, librarySource); | 5147 getResolvedCompilationUnit2(unitSource, librarySource); |
| 5099 if (oldUnit == null) { | 5148 if (oldUnit == null) { |
| 5100 return false; | 5149 return false; |
| 5101 } | 5150 } |
| 5102 // do resolution | 5151 // do resolution |
| 5103 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( | 5152 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( |
| 5104 typeProvider, | 5153 typeProvider, |
| 5105 unitSource, | 5154 unitSource, |
| 5106 dartEntry, | 5155 dartEntry, |
| 5107 analysisOptions.incrementalApi); | 5156 analysisOptions.incrementalApi); |
| 5108 bool success = resolver.resolve(oldUnit, newCode); | 5157 bool success = resolver.resolve(oldUnit, newCode); |
| 5109 if (!success) { | 5158 if (!success) { |
| 5110 return false; | 5159 return false; |
| 5111 } | 5160 } |
| 5161 // if validation, remember the result, but throw it away | |
|
danrubel
2015/01/07 22:32:48
Can we switch this around so that it remembers the
scheglov
2015/01/07 23:24:11
Unfortunately I don't see how to make it work.
If
| |
| 5162 if (analysisOptions.incrementalValidation) { | |
| 5163 incrementalResolutionValidation_lastUnitSource = oldUnit.element.source; | |
| 5164 incrementalResolutionValidation_lastLibrarySource = oldUnit.element.librar y.source; | |
| 5165 incrementalResolutionValidation_lastUnit = oldUnit; | |
| 5166 return false; | |
| 5167 } | |
| 5112 // prepare notice | 5168 // prepare notice |
| 5113 ChangeNoticeImpl notice = _getNotice(unitSource); | 5169 ChangeNoticeImpl notice = _getNotice(unitSource); |
| 5114 notice.compilationUnit = oldUnit; | 5170 notice.compilationUnit = oldUnit; |
| 5115 // apply updated errors | 5171 // apply updated errors |
| 5116 { | 5172 { |
| 5117 LineInfo lineInfo = getLineInfo(unitSource); | 5173 LineInfo lineInfo = getLineInfo(unitSource); |
| 5118 notice.setErrors(dartEntry.allErrors, lineInfo); | 5174 notice.setErrors(dartEntry.allErrors, lineInfo); |
| 5119 } | 5175 } |
| 5176 // OK | |
| 5120 return true; | 5177 return true; |
| 5121 } | 5178 } |
| 5122 | 5179 |
| 5123 /** | 5180 /** |
| 5124 * Check the cache for any invalid entries (entries whose modification time do es not match the | 5181 * Check the cache for any invalid entries (entries whose modification time do es not match the |
| 5125 * modification time of the source associated with the entry). Invalid entries will be marked as | 5182 * modification time of the source associated with the entry). Invalid entries will be marked as |
| 5126 * invalid so that the source will be re-analyzed. | 5183 * invalid so that the source will be re-analyzed. |
| 5127 * | 5184 * |
| 5128 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. | 5185 * <b>Note:</b> This method must only be invoked while we are synchronized on [cacheLock]. |
| 5129 * | 5186 * |
| (...skipping 9311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14441 | 14498 |
| 14442 @override | 14499 @override |
| 14443 Object visitPolymerTagDartElement(PolymerTagDartElement element) { | 14500 Object visitPolymerTagDartElement(PolymerTagDartElement element) { |
| 14444 if (element.name == PolymerHtmlUnitBuilder_this._elementName) { | 14501 if (element.name == PolymerHtmlUnitBuilder_this._elementName) { |
| 14445 throw new PolymerHtmlUnitBuilder_FoundTagDartElementError( | 14502 throw new PolymerHtmlUnitBuilder_FoundTagDartElementError( |
| 14446 element as PolymerTagDartElementImpl); | 14503 element as PolymerTagDartElementImpl); |
| 14447 } | 14504 } |
| 14448 return null; | 14505 return null; |
| 14449 } | 14506 } |
| 14450 } | 14507 } |
| OLD | NEW |