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

Unified Diff: pkg/analysis_server/lib/src/services/dependencies/library_dependencies.dart

Issue 861893003: Library Dependencies Analysis service API. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 months 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/library_dependencies.dart
===================================================================
--- pkg/analysis_server/lib/src/services/dependencies/library_dependencies.dart (revision 0)
+++ pkg/analysis_server/lib/src/services/dependencies/library_dependencies.dart (revision 0)
@@ -0,0 +1,44 @@
+// 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.
+
scheglov 2015/01/22 20:14:20 Add a library name.
pquitslund 2015/01/26 20:21:28 Done.
+import 'package:analyzer/src/generated/element.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/source.dart';
+
+
+class LibraryDependencyCollector {
+
+ final Set<LibraryElement> myVisitedLibraries = new Set<LibraryElement>();
scheglov 2015/01/22 20:14:20 Strange name ;-) Why not just "_visitedLibraries"?
pquitslund 2015/01/26 20:21:28 Done.
+ final Set<String> _dependencies = new Set<String>();
+
+ final List<AnalysisContext> _contexts;
+
+ LibraryDependencyCollector(this._contexts);
+
+ Set<String> collectLibraryDependencies() {
+ _contexts.forEach(
+ (AnalysisContext context) =>
+ context.librarySources.forEach(
+ (Source source) => _addDependencies(context.getLibraryElement(source))));
+ return _dependencies;
+ }
+
+ void _addDependencies(LibraryElement libraryElement) {
+ if (libraryElement == null) {
+ return;
+ }
+ if (myVisitedLibraries.add(libraryElement)) {
+ for (CompilationUnitElement cu in libraryElement.units) {
+ final String path = cu.source.fullName;
scheglov 2015/01/22 20:14:20 I don't think we need to make local variables priv
pquitslund 2015/01/26 20:21:28 Done.
+ if (path != null) {
+ _dependencies.add(path);
+ }
+ }
+ libraryElement.imports.forEach(
+ (ImportElement import) => _addDependencies(import.importedLibrary));
+ libraryElement.exports.forEach(
+ (ExportElement export) => _addDependencies(export.exportedLibrary));
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698