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

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

Issue 737673002: add source changed event stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
11 import 'dart:async';
11 import 'dart:collection'; 12 import 'dart:collection';
12 13
13 import 'package:analyzer/src/task/task_dart.dart'; 14 import 'package:analyzer/src/task/task_dart.dart';
14 15
15 import 'ast.dart'; 16 import 'ast.dart';
16 import 'constant.dart'; 17 import 'constant.dart';
17 import 'element.dart'; 18 import 'element.dart';
18 import 'error.dart'; 19 import 'error.dart';
19 import 'error_verifier.dart'; 20 import 'error_verifier.dart';
20 import 'html.dart' as ht; 21 import 'html.dart' as ht;
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 /** 374 /**
374 * Return an array containing all of the sources known to this context that re present the defining 375 * Return an array containing all of the sources known to this context that re present the defining
375 * compilation unit of a library. The contents of the array can be incomplete. 376 * compilation unit of a library. The contents of the array can be incomplete.
376 * 377 *
377 * @return the sources known to this context that represent the defining compi lation unit of a 378 * @return the sources known to this context that represent the defining compi lation unit of a
378 * library 379 * library
379 */ 380 */
380 List<Source> get librarySources; 381 List<Source> get librarySources;
381 382
382 /** 383 /**
384 * The stream that is notified when sources have been added or removed,
385 * or the source's content has changed.
386 */
387 Stream<ChangeSet> get onSourcesChanged;
388
389 /**
383 * Return an array containing all of the sources known to this context and the ir resolution state 390 * Return an array containing all of the sources known to this context and the ir resolution state
384 * is not valid or flush. So, these sources are not safe to update during refa ctoring, because we 391 * is not valid or flush. So, these sources are not safe to update during refa ctoring, because we
385 * may be don't know all the references in them. 392 * may be don't know all the references in them.
386 * 393 *
387 * @return the sources known to this context and are not safe for refactoring 394 * @return the sources known to this context and are not safe for refactoring
388 */ 395 */
389 List<Source> get refactoringUnsafeSources; 396 List<Source> get refactoringUnsafeSources;
390 397
391 /** 398 /**
392 * Return the source factory used to create the sources that can be analyzed i n this context. 399 * Return the source factory used to create the sources that can be analyzed i n this context.
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 * The object used to manage the list of sources that need to be analyzed. 975 * The object used to manage the list of sources that need to be analyzed.
969 */ 976 */
970 WorkManager _workManager = new WorkManager(); 977 WorkManager _workManager = new WorkManager();
971 978
972 /** 979 /**
973 * The set of [AngularApplication] in this context. 980 * The set of [AngularApplication] in this context.
974 */ 981 */
975 Set<AngularApplication> _angularApplications = new Set(); 982 Set<AngularApplication> _angularApplications = new Set();
976 983
977 /** 984 /**
985 * The controller for sending [SourcesChangedEvent]s.
986 */
987 StreamController<ChangeSet> _onSourcesChangedController;
Brian Wilkerson 2014/11/18 15:22:19 Shouldn't this be StreamController<SourcesChangedE
danrubel 2014/11/19 01:02:17 Good point and addressed as per discussion.
988
989 /**
990 * The stream that is notified when sources have been added or removed,
991 * or the source's content has changed.
992 */
993 Stream<ChangeSet> _onSourcesChanged;
994
995 /**
978 * The listeners that are to be notified when various analysis results are pro duced in this 996 * The listeners that are to be notified when various analysis results are pro duced in this
979 * context. 997 * context.
980 */ 998 */
981 List<AnalysisListener> _listeners = new List<AnalysisListener>(); 999 List<AnalysisListener> _listeners = new List<AnalysisListener>();
982 1000
983 /** 1001 /**
984 * Initialize a newly created analysis context. 1002 * Initialize a newly created analysis context.
985 */ 1003 */
986 AnalysisContextImpl() { 1004 AnalysisContextImpl() {
987 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this); 1005 _resultRecorder = new AnalysisContextImpl_AnalysisTaskResultRecorder(this);
988 _privatePartition = new UniversalCachePartition( 1006 _privatePartition = new UniversalCachePartition(
989 this, 1007 this,
990 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE, 1008 AnalysisOptionsImpl.DEFAULT_CACHE_SIZE,
991 new AnalysisContextImpl_ContextRetentionPolicy(this)); 1009 new AnalysisContextImpl_ContextRetentionPolicy(this));
992 _cache = createCacheFromSourceFactory(null); 1010 _cache = createCacheFromSourceFactory(null);
1011 _onSourcesChangedController = new StreamController<ChangeSet>();
1012 _onSourcesChanged = _onSourcesChangedController.stream.asBroadcastStream();
993 } 1013 }
994 1014
995 @override 1015 @override
996 AnalysisOptions get analysisOptions => _options; 1016 AnalysisOptions get analysisOptions => _options;
997 1017
998 @override 1018 @override
999 void set analysisOptions(AnalysisOptions options) { 1019 void set analysisOptions(AnalysisOptions options) {
1000 bool needsRecompute = 1020 bool needsRecompute =
1001 this._options.analyzeAngular != options.analyzeAngular || 1021 this._options.analyzeAngular != options.analyzeAngular ||
1002 this._options.analyzeFunctionBodies != options.analyzeFunctionBodies || 1022 this._options.analyzeFunctionBodies != options.analyzeFunctionBodies ||
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 } 1230 }
1211 if (hasBlockedTask) { 1231 if (hasBlockedTask) {
1212 // All of the analysis work is blocked waiting for an asynchronous task 1232 // All of the analysis work is blocked waiting for an asynchronous task
1213 // to complete. 1233 // to complete.
1214 return WaitForAsyncTask.instance; 1234 return WaitForAsyncTask.instance;
1215 } 1235 }
1216 return null; 1236 return null;
1217 } 1237 }
1218 1238
1219 @override 1239 @override
1240 Stream<ChangeSet> get onSourcesChanged => _onSourcesChanged;
1241
1242 @override
1220 List<Source> get prioritySources => _priorityOrder; 1243 List<Source> get prioritySources => _priorityOrder;
1221 1244
1222 @override 1245 @override
1223 List<Source> get refactoringUnsafeSources { 1246 List<Source> get refactoringUnsafeSources {
1224 List<Source> sources = new List<Source>(); 1247 List<Source> sources = new List<Source>();
1225 MapIterator<Source, SourceEntry> iterator = _cache.iterator(); 1248 MapIterator<Source, SourceEntry> iterator = _cache.iterator();
1226 while (iterator.moveNext()) { 1249 while (iterator.moveNext()) {
1227 SourceEntry sourceEntry = iterator.value; 1250 SourceEntry sourceEntry = iterator.value;
1228 if (sourceEntry is DartEntry) { 1251 if (sourceEntry is DartEntry) {
1229 Source source = iterator.key; 1252 Source source = iterator.key;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 for (Source source in changeSet.changedSources) { 1401 for (Source source in changeSet.changedSources) {
1379 if (_contentCache.getContents(source) != null) { 1402 if (_contentCache.getContents(source) != null) {
1380 // This source is overridden in the content cache, so the change will 1403 // This source is overridden in the content cache, so the change will
1381 // have no effect. Just ignore it to avoid wasting time doing 1404 // have no effect. Just ignore it to avoid wasting time doing
1382 // re-analysis. 1405 // re-analysis.
1383 continue; 1406 continue;
1384 } 1407 }
1385 _sourceChanged(source); 1408 _sourceChanged(source);
1386 } 1409 }
1387 changeSet.changedContents.forEach((Source key, String value) { 1410 changeSet.changedContents.forEach((Source key, String value) {
1388 setContents(key, value); 1411 _contentsChanged(key, value);
1389 }); 1412 });
1390 changeSet.changedRanges.forEach( 1413 changeSet.changedRanges.forEach(
1391 (Source source, ChangeSet_ContentChange change) { 1414 (Source source, ChangeSet_ContentChange change) {
1392 setChangedContents( 1415 _contentRangeChanged(
1393 source, 1416 source,
1394 change.contents, 1417 change.contents,
1395 change.offset, 1418 change.offset,
1396 change.oldLength, 1419 change.oldLength,
1397 change.newLength); 1420 change.newLength);
1398 }); 1421 });
1399 for (Source source in changeSet.deletedSources) { 1422 for (Source source in changeSet.deletedSources) {
1400 _sourceDeleted(source); 1423 _sourceDeleted(source);
1401 } 1424 }
1402 for (Source source in removedSources) { 1425 for (Source source in removedSources) {
(...skipping 22 matching lines...) Expand all
1425 SourceEntry entry = _getReadableSourceEntry(source); 1448 SourceEntry entry = _getReadableSourceEntry(source);
1426 if (entry is DartEntry) { 1449 if (entry is DartEntry) {
1427 entry.invalidateAllResolutionInformation(false); 1450 entry.invalidateAllResolutionInformation(false);
1428 _workManager.add(source, _computePriority(entry)); 1451 _workManager.add(source, _computePriority(entry));
1429 } else if (entry is HtmlEntry) { 1452 } else if (entry is HtmlEntry) {
1430 entry.invalidateAllResolutionInformation(false); 1453 entry.invalidateAllResolutionInformation(false);
1431 _workManager.add(source, SourcePriority.HTML); 1454 _workManager.add(source, SourcePriority.HTML);
1432 } 1455 }
1433 } 1456 }
1434 } 1457 }
1458 _onSourcesChangedController.add(changeSet);
1435 } 1459 }
1436 1460
1437 @override 1461 @override
1438 String computeDocumentationComment(Element element) { 1462 String computeDocumentationComment(Element element) {
1439 if (element == null) { 1463 if (element == null) {
1440 return null; 1464 return null;
1441 } 1465 }
1442 Source source = element.source; 1466 Source source = element.source;
1443 if (source == null) { 1467 if (source == null) {
1444 return null; 1468 return null;
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 2296
2273 @override 2297 @override
2274 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { 2298 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) {
2275 computeHtmlElement(htmlSource); 2299 computeHtmlElement(htmlSource);
2276 return parseHtmlUnit(htmlSource); 2300 return parseHtmlUnit(htmlSource);
2277 } 2301 }
2278 2302
2279 @override 2303 @override
2280 void setChangedContents(Source source, String contents, int offset, 2304 void setChangedContents(Source source, String contents, int offset,
2281 int oldLength, int newLength) { 2305 int oldLength, int newLength) {
2282 String originalContents = _contentCache.setContents(source, contents); 2306 if (_contentRangeChanged(source, contents, offset, oldLength, newLength)) {
2283 if (contents != null) { 2307 ChangeSet changeSet = new ChangeSet();
2284 if (contents != originalContents) { 2308 changeSet.changedRange(source, contents, offset, oldLength, newLength);
2285 if (_options.incremental) { 2309 _onSourcesChangedController.add(changeSet);
2286 _incrementalAnalysisCache = IncrementalAnalysisCache.update(
2287 _incrementalAnalysisCache,
2288 source,
2289 originalContents,
2290 contents,
2291 offset,
2292 oldLength,
2293 newLength,
2294 _getReadableSourceEntry(source));
2295 }
2296 _sourceChanged(source);
2297 SourceEntry sourceEntry = _cache.get(source);
2298 if (sourceEntry != null) {
2299 sourceEntry.modificationTime =
2300 _contentCache.getModificationStamp(source);
2301 sourceEntry.setValue(SourceEntry.CONTENT, contents);
2302 }
2303 }
2304 } else if (originalContents != null) {
2305 _incrementalAnalysisCache =
2306 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source);
2307 _sourceChanged(source);
2308 } 2310 }
2309 } 2311 }
2310 2312
2311 @override 2313 @override
2312 void setContents(Source source, String contents) { 2314 void setContents(Source source, String contents) {
2313 String originalContents = _contentCache.setContents(source, contents); 2315 if (_contentsChanged(source, contents)) {
2314 if (contents != null) { 2316 ChangeSet changeSet = new ChangeSet();
2315 if (contents != originalContents) { 2317 changeSet.changedContent(source, contents);
2316 _incrementalAnalysisCache = 2318 _onSourcesChangedController.add(changeSet);
2317 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source);
2318 _sourceChanged(source);
2319 SourceEntry sourceEntry = _cache.get(source);
2320 if (sourceEntry != null) {
2321 sourceEntry.modificationTime =
2322 _contentCache.getModificationStamp(source);
2323 sourceEntry.setValue(SourceEntry.CONTENT, contents);
2324 }
2325 }
2326 } else if (originalContents != null) {
2327 _incrementalAnalysisCache =
2328 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source);
2329 _sourceChanged(source);
2330 } 2319 }
2331 } 2320 }
2332 2321
2333 @override 2322 @override
2334 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, 2323 void visitCacheItems(void callback(Source source, SourceEntry dartEntry,
2335 DataDescriptor rowDesc, CacheState state)) { 2324 DataDescriptor rowDesc, CacheState state)) {
2336 void handleCacheItem(Source source, SourceEntry dartEntry, 2325 void handleCacheItem(Source source, SourceEntry dartEntry,
2337 DataDescriptor descriptor) { 2326 DataDescriptor descriptor) {
2338 callback(source, dartEntry, descriptor, dartEntry.getState(descriptor)); 2327 callback(source, dartEntry, descriptor, dartEntry.getState(descriptor));
2339 } 2328 }
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2855 bool _containsAny(List<Source> sources, List<Source> targetSources) { 2844 bool _containsAny(List<Source> sources, List<Source> targetSources) {
2856 for (Source targetSource in targetSources) { 2845 for (Source targetSource in targetSources) {
2857 if (_contains(sources, targetSource)) { 2846 if (_contains(sources, targetSource)) {
2858 return true; 2847 return true;
2859 } 2848 }
2860 } 2849 }
2861 return false; 2850 return false;
2862 } 2851 }
2863 2852
2864 /** 2853 /**
2854 * Set the contents of the given source to the given contents and mark the sou rce as having
2855 * changed. The additional offset and length information is used by the contex t to determine what
2856 * reanalysis is necessary. [setChangedContents] triggers a source changed eve nt
2857 * where as this method does not.
2858 *
2859 * @param source the source whose contents are being overridden
2860 * @param contents the text to replace the range in the current contents
2861 * @param offset the offset into the current contents
2862 * @param oldLength the number of characters in the original contents that wer e replaced
2863 * @param newLength the number of characters in the replacement text
2864 */
2865 bool _contentRangeChanged(Source source, String contents, int offset, int oldL ength, int newLength) {
2866 bool changed = false;
2867 String originalContents = _contentCache.setContents(source, contents);
2868 if (contents != null) {
2869 if (contents != originalContents) {
2870 if (_options.incremental) {
2871 _incrementalAnalysisCache = IncrementalAnalysisCache.update(_increment alAnalysisCache, source, originalContents, contents, offset, oldLength, newLengt h, _getReadableSourceEntry(source));
2872 }
2873 _sourceChanged(source);
2874 changed = true;
2875 SourceEntry sourceEntry = _cache.get(source);
2876 if (sourceEntry != null) {
2877 sourceEntry.modificationTime = _contentCache.getModificationStamp(sour ce);
2878 sourceEntry.setValue(SourceEntry.CONTENT, contents);
2879 }
2880 }
2881 } else if (originalContents != null) {
2882 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalAna lysisCache, source);
2883 _sourceChanged(source);
2884 changed = true;
2885 }
2886 return changed;
2887 }
2888
2889 /**
2890 * Set the contents of the given source to the given contents and mark the sou rce as having
2891 * changed. This has the effect of overriding the default contents of the sour ce. If the contents
2892 * are `null` the override is removed so that the default contents will be ret urned.
2893 * [setContents] triggers a source changed event where as this method does not .
2894 *
2895 * @param source the source whose contents are being overridden
2896 * @param contents the new contents of the source
2897 */
2898 bool _contentsChanged(Source source, String contents) {
2899 bool changed = false;
2900 String originalContents = _contentCache.setContents(source, contents);
2901 if (contents != null) {
2902 if (contents != originalContents) {
2903 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalA nalysisCache, source);
2904 _sourceChanged(source);
2905 changed = true;
2906 SourceEntry sourceEntry = _cache.get(source);
2907 if (sourceEntry != null) {
2908 sourceEntry.modificationTime = _contentCache.getModificationStamp(sour ce);
2909 sourceEntry.setValue(SourceEntry.CONTENT, contents);
2910 }
2911 }
2912 } else if (originalContents != null) {
2913 _incrementalAnalysisCache = IncrementalAnalysisCache.clear(_incrementalAna lysisCache, source);
2914 _sourceChanged(source);
2915 changed = true;
2916 }
2917 return changed;
2918 }
2919
2920 /**
2865 * Create a [BuildUnitElementTask] for the given [source]. 2921 * Create a [BuildUnitElementTask] for the given [source].
2866 */ 2922 */
2867 AnalysisContextImpl_TaskData _createBuildUnitElementTask(Source source, 2923 AnalysisContextImpl_TaskData _createBuildUnitElementTask(Source source,
2868 DartEntry dartEntry, Source librarySource) { 2924 DartEntry dartEntry, Source librarySource) {
2869 CompilationUnit unit = dartEntry.resolvableCompilationUnit; 2925 CompilationUnit unit = dartEntry.resolvableCompilationUnit;
2870 if (unit == null) { 2926 if (unit == null) {
2871 return _createParseDartTask(source, dartEntry); 2927 return _createParseDartTask(source, dartEntry);
2872 } 2928 }
2873 return new AnalysisContextImpl_TaskData( 2929 return new AnalysisContextImpl_TaskData(
2874 new BuildUnitElementTask(this, source, librarySource, unit), 2930 new BuildUnitElementTask(this, source, librarySource, unit),
(...skipping 7652 matching lines...) Expand 10 before | Expand all | Expand 10 after
10527 if (ret != null) { 10583 if (ret != null) {
10528 instrumentation.metric2("Source-count", ret.length); 10584 instrumentation.metric2("Source-count", ret.length);
10529 } 10585 }
10530 return ret; 10586 return ret;
10531 } finally { 10587 } finally {
10532 instrumentation.log(); 10588 instrumentation.log();
10533 } 10589 }
10534 } 10590 }
10535 10591
10536 @override 10592 @override
10593 Stream<ChangeSet> get onSourcesChanged => _basis.onSourcesChanged;
10594
10595 @override
10537 List<Source> get prioritySources { 10596 List<Source> get prioritySources {
10538 InstrumentationBuilder instrumentation = 10597 InstrumentationBuilder instrumentation =
10539 Instrumentation.builder2("Analysis-getPrioritySources"); 10598 Instrumentation.builder2("Analysis-getPrioritySources");
10540 _checkThread(instrumentation); 10599 _checkThread(instrumentation);
10541 try { 10600 try {
10542 instrumentation.metric3("contextId", _contextId); 10601 instrumentation.metric3("contextId", _contextId);
10543 return _basis.prioritySources; 10602 return _basis.prioritySources;
10544 } finally { 10603 } finally {
10545 instrumentation.log(); 10604 instrumentation.log();
10546 } 10605 }
(...skipping 4141 matching lines...) Expand 10 before | Expand all | Expand 10 after
14688 14747
14689 @override 14748 @override
14690 Object visitPolymerTagDartElement(PolymerTagDartElement element) { 14749 Object visitPolymerTagDartElement(PolymerTagDartElement element) {
14691 if (element.name == PolymerHtmlUnitBuilder_this._elementName) { 14750 if (element.name == PolymerHtmlUnitBuilder_this._elementName) {
14692 throw new PolymerHtmlUnitBuilder_FoundTagDartElementError( 14751 throw new PolymerHtmlUnitBuilder_FoundTagDartElementError(
14693 element as PolymerTagDartElementImpl); 14752 element as PolymerTagDartElementImpl);
14694 } 14753 }
14695 return null; 14754 return null;
14696 } 14755 }
14697 } 14756 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698