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 /// Data structure storing an association between URI and file contents. | 5 /// Data structure storing an association between URI and file contents. |
6 /// | 6 /// |
7 /// Each URI is also associated with a unique arbitrary path ending in ".dart". | 7 /// Each URI is also associated with a unique arbitrary path ending in ".dart". |
8 /// This allows interfacing with analyzer code that expects to manipulate paths | 8 /// This allows interfacing with analyzer code that expects to manipulate paths |
9 /// rather than URIs. | 9 /// rather than URIs. |
10 class FileRepository { | 10 class FileRepository { |
(...skipping 14 matching lines...) Expand all Loading... |
25 /// URI and arbitrary path is preserved. | 25 /// URI and arbitrary path is preserved. |
26 /// | 26 /// |
27 /// Subsequent calls to [contentsForPath] will have undefined results until | 27 /// Subsequent calls to [contentsForPath] will have undefined results until |
28 /// new contents are stored using [store]. | 28 /// new contents are stored using [store]. |
29 void clearContents() { | 29 void clearContents() { |
30 for (var i = 0; i < _contents.length; i++) { | 30 for (var i = 0; i < _contents.length; i++) { |
31 _contents[i] = null; | 31 _contents[i] = null; |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 /// Return the contents of the file whose arbitary path is [path]. | 35 /// Return the contents of the file whose arbitrary path is [path]. |
36 /// | 36 /// |
37 /// The path must have been returned by a previous call to [store] or | 37 /// The path must have been returned by a previous call to [store] or |
38 /// [pathForUri]. | 38 /// [pathForUri]. |
39 String contentsForPath(String path) { | 39 String contentsForPath(String path) { |
40 var contents = _contents[_indexForPath(path)]; | 40 var contents = _contents[_indexForPath(path)]; |
41 assert(contents != null); | 41 assert(contents != null); |
42 return contents; | 42 return contents; |
43 } | 43 } |
44 | 44 |
45 /// For testing purposes, return the contents of all files stored in the file | 45 /// For testing purposes, return the contents of all files stored in the file |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 _uris.add(uri); | 91 _uris.add(uri); |
92 _uriToIndexMap[uri] = index; | 92 _uriToIndexMap[uri] = index; |
93 _contents.add(null); | 93 _contents.add(null); |
94 } | 94 } |
95 return index; | 95 return index; |
96 } | 96 } |
97 | 97 |
98 /// Return the arbitrary path associated with the given index. | 98 /// Return the arbitrary path associated with the given index. |
99 String _pathForIndex(int index) => '/$index.dart'; | 99 String _pathForIndex(int index) => '/$index.dart'; |
100 } | 100 } |
OLD | NEW |