OLD | NEW |
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 import 'dart:collection'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:core' hide Resource; | 10 import 'dart:core' hide Resource; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 /** | 397 /** |
398 * Virtual [ContextInfo] which acts as the ancestor of all other | 398 * Virtual [ContextInfo] which acts as the ancestor of all other |
399 * [ContextInfo]s. | 399 * [ContextInfo]s. |
400 */ | 400 */ |
401 final ContextInfo _rootInfo = new ContextInfo._root(); | 401 final ContextInfo _rootInfo = new ContextInfo._root(); |
402 | 402 |
403 /** | 403 /** |
404 * Stream subscription we are using to watch each analysis root directory for | 404 * Stream subscription we are using to watch each analysis root directory for |
405 * changes. | 405 * changes. |
406 */ | 406 */ |
407 final Map<Folder, StreamSubscription<WatchEvent>> _changeSubscriptions = | 407 final Map<Folder, StreamSubscription<WatchEvent>> changeSubscriptions = |
408 <Folder, StreamSubscription<WatchEvent>>{}; | 408 <Folder, StreamSubscription<WatchEvent>>{}; |
409 | 409 |
410 ContextManagerImpl(this.resourceProvider, this.packageResolverProvider, | 410 ContextManagerImpl(this.resourceProvider, this.packageResolverProvider, |
411 this._packageMapProvider, this._instrumentationService) { | 411 this._packageMapProvider, this._instrumentationService) { |
412 pathContext = resourceProvider.pathContext; | 412 pathContext = resourceProvider.pathContext; |
413 } | 413 } |
414 | 414 |
415 @override | 415 @override |
416 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { | 416 List<AnalysisContext> contextsInAnalysisRoot(Folder analysisRoot) { |
417 List<AnalysisContext> contexts = <AnalysisContext>[]; | 417 List<AnalysisContext> contexts = <AnalysisContext>[]; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 info.packageRoot = newPackageRoot; | 594 info.packageRoot = newPackageRoot; |
595 _recomputeFolderDisposition(info); | 595 _recomputeFolderDisposition(info); |
596 } | 596 } |
597 } | 597 } |
598 // create new contexts | 598 // create new contexts |
599 for (Folder includedFolder in includedFolders) { | 599 for (Folder includedFolder in includedFolders) { |
600 bool wasIncluded = contextInfos.any((info) { | 600 bool wasIncluded = contextInfos.any((info) { |
601 return info.folder.isOrContains(includedFolder.path); | 601 return info.folder.isOrContains(includedFolder.path); |
602 }); | 602 }); |
603 if (!wasIncluded) { | 603 if (!wasIncluded) { |
604 _changeSubscriptions[includedFolder] = | 604 changeSubscriptions[includedFolder] = |
605 includedFolder.changes.listen(_handleWatchEvent); | 605 includedFolder.changes.listen(_handleWatchEvent); |
606 _createContexts(_rootInfo, includedFolder, false); | 606 _createContexts(_rootInfo, includedFolder, false); |
607 } | 607 } |
608 } | 608 } |
609 // remove newly excluded sources | 609 // remove newly excluded sources |
610 for (ContextInfo info in _rootInfo.descendants) { | 610 for (ContextInfo info in _rootInfo.descendants) { |
611 // prepare excluded sources | 611 // prepare excluded sources |
612 Map<String, Source> excludedSources = new HashMap<String, Source>(); | 612 Map<String, Source> excludedSources = new HashMap<String, Source>(); |
613 info.sources.forEach((String path, Source source) { | 613 info.sources.forEach((String path, Source source) { |
614 if (_isExcludedBy(excludedPaths, path) && | 614 if (_isExcludedBy(excludedPaths, path) && |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 ChangeSet changeSet = new ChangeSet(); | 928 ChangeSet changeSet = new ChangeSet(); |
929 _addSourceFiles(changeSet, folder, parent); | 929 _addSourceFiles(changeSet, folder, parent); |
930 callbacks.applyChangesToContext(folder, changeSet); | 930 callbacks.applyChangesToContext(folder, changeSet); |
931 } | 931 } |
932 } | 932 } |
933 | 933 |
934 /** | 934 /** |
935 * Clean up and destroy the context associated with the given folder. | 935 * Clean up and destroy the context associated with the given folder. |
936 */ | 936 */ |
937 void _destroyContext(ContextInfo info) { | 937 void _destroyContext(ContextInfo info) { |
938 if (_changeSubscriptions.containsKey(info.folder)) { | 938 changeSubscriptions.remove(info.folder)?.cancel(); |
939 _changeSubscriptions[info.folder].cancel(); | |
940 } | |
941 callbacks.removeContext(info.folder, _computeFlushedFiles(info)); | 939 callbacks.removeContext(info.folder, _computeFlushedFiles(info)); |
942 bool wasRemoved = info.parent.children.remove(info); | 940 bool wasRemoved = info.parent.children.remove(info); |
943 assert(wasRemoved); | 941 assert(wasRemoved); |
944 } | 942 } |
945 | 943 |
946 /** | 944 /** |
947 * Extract a new [packagespecFile]-based context from [oldInfo]. | 945 * Extract a new [packagespecFile]-based context from [oldInfo]. |
948 */ | 946 */ |
949 void _extractContext(ContextInfo oldInfo, File packagespecFile) { | 947 void _extractContext(ContextInfo oldInfo, File packagespecFile) { |
950 Folder newFolder = packagespecFile.parent; | 948 Folder newFolder = packagespecFile.parent; |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 var path = resourceProvider.pathContext.fromUri(uri); | 1445 var path = resourceProvider.pathContext.fromUri(uri); |
1448 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; | 1446 packageMap[name] = <Folder>[resourceProvider.getFolder(path)]; |
1449 } | 1447 } |
1450 }); | 1448 }); |
1451 return <UriResolver>[new SdkExtUriResolver(packageMap)]; | 1449 return <UriResolver>[new SdkExtUriResolver(packageMap)]; |
1452 } else { | 1450 } else { |
1453 return const <UriResolver>[]; | 1451 return const <UriResolver>[]; |
1454 } | 1452 } |
1455 } | 1453 } |
1456 } | 1454 } |
OLD | NEW |