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

Side by Side Diff: pkg/analysis_server/lib/src/context_directory_manager.dart

Issue 325433003: Replace Map with HashMap (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library context.directory.manager; 5 library context.directory.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection';
8 9
9 import 'package:analysis_server/src/resource.dart'; 10 import 'package:analysis_server/src/resource.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 11 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
12 import 'package:watcher/watcher.dart'; 13 import 'package:watcher/watcher.dart';
13 14
14 /** 15 /**
15 * Information tracked by the [ContextDirectoryManager] for each context. 16 * Information tracked by the [ContextDirectoryManager] for each context.
16 */ 17 */
17 class _ContextDirectoryInfo { 18 class _ContextDirectoryInfo {
18 /** 19 /**
19 * Stream subscription we are using to watch the context's directory for 20 * Stream subscription we are using to watch the context's directory for
20 * changes. 21 * changes.
21 */ 22 */
22 StreamSubscription<WatchEvent> changeSubscription; 23 StreamSubscription<WatchEvent> changeSubscription;
23 24
24 /** 25 /**
25 * Map from full path to the [Source] object, for each source that has been 26 * Map from full path to the [Source] object, for each source that has been
26 * added to the context. 27 * added to the context.
27 */ 28 */
28 Map<String, Source> sources = <String, Source>{}; 29 Map<String, Source> sources = new HashMap<String, Source>();
29 } 30 }
30 31
31 /** 32 /**
32 * Class that maintains a mapping from included/excluded paths to a set of 33 * Class that maintains a mapping from included/excluded paths to a set of
33 * folders that should correspond to analysis contexts. 34 * folders that should correspond to analysis contexts.
34 */ 35 */
35 abstract class ContextDirectoryManager { 36 abstract class ContextDirectoryManager {
36 /** 37 /**
37 * [_ContextDirectoryInfo] object for each included directory in the most 38 * [_ContextDirectoryInfo] object for each included directory in the most
38 * recent successful call to [setRoots]. 39 * recent successful call to [setRoots].
39 */ 40 */
40 Map<Folder, _ContextDirectoryInfo> _currentDirectoryInfo = 41 Map<Folder, _ContextDirectoryInfo> _currentDirectoryInfo =
41 <Folder, _ContextDirectoryInfo>{}; 42 new HashMap<Folder, _ContextDirectoryInfo>();
42 43
43 /** 44 /**
44 * The [ResourceProvider] using which paths are converted into [Resource]s. 45 * The [ResourceProvider] using which paths are converted into [Resource]s.
45 */ 46 */
46 final ResourceProvider resourceProvider; 47 final ResourceProvider resourceProvider;
47 48
48 ContextDirectoryManager(this.resourceProvider); 49 ContextDirectoryManager(this.resourceProvider);
49 50
50 /** 51 /**
51 * Change the set of paths which should be used as starting points to 52 * Change the set of paths which should be used as starting points to
52 * determine the context directories. 53 * determine the context directories.
53 */ 54 */
54 void setRoots(List<String> includedPaths, 55 void setRoots(List<String> includedPaths,
55 List<String> excludedPaths) { 56 List<String> excludedPaths) {
56 // included 57 // included
57 Set<Folder> includedFolders = new Set<Folder>(); 58 Set<Folder> includedFolders = new HashSet<Folder>();
58 for (int i = 0; i < includedPaths.length; i++) { 59 for (int i = 0; i < includedPaths.length; i++) {
59 String path = includedPaths[i]; 60 String path = includedPaths[i];
60 Resource resource = resourceProvider.getResource(path); 61 Resource resource = resourceProvider.getResource(path);
61 if (resource is Folder) { 62 if (resource is Folder) {
62 includedFolders.add(resource); 63 includedFolders.add(resource);
63 } else { 64 } else {
64 // TODO(scheglov) implemented separate files analysis 65 // TODO(scheglov) implemented separate files analysis
65 throw new UnimplementedError( 66 throw new UnimplementedError(
66 '$path is not a folder. ' 67 '$path is not a folder. '
67 'Only support for folder analysis is implemented currently.'); 68 'Only support for folder analysis is implemented currently.');
68 } 69 }
69 } 70 }
70 // excluded 71 // excluded
71 // TODO(scheglov) remove when implemented 72 // TODO(scheglov) remove when implemented
72 if (excludedPaths.isNotEmpty) { 73 if (excludedPaths.isNotEmpty) {
73 throw new UnimplementedError( 74 throw new UnimplementedError(
74 'Excluded paths are not supported yet'); 75 'Excluded paths are not supported yet');
75 } 76 }
76 Set<Folder> excludedFolders = new Set<Folder>(); 77 Set<Folder> excludedFolders = new HashSet<Folder>();
77 // diff 78 // diff
78 Set<Folder> currentFolders = _currentDirectoryInfo.keys.toSet(); 79 Set<Folder> currentFolders = _currentDirectoryInfo.keys.toSet();
79 Set<Folder> newFolders = includedFolders.difference(currentFolders); 80 Set<Folder> newFolders = includedFolders.difference(currentFolders);
80 Set<Folder> oldFolders = currentFolders.difference(includedFolders); 81 Set<Folder> oldFolders = currentFolders.difference(includedFolders);
81 // remove old contexts 82 // remove old contexts
82 for (Folder folder in oldFolders) { 83 for (Folder folder in oldFolders) {
83 _currentDirectoryInfo.remove(folder); 84 _currentDirectoryInfo.remove(folder);
84 removeContext(folder); 85 removeContext(folder);
85 } 86 }
86 // add new contexts 87 // add new contexts
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 * some of those files have been modified). [changeSet] is the set of 194 * some of those files have been modified). [changeSet] is the set of
194 * changes that need to be applied to the context. 195 * changes that need to be applied to the context.
195 */ 196 */
196 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet); 197 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet);
197 198
198 /** 199 /**
199 * Remove the context associated with the given [folder]. 200 * Remove the context associated with the given [folder].
200 */ 201 */
201 void removeContext(Folder folder); 202 void removeContext(Folder folder);
202 } 203 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698