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

Side by Side Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1200313002: Initial HTML work manager (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/html_work_manager.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.src.context.context; 5 library analyzer.src.context.context;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/instrumentation/instrumentation.dart'; 10 import 'package:analyzer/instrumentation/instrumentation.dart';
(...skipping 15 matching lines...) Expand all
26 import 'package:analyzer/src/generated/java_core.dart'; 26 import 'package:analyzer/src/generated/java_core.dart';
27 import 'package:analyzer/src/generated/java_engine.dart'; 27 import 'package:analyzer/src/generated/java_engine.dart';
28 import 'package:analyzer/src/generated/resolver.dart'; 28 import 'package:analyzer/src/generated/resolver.dart';
29 import 'package:analyzer/src/generated/scanner.dart'; 29 import 'package:analyzer/src/generated/scanner.dart';
30 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 30 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
31 import 'package:analyzer/src/generated/source.dart'; 31 import 'package:analyzer/src/generated/source.dart';
32 import 'package:analyzer/src/generated/utilities_collection.dart'; 32 import 'package:analyzer/src/generated/utilities_collection.dart';
33 import 'package:analyzer/src/task/dart.dart'; 33 import 'package:analyzer/src/task/dart.dart';
34 import 'package:analyzer/src/task/dart_work_manager.dart'; 34 import 'package:analyzer/src/task/dart_work_manager.dart';
35 import 'package:analyzer/src/task/driver.dart'; 35 import 'package:analyzer/src/task/driver.dart';
36 import 'package:analyzer/src/task/html.dart';
37 import 'package:analyzer/src/task/html_work_manager.dart';
36 import 'package:analyzer/src/task/manager.dart'; 38 import 'package:analyzer/src/task/manager.dart';
37 import 'package:analyzer/task/dart.dart'; 39 import 'package:analyzer/task/dart.dart';
38 import 'package:analyzer/task/general.dart'; 40 import 'package:analyzer/task/general.dart';
39 import 'package:analyzer/task/html.dart'; 41 import 'package:analyzer/task/html.dart';
40 import 'package:analyzer/task/model.dart'; 42 import 'package:analyzer/task/model.dart';
41 import 'package:html/dom.dart' show Document; 43 import 'package:html/dom.dart' show Document;
42 44
43 /** 45 /**
44 * Type of callback functions used by PendingFuture. Functions of this type 46 * Type of callback functions used by PendingFuture. Functions of this type
45 * should perform a computation based on the data in [entry] and return it. If 47 * should perform a computation based on the data in [entry] and return it. If
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 * The task manager used to manage the tasks used to analyze code. 119 * The task manager used to manage the tasks used to analyze code.
118 */ 120 */
119 TaskManager _taskManager; 121 TaskManager _taskManager;
120 122
121 /** 123 /**
122 * The [DartWorkManager] instance that performs Dart specific scheduling. 124 * The [DartWorkManager] instance that performs Dart specific scheduling.
123 */ 125 */
124 DartWorkManager dartWorkManager; 126 DartWorkManager dartWorkManager;
125 127
126 /** 128 /**
129 * The work manager that performs HTML specific scheduling.
130 */
131 HtmlWorkManager htmlWorkManager;
132
133 /**
127 * The analysis driver used to perform analysis. 134 * The analysis driver used to perform analysis.
128 */ 135 */
129 AnalysisDriver driver; 136 AnalysisDriver driver;
130 137
131 /** 138 /**
132 * A list containing sources for which data should not be flushed. 139 * A list containing sources for which data should not be flushed.
133 */ 140 */
134 List<Source> _priorityOrder = <Source>[]; 141 List<Source> _priorityOrder = <Source>[];
135 142
136 /** 143 /**
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 212
206 /** 213 /**
207 * Initialize a newly created analysis context. 214 * Initialize a newly created analysis context.
208 */ 215 */
209 AnalysisContextImpl() { 216 AnalysisContextImpl() {
210 _privatePartition = new UniversalCachePartition(this); 217 _privatePartition = new UniversalCachePartition(this);
211 _cache = createCacheFromSourceFactory(null); 218 _cache = createCacheFromSourceFactory(null);
212 _taskManager = AnalysisEngine.instance.taskManager; 219 _taskManager = AnalysisEngine.instance.taskManager;
213 // TODO(scheglov) Get WorkManager(Factory)(s) from plugins. 220 // TODO(scheglov) Get WorkManager(Factory)(s) from plugins.
214 dartWorkManager = new DartWorkManager(this); 221 dartWorkManager = new DartWorkManager(this);
215 driver = 222 htmlWorkManager = new HtmlWorkManager(this);
216 new AnalysisDriver(_taskManager, <WorkManager>[dartWorkManager], this); 223 driver = new AnalysisDriver(
224 _taskManager, <WorkManager>[dartWorkManager, htmlWorkManager], this);
217 _onSourcesChangedController = 225 _onSourcesChangedController =
218 new StreamController<SourcesChangedEvent>.broadcast(); 226 new StreamController<SourcesChangedEvent>.broadcast();
219 } 227 }
220 228
221 @override 229 @override
222 AnalysisCache get analysisCache => _cache; 230 AnalysisCache get analysisCache => _cache;
223 231
224 @override 232 @override
225 AnalysisOptions get analysisOptions => _options; 233 AnalysisOptions get analysisOptions => _options;
226 234
(...skipping 23 matching lines...) Expand all
250 this._options.enableNullAwareOperators = options.enableNullAwareOperators; 258 this._options.enableNullAwareOperators = options.enableNullAwareOperators;
251 this._options.enableStrictCallChecks = options.enableStrictCallChecks; 259 this._options.enableStrictCallChecks = options.enableStrictCallChecks;
252 this._options.hint = options.hint; 260 this._options.hint = options.hint;
253 this._options.incremental = options.incremental; 261 this._options.incremental = options.incremental;
254 this._options.incrementalApi = options.incrementalApi; 262 this._options.incrementalApi = options.incrementalApi;
255 this._options.incrementalValidation = options.incrementalValidation; 263 this._options.incrementalValidation = options.incrementalValidation;
256 this._options.lint = options.lint; 264 this._options.lint = options.lint;
257 this._options.preserveComments = options.preserveComments; 265 this._options.preserveComments = options.preserveComments;
258 if (needsRecompute) { 266 if (needsRecompute) {
259 dartWorkManager.onAnalysisOptionsChanged(); 267 dartWorkManager.onAnalysisOptionsChanged();
268 htmlWorkManager.onAnalysisOptionsChanged();
260 } 269 }
261 } 270 }
262 271
263 @override 272 @override
264 void set analysisPriorityOrder(List<Source> sources) { 273 void set analysisPriorityOrder(List<Source> sources) {
265 if (sources == null || sources.isEmpty) { 274 if (sources == null || sources.isEmpty) {
266 _priorityOrder = Source.EMPTY_LIST; 275 _priorityOrder = Source.EMPTY_LIST;
267 } else { 276 } else {
268 while (sources.remove(null)) { 277 while (sources.remove(null)) {
269 // Nothing else to do. 278 // Nothing else to do.
270 } 279 }
271 if (sources.isEmpty) { 280 if (sources.isEmpty) {
272 _priorityOrder = Source.EMPTY_LIST; 281 _priorityOrder = Source.EMPTY_LIST;
273 } else { 282 } else {
274 _priorityOrder = sources; 283 _priorityOrder = sources;
275 } 284 }
276 } 285 }
277 dartWorkManager.applyPriorityTargets(_priorityOrder); 286 dartWorkManager.applyPriorityTargets(_priorityOrder);
287 htmlWorkManager.applyPriorityTargets(_priorityOrder);
278 } 288 }
279 289
280 @override 290 @override
281 set contentCache(ContentCache value) { 291 set contentCache(ContentCache value) {
282 _contentCache = value; 292 _contentCache = value;
283 } 293 }
284 294
285 @override 295 @override
286 DeclaredVariables get declaredVariables => _declaredVariables; 296 DeclaredVariables get declaredVariables => _declaredVariables;
287 297
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 throw new IllegalStateException( 375 throw new IllegalStateException(
366 "Source factories cannot be shared between contexts"); 376 "Source factories cannot be shared between contexts");
367 } 377 }
368 if (_sourceFactory != null) { 378 if (_sourceFactory != null) {
369 _sourceFactory.context = null; 379 _sourceFactory.context = null;
370 } 380 }
371 factory.context = this; 381 factory.context = this;
372 _sourceFactory = factory; 382 _sourceFactory = factory;
373 _cache = createCacheFromSourceFactory(factory); 383 _cache = createCacheFromSourceFactory(factory);
374 dartWorkManager.onSourceFactoryChanged(); 384 dartWorkManager.onSourceFactoryChanged();
385 htmlWorkManager.onSourceFactoryChanged();
375 } 386 }
376 387
377 @override 388 @override
378 List<Source> get sources { 389 List<Source> get sources {
379 return _cache.sources.toList(); 390 return _cache.sources.toList();
380 } 391 }
381 392
382 /** 393 /**
383 * Return a list of the sources that would be processed by 394 * Return a list of the sources that would be processed by
384 * [performAnalysisTask]. This method duplicates, and must therefore be kept 395 * [performAnalysisTask]. This method duplicates, and must therefore be kept
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 change.oldLength, change.newLength); 526 change.oldLength, change.newLength);
516 }); 527 });
517 for (Source source in changeSet.deletedSources) { 528 for (Source source in changeSet.deletedSources) {
518 _sourceDeleted(source); 529 _sourceDeleted(source);
519 } 530 }
520 for (Source source in removedSources) { 531 for (Source source in removedSources) {
521 _sourceRemoved(source); 532 _sourceRemoved(source);
522 } 533 }
523 dartWorkManager.applyChange( 534 dartWorkManager.applyChange(
524 changeSet.addedSources, changeSet.changedSources, removedSources); 535 changeSet.addedSources, changeSet.changedSources, removedSources);
536 htmlWorkManager.applyChange(
537 changeSet.addedSources, changeSet.changedSources, removedSources);
525 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet)); 538 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet));
526 } 539 }
527 540
528 @override 541 @override
529 String computeDocumentationComment(Element element) { 542 String computeDocumentationComment(Element element) {
530 if (element == null) { 543 if (element == null) {
531 return null; 544 return null;
532 } 545 }
533 Source source = element.source; 546 Source source = element.source;
534 if (source == null) { 547 if (source == null) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 // If the location cannot be decoded for some reason then the underlying 775 // If the location cannot be decoded for some reason then the underlying
763 // cause should have been logged already and we can fall though to return 776 // cause should have been logged already and we can fall though to return
764 // null. 777 // null.
765 } 778 }
766 return null; 779 return null;
767 } 780 }
768 781
769 @override 782 @override
770 AnalysisErrorInfo getErrors(Source source) { 783 AnalysisErrorInfo getErrors(Source source) {
771 String name = source.shortName; 784 String name = source.shortName;
772 if (AnalysisEngine.isDartFileName(name)) { 785 if (AnalysisEngine.isDartFileName(name) || source is DartScript) {
773 return dartWorkManager.getErrors(source); 786 return dartWorkManager.getErrors(source);
774 } else if (AnalysisEngine.isHtmlFileName(name)) { 787 } else if (AnalysisEngine.isHtmlFileName(name)) {
775 List<AnalysisError> errors = analysisCache.getValue(source, HTML_ERRORS); 788 return htmlWorkManager.getErrors(source);
776 // TODO(brianwilkerson) We don't currently have line info for HTML files.
777 return new AnalysisErrorInfoImpl(errors, null);
778 } 789 }
779 return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, null); 790 return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, null);
780 } 791 }
781 792
782 @override 793 @override
783 @deprecated 794 @deprecated
784 HtmlElement getHtmlElement(Source source) { 795 HtmlElement getHtmlElement(Source source) {
785 // TODO(brianwilkerson) Remove this method after switching to the new task 796 // TODO(brianwilkerson) Remove this method after switching to the new task
786 // model. 797 // model.
787 throw new UnimplementedError('Not supported in the new task model'); 798 throw new UnimplementedError('Not supported in the new task model');
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 entry.modificationTime = time; 1706 entry.modificationTime = time;
1696 } 1707 }
1697 return; 1708 return;
1698 } 1709 }
1699 } catch (e) {} 1710 } catch (e) {}
1700 } 1711 }
1701 // We need to invalidate the cache. 1712 // We need to invalidate the cache.
1702 entry.setState(CONTENT, CacheState.INVALID); 1713 entry.setState(CONTENT, CacheState.INVALID);
1703 dartWorkManager.applyChange( 1714 dartWorkManager.applyChange(
1704 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST); 1715 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST);
1716 htmlWorkManager.applyChange(
1717 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST);
1705 } 1718 }
1706 1719
1707 /** 1720 /**
1708 * Record that the give [source] has been deleted. 1721 * Record that the give [source] has been deleted.
1709 */ 1722 */
1710 void _sourceDeleted(Source source) { 1723 void _sourceDeleted(Source source) {
1711 // TODO(brianwilkerson) Implement this. 1724 // TODO(brianwilkerson) Implement this.
1712 // SourceEntry sourceEntry = _cache.get(source); 1725 // SourceEntry sourceEntry = _cache.get(source);
1713 // if (sourceEntry is HtmlEntry) { 1726 // if (sourceEntry is HtmlEntry) {
1714 // HtmlEntry htmlEntry = sourceEntry; 1727 // HtmlEntry htmlEntry = sourceEntry;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 new PendingFuture<T>(_context, target, computeValue); 2005 new PendingFuture<T>(_context, target, computeValue);
1993 if (!pendingFuture.evaluate(entry)) { 2006 if (!pendingFuture.evaluate(entry)) {
1994 _context._pendingFutureTargets 2007 _context._pendingFutureTargets
1995 .putIfAbsent(target, () => <PendingFuture>[]) 2008 .putIfAbsent(target, () => <PendingFuture>[])
1996 .add(pendingFuture); 2009 .add(pendingFuture);
1997 scheduleComputation(); 2010 scheduleComputation();
1998 } 2011 }
1999 return pendingFuture.future; 2012 return pendingFuture.future;
2000 } 2013 }
2001 } 2014 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/html_work_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698