| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/src/generated/utilities_general.dart'; | 5 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 6 import 'package:path/path.dart' as path; |
| 6 | 7 |
| 7 /** | 8 /** |
| 8 * Information about the root directory associated with an analysis context. | 9 * Information about the root directory associated with an analysis context. |
| 9 * | 10 * |
| 10 * Clients may not extend, implement or mix-in this class. | 11 * Clients may not extend, implement or mix-in this class. |
| 11 */ | 12 */ |
| 12 class ContextRoot { | 13 class ContextRoot { |
| 13 /** | 14 /** |
| 14 * The absolute path of the root directory containing the files to be | 15 * The absolute path of the root directory containing the files to be |
| 15 * analyzed. | 16 * analyzed. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 38 @override | 39 @override |
| 39 bool operator ==(other) { | 40 bool operator ==(other) { |
| 40 if (other is ContextRoot) { | 41 if (other is ContextRoot) { |
| 41 return root == other.root && | 42 return root == other.root && |
| 42 _listEqual(exclude, other.exclude, (String a, String b) => a == b); | 43 _listEqual(exclude, other.exclude, (String a, String b) => a == b); |
| 43 } | 44 } |
| 44 return false; | 45 return false; |
| 45 } | 46 } |
| 46 | 47 |
| 47 /** | 48 /** |
| 49 * Return `true` if the file with the given [filePath] is contained within |
| 50 * this context root. A file contained in a context root if it is within the |
| 51 * context [root] neither explicitly excluded or within one of the excluded |
| 52 * directories. |
| 53 */ |
| 54 bool containsFile(String filePath) { |
| 55 if (!path.isWithin(root, filePath)) { |
| 56 return false; |
| 57 } |
| 58 for (String excluded in exclude) { |
| 59 if (filePath == excluded || path.isWithin(excluded, filePath)) { |
| 60 return false; |
| 61 } |
| 62 } |
| 63 return true; |
| 64 } |
| 65 |
| 66 /** |
| 48 * Compare the lists [listA] and [listB], using [itemEqual] to compare | 67 * Compare the lists [listA] and [listB], using [itemEqual] to compare |
| 49 * list elements. | 68 * list elements. |
| 50 */ | 69 */ |
| 51 bool _listEqual(List listA, List listB, bool itemEqual(a, b)) { | 70 bool _listEqual(List listA, List listB, bool itemEqual(a, b)) { |
| 52 if (listA == null) { | 71 if (listA == null) { |
| 53 return listB == null; | 72 return listB == null; |
| 54 } | 73 } |
| 55 if (listB == null) { | 74 if (listB == null) { |
| 56 return false; | 75 return false; |
| 57 } | 76 } |
| 58 if (listA.length != listB.length) { | 77 if (listA.length != listB.length) { |
| 59 return false; | 78 return false; |
| 60 } | 79 } |
| 61 for (int i = 0; i < listA.length; i++) { | 80 for (int i = 0; i < listA.length; i++) { |
| 62 if (!itemEqual(listA[i], listB[i])) { | 81 if (!itemEqual(listA[i], listB[i])) { |
| 63 return false; | 82 return false; |
| 64 } | 83 } |
| 65 } | 84 } |
| 66 return true; | 85 return true; |
| 67 } | 86 } |
| 68 } | 87 } |
| OLD | NEW |