Chromium Code Reviews| 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)); |
| + } |
| + } |
| +} |