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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/dependencies/reachable_source_collector.dart
diff --git a/pkg/analysis_server/lib/src/services/dependencies/reachable_source_collector.dart b/pkg/analysis_server/lib/src/services/dependencies/reachable_source_collector.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a0273cea86dc04b06a0814d7a316671b480b6716
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/dependencies/reachable_source_collector.dart
@@ -0,0 +1,53 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library services.dependencies.reachable_source_collector;
+
+import 'dart:collection';
+
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/task/dart.dart';
+
+/// Collects reachable sources.
+class ReachableSourceCollector {
+ final Map<String, List<String>> _sourceMap =
+ new HashMap<String, List<String>>();
+
+ final Source source;
+ final AnalysisContext context;
+ ReachableSourceCollector(this.source, this.context) {
+ if (source == null) {
+ throw new ArgumentError.notNull('source');
+ }
+ if (context == null) {
+ throw new ArgumentError.notNull('context');
+ }
+ }
+
+ /// Collect reachable sources.
+ Map<String, List<String>> collectSources() {
+ _addDependencies(source);
+ return _sourceMap;
+ }
+
+ void _addDependencies(Source source) {
+
+ String sourceUri = source.uri.toString();
+
+ // Careful not to revisit.
+ if (_sourceMap[source.uri.toString()] != null) {
+ return;
+ }
+
+ List<Source> sources = <Source>[];
+ sources.addAll(context.computeResult(source, IMPORTED_LIBRARIES));
+ sources.addAll(context.computeResult(source, EXPORTED_LIBRARIES));
+
+ _sourceMap[sourceUri] =
+ sources.map((source) => source.uri.toString()).toList();
+
+ sources.forEach((s) => _addDependencies(s));
+ }
+}
« 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