Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

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: spec_bump Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 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 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_analysis.dart ('k') | pkg/analysis_server/test/domain_analysis_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698