Chromium Code Reviews

Side by Side Diff: pkg/analysis_server/lib/src/services/dependencies/reachable_source_collector.dart

Issue 1491013002: Analysis request `getReachableSources` (#24893). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(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
22 /// Collect reachable sources.
23 Map<String, List<String>> collectSources() {
24 // Play it safe in case we're passed a source with no context.
25 if (context != null) {
26 _addDependencies(source);
27 }
28 return _sourceMap;
29 }
30
31 void _addDependencies(Source source) {
32 String sourceUri = source?.uri?.toString();
Brian Wilkerson 2015/12/02 01:56:27 nit: We don't need the null-aware operators if we
pquitslund 2015/12/02 16:40:22 Except that this is called recursively... My thin
Brian Wilkerson 2015/12/02 18:04:53 That shouldn't be the case. IMPORTED_LIBRARIES and
33
34 // Bail if the source or URI are null.
35 if (sourceUri == null) {
Brian Wilkerson 2015/12/02 01:56:27 Similarly, we don't need this test.
pquitslund 2015/12/02 16:40:22 See above. FWIW: my rationale is based on doing a
36 return;
37 }
38
39 // Careful not to revisit.
40 if (_sourceMap[sourceUri] != 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 }
OLDNEW

Powered by Google App Engine