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

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

Issue 880643005: Fix "reanalyze sources" when there are unsaved files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine; 8 library engine;
9 9
10 import "dart:math" as math; 10 import "dart:math" as math;
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 int count = 1144 int count =
1145 math.min(sources.length, _options.cacheSize - _PRIORITY_ORDER_SIZE_DEL TA); 1145 math.min(sources.length, _options.cacheSize - _PRIORITY_ORDER_SIZE_DEL TA);
1146 _priorityOrder = new List<Source>(count); 1146 _priorityOrder = new List<Source>(count);
1147 for (int i = 0; i < count; i++) { 1147 for (int i = 0; i < count; i++) {
1148 _priorityOrder[i] = sources[i]; 1148 _priorityOrder[i] = sources[i];
1149 } 1149 }
1150 } 1150 }
1151 } 1151 }
1152 1152
1153 @override 1153 @override
1154 set contentCache(ContentCache value) {
1155 _contentCache = value;
1156 }
1157
1158 @override
1154 DeclaredVariables get declaredVariables => _declaredVariables; 1159 DeclaredVariables get declaredVariables => _declaredVariables;
1155 1160
1156 @override 1161 @override
1157 List<Source> get htmlSources => _getSources(SourceKind.HTML); 1162 List<Source> get htmlSources => _getSources(SourceKind.HTML);
1158 1163
1159 @override 1164 @override
1160 bool get isDisposed => _disposed; 1165 bool get isDisposed => _disposed;
1161 1166
1162 @override 1167 @override
1163 List<Source> get launchableClientLibrarySources { 1168 List<Source> get launchableClientLibrarySources {
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 for (Source source in changeSet.changedSources) { 1532 for (Source source in changeSet.changedSources) {
1528 if (_contentCache.getContents(source) != null) { 1533 if (_contentCache.getContents(source) != null) {
1529 // This source is overridden in the content cache, so the change will 1534 // This source is overridden in the content cache, so the change will
1530 // have no effect. Just ignore it to avoid wasting time doing 1535 // have no effect. Just ignore it to avoid wasting time doing
1531 // re-analysis. 1536 // re-analysis.
1532 continue; 1537 continue;
1533 } 1538 }
1534 _sourceChanged(source); 1539 _sourceChanged(source);
1535 } 1540 }
1536 changeSet.changedContents.forEach((Source key, String value) { 1541 changeSet.changedContents.forEach((Source key, String value) {
1537 _contentsChanged(key, value); 1542 _contentsChanged(key, value, false);
1538 }); 1543 });
1539 changeSet.changedRanges.forEach( 1544 changeSet.changedRanges.forEach(
1540 (Source source, ChangeSet_ContentChange change) { 1545 (Source source, ChangeSet_ContentChange change) {
1541 _contentRangeChanged( 1546 _contentRangeChanged(
1542 source, 1547 source,
1543 change.contents, 1548 change.contents,
1544 change.offset, 1549 change.offset,
1545 change.oldLength, 1550 change.oldLength,
1546 change.newLength); 1551 change.newLength);
1547 }); 1552 });
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) { 2147 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) {
2143 SourceEntry sourceEntry = getReadableSourceEntryOrNull(htmlSource); 2148 SourceEntry sourceEntry = getReadableSourceEntryOrNull(htmlSource);
2144 if (sourceEntry is HtmlEntry) { 2149 if (sourceEntry is HtmlEntry) {
2145 HtmlEntry htmlEntry = sourceEntry; 2150 HtmlEntry htmlEntry = sourceEntry;
2146 return htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT); 2151 return htmlEntry.getValue(HtmlEntry.RESOLVED_UNIT);
2147 } 2152 }
2148 return null; 2153 return null;
2149 } 2154 }
2150 2155
2151 @override 2156 @override
2157 bool handleContentsChanged(Source source, String originalContents,
2158 String newContents, bool notify) {
2159 SourceEntry sourceEntry = _cache.get(source);
2160 if (sourceEntry == null) {
2161 return false;
2162 }
2163 bool changed = newContents != originalContents;
2164 if (newContents != null) {
2165 if (newContents != originalContents) {
2166 _incrementalAnalysisCache =
2167 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source);
2168 if (!analysisOptions.incremental ||
2169 !_tryPoorMansIncrementalResolution(source, newContents)) {
2170 _sourceChanged(source);
2171 }
2172 if (sourceEntry != null) {
2173 sourceEntry.modificationTime =
2174 _contentCache.getModificationStamp(source);
2175 sourceEntry.setValue(SourceEntry.CONTENT, newContents);
2176 }
2177 } else {
2178 if (sourceEntry != null) {
2179 sourceEntry.modificationTime =
2180 _contentCache.getModificationStamp(source);
2181 }
2182 }
2183 } else if (originalContents != null) {
2184 _incrementalAnalysisCache =
2185 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source);
2186 changed = newContents != originalContents;
2187 // We are removing the overlay for the file, check if the file's
2188 // contents is the same as it was in the overlay.
2189 if (sourceEntry != null) {
2190 try {
2191 TimestampedData<String> fileContents = getContents(source);
2192 String fileContentsData = fileContents.data;
2193 if (fileContentsData == originalContents) {
2194 sourceEntry.modificationTime = fileContents.modificationTime;
2195 sourceEntry.setValue(SourceEntry.CONTENT, fileContentsData);
2196 changed = false;
2197 }
2198 } catch (e) {
2199 }
2200 }
2201 // If not the same content (e.g. the file is being closed without save),
2202 // then force analysis.
2203 if (changed) {
2204 _sourceChanged(source);
2205 }
2206 }
2207 if (notify && changed) {
2208 _onSourcesChangedController.add(
2209 new SourcesChangedEvent.changedContent(source, newContents));
2210 }
2211 return changed;
2212 }
2213
2214 @override
2152 bool isClientLibrary(Source librarySource) { 2215 bool isClientLibrary(Source librarySource) {
2153 SourceEntry sourceEntry = _getReadableSourceEntry(librarySource); 2216 SourceEntry sourceEntry = _getReadableSourceEntry(librarySource);
2154 if (sourceEntry is DartEntry) { 2217 if (sourceEntry is DartEntry) {
2155 DartEntry dartEntry = sourceEntry; 2218 DartEntry dartEntry = sourceEntry;
2156 return dartEntry.getValue(DartEntry.IS_CLIENT) && 2219 return dartEntry.getValue(DartEntry.IS_CLIENT) &&
2157 dartEntry.getValue(DartEntry.IS_LAUNCHABLE); 2220 dartEntry.getValue(DartEntry.IS_LAUNCHABLE);
2158 } 2221 }
2159 return false; 2222 return false;
2160 } 2223 }
2161 2224
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 source, 2566 source,
2504 contents, 2567 contents,
2505 offset, 2568 offset,
2506 oldLength, 2569 oldLength,
2507 newLength)); 2570 newLength));
2508 } 2571 }
2509 } 2572 }
2510 2573
2511 @override 2574 @override
2512 void setContents(Source source, String contents) { 2575 void setContents(Source source, String contents) {
2513 if (_contentsChanged(source, contents)) { 2576 _contentsChanged(source, contents, true);
2514 _onSourcesChangedController.add(
2515 new SourcesChangedEvent.changedContent(source, contents));
2516 }
2517 } 2577 }
2518 2578
2519 @override 2579 @override
2520 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, 2580 void visitCacheItems(void callback(Source source, SourceEntry dartEntry,
2521 DataDescriptor rowDesc, CacheState state)) { 2581 DataDescriptor rowDesc, CacheState state)) {
2522 bool hintsEnabled = _options.hint; 2582 bool hintsEnabled = _options.hint;
2523 bool lintsEnabled = _options.lint; 2583 bool lintsEnabled = _options.lint;
2524 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); 2584 MapIterator<Source, SourceEntry> iterator = _cache.iterator();
2525 while (iterator.moveNext()) { 2585 while (iterator.moveNext()) {
2526 Source source = iterator.key; 2586 Source source = iterator.key;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 this, 2839 this,
2780 source, 2840 source,
2781 dartEntry.getValue(DartEntry.TOKEN_STREAM), 2841 dartEntry.getValue(DartEntry.TOKEN_STREAM),
2782 dartEntry.getValue( 2842 dartEntry.getValue(
2783 SourceEntry.LINE_INFO)).perform(_resultRecorder) as DartEntry; 2843 SourceEntry.LINE_INFO)).perform(_resultRecorder) as DartEntry;
2784 state = dartEntry.getState(descriptor); 2844 state = dartEntry.getState(descriptor);
2785 } 2845 }
2786 return dartEntry; 2846 return dartEntry;
2787 } 2847 }
2788 2848
2789
2790 /** 2849 /**
2791 * Given a source for a Dart file and the library that contains it, return a c ache entry in which 2850 * Given a source for a Dart file and the library that contains it, return a c ache entry in which
2792 * the state of the data represented by the given descriptor is either [CacheS tate.VALID] or 2851 * the state of the data represented by the given descriptor is either [CacheS tate.VALID] or
2793 * [CacheState.ERROR]. This method assumes that the data can be produced by re solving the 2852 * [CacheState.ERROR]. This method assumes that the data can be produced by re solving the
2794 * source in the context of the library if it is not already cached. 2853 * source in the context of the library if it is not already cached.
2795 * 2854 *
2796 * <b>Note:</b> This method cannot be used in an async environment. 2855 * <b>Note:</b> This method cannot be used in an async environment.
2797 * 2856 *
2798 * @param unitSource the source representing the Dart file 2857 * @param unitSource the source representing the Dart file
2799 * @param librarySource the source representing the library containing the Dar t file 2858 * @param librarySource the source representing the library containing the Dar t file
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
3143 _sourceChanged(source); 3202 _sourceChanged(source);
3144 changed = true; 3203 changed = true;
3145 } 3204 }
3146 return changed; 3205 return changed;
3147 } 3206 }
3148 3207
3149 /** 3208 /**
3150 * Set the contents of the given source to the given contents and mark the sou rce as having 3209 * Set the contents of the given source to the given contents and mark the sou rce as having
3151 * changed. This has the effect of overriding the default contents of the sour ce. If the contents 3210 * changed. This has the effect of overriding the default contents of the sour ce. If the contents
3152 * are `null` the override is removed so that the default contents will be ret urned. 3211 * are `null` the override is removed so that the default contents will be ret urned.
3153 * [setContents] triggers a source changed event where as this method does not . 3212 *
3213 * If [notify] is true, a source changed event is triggered.
3154 * 3214 *
3155 * @param source the source whose contents are being overridden 3215 * @param source the source whose contents are being overridden
3156 * @param contents the new contents of the source 3216 * @param contents the new contents of the source
3157 */ 3217 */
3158 bool _contentsChanged(Source source, String contents) { 3218 void _contentsChanged(Source source, String contents, bool notify) {
3159 bool changed = false;
3160 String originalContents = _contentCache.setContents(source, contents); 3219 String originalContents = _contentCache.setContents(source, contents);
3161 if (contents != null) { 3220 handleContentsChanged(source, originalContents, contents, notify);
3162 if (contents != originalContents) {
3163 _incrementalAnalysisCache =
3164 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source);
3165 if (!analysisOptions.incremental ||
3166 !_tryPoorMansIncrementalResolution(source, contents)) {
3167 _sourceChanged(source);
3168 }
3169 changed = true;
3170 SourceEntry sourceEntry = _cache.get(source);
3171 if (sourceEntry != null) {
3172 sourceEntry.modificationTime =
3173 _contentCache.getModificationStamp(source);
3174 sourceEntry.setValue(SourceEntry.CONTENT, contents);
3175 }
3176 } else {
3177 SourceEntry sourceEntry = _cache.get(source);
3178 if (sourceEntry != null) {
3179 sourceEntry.modificationTime =
3180 _contentCache.getModificationStamp(source);
3181 }
3182 }
3183 } else if (originalContents != null) {
3184 _incrementalAnalysisCache =
3185 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source);
3186 changed = true;
3187 // We are removing the overlay for the file, check if the file's
3188 // contents is the same as it was in the overlay.
3189 SourceEntry sourceEntry = _cache.get(source);
3190 if (sourceEntry != null) {
3191 try {
3192 TimestampedData<String> fileContents = getContents(source);
3193 String fileContentsData = fileContents.data;
3194 if (fileContentsData == originalContents) {
3195 sourceEntry.modificationTime = fileContents.modificationTime;
3196 sourceEntry.setValue(SourceEntry.CONTENT, fileContentsData);
3197 changed = false;
3198 }
3199 } catch (e) {
3200 }
3201 }
3202 // If not the same content (e.g. the file is being closed without save),
3203 // then force analysis.
3204 if (changed) {
3205 _sourceChanged(source);
3206 }
3207 }
3208 return changed;
3209 } 3221 }
3210 3222
3211 // /** 3223 // /**
3212 // * Create a [BuildUnitElementTask] for the given [source]. 3224 // * Create a [BuildUnitElementTask] for the given [source].
3213 // */ 3225 // */
3214 // AnalysisContextImpl_TaskData _createBuildUnitElementTask(Source source, 3226 // AnalysisContextImpl_TaskData _createBuildUnitElementTask(Source source,
3215 // DartEntry dartEntry, Source librarySource) { 3227 // DartEntry dartEntry, Source librarySource) {
3216 // CompilationUnit unit = dartEntry.resolvableCompilationUnit; 3228 // CompilationUnit unit = dartEntry.resolvableCompilationUnit;
3217 // if (unit == null) { 3229 // if (unit == null) {
3218 // return _createParseDartTask(source, dartEntry); 3230 // return _createParseDartTask(source, dartEntry);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
3360 * @return task data representing the created task 3372 * @return task data representing the created task
3361 */ 3373 */
3362 AnalysisContextImpl_TaskData _createGetContentTask(Source source, 3374 AnalysisContextImpl_TaskData _createGetContentTask(Source source,
3363 SourceEntry sourceEntry) { 3375 SourceEntry sourceEntry) {
3364 sourceEntry.setState(SourceEntry.CONTENT, CacheState.IN_PROCESS); 3376 sourceEntry.setState(SourceEntry.CONTENT, CacheState.IN_PROCESS);
3365 return new AnalysisContextImpl_TaskData( 3377 return new AnalysisContextImpl_TaskData(
3366 new GetContentTask(this, source), 3378 new GetContentTask(this, source),
3367 false); 3379 false);
3368 } 3380 }
3369 3381
3370
3371
3372 /** 3382 /**
3373 * Create a [ParseDartTask] for the given [source]. 3383 * Create a [ParseDartTask] for the given [source].
3374 */ 3384 */
3375 AnalysisContextImpl_TaskData _createParseDartTask(Source source, 3385 AnalysisContextImpl_TaskData _createParseDartTask(Source source,
3376 DartEntry dartEntry) { 3386 DartEntry dartEntry) {
3377 if (dartEntry.getState(DartEntry.TOKEN_STREAM) != CacheState.VALID || 3387 if (dartEntry.getState(DartEntry.TOKEN_STREAM) != CacheState.VALID ||
3378 dartEntry.getState(SourceEntry.LINE_INFO) != CacheState.VALID) { 3388 dartEntry.getState(SourceEntry.LINE_INFO) != CacheState.VALID) {
3379 return _createScanDartTask(source, dartEntry); 3389 return _createScanDartTask(source, dartEntry);
3380 } 3390 }
3381 Token tokenStream = dartEntry.getValue(DartEntry.TOKEN_STREAM); 3391 Token tokenStream = dartEntry.getValue(DartEntry.TOKEN_STREAM);
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
4606 if (thrownException != null) { 4616 if (thrownException != null) {
4607 sourceEntry.recordContentError(thrownException); 4617 sourceEntry.recordContentError(thrownException);
4608 _workManager.remove(source); 4618 _workManager.remove(source);
4609 throw new AnalysisException('<rethrow>', thrownException); 4619 throw new AnalysisException('<rethrow>', thrownException);
4610 } 4620 }
4611 sourceEntry.modificationTime = task.modificationTime; 4621 sourceEntry.modificationTime = task.modificationTime;
4612 sourceEntry.setValue(SourceEntry.CONTENT, task.content); 4622 sourceEntry.setValue(SourceEntry.CONTENT, task.content);
4613 return sourceEntry; 4623 return sourceEntry;
4614 } 4624 }
4615 4625
4616
4617 /** 4626 /**
4618 * Record the results produced by performing a [IncrementalAnalysisTask]. 4627 * Record the results produced by performing a [IncrementalAnalysisTask].
4619 * 4628 *
4620 * @param task the task that was performed 4629 * @param task the task that was performed
4621 * @return an entry containing the computed results 4630 * @return an entry containing the computed results
4622 * @throws AnalysisException if the results could not be recorded 4631 * @throws AnalysisException if the results could not be recorded
4623 */ 4632 */
4624 DartEntry 4633 DartEntry
4625 _recordIncrementalAnalysisTaskResults(IncrementalAnalysisTask task) { 4634 _recordIncrementalAnalysisTaskResults(IncrementalAnalysisTask task) {
4626 CompilationUnit unit = task.compilationUnit; 4635 CompilationUnit unit = task.compilationUnit;
(...skipping 4980 matching lines...) Expand 10 before | Expand all | Expand 10 after
9607 } 9616 }
9608 } 9617 }
9609 } 9618 }
9610 9619
9611 /** 9620 /**
9612 * The interface `InternalAnalysisContext` defines additional behavior for an an alysis context 9621 * The interface `InternalAnalysisContext` defines additional behavior for an an alysis context
9613 * that is required by internal users of the context. 9622 * that is required by internal users of the context.
9614 */ 9623 */
9615 abstract class InternalAnalysisContext implements AnalysisContext { 9624 abstract class InternalAnalysisContext implements AnalysisContext {
9616 /** 9625 /**
9626 * Allow the client to supply its own content cache. This will take the
9627 * place of the content cache created by default, allowing clients to share
9628 * the content cache between contexts.
9629 */
9630 set contentCache(ContentCache value);
9631
9632 /**
9617 * Return an array containing all of the sources that have been marked as prio rity sources. 9633 * Return an array containing all of the sources that have been marked as prio rity sources.
9618 * Clients must not modify the returned array. 9634 * Clients must not modify the returned array.
9619 * 9635 *
9620 * @return the sources that have been marked as priority sources 9636 * @return the sources that have been marked as priority sources
9621 */ 9637 */
9622 List<Source> get prioritySources; 9638 List<Source> get prioritySources;
9623 9639
9624 /** 9640 /**
9625 * Returns a statistics about this context. 9641 * Returns a statistics about this context.
9626 */ 9642 */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
9689 /** 9705 /**
9690 * Return a namespace containing mappings for all of the public names defined by the given 9706 * Return a namespace containing mappings for all of the public names defined by the given
9691 * library. 9707 * library.
9692 * 9708 *
9693 * @param library the library whose public namespace is to be returned 9709 * @param library the library whose public namespace is to be returned
9694 * @return the public namespace of the given library 9710 * @return the public namespace of the given library
9695 */ 9711 */
9696 Namespace getPublicNamespace(LibraryElement library); 9712 Namespace getPublicNamespace(LibraryElement library);
9697 9713
9698 /** 9714 /**
9715 * Respond to a change which has been made to the given [source] file.
9716 * [originalContents] is the former contents of the file, and [newContents]
9717 * is the updated contents. If [notify] is true, a source changed event is
9718 * triggered.
9719 *
9720 * Normally it should not be necessary for clinets to call this function,
9721 * since it will be automatically invoked in response to a call to
9722 * [applyChanges] or [setContents]. However, if this analysis context is
9723 * sharing its content cache with other contexts, then the client must
9724 * manually update the content cache and call this function for each context.
9725 *
9726 * Return `true` if the change was significant to this context (i.e. [source]
9727 * is either implicitly or explicitly analyzed by this context, and a change
9728 * actually occurred).
9729 */
9730 bool handleContentsChanged(Source source, String originalContents,
9731 String newContents, bool notify);
9732
9733 /**
9699 * Given a table mapping the source for the libraries represented by the corre sponding elements to 9734 * Given a table mapping the source for the libraries represented by the corre sponding elements to
9700 * the elements representing the libraries, record those mappings. 9735 * the elements representing the libraries, record those mappings.
9701 * 9736 *
9702 * @param elementMap a table mapping the source for the libraries represented by the elements to 9737 * @param elementMap a table mapping the source for the libraries represented by the elements to
9703 * the elements representing the libraries 9738 * the elements representing the libraries
9704 */ 9739 */
9705 void recordLibraryElements(Map<Source, LibraryElement> elementMap); 9740 void recordLibraryElements(Map<Source, LibraryElement> elementMap);
9706 9741
9707 /** 9742 /**
9708 * Call the given callback function for eache cache item in the context. 9743 * Call the given callback function for eache cache item in the context.
(...skipping 2569 matching lines...) Expand 10 before | Expand all | Expand 10 after
12278 if (element.id == _id) { 12313 if (element.id == _id) {
12279 result = element; 12314 result = element;
12280 throw new _ElementByIdFinderException(); 12315 throw new _ElementByIdFinderException();
12281 } 12316 }
12282 super.visitElement(element); 12317 super.visitElement(element);
12283 } 12318 }
12284 } 12319 }
12285 12320
12286 class _ElementByIdFinderException { 12321 class _ElementByIdFinderException {
12287 } 12322 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698