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