| OLD | NEW |
| 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.task.dart_work_manager; | 5 library analyzer.src.task.dart_work_manager; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // part | 60 // part |
| 61 partSources.removeAll(changedSources); | 61 partSources.removeAll(changedSources); |
| 62 partSources.removeAll(removedSources); | 62 partSources.removeAll(removedSources); |
| 63 // unknown queue | 63 // unknown queue |
| 64 unknownSourceQueue.addAll(addedSources); | 64 unknownSourceQueue.addAll(addedSources); |
| 65 unknownSourceQueue.addAll(changedSources); | 65 unknownSourceQueue.addAll(changedSources); |
| 66 unknownSourceQueue.removeAll(removedSources); | 66 unknownSourceQueue.removeAll(removedSources); |
| 67 // library queue | 67 // library queue |
| 68 librarySourceQueue.removeAll(changedSources); | 68 librarySourceQueue.removeAll(changedSources); |
| 69 librarySourceQueue.removeAll(removedSources); | 69 librarySourceQueue.removeAll(removedSources); |
| 70 // TODO(scheglov) This is an inefficient implementation. |
| 71 // We could make the cache to return invalidated results and use them |
| 72 // to allow work managers to schedule work request. |
| 73 librarySourceQueue.addAll(librarySources); |
| 70 } | 74 } |
| 71 | 75 |
| 72 @override | 76 @override |
| 73 TargetedResult getNextResult() { | 77 TargetedResult getNextResult() { |
| 74 // Try to find a new library to analyze. | 78 // Try to find a new library to analyze. |
| 75 while (librarySourceQueue.isNotEmpty) { | 79 while (librarySourceQueue.isNotEmpty) { |
| 76 Source librarySource = librarySourceQueue.first; | 80 Source librarySource = librarySourceQueue.first; |
| 77 CacheEntry entry = context.getCacheEntry(librarySource); | 81 CacheEntry entry = context.getCacheEntry(librarySource); |
| 78 CacheState state = entry.getState(LIBRARY_ERRORS_READY); | 82 CacheState state = entry.getState(LIBRARY_ERRORS_READY); |
| 79 // Maybe done with this library. | 83 // Maybe done with this library. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 97 // Compute the kind of this source. | 101 // Compute the kind of this source. |
| 98 return new TargetedResult(source, SOURCE_KIND); | 102 return new TargetedResult(source, SOURCE_KIND); |
| 99 } | 103 } |
| 100 // TODO(scheglov) Report errors for parts that remained in the queue after | 104 // TODO(scheglov) Report errors for parts that remained in the queue after |
| 101 // all libraries had been processed. | 105 // all libraries had been processed. |
| 102 // No results to compute. | 106 // No results to compute. |
| 103 return null; | 107 return null; |
| 104 } | 108 } |
| 105 | 109 |
| 106 @override | 110 @override |
| 111 WorkOrderPriority getNextResultPriority() { |
| 112 if (unknownSourceQueue.isNotEmpty || librarySourceQueue.isNotEmpty) { |
| 113 return WorkOrderPriority.NORMAL; |
| 114 } |
| 115 return WorkOrderPriority.NONE; |
| 116 } |
| 117 |
| 118 @override |
| 107 void resultsComputed( | 119 void resultsComputed( |
| 108 AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) { | 120 AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) { |
| 109 // Organize sources. | 121 // Organize sources. |
| 110 if (_isDartSource(target)) { | 122 if (_isDartSource(target)) { |
| 111 SourceKind kind = outputs[SOURCE_KIND]; | 123 SourceKind kind = outputs[SOURCE_KIND]; |
| 112 if (kind != null) { | 124 if (kind != null) { |
| 113 unknownSourceQueue.remove(target); | 125 unknownSourceQueue.remove(target); |
| 114 if (kind == SourceKind.PART) { | 126 if (kind == SourceKind.PART) { |
| 115 librarySources.remove(target); | 127 librarySources.remove(target); |
| 116 partSources.add(target); | 128 partSources.add(target); |
| 117 } else { | 129 } else { |
| 118 librarySources.add(target); | 130 librarySources.add(target); |
| 119 partSources.remove(target); | 131 partSources.remove(target); |
| 120 librarySourceQueue.add(target); | 132 librarySourceQueue.add(target); |
| 121 } | 133 } |
| 122 } | 134 } |
| 123 } | 135 } |
| 124 } | 136 } |
| 125 | 137 |
| 126 bool _isDartSource(AnalysisTarget target) { | 138 bool _isDartSource(AnalysisTarget target) { |
| 127 return target is Source && AnalysisEngine.isDartFileName(target.fullName); | 139 return target is Source && AnalysisEngine.isDartFileName(target.fullName); |
| 128 } | 140 } |
| 129 } | 141 } |
| OLD | NEW |