Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library analyzer.src.task.dart_work_manager; | |
| 6 | |
| 7 import 'dart:collection'; | |
| 8 | |
| 9 import 'package:analyzer/src/context/cache.dart'; | |
| 10 import 'package:analyzer/src/generated/engine.dart' | |
| 11 show AnalysisEngine, CacheState, InternalAnalysisContext; | |
| 12 import 'package:analyzer/src/generated/source.dart'; | |
| 13 import 'package:analyzer/src/task/dart.dart'; | |
| 14 import 'package:analyzer/src/task/driver.dart'; | |
| 15 import 'package:analyzer/task/dart.dart'; | |
| 16 import 'package:analyzer/task/model.dart'; | |
| 17 | |
| 18 /** | |
| 19 * The manager for Dart specific analysis. | |
| 20 */ | |
| 21 class DartWorkManager implements WorkManager { | |
| 22 final InternalAnalysisContext context; | |
| 23 | |
| 24 /** | |
| 25 * The explicit sources to analyze. | |
| 26 */ | |
| 27 final HashSet<Source> explicitSources = new HashSet<Source>(); | |
|
Brian Wilkerson
2015/05/09 17:22:00
The sets of 'explicitSources', 'librarySources' an
scheglov
2015/05/09 23:20:17
Well, you're right that they're not used now.
But:
| |
| 28 | |
| 29 /** | |
| 30 * The known library source. | |
| 31 */ | |
| 32 final HashSet<Source> librarySources = new HashSet<Source>(); | |
| 33 | |
| 34 /** | |
| 35 * The know part sources. | |
| 36 */ | |
| 37 final HashSet<Source> partSources = new HashSet<Source>(); | |
| 38 | |
| 39 /** | |
| 40 * The sources whose kind we don't know yet. | |
| 41 */ | |
| 42 final LinkedHashSet<Source> unknownSourceQueue = new LinkedHashSet<Source>(); | |
| 43 | |
| 44 /** | |
| 45 * The queue of library sources to process. | |
| 46 */ | |
| 47 final LinkedHashSet<Source> librarySourceQueue = new LinkedHashSet<Source>(); | |
| 48 | |
| 49 /** | |
| 50 * Initialize a newly created manager. | |
| 51 */ | |
| 52 DartWorkManager(this.context); | |
| 53 | |
| 54 /** | |
| 55 * Notifies the manager about changes in the explicit source list. | |
| 56 */ | |
| 57 void applyChange(List<Source> addedSources, List<Source> changedSources, | |
| 58 List<Source> removedSources) { | |
| 59 addedSources = addedSources.where(_isDartSource).toList(); | |
| 60 changedSources = changedSources.where(_isDartSource).toList(); | |
| 61 removedSources = removedSources.where(_isDartSource).toList(); | |
| 62 // explicit | |
| 63 explicitSources.addAll(addedSources); | |
| 64 explicitSources.removeAll(removedSources); | |
| 65 // library | |
| 66 librarySources.removeAll(changedSources); | |
| 67 librarySources.removeAll(removedSources); | |
| 68 // part | |
| 69 partSources.removeAll(changedSources); | |
| 70 partSources.removeAll(removedSources); | |
| 71 // unknown queue | |
| 72 unknownSourceQueue.addAll(addedSources); | |
| 73 unknownSourceQueue.addAll(changedSources); | |
| 74 unknownSourceQueue.removeAll(removedSources); | |
| 75 // library queue | |
| 76 librarySourceQueue.removeAll(changedSources); | |
| 77 librarySourceQueue.removeAll(removedSources); | |
| 78 } | |
| 79 | |
| 80 @override | |
| 81 TargetedResult getNextResult() { | |
| 82 // Try to find a new library to analyze. | |
| 83 while (librarySourceQueue.isNotEmpty) { | |
| 84 Source librarySource = librarySourceQueue.first; | |
| 85 CacheEntry entry = context.getCacheEntry(librarySource); | |
| 86 CacheState state = entry.getState(LIBRARY_ERRORS_READY); | |
| 87 // Maybe done with this library. | |
| 88 if (state == CacheState.VALID || state == CacheState.ERROR) { | |
| 89 librarySourceQueue.remove(librarySource); | |
| 90 continue; | |
| 91 } | |
| 92 // Analyze this library. | |
| 93 return new TargetedResult(librarySource, LIBRARY_ERRORS_READY); | |
| 94 } | |
| 95 // No libraries in the queue, check whether there are sources to organize. | |
| 96 while (unknownSourceQueue.isNotEmpty) { | |
| 97 Source source = unknownSourceQueue.first; | |
| 98 CacheEntry entry = context.getCacheEntry(source); | |
| 99 CacheState state = entry.getState(SOURCE_KIND); | |
| 100 // Maybe done with this source. | |
| 101 if (state == CacheState.VALID || state == CacheState.ERROR) { | |
| 102 unknownSourceQueue.remove(source); | |
| 103 continue; | |
| 104 } | |
| 105 // Compute the kind of this source. | |
| 106 return new TargetedResult(source, SOURCE_KIND); | |
| 107 } | |
| 108 // No results to compute. | |
| 109 return null; | |
|
Brian Wilkerson
2015/05/09 17:22:00
The old work manager also maintained a queue of pa
scheglov
2015/05/09 23:20:17
Good idea.
I've added a TODO comment.
| |
| 110 } | |
| 111 | |
| 112 @override | |
| 113 void resultsComputed( | |
| 114 AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) { | |
| 115 // Organize sources. | |
| 116 if (_isDartSource(target)) { | |
| 117 SourceKind kind = outputs[SOURCE_KIND]; | |
| 118 if (kind != null) { | |
| 119 unknownSourceQueue.remove(target); | |
| 120 if (kind == SourceKind.PART) { | |
| 121 librarySources.remove(target); | |
| 122 partSources.add(target); | |
| 123 } else { | |
| 124 librarySources.add(target); | |
| 125 partSources.remove(target); | |
| 126 librarySourceQueue.add(target); | |
| 127 } | |
| 128 } | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 bool _isDartSource(AnalysisTarget target) { | |
| 133 return target is Source && AnalysisEngine.isDartFileName(target.fullName); | |
| 134 } | |
| 135 } | |
| OLD | NEW |