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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 import 'dart:math' as math;
6
7 import 'package:analyzer/src/generated/element.dart';
8 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/source.dart';
10
11 String _getParentPath(String path) {
scheglov 2015/01/21 15:10:06 Use "dirname" from "package:path" instead.
pquitslund 2015/01/22 19:22:15 Good idea. I'm changing the API to return librari
12 if (path.length == 0) {
13 return '';
14 }
15 int end = math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
16 if (end == path.length - 1) {
17 end =
18 math.max(path.lastIndexOf('/', end - 1), path.lastIndexOf('\\', end - 1) );
19 }
20 return end == -1 ? '' : path.substring(0, end);
21 }
22
23 class LibraryDependencyCollector {
24
25 final Set<LibraryElement> myVisitedLibraries = new Set<LibraryElement>();
26 final Set<String> _dependencies = new Set<String>();
27
28 final List<AnalysisContext> _contexts;
29
30 LibraryDependencyCollector(this._contexts);
31
32 Set<String> collectFolderDependencies() {
33 _contexts.forEach(
34 (AnalysisContext context) =>
35 context.librarySources.forEach(
36 (Source source) => _addDependencies(context.getLibraryElement(so urce))));
37 return _dependencies;
38 }
39
40 void _addDependencies(LibraryElement libraryElement) {
41 if (libraryElement == null) {
42 return;
43 }
44 if (myVisitedLibraries.add(libraryElement)) {
45 for (CompilationUnitElement cu in libraryElement.units) {
46 final String path = cu.source.fullName;
47 if (path != null) {
48 _dependencies.add(_getParentPath(path));
49 }
50 }
51 libraryElement.imports.forEach(
52 (ImportElement import) => _addDependencies(import.importedLibrary));
53 libraryElement.exports.forEach(
54 (ExportElement export) => _addDependencies(export.exportedLibrary));
55 }
56 }
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698