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

Unified Diff: pkg/analysis_server/lib/src/context_directory_manager.dart

Issue 450643005: Churn-only CL for ContextDirectoryManager. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_directory_manager_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/context_directory_manager.dart
diff --git a/pkg/analysis_server/lib/src/context_directory_manager.dart b/pkg/analysis_server/lib/src/context_directory_manager.dart
index a8d024e1c90047cc0ed5a574b662501fff926e21..90b4d237253e802a087ae7a73a626830b6ed29e4 100644
--- a/pkg/analysis_server/lib/src/context_directory_manager.dart
+++ b/pkg/analysis_server/lib/src/context_directory_manager.dart
@@ -7,36 +7,13 @@ library context.directory.manager;
import 'dart:async';
import 'dart:collection';
-import 'package:analyzer/file_system/file_system.dart';
import 'package:analysis_server/src/package_map_provider.dart';
+import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:watcher/watcher.dart';
/**
- * Information tracked by the [ContextDirectoryManager] for each context.
- */
-class _ContextDirectoryInfo {
- /**
- * Stream subscription we are using to watch the context's directory for
- * changes.
- */
- StreamSubscription<WatchEvent> changeSubscription;
-
- /**
- * Map from full path to the [Source] object, for each source that has been
- * added to the context.
- */
- Map<String, Source> sources = new HashMap<String, Source>();
-
- /**
- * Dependencies of the context's package map. If any of these files changes,
- * the package map needs to be recomputed.
- */
- Set<String> packageMapDependencies;
-}
-
-/**
* Class that maintains a mapping from included/excluded paths to a set of
* folders that should correspond to analysis contexts.
*/
@@ -67,11 +44,41 @@ abstract class ContextDirectoryManager {
ContextDirectoryManager(this.resourceProvider, this.packageMapProvider);
/**
+ * Called when a new context needs to be created.
+ */
+ void addContext(Folder folder, Map<String, List<Folder>> packageMap);
+
+ /**
+ * Called when the set of files associated with a context have changed (or
+ * some of those files have been modified). [changeSet] is the set of
+ * changes that need to be applied to the context.
+ */
+ void applyChangesToContext(Folder contextFolder, ChangeSet changeSet);
+
+ /**
+ * Returns `true` if the given absolute [path] is in one of the current
+ * root folders and is not excluded.
+ */
+ bool isInAnalysisRoot(String path) {
+ // TODO(scheglov) check for excluded paths
+ for (Folder root in _currentDirectoryInfo.keys) {
+ if (root.contains(path)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Remove the context associated with the given [folder].
+ */
+ void removeContext(Folder folder);
+
+ /**
* Change the set of paths which should be used as starting points to
* determine the context directories.
*/
- void setRoots(List<String> includedPaths,
- List<String> excludedPaths) {
+ void setRoots(List<String> includedPaths, List<String> excludedPaths) {
// included
Set<Folder> includedFolders = new HashSet<Folder>();
for (int i = 0; i < includedPaths.length; i++) {
@@ -83,14 +90,13 @@ abstract class ContextDirectoryManager {
// TODO(scheglov) implemented separate files analysis
throw new UnimplementedError(
'$path is not a folder. '
- 'Only support for folder analysis is implemented currently.');
+ 'Only support for folder analysis is implemented currently.');
}
}
// excluded
// TODO(scheglov) remove when implemented
if (excludedPaths.isNotEmpty) {
- throw new UnimplementedError(
- 'Excluded paths are not supported yet');
+ throw new UnimplementedError('Excluded paths are not supported yet');
}
Set<Folder> excludedFolders = new HashSet<Folder>();
// diff
@@ -108,6 +114,12 @@ abstract class ContextDirectoryManager {
}
/**
+ * Called when the package map for a context has changed.
+ */
+ void updateContextPackageMap(Folder contextFolder, Map<String,
+ List<Folder>> packageMap);
+
+ /**
* Create a new context associated with the given folder.
*/
void _createContext(Folder folder) {
@@ -117,7 +129,8 @@ abstract class ContextDirectoryManager {
_handleWatchEvent(folder, info, event);
});
File pubspecFile = folder.getChild(PUBSPEC_NAME);
- PackageMapInfo packageMapInfo = packageMapProvider.computePackageMap(folder);
+ PackageMapInfo packageMapInfo =
+ packageMapProvider.computePackageMap(folder);
info.packageMapDependencies = packageMapInfo.dependencies;
// TODO(paulberry): if any of the dependencies is outside of [folder],
// we'll need to watch their parent folders as well.
@@ -136,7 +149,8 @@ abstract class ContextDirectoryManager {
removeContext(folder);
}
- void _handleWatchEvent(Folder folder, _ContextDirectoryInfo info, WatchEvent event) {
+ void _handleWatchEvent(Folder folder, _ContextDirectoryInfo info,
+ WatchEvent event) {
switch (event.type) {
case ChangeType.ADD:
if (_isInPackagesDir(event.path, folder)) {
@@ -155,7 +169,7 @@ abstract class ContextDirectoryManager {
Source source = file.createSource();
changeSet.addedSource(source);
applyChangesToContext(folder, changeSet);
- info.sources[event.path]= source;
+ info.sources[event.path] = source;
}
}
break;
@@ -183,7 +197,8 @@ abstract class ContextDirectoryManager {
// asynchronous API call, we'll want to suspend analysis for this context
// while we're rerunning "pub list", since any analysis we complete while
// "pub list" is in progress is just going to get thrown away anyhow.
- PackageMapInfo packageMapInfo = packageMapProvider.computePackageMap(folder);
+ PackageMapInfo packageMapInfo =
+ packageMapProvider.computePackageMap(folder);
info.packageMapDependencies = packageMapInfo.dependencies;
updateContextPackageMap(folder, packageMapInfo.packageMap);
}
@@ -194,7 +209,8 @@ abstract class ContextDirectoryManager {
* directory.
*/
bool _isInPackagesDir(String path, Folder folder) {
- String relativePath = resourceProvider.pathContext.relative(path, from: folder.path);
+ String relativePath =
+ resourceProvider.pathContext.relative(path, from: folder.path);
List<String> pathParts = resourceProvider.pathContext.split(relativePath);
for (int i = 0; i < pathParts.length - 1; i++) {
if (pathParts[i] == 'packages') {
@@ -207,7 +223,8 @@ abstract class ContextDirectoryManager {
/**
* Resursively adds all Dart and HTML files to the [changeSet].
*/
- static void _addSourceFiles(ChangeSet changeSet, Folder folder, _ContextDirectoryInfo info) {
+ static void _addSourceFiles(ChangeSet changeSet, Folder folder,
+ _ContextDirectoryInfo info) {
List<Resource> children = folder.getChildren();
for (Resource child in children) {
if (child is File) {
@@ -228,8 +245,8 @@ abstract class ContextDirectoryManager {
}
static bool _shouldFileBeAnalyzed(File file) {
- if (!(AnalysisEngine.isDartFileName(file.path)
- || AnalysisEngine.isHtmlFileName(file.path))) {
+ if (!(AnalysisEngine.isDartFileName(file.path) ||
+ AnalysisEngine.isHtmlFileName(file.path))) {
return false;
}
// Emacs creates dummy links to track the fact that a file is open for
@@ -239,41 +256,27 @@ abstract class ContextDirectoryManager {
// causing the analyzer to thrash, just ignore links to non-existent files.
return file.exists;
}
+}
+/**
+ * Information tracked by the [ContextDirectoryManager] for each context.
+ */
+class _ContextDirectoryInfo {
/**
- * Returns `true` if the given absolute [path] is in one of the current
- * root folders and is not excluded.
- */
- bool isInAnalysisRoot(String path) {
- // TODO(scheglov) check for excluded paths
- for (Folder root in _currentDirectoryInfo.keys) {
- if (root.contains(path)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Called when a new context needs to be created.
- */
- void addContext(Folder folder, Map<String, List<Folder>> packageMap);
-
- /**
- * Called when the set of files associated with a context have changed (or
- * some of those files have been modified). [changeSet] is the set of
- * changes that need to be applied to the context.
+ * Stream subscription we are using to watch the context's directory for
+ * changes.
*/
- void applyChangesToContext(Folder contextFolder, ChangeSet changeSet);
+ StreamSubscription<WatchEvent> changeSubscription;
/**
- * Remove the context associated with the given [folder].
+ * Map from full path to the [Source] object, for each source that has been
+ * added to the context.
*/
- void removeContext(Folder folder);
+ Map<String, Source> sources = new HashMap<String, Source>();
/**
- * Called when the package map for a context has changed.
+ * Dependencies of the context's package map.
+ * If any of these files changes, the package map needs to be recomputed.
*/
- void updateContextPackageMap(Folder contextFolder,
- Map<String, List<Folder>> packageMap);
+ Set<String> packageMapDependencies;
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/context_directory_manager_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698