| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library context.directory.manager; |
| 6 |
| 7 import 'package:analysis_server/src/resource.dart'; |
| 8 |
| 9 /** |
| 10 * Class that maintains a mapping from included/excluded paths to a set of |
| 11 * folders that should correspond to analysis contexts. |
| 12 */ |
| 13 abstract class ContextDirectoryManager { |
| 14 /** |
| 15 * The set of included folders in the most recent successful call to |
| 16 * [setRoots]. |
| 17 */ |
| 18 Set<Folder> currentFolders = new Set<Folder>(); |
| 19 |
| 20 /** |
| 21 * The [ResourceProvider] using which paths are converted into [Resource]s. |
| 22 */ |
| 23 final ResourceProvider resourceProvider; |
| 24 |
| 25 ContextDirectoryManager(this.resourceProvider); |
| 26 |
| 27 /** |
| 28 * Change the set of paths which should be used as starting points to |
| 29 * determine the context directories. |
| 30 */ |
| 31 void setRoots(List<String> includedPaths, |
| 32 List<String> excludedPaths) { |
| 33 // included |
| 34 Set<Folder> includedFolders = new Set<Folder>(); |
| 35 for (int i = 0; i < includedPaths.length; i++) { |
| 36 String path = includedPaths[i]; |
| 37 Resource resource = resourceProvider.getResource(path); |
| 38 if (resource is Folder) { |
| 39 includedFolders.add(resource); |
| 40 } else { |
| 41 // TODO(scheglov) implemented separate files analysis |
| 42 throw new UnimplementedError( |
| 43 '$path is not a folder. ' |
| 44 'Only support for folder analysis is implemented currently.'); |
| 45 } |
| 46 } |
| 47 // excluded |
| 48 // TODO(scheglov) remove when implemented |
| 49 if (excludedPaths.isNotEmpty) { |
| 50 throw new UnimplementedError( |
| 51 'Excluded paths are not supported yet'); |
| 52 } |
| 53 Set<Folder> excludedFolders = new Set<Folder>(); |
| 54 // diff |
| 55 Set<Folder> newFolders = includedFolders.difference(currentFolders); |
| 56 Set<Folder> oldFolders = currentFolders.difference(includedFolders); |
| 57 // remove old contexts |
| 58 for (Folder folder in oldFolders) { |
| 59 // TODO(scheglov) implement |
| 60 } |
| 61 // add new contexts |
| 62 for (Folder folder in newFolders) { |
| 63 addContext(folder); |
| 64 } |
| 65 currentFolders = new Set<Folder>.from(includedFolders); |
| 66 } |
| 67 |
| 68 /** |
| 69 * Called when a new context needs to be created. |
| 70 */ |
| 71 void addContext(Folder folder); |
| 72 } |
| OLD | NEW |