| 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.task.model; | 5 library analyzer.task.model; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:developer'; | 8 import 'dart:developer'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; | 10 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 caughtException = new CaughtException(exception, stackTrace); | 207 caughtException = new CaughtException(exception, stackTrace); |
| 208 AnalysisEngine.instance.logger | 208 AnalysisEngine.instance.logger |
| 209 .logInformation("Task failed: ${description}", caughtException); | 209 .logInformation("Task failed: ${description}", caughtException); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 | 212 |
| 213 @override | 213 @override |
| 214 String toString() => description; | 214 String toString() => description; |
| 215 | 215 |
| 216 /** | 216 /** |
| 217 * Given a strongly connected component, find and return a list of |
| 218 * [TargetedResult]s that describes a cyclic path within the cycle. Returns |
| 219 * null if no cyclic path is found. |
| 220 */ |
| 221 List<TargetedResult> _findCyclicPath(List<WorkItem> cycle) { |
| 222 WorkItem findInCycle(AnalysisTarget target, ResultDescriptor descriptor) { |
| 223 for (WorkItem item in cycle) { |
| 224 if (target == item.target && descriptor == item.spawningResult) { |
| 225 return item; |
| 226 } |
| 227 } |
| 228 return null; |
| 229 } |
| 230 |
| 231 HashSet<WorkItem> active = new HashSet<WorkItem>(); |
| 232 List<TargetedResult> path = null; |
| 233 bool traverse(WorkItem item) { |
| 234 if (!active.add(item)) { |
| 235 // We've found a cycle |
| 236 path = <TargetedResult>[]; |
| 237 return true; |
| 238 } |
| 239 for (TargetedResult result in item.inputTargetedResults) { |
| 240 WorkItem item = findInCycle(result.target, result.result); |
| 241 // Ignore edges that leave the cycle. |
| 242 if (item != null) { |
| 243 if (traverse(item)) { |
| 244 // This edge is in a cycle (or leads to a cycle) so add it to the |
| 245 // path |
| 246 path.add(result); |
| 247 return true; |
| 248 } |
| 249 } |
| 250 } |
| 251 // There was no cycle. |
| 252 return false; |
| 253 } |
| 254 if (cycle.length > 0) { |
| 255 traverse(cycle[0]); |
| 256 } |
| 257 return path; |
| 258 } |
| 259 |
| 260 /** |
| 217 * Perform this analysis task, ensuring that all exceptions are wrapped in an | 261 * Perform this analysis task, ensuring that all exceptions are wrapped in an |
| 218 * [AnalysisException]. | 262 * [AnalysisException]. |
| 219 * | 263 * |
| 220 * Clients may not override this method. | 264 * Clients may not override this method. |
| 221 */ | 265 */ |
| 222 void _safelyPerform() { | 266 void _safelyPerform() { |
| 223 try { | 267 try { |
| 224 // | 268 // |
| 225 // Report that this task is being performed. | 269 // Report that this task is being performed. |
| 226 // | 270 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 243 stopwatchMap[runtimeType] = stopwatch; | 287 stopwatchMap[runtimeType] = stopwatch; |
| 244 } | 288 } |
| 245 // UserTag previousTag = tag.makeCurrent(); | 289 // UserTag previousTag = tag.makeCurrent(); |
| 246 // try { | 290 // try { |
| 247 stopwatch.start(); | 291 stopwatch.start(); |
| 248 // | 292 // |
| 249 // Actually perform the task. | 293 // Actually perform the task. |
| 250 // | 294 // |
| 251 try { | 295 try { |
| 252 if (dependencyCycle != null && !handlesDependencyCycles) { | 296 if (dependencyCycle != null && !handlesDependencyCycles) { |
| 253 throw new InfiniteTaskLoopException(this, dependencyCycle); | 297 throw new InfiniteTaskLoopException( |
| 298 this, dependencyCycle, _findCyclicPath(dependencyCycle)); |
| 254 } | 299 } |
| 255 internalPerform(); | 300 internalPerform(); |
| 256 } finally { | 301 } finally { |
| 257 stopwatch.stop(); | 302 stopwatch.stop(); |
| 258 } | 303 } |
| 259 // } finally { | 304 // } finally { |
| 260 // previousTag.makeCurrent(); | 305 // previousTag.makeCurrent(); |
| 261 // } | 306 // } |
| 262 } on AnalysisException { | 307 } on AnalysisException { |
| 263 rethrow; | 308 rethrow; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 /** | 718 /** |
| 674 * A work should be done, but without any special urgency. | 719 * A work should be done, but without any special urgency. |
| 675 */ | 720 */ |
| 676 NORMAL, | 721 NORMAL, |
| 677 | 722 |
| 678 /** | 723 /** |
| 679 * Nothing to do. | 724 * Nothing to do. |
| 680 */ | 725 */ |
| 681 NONE | 726 NONE |
| 682 } | 727 } |
| OLD | NEW |