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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
7 | 7 |
8 library engine.source.io; | 8 library engine.source.io; |
9 | 9 |
10 import 'source.dart'; | 10 import 'source.dart'; |
11 import 'java_core.dart'; | 11 import 'java_core.dart'; |
12 import 'java_io.dart'; | 12 import 'java_io.dart'; |
13 import 'utilities_general.dart'; | 13 import 'utilities_general.dart'; |
14 import 'instrumentation.dart'; | 14 import 'instrumentation.dart'; |
15 import 'engine.dart'; | 15 import 'engine.dart'; |
| 16 import 'java_engine.dart'; |
16 export 'source.dart'; | 17 export 'source.dart'; |
17 | 18 |
18 /** | 19 /** |
19 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that | 20 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that |
20 * contains all sources within a given directory. | 21 * contains all sources within a given directory. |
21 */ | 22 */ |
22 class DirectoryBasedSourceContainer implements SourceContainer { | 23 class DirectoryBasedSourceContainer implements SourceContainer { |
23 /** | 24 /** |
24 * Append the system file separator to the given path unless the path already
ends with a | 25 * Append the system file separator to the given path unless the path already
ends with a |
25 * separator. | 26 * separator. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 78 |
78 @override | 79 @override |
79 String toString() => "SourceContainer[${_path}]"; | 80 String toString() => "SourceContainer[${_path}]"; |
80 } | 81 } |
81 | 82 |
82 /** | 83 /** |
83 * Instances of the class `FileBasedSource` implement a source that represents a
file. | 84 * Instances of the class `FileBasedSource` implement a source that represents a
file. |
84 */ | 85 */ |
85 class FileBasedSource implements Source { | 86 class FileBasedSource implements Source { |
86 /** | 87 /** |
| 88 * The URI from which this source was originally derived. |
| 89 */ |
| 90 final Uri uri; |
| 91 |
| 92 /** |
87 * The file represented by this source. | 93 * The file represented by this source. |
88 */ | 94 */ |
89 final JavaFile file; | 95 final JavaFile file; |
90 | 96 |
91 /** | 97 /** |
92 * The cached encoding for this source. | 98 * The cached encoding for this source. |
93 */ | 99 */ |
94 String _encoding; | 100 String _encoding; |
95 | 101 |
96 /** | 102 /** |
97 * The kind of URI from which this source was originally derived. | |
98 */ | |
99 final UriKind uriKind; | |
100 | |
101 /** | |
102 * Initialize a newly created source object. The source object is assumed to n
ot be in a system | |
103 * library. | |
104 * | |
105 * @param file the file represented by this source | |
106 */ | |
107 FileBasedSource.con1(JavaFile file) : this.con2(file, UriKind.FILE_URI); | |
108 | |
109 /** | |
110 * Initialize a newly created source object. | 103 * Initialize a newly created source object. |
111 * | 104 * |
112 * @param file the file represented by this source | 105 * @param file the file represented by this source |
113 * @param flags `true` if this source is in one of the system libraries | |
114 */ | 106 */ |
115 FileBasedSource.con2(this.file, this.uriKind); | 107 FileBasedSource.con1(JavaFile file) : this.con2(file.toURI(), file); |
| 108 |
| 109 /** |
| 110 * Initialize a newly created source object. |
| 111 * |
| 112 * @param file the file represented by this source |
| 113 * @param uri the URI from which this source was originally derived |
| 114 */ |
| 115 FileBasedSource.con2(this.uri, this.file); |
116 | 116 |
117 @override | 117 @override |
118 bool operator ==(Object object) => object != null && object is FileBasedSource
&& file == object.file; | 118 bool operator ==(Object object) => object != null && object is FileBasedSource
&& file == object.file; |
119 | 119 |
120 @override | 120 @override |
121 bool exists() => file.isFile(); | 121 bool exists() => file.isFile(); |
122 | 122 |
123 @override | 123 @override |
124 TimestampedData<String> get contents { | 124 TimestampedData<String> get contents { |
125 TimeCounter_TimeCounterHandle handle = PerformanceStatistics.io.start(); | 125 TimeCounter_TimeCounterHandle handle = PerformanceStatistics.io.start(); |
126 try { | 126 try { |
127 return contentsFromFile; | 127 return contentsFromFile; |
128 } finally { | 128 } finally { |
129 _reportIfSlowIO(handle.stop()); | 129 _reportIfSlowIO(handle.stop()); |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 @override | 133 @override |
134 String get encoding { | 134 String get encoding { |
135 if (_encoding == null) { | 135 if (_encoding == null) { |
136 _encoding = "${new String.fromCharCode(uriKind.encoding)}${file.toURI().to
String()}"; | 136 _encoding = uri.toString(); |
137 } | 137 } |
138 return _encoding; | 138 return _encoding; |
139 } | 139 } |
140 | 140 |
141 @override | 141 @override |
142 String get fullName => file.getAbsolutePath(); | 142 String get fullName => file.getAbsolutePath(); |
143 | 143 |
144 @override | 144 @override |
145 int get modificationStamp => file.lastModified(); | 145 int get modificationStamp => file.lastModified(); |
146 | 146 |
147 @override | 147 @override |
148 String get shortName => file.getName(); | 148 String get shortName => file.getName(); |
149 | 149 |
150 @override | 150 @override |
| 151 UriKind get uriKind { |
| 152 String scheme = uri.scheme; |
| 153 if (scheme == PackageUriResolver.PACKAGE_SCHEME) { |
| 154 return UriKind.PACKAGE_URI; |
| 155 } else if (scheme == DartUriResolver.DART_SCHEME) { |
| 156 return UriKind.DART_URI; |
| 157 } else if (scheme == FileUriResolver.FILE_SCHEME) { |
| 158 return UriKind.FILE_URI; |
| 159 } |
| 160 return UriKind.FILE_URI; |
| 161 } |
| 162 |
| 163 @override |
151 int get hashCode => file.hashCode; | 164 int get hashCode => file.hashCode; |
152 | 165 |
153 @override | 166 @override |
154 bool get isInSystemLibrary => uriKind == UriKind.DART_URI; | 167 bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME; |
155 | 168 |
156 @override | 169 @override |
157 Source resolveRelative(Uri containedUri) { | 170 Uri resolveRelative(Uri containedUri) { |
158 try { | 171 try { |
159 Uri resolvedUri = file.toURI().resolveUri(containedUri); | 172 Uri baseUri = uri; |
160 return new FileBasedSource.con2(new JavaFile.fromUri(resolvedUri), uriKind
); | 173 bool isOpaque = uri.isAbsolute && !uri.path.startsWith('/'); |
161 } catch (exception) { | 174 if (isOpaque) { |
| 175 String scheme = uri.scheme; |
| 176 String part = uri.path; |
| 177 if (scheme == DartUriResolver.DART_SCHEME && part.indexOf('/') < 0) { |
| 178 part = "${part}/${part}.dart"; |
| 179 } |
| 180 baseUri = parseUriWithException("${scheme}:/${part}"); |
| 181 } |
| 182 Uri result = baseUri.resolveUri(containedUri); |
| 183 if (isOpaque) { |
| 184 result = parseUriWithException("${result.scheme}:${result.path.substring
(1)}"); |
| 185 } |
| 186 return result; |
| 187 } catch (exception, stackTrace) { |
| 188 throw new AnalysisException("Could not resolve URI (${containedUri}) relat
ive to source (${uri})", new CaughtException(exception, stackTrace)); |
162 } | 189 } |
163 return null; | |
164 } | 190 } |
165 | 191 |
166 @override | 192 @override |
167 String toString() { | 193 String toString() { |
168 if (file == null) { | 194 if (file == null) { |
169 return "<unknown source>"; | 195 return "<unknown source>"; |
170 } | 196 } |
171 return file.getAbsolutePath(); | 197 return file.getAbsolutePath(); |
172 } | 198 } |
173 | 199 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 240 |
215 /** | 241 /** |
216 * Return `true` if the given URI is a `file` URI. | 242 * Return `true` if the given URI is a `file` URI. |
217 * | 243 * |
218 * @param uri the URI being tested | 244 * @param uri the URI being tested |
219 * @return `true` if the given URI is a `file` URI | 245 * @return `true` if the given URI is a `file` URI |
220 */ | 246 */ |
221 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; | 247 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; |
222 | 248 |
223 @override | 249 @override |
224 Source fromEncoding(UriKind kind, Uri uri) { | |
225 if (kind == UriKind.FILE_URI) { | |
226 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind); | |
227 } | |
228 return null; | |
229 } | |
230 | |
231 @override | |
232 Source resolveAbsolute(Uri uri) { | 250 Source resolveAbsolute(Uri uri) { |
233 if (!isFileUri(uri)) { | 251 if (!isFileUri(uri)) { |
234 return null; | 252 return null; |
235 } | 253 } |
236 return new FileBasedSource.con1(new JavaFile.fromUri(uri)); | 254 return new FileBasedSource.con2(uri, new JavaFile.fromUri(uri)); |
237 } | 255 } |
238 } | 256 } |
239 | 257 |
240 /** | 258 /** |
241 * Instances of interface `LocalSourcePredicate` are used to determine if the gi
ven | 259 * Instances of interface `LocalSourcePredicate` are used to determine if the gi
ven |
242 * [Source] is "local" in some sense, so can be updated. | 260 * [Source] is "local" in some sense, so can be updated. |
243 */ | 261 */ |
244 abstract class LocalSourcePredicate { | 262 abstract class LocalSourcePredicate { |
245 /** | 263 /** |
246 * Instance of [LocalSourcePredicate] that always returns `false`. | 264 * Instance of [LocalSourcePredicate] that always returns `false`. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 * @param packagesDirectories the package directories that `package` URI's are
assumed to be | 339 * @param packagesDirectories the package directories that `package` URI's are
assumed to be |
322 * relative to | 340 * relative to |
323 */ | 341 */ |
324 PackageUriResolver(this._packagesDirectories) { | 342 PackageUriResolver(this._packagesDirectories) { |
325 if (_packagesDirectories.length < 1) { | 343 if (_packagesDirectories.length < 1) { |
326 throw new IllegalArgumentException("At least one package directory must be
provided"); | 344 throw new IllegalArgumentException("At least one package directory must be
provided"); |
327 } | 345 } |
328 } | 346 } |
329 | 347 |
330 @override | 348 @override |
331 Source fromEncoding(UriKind kind, Uri uri) { | |
332 if (kind == UriKind.PACKAGE_URI) { | |
333 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind); | |
334 } | |
335 return null; | |
336 } | |
337 | |
338 @override | |
339 Source resolveAbsolute(Uri uri) { | 349 Source resolveAbsolute(Uri uri) { |
340 if (!isPackageUri(uri)) { | 350 if (!isPackageUri(uri)) { |
341 return null; | 351 return null; |
342 } | 352 } |
343 String path = uri.path; | 353 String path = uri.path; |
344 if (path == null) { | 354 if (path == null) { |
345 path = uri.path; | 355 path = uri.path; |
346 if (path == null) { | 356 if (path == null) { |
347 return null; | 357 return null; |
348 } | 358 } |
(...skipping 10 matching lines...) Expand all Loading... |
359 return null; | 369 return null; |
360 } else { | 370 } else { |
361 // <pkgName>/<relPath> | 371 // <pkgName>/<relPath> |
362 pkgName = path.substring(0, index); | 372 pkgName = path.substring(0, index); |
363 relPath = path.substring(index + 1); | 373 relPath = path.substring(index + 1); |
364 } | 374 } |
365 for (JavaFile packagesDirectory in _packagesDirectories) { | 375 for (JavaFile packagesDirectory in _packagesDirectories) { |
366 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); | 376 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); |
367 if (resolvedFile.exists()) { | 377 if (resolvedFile.exists()) { |
368 JavaFile canonicalFile = getCanonicalFile(packagesDirectory, pkgName, re
lPath); | 378 JavaFile canonicalFile = getCanonicalFile(packagesDirectory, pkgName, re
lPath); |
369 UriKind uriKind = _isSelfReference(packagesDirectory, canonicalFile) ? U
riKind.FILE_URI : UriKind.PACKAGE_URI; | 379 if (_isSelfReference(packagesDirectory, canonicalFile)) { |
370 return new FileBasedSource.con2(canonicalFile, uriKind); | 380 uri = canonicalFile.toURI(); |
| 381 } |
| 382 return new FileBasedSource.con2(uri, canonicalFile); |
371 } | 383 } |
372 } | 384 } |
373 return new FileBasedSource.con2(getCanonicalFile(_packagesDirectories[0], pk
gName, relPath), UriKind.PACKAGE_URI); | 385 return new FileBasedSource.con2(uri, getCanonicalFile(_packagesDirectories[0
], pkgName, relPath)); |
374 } | 386 } |
375 | 387 |
376 @override | 388 @override |
377 Uri restoreAbsolute(Source source) { | 389 Uri restoreAbsolute(Source source) { |
378 if (source is FileBasedSource) { | 390 if (source is FileBasedSource) { |
379 String sourcePath = source.file.getPath(); | 391 String sourcePath = source.file.getPath(); |
380 for (JavaFile packagesDirectory in _packagesDirectories) { | 392 for (JavaFile packagesDirectory in _packagesDirectories) { |
381 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); | 393 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); |
382 if (pkgFolders != null) { | 394 if (pkgFolders != null) { |
383 for (JavaFile pkgFolder in pkgFolders) { | 395 for (JavaFile pkgFolder in pkgFolders) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 */ | 474 */ |
463 final JavaFile _rootDirectory; | 475 final JavaFile _rootDirectory; |
464 | 476 |
465 /** | 477 /** |
466 * Initialize a newly created resolver to resolve `file` URI's relative to the
given root | 478 * Initialize a newly created resolver to resolve `file` URI's relative to the
given root |
467 * directory. | 479 * directory. |
468 */ | 480 */ |
469 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories) : supe
r(); | 481 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories) : supe
r(); |
470 | 482 |
471 @override | 483 @override |
472 Source fromEncoding(UriKind kind, Uri uri) { | |
473 if (kind == UriKind.FILE_URI) { | |
474 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind); | |
475 } | |
476 return null; | |
477 } | |
478 | |
479 @override | |
480 Source resolveAbsolute(Uri uri) { | 484 Source resolveAbsolute(Uri uri) { |
481 String rootPath = _rootDirectory.toURI().path; | 485 String rootPath = _rootDirectory.toURI().path; |
482 String uriPath = uri.path; | 486 String uriPath = uri.path; |
483 if (uriPath != null && uriPath.startsWith(rootPath)) { | 487 if (uriPath != null && uriPath.startsWith(rootPath)) { |
484 String filePath = uri.path.substring(rootPath.length); | 488 String filePath = uri.path.substring(rootPath.length); |
485 for (JavaFile dir in _relativeDirectories) { | 489 for (JavaFile dir in _relativeDirectories) { |
486 JavaFile file = new JavaFile.relative(dir, filePath); | 490 JavaFile file = new JavaFile.relative(dir, filePath); |
487 if (file.exists()) { | 491 if (file.exists()) { |
488 return new FileBasedSource.con2(file, UriKind.FILE_URI); | 492 return new FileBasedSource.con2(uri, file); |
489 } | 493 } |
490 } | 494 } |
491 } | 495 } |
492 return null; | 496 return null; |
493 } | 497 } |
494 } | 498 } |
OLD | NEW |