OLD | NEW |
1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
3 | 3 |
4 library engine.source.io; | 4 library engine.source.io; |
5 | 5 |
6 import 'source.dart'; | 6 import 'source.dart'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'java_core.dart'; | 8 import 'java_core.dart'; |
9 import 'java_io.dart'; | 9 import 'java_io.dart'; |
10 import 'sdk.dart' show DartSdk; | 10 import 'sdk.dart' show DartSdk; |
11 import 'engine.dart' show AnalysisContext, AnalysisEngine; | 11 import 'engine.dart' show AnalysisContext, AnalysisEngine; |
12 export 'source.dart'; | 12 export 'source.dart'; |
13 | 13 |
| 14 |
14 /** | 15 /** |
15 * Instances of the class {@code FileBasedSource} implement a source that repres
ents a file. | 16 * Instances of the class {@code FileBasedSource} implement a source that repres
ents a file. |
16 * @coverage dart.engine.source | 17 * @coverage dart.engine.source |
17 */ | 18 */ |
18 class FileBasedSource implements Source { | 19 class FileBasedSource implements Source { |
| 20 |
19 /** | 21 /** |
20 * The content cache used to access the contents of this source if they have b
een overridden from | 22 * The content cache used to access the contents of this source if they have b
een overridden from |
21 * what is on disk or cached. | 23 * what is on disk or cached. |
22 */ | 24 */ |
23 ContentCache _contentCache; | 25 ContentCache _contentCache; |
| 26 |
24 /** | 27 /** |
25 * The file represented by this source. | 28 * The file represented by this source. |
26 */ | 29 */ |
27 JavaFile _file; | 30 JavaFile _file; |
| 31 |
28 /** | 32 /** |
29 * The cached encoding for this source. | 33 * The cached encoding for this source. |
30 */ | 34 */ |
31 String _encoding; | 35 String _encoding; |
| 36 |
32 /** | 37 /** |
33 * The kind of URI from which this source was originally derived. | 38 * The kind of URI from which this source was originally derived. |
34 */ | 39 */ |
35 UriKind _uriKind; | 40 UriKind _uriKind; |
| 41 |
36 /** | 42 /** |
37 * Initialize a newly created source object. The source object is assumed to n
ot be in a system | 43 * Initialize a newly created source object. The source object is assumed to n
ot be in a system |
38 * library. | 44 * library. |
39 * @param contentCache the content cache used to access the contents of this s
ource | 45 * @param contentCache the content cache used to access the contents of this s
ource |
40 * @param file the file represented by this source | 46 * @param file the file represented by this source |
41 */ | 47 */ |
42 FileBasedSource.con1(ContentCache contentCache, JavaFile file) { | 48 FileBasedSource.con1(ContentCache contentCache, JavaFile file) { |
43 _jtd_constructor_329_impl(contentCache, file); | 49 _jtd_constructor_336_impl(contentCache, file); |
44 } | 50 } |
45 _jtd_constructor_329_impl(ContentCache contentCache, JavaFile file) { | 51 _jtd_constructor_336_impl(ContentCache contentCache, JavaFile file) { |
46 _jtd_constructor_330_impl(contentCache, file, UriKind.FILE_URI); | 52 _jtd_constructor_337_impl(contentCache, file, UriKind.FILE_URI); |
47 } | 53 } |
| 54 |
48 /** | 55 /** |
49 * Initialize a newly created source object. | 56 * Initialize a newly created source object. |
50 * @param contentCache the content cache used to access the contents of this s
ource | 57 * @param contentCache the content cache used to access the contents of this s
ource |
51 * @param file the file represented by this source | 58 * @param file the file represented by this source |
52 * @param flags {@code true} if this source is in one of the system libraries | 59 * @param flags {@code true} if this source is in one of the system libraries |
53 */ | 60 */ |
54 FileBasedSource.con2(ContentCache contentCache2, JavaFile file2, UriKind uriKi
nd2) { | 61 FileBasedSource.con2(ContentCache contentCache2, JavaFile file2, UriKind uriKi
nd2) { |
55 _jtd_constructor_330_impl(contentCache2, file2, uriKind2); | 62 _jtd_constructor_337_impl(contentCache2, file2, uriKind2); |
56 } | 63 } |
57 _jtd_constructor_330_impl(ContentCache contentCache2, JavaFile file2, UriKind
uriKind2) { | 64 _jtd_constructor_337_impl(ContentCache contentCache2, JavaFile file2, UriKind
uriKind2) { |
58 this._contentCache = contentCache2; | 65 this._contentCache = contentCache2; |
59 this._file = file2; | 66 this._file = file2; |
60 this._uriKind = uriKind2; | 67 this._uriKind = uriKind2; |
61 this._encoding = "${uriKind2.encoding}${file2.toURI().toString()}"; | 68 this._encoding = "${uriKind2.encoding}${file2.toURI().toString()}"; |
62 } | 69 } |
63 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && _file == ((object as FileBasedSource))._file; | 70 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && _file == ((object as FileBasedSource))._file; |
64 bool exists() => _contentCache.getContents(this) != null || (_file.exists() &&
!_file.isDirectory()); | 71 bool exists() => _contentCache.getContents(this) != null || (_file.exists() &&
!_file.isDirectory()); |
65 void getContents(Source_ContentReceiver receiver) { | 72 void getContents(Source_ContentReceiver receiver) { |
66 { | 73 { |
67 String contents = _contentCache.getContents(this); | 74 String contents = _contentCache.getContents(this); |
(...skipping 24 matching lines...) Expand all Loading... |
92 } catch (exception) { | 99 } catch (exception) { |
93 } | 100 } |
94 return null; | 101 return null; |
95 } | 102 } |
96 String toString() { | 103 String toString() { |
97 if (_file == null) { | 104 if (_file == null) { |
98 return "<unknown source>"; | 105 return "<unknown source>"; |
99 } | 106 } |
100 return _file.getAbsolutePath(); | 107 return _file.getAbsolutePath(); |
101 } | 108 } |
| 109 |
102 /** | 110 /** |
103 * Return the file represented by this source. This is an internal method that
is only intended to | 111 * Return the file represented by this source. This is an internal method that
is only intended to |
104 * be used by {@link UriResolver}. | 112 * be used by {@link UriResolver}. |
105 * @return the file represented by this source | 113 * @return the file represented by this source |
106 */ | 114 */ |
107 JavaFile get file => _file; | 115 JavaFile get file => _file; |
108 } | 116 } |
| 117 |
109 /** | 118 /** |
110 * Instances of the class {@code PackageUriResolver} resolve {@code package} URI
's in the context of | 119 * Instances of the class {@code PackageUriResolver} resolve {@code package} URI
's in the context of |
111 * an application. | 120 * an application. |
112 * <p> | 121 * <p> |
113 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory | 122 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory |
114 * should be canonicalized, but to preserve relative links within a package, the
remainder of the | 123 * should be canonicalized, but to preserve relative links within a package, the
remainder of the |
115 * path from the package directory to the leaf should not. | 124 * path from the package directory to the leaf should not. |
116 * @coverage dart.engine.source | 125 * @coverage dart.engine.source |
117 */ | 126 */ |
118 class PackageUriResolver extends UriResolver { | 127 class PackageUriResolver extends UriResolver { |
| 128 |
119 /** | 129 /** |
120 * The package directories that {@code package} URI's are assumed to be relati
ve to. | 130 * The package directories that {@code package} URI's are assumed to be relati
ve to. |
121 */ | 131 */ |
122 List<JavaFile> _packagesDirectories; | 132 List<JavaFile> _packagesDirectories; |
| 133 |
123 /** | 134 /** |
124 * The name of the {@code package} scheme. | 135 * The name of the {@code package} scheme. |
125 */ | 136 */ |
126 static String _PACKAGE_SCHEME = "package"; | 137 static String _PACKAGE_SCHEME = "package"; |
| 138 |
| 139 /** |
| 140 * Log exceptions thrown with the message "Required key not available" only on
ce. |
| 141 */ |
| 142 static bool _CanLogRequiredKeyIoException = true; |
| 143 |
127 /** | 144 /** |
128 * Return {@code true} if the given URI is a {@code package} URI. | 145 * Return {@code true} if the given URI is a {@code package} URI. |
129 * @param uri the URI being tested | 146 * @param uri the URI being tested |
130 * @return {@code true} if the given URI is a {@code package} URI | 147 * @return {@code true} if the given URI is a {@code package} URI |
131 */ | 148 */ |
132 static bool isPackageUri(Uri uri) => uri.scheme == _PACKAGE_SCHEME; | 149 static bool isPackageUri(Uri uri) => _PACKAGE_SCHEME == uri.scheme; |
| 150 |
133 /** | 151 /** |
134 * Initialize a newly created resolver to resolve {@code package} URI's relati
ve to the given | 152 * Initialize a newly created resolver to resolve {@code package} URI's relati
ve to the given |
135 * package directories. | 153 * package directories. |
136 * @param packagesDirectories the package directories that {@code package} URI
's are assumed to be | 154 * @param packagesDirectories the package directories that {@code package} URI
's are assumed to be |
137 * relative to | 155 * relative to |
138 */ | 156 */ |
139 PackageUriResolver(List<JavaFile> packagesDirectories) { | 157 PackageUriResolver(List<JavaFile> packagesDirectories) { |
140 if (packagesDirectories.length < 1) { | 158 if (packagesDirectories.length < 1) { |
141 throw new IllegalArgumentException("At least one package directory must be
provided"); | 159 throw new IllegalArgumentException("At least one package directory must be
provided"); |
142 } | 160 } |
(...skipping 29 matching lines...) Expand all Loading... |
172 relPath = path2.substring(index + 1); | 190 relPath = path2.substring(index + 1); |
173 } | 191 } |
174 for (JavaFile packagesDirectory in _packagesDirectories) { | 192 for (JavaFile packagesDirectory in _packagesDirectories) { |
175 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path2); | 193 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path2); |
176 if (resolvedFile.exists()) { | 194 if (resolvedFile.exists()) { |
177 return new FileBasedSource.con2(contentCache, getCanonicalFile(packagesD
irectory, pkgName, relPath), UriKind.PACKAGE_URI); | 195 return new FileBasedSource.con2(contentCache, getCanonicalFile(packagesD
irectory, pkgName, relPath), UriKind.PACKAGE_URI); |
178 } | 196 } |
179 } | 197 } |
180 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); | 198 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); |
181 } | 199 } |
| 200 Uri restoreAbsolute(Source source) { |
| 201 if (source is FileBasedSource) { |
| 202 String sourcePath = ((source as FileBasedSource)).file.getPath(); |
| 203 for (JavaFile packagesDirectory in _packagesDirectories) { |
| 204 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); |
| 205 if (pkgFolders != null) { |
| 206 for (JavaFile pkgFolder in pkgFolders) { |
| 207 try { |
| 208 String pkgCanonicalPath = pkgFolder.getCanonicalPath(); |
| 209 if (sourcePath.startsWith(pkgCanonicalPath)) { |
| 210 String relPath = sourcePath.substring(pkgCanonicalPath.length); |
| 211 return parseUriWithException("${_PACKAGE_SCHEME}:${pkgFolder.get
Name()}${relPath}"); |
| 212 } |
| 213 } catch (e) { |
| 214 } |
| 215 } |
| 216 } |
| 217 } |
| 218 } |
| 219 return null; |
| 220 } |
| 221 |
182 /** | 222 /** |
183 * Answer the canonical file for the specified package. | 223 * Answer the canonical file for the specified package. |
184 * @param packagesDirectory the "packages" directory (not {@code null}) | 224 * @param packagesDirectory the "packages" directory (not {@code null}) |
185 * @param pkgName the package name (not {@code null}, not empty) | 225 * @param pkgName the package name (not {@code null}, not empty) |
186 * @param relPath the path relative to the package directory (not {@code null}
, no leading slash, | 226 * @param relPath the path relative to the package directory (not {@code null}
, no leading slash, |
187 * but may be empty string) | 227 * but may be empty string) |
188 * @return the file (not {@code null}) | 228 * @return the file (not {@code null}) |
189 */ | 229 */ |
190 JavaFile getCanonicalFile(JavaFile packagesDirectory, String pkgName, String r
elPath) { | 230 JavaFile getCanonicalFile(JavaFile packagesDirectory, String pkgName, String r
elPath) { |
191 JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName); | 231 JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName); |
192 try { | 232 try { |
193 pkgDir = pkgDir.getCanonicalFile(); | 233 pkgDir = pkgDir.getCanonicalFile(); |
194 } on IOException catch (e) { | 234 } on IOException catch (e) { |
195 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}", e)
; | 235 if (!e.toString().contains("Required key not available")) { |
| 236 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}",
e); |
| 237 } else if (_CanLogRequiredKeyIoException) { |
| 238 _CanLogRequiredKeyIoException = false; |
| 239 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}",
e); |
| 240 } |
196 } | 241 } |
197 return new JavaFile.relative(pkgDir, relPath.replaceAll('/', JavaFile.separa
torChar)); | 242 return new JavaFile.relative(pkgDir, relPath.replaceAll('/', JavaFile.separa
torChar)); |
198 } | 243 } |
199 } | 244 } |
| 245 |
200 /** | 246 /** |
201 * Instances of the class {@link DirectoryBasedSourceContainer} represent a sour
ce container that | 247 * Instances of the class {@link DirectoryBasedSourceContainer} represent a sour
ce container that |
202 * contains all sources within a given directory. | 248 * contains all sources within a given directory. |
203 * @coverage dart.engine.source | 249 * @coverage dart.engine.source |
204 */ | 250 */ |
205 class DirectoryBasedSourceContainer implements SourceContainer { | 251 class DirectoryBasedSourceContainer implements SourceContainer { |
| 252 |
206 /** | 253 /** |
207 * Append the system file separator to the given path unless the path already
ends with a | 254 * Append the system file separator to the given path unless the path already
ends with a |
208 * separator. | 255 * separator. |
209 * @param path the path to which the file separator is to be added | 256 * @param path the path to which the file separator is to be added |
210 * @return a path that ends with the system file separator | 257 * @return a path that ends with the system file separator |
211 */ | 258 */ |
212 static String appendFileSeparator(String path) { | 259 static String appendFileSeparator(String path) { |
213 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) ==
JavaFile.separatorChar) { | 260 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) ==
JavaFile.separatorChar) { |
214 return path; | 261 return path; |
215 } | 262 } |
216 return "${path}${JavaFile.separator}"; | 263 return "${path}${JavaFile.separator}"; |
217 } | 264 } |
| 265 |
218 /** | 266 /** |
219 * The container's path (not {@code null}). | 267 * The container's path (not {@code null}). |
220 */ | 268 */ |
221 String _path; | 269 String _path; |
| 270 |
222 /** | 271 /** |
223 * Construct a container representing the specified directory and containing a
ny sources whose{@link Source#getFullName()} starts with the directory's path. T
his is a convenience method, | 272 * Construct a container representing the specified directory and containing a
ny sources whose{@link Source#getFullName()} starts with the directory's path. T
his is a convenience method, |
224 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour
ceContainer(String)}. | 273 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour
ceContainer(String)}. |
225 * @param directory the directory (not {@code null}) | 274 * @param directory the directory (not {@code null}) |
226 */ | 275 */ |
227 DirectoryBasedSourceContainer.con1(JavaFile directory) { | 276 DirectoryBasedSourceContainer.con1(JavaFile directory) { |
228 _jtd_constructor_327_impl(directory); | 277 _jtd_constructor_334_impl(directory); |
229 } | 278 } |
230 _jtd_constructor_327_impl(JavaFile directory) { | 279 _jtd_constructor_334_impl(JavaFile directory) { |
231 _jtd_constructor_328_impl(directory.getPath()); | 280 _jtd_constructor_335_impl(directory.getPath()); |
232 } | 281 } |
| 282 |
233 /** | 283 /** |
234 * Construct a container representing the specified path and containing any so
urces whose{@link Source#getFullName()} starts with the specified path. | 284 * Construct a container representing the specified path and containing any so
urces whose{@link Source#getFullName()} starts with the specified path. |
235 * @param path the path (not {@code null} and not empty) | 285 * @param path the path (not {@code null} and not empty) |
236 */ | 286 */ |
237 DirectoryBasedSourceContainer.con2(String path2) { | 287 DirectoryBasedSourceContainer.con2(String path2) { |
238 _jtd_constructor_328_impl(path2); | 288 _jtd_constructor_335_impl(path2); |
239 } | 289 } |
240 _jtd_constructor_328_impl(String path2) { | 290 _jtd_constructor_335_impl(String path2) { |
241 this._path = appendFileSeparator(path2); | 291 this._path = appendFileSeparator(path2); |
242 } | 292 } |
243 bool contains(Source source) => source.fullName.startsWith(_path); | 293 bool contains(Source source) => source.fullName.startsWith(_path); |
244 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; | 294 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; |
| 295 |
245 /** | 296 /** |
246 * Answer the receiver's path, used to determine if a source is contained in t
he receiver. | 297 * Answer the receiver's path, used to determine if a source is contained in t
he receiver. |
247 * @return the path (not {@code null}, not empty) | 298 * @return the path (not {@code null}, not empty) |
248 */ | 299 */ |
249 String get path => _path; | 300 String get path => _path; |
250 int get hashCode => _path.hashCode; | 301 int get hashCode => _path.hashCode; |
251 String toString() => "SourceContainer[${_path}]"; | 302 String toString() => "SourceContainer[${_path}]"; |
252 } | 303 } |
| 304 |
253 /** | 305 /** |
254 * Instances of the class {@code FileUriResolver} resolve {@code file} URI's. | 306 * Instances of the class {@code FileUriResolver} resolve {@code file} URI's. |
255 * @coverage dart.engine.source | 307 * @coverage dart.engine.source |
256 */ | 308 */ |
257 class FileUriResolver extends UriResolver { | 309 class FileUriResolver extends UriResolver { |
| 310 |
258 /** | 311 /** |
259 * The name of the {@code file} scheme. | 312 * The name of the {@code file} scheme. |
260 */ | 313 */ |
261 static String _FILE_SCHEME = "file"; | 314 static String _FILE_SCHEME = "file"; |
| 315 |
262 /** | 316 /** |
263 * Return {@code true} if the given URI is a {@code file} URI. | 317 * Return {@code true} if the given URI is a {@code file} URI. |
264 * @param uri the URI being tested | 318 * @param uri the URI being tested |
265 * @return {@code true} if the given URI is a {@code file} URI | 319 * @return {@code true} if the given URI is a {@code file} URI |
266 */ | 320 */ |
267 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; | 321 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; |
268 /** | |
269 * Initialize a newly created resolver to resolve {@code file} URI's relative
to the given root | |
270 * directory. | |
271 */ | |
272 FileUriResolver() : super() { | |
273 } | |
274 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { | 322 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { |
275 if (identical(kind, UriKind.FILE_URI)) { | 323 if (identical(kind, UriKind.FILE_URI)) { |
276 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); | 324 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); |
277 } | 325 } |
278 return null; | 326 return null; |
279 } | 327 } |
280 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 328 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
281 if (!isFileUri(uri)) { | 329 if (!isFileUri(uri)) { |
282 return null; | 330 return null; |
283 } | 331 } |
284 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); | 332 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); |
285 } | 333 } |
286 } | 334 } |
OLD | NEW |