Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
|
scheglov
2015/01/22 20:14:20
Add a library name.
pquitslund
2015/01/26 20:21:28
Done.
| |
| 5 import 'package:analyzer/src/generated/element.dart'; | |
| 6 import 'package:analyzer/src/generated/engine.dart'; | |
| 7 import 'package:analyzer/src/generated/source.dart'; | |
| 8 | |
| 9 | |
| 10 class LibraryDependencyCollector { | |
| 11 | |
| 12 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.
| |
| 13 final Set<String> _dependencies = new Set<String>(); | |
| 14 | |
| 15 final List<AnalysisContext> _contexts; | |
| 16 | |
| 17 LibraryDependencyCollector(this._contexts); | |
| 18 | |
| 19 Set<String> collectLibraryDependencies() { | |
| 20 _contexts.forEach( | |
| 21 (AnalysisContext context) => | |
| 22 context.librarySources.forEach( | |
| 23 (Source source) => _addDependencies(context.getLibraryElement(so urce)))); | |
| 24 return _dependencies; | |
| 25 } | |
| 26 | |
| 27 void _addDependencies(LibraryElement libraryElement) { | |
| 28 if (libraryElement == null) { | |
| 29 return; | |
| 30 } | |
| 31 if (myVisitedLibraries.add(libraryElement)) { | |
| 32 for (CompilationUnitElement cu in libraryElement.units) { | |
| 33 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.
| |
| 34 if (path != null) { | |
| 35 _dependencies.add(path); | |
| 36 } | |
| 37 } | |
| 38 libraryElement.imports.forEach( | |
| 39 (ImportElement import) => _addDependencies(import.importedLibrary)); | |
| 40 libraryElement.exports.forEach( | |
| 41 (ExportElement export) => _addDependencies(export.exportedLibrary)); | |
| 42 } | |
| 43 } | |
| 44 } | |
| OLD | NEW |