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 services.dependencies.reachable_source_collector; |
| 6 |
| 7 import 'dart:collection'; |
| 8 |
| 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:analyzer/task/dart.dart'; |
| 12 |
| 13 /// Collects reachable sources. |
| 14 class ReachableSourceCollector { |
| 15 final Map<String, List<String>> _sourceMap = |
| 16 new HashMap<String, List<String>>(); |
| 17 |
| 18 final Source source; |
| 19 final AnalysisContext context; |
| 20 ReachableSourceCollector(this.source, this.context) { |
| 21 if (source == null) { |
| 22 throw new ArgumentError.notNull('source'); |
| 23 } |
| 24 if (context == null) { |
| 25 throw new ArgumentError.notNull('context'); |
| 26 } |
| 27 } |
| 28 |
| 29 /// Collect reachable sources. |
| 30 Map<String, List<String>> collectSources() { |
| 31 _addDependencies(source); |
| 32 return _sourceMap; |
| 33 } |
| 34 |
| 35 void _addDependencies(Source source) { |
| 36 |
| 37 String sourceUri = source.uri.toString(); |
| 38 |
| 39 // Careful not to revisit. |
| 40 if (_sourceMap[source.uri.toString()] != null) { |
| 41 return; |
| 42 } |
| 43 |
| 44 List<Source> sources = <Source>[]; |
| 45 sources.addAll(context.computeResult(source, IMPORTED_LIBRARIES)); |
| 46 sources.addAll(context.computeResult(source, EXPORTED_LIBRARIES)); |
| 47 |
| 48 _sourceMap[sourceUri] = |
| 49 sources.map((source) => source.uri.toString()).toList(); |
| 50 |
| 51 sources.forEach((s) => _addDependencies(s)); |
| 52 } |
| 53 } |
OLD | NEW |