| 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 library engine.source.io; | 4 library engine.source.io; |
| 5 |
| 4 import 'source.dart'; | 6 import 'source.dart'; |
| 5 import 'java_core.dart'; | 7 import 'java_core.dart'; |
| 6 import 'java_io.dart'; | 8 import 'java_io.dart'; |
| 7 import 'engine.dart' show AnalysisContext, AnalysisEngine; | 9 import 'engine.dart' show AnalysisContext, AnalysisEngine; |
| 8 export 'source.dart'; | 10 export 'source.dart'; |
| 11 |
| 9 /** | 12 /** |
| 10 * Instances of the class `FileBasedSource` implement a source that represents a
file. | 13 * Instances of the class `FileBasedSource` implement a source that represents a
file. |
| 11 * | 14 * |
| 12 * @coverage dart.engine.source | 15 * @coverage dart.engine.source |
| 13 */ | 16 */ |
| 14 class FileBasedSource implements Source { | 17 class FileBasedSource implements Source { |
| 15 | |
| 16 /** | 18 /** |
| 17 * The content cache used to access the contents of this source if they have b
een overridden from | 19 * The content cache used to access the contents of this source if they have b
een overridden from |
| 18 * what is on disk or cached. | 20 * what is on disk or cached. |
| 19 */ | 21 */ |
| 20 ContentCache _contentCache; | 22 ContentCache _contentCache; |
| 21 | 23 |
| 22 /** | 24 /** |
| 23 * The file represented by this source. | 25 * The file represented by this source. |
| 24 */ | 26 */ |
| 25 JavaFile file; | 27 JavaFile file; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 * Initialize a newly created source object. | 49 * Initialize a newly created source object. |
| 48 * | 50 * |
| 49 * @param contentCache the content cache used to access the contents of this s
ource | 51 * @param contentCache the content cache used to access the contents of this s
ource |
| 50 * @param file the file represented by this source | 52 * @param file the file represented by this source |
| 51 * @param flags `true` if this source is in one of the system libraries | 53 * @param flags `true` if this source is in one of the system libraries |
| 52 */ | 54 */ |
| 53 FileBasedSource.con2(ContentCache contentCache, JavaFile file, UriKind uriKind
) { | 55 FileBasedSource.con2(ContentCache contentCache, JavaFile file, UriKind uriKind
) { |
| 54 this._contentCache = contentCache; | 56 this._contentCache = contentCache; |
| 55 this.file = file; | 57 this.file = file; |
| 56 this._uriKind = uriKind; | 58 this._uriKind = uriKind; |
| 57 if (file.getPath().indexOf(':') > 2) { | |
| 58 try { | |
| 59 throw new IllegalArgumentException("Invalid source path: ${file}"); | |
| 60 } on IllegalArgumentException catch (e) { | |
| 61 AnalysisEngine.instance.logger.logError3(e); | |
| 62 throw e; | |
| 63 } | |
| 64 } | |
| 65 } | 59 } |
| 66 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && file == ((object as FileBasedSource)).file; | 60 |
| 61 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && file == (object as FileBasedSource).file; |
| 62 |
| 67 bool exists() => _contentCache.getContents(this) != null || (file.exists() &&
!file.isDirectory()); | 63 bool exists() => _contentCache.getContents(this) != null || (file.exists() &&
!file.isDirectory()); |
| 64 |
| 68 void getContents(Source_ContentReceiver receiver) { | 65 void getContents(Source_ContentReceiver receiver) { |
| 69 String contents = _contentCache.getContents(this); | 66 String contents = _contentCache.getContents(this); |
| 70 if (contents != null) { | 67 if (contents != null) { |
| 71 receiver.accept2(contents, _contentCache.getModificationStamp(this)); | 68 receiver.accept2(contents, _contentCache.getModificationStamp(this)); |
| 72 return; | 69 return; |
| 73 } | 70 } |
| 74 getContentsFromFile(receiver); | 71 getContentsFromFile(receiver); |
| 75 } | 72 } |
| 73 |
| 76 String get encoding { | 74 String get encoding { |
| 77 if (_encoding == null) { | 75 if (_encoding == null) { |
| 78 _encoding = "${_uriKind.encoding}${file.toURI().toString()}"; | 76 _encoding = "${_uriKind.encoding}${file.toURI().toString()}"; |
| 79 } | 77 } |
| 80 return _encoding; | 78 return _encoding; |
| 81 } | 79 } |
| 80 |
| 82 String get fullName => file.getAbsolutePath(); | 81 String get fullName => file.getAbsolutePath(); |
| 82 |
| 83 int get modificationStamp { | 83 int get modificationStamp { |
| 84 int stamp = _contentCache.getModificationStamp(this); | 84 int stamp = _contentCache.getModificationStamp(this); |
| 85 if (stamp != null) { | 85 if (stamp != null) { |
| 86 return stamp; | 86 return stamp; |
| 87 } | 87 } |
| 88 return file.lastModified(); | 88 return file.lastModified(); |
| 89 } | 89 } |
| 90 |
| 90 String get shortName => file.getName(); | 91 String get shortName => file.getName(); |
| 92 |
| 91 UriKind get uriKind => _uriKind; | 93 UriKind get uriKind => _uriKind; |
| 94 |
| 92 int get hashCode => file.hashCode; | 95 int get hashCode => file.hashCode; |
| 96 |
| 93 bool get isInSystemLibrary => identical(_uriKind, UriKind.DART_URI); | 97 bool get isInSystemLibrary => identical(_uriKind, UriKind.DART_URI); |
| 98 |
| 94 Source resolveRelative(Uri containedUri) { | 99 Source resolveRelative(Uri containedUri) { |
| 95 try { | 100 try { |
| 96 Uri resolvedUri = file.toURI().resolveUri(containedUri); | 101 Uri resolvedUri = file.toURI().resolveUri(containedUri); |
| 97 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv
edUri), _uriKind); | 102 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv
edUri), _uriKind); |
| 98 } on JavaException catch (exception) { | 103 } on JavaException catch (exception) { |
| 99 } | 104 } |
| 100 return null; | 105 return null; |
| 101 } | 106 } |
| 107 |
| 102 String toString() { | 108 String toString() { |
| 103 if (file == null) { | 109 if (file == null) { |
| 104 return "<unknown source>"; | 110 return "<unknown source>"; |
| 105 } | 111 } |
| 106 return file.getAbsolutePath(); | 112 return file.getAbsolutePath(); |
| 107 } | 113 } |
| 108 | 114 |
| 109 /** | 115 /** |
| 110 * Get the contents of underlying file and pass it to the given receiver. Exac
tly one of the | 116 * Get the contents of underlying file and pass it to the given receiver. Exac
tly one of the |
| 111 * methods defined on the receiver will be invoked unless an exception is thro
wn. The method that | 117 * methods defined on the receiver will be invoked unless an exception is thro
wn. The method that |
| 112 * will be invoked depends on which of the possible representations of the con
tents is the most | 118 * will be invoked depends on which of the possible representations of the con
tents is the most |
| 113 * efficient. Whichever method is invoked, it will be invoked before this meth
od returns. | 119 * efficient. Whichever method is invoked, it will be invoked before this meth
od returns. |
| 114 * | 120 * |
| 115 * @param receiver the content receiver to which the content of this source wi
ll be passed | 121 * @param receiver the content receiver to which the content of this source wi
ll be passed |
| 116 * @throws Exception if the contents of this source could not be accessed | 122 * @throws Exception if the contents of this source could not be accessed |
| 117 * @see #getContents(com.google.dart.engine.source.Source.ContentReceiver) | 123 * @see #getContents(com.google.dart.engine.source.Source.ContentReceiver) |
| 118 */ | 124 */ |
| 119 void getContentsFromFile(Source_ContentReceiver receiver) { | 125 void getContentsFromFile(Source_ContentReceiver receiver) { |
| 120 { | 126 { |
| 121 } | 127 } |
| 122 receiver.accept2(file.readAsStringSync(), file.lastModified()); | 128 receiver.accept2(file.readAsStringSync(), file.lastModified()); |
| 123 } | 129 } |
| 124 } | 130 } |
| 131 |
| 125 /** | 132 /** |
| 126 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co
ntext of | 133 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co
ntext of |
| 127 * an application. | 134 * an application. |
| 128 * | 135 * |
| 129 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory | 136 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory |
| 130 * should be canonicalized, but to preserve relative links within a package, the
remainder of the | 137 * should be canonicalized, but to preserve relative links within a package, the
remainder of the |
| 131 * path from the package directory to the leaf should not. | 138 * path from the package directory to the leaf should not. |
| 132 * | 139 * |
| 133 * @coverage dart.engine.source | 140 * @coverage dart.engine.source |
| 134 */ | 141 */ |
| 135 class PackageUriResolver extends UriResolver { | 142 class PackageUriResolver extends UriResolver { |
| 136 | |
| 137 /** | 143 /** |
| 138 * The package directories that `package` URI's are assumed to be relative to. | 144 * The package directories that `package` URI's are assumed to be relative to. |
| 139 */ | 145 */ |
| 140 List<JavaFile> _packagesDirectories; | 146 List<JavaFile> _packagesDirectories; |
| 141 | 147 |
| 142 /** | 148 /** |
| 143 * The name of the `package` scheme. | 149 * The name of the `package` scheme. |
| 144 */ | 150 */ |
| 145 static String PACKAGE_SCHEME = "package"; | 151 static String PACKAGE_SCHEME = "package"; |
| 146 | 152 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 163 * | 169 * |
| 164 * @param packagesDirectories the package directories that `package` URI's are
assumed to be | 170 * @param packagesDirectories the package directories that `package` URI's are
assumed to be |
| 165 * relative to | 171 * relative to |
| 166 */ | 172 */ |
| 167 PackageUriResolver(List<JavaFile> packagesDirectories) { | 173 PackageUriResolver(List<JavaFile> packagesDirectories) { |
| 168 if (packagesDirectories.length < 1) { | 174 if (packagesDirectories.length < 1) { |
| 169 throw new IllegalArgumentException("At least one package directory must be
provided"); | 175 throw new IllegalArgumentException("At least one package directory must be
provided"); |
| 170 } | 176 } |
| 171 this._packagesDirectories = packagesDirectories; | 177 this._packagesDirectories = packagesDirectories; |
| 172 } | 178 } |
| 179 |
| 173 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { | 180 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { |
| 174 if (identical(kind, UriKind.PACKAGE_SELF_URI) || identical(kind, UriKind.PAC
KAGE_URI)) { | 181 if (identical(kind, UriKind.PACKAGE_SELF_URI) || identical(kind, UriKind.PAC
KAGE_URI)) { |
| 175 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); | 182 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); |
| 176 } | 183 } |
| 177 return null; | 184 return null; |
| 178 } | 185 } |
| 186 |
| 179 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 187 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 180 if (!isPackageUri(uri)) { | 188 if (!isPackageUri(uri)) { |
| 181 return null; | 189 return null; |
| 182 } | 190 } |
| 183 String path = uri.path; | 191 String path = uri.path; |
| 184 if (path == null) { | 192 if (path == null) { |
| 185 path = uri.path; | 193 path = uri.path; |
| 186 if (path == null) { | 194 if (path == null) { |
| 187 return null; | 195 return null; |
| 188 } | 196 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 202 for (JavaFile packagesDirectory in _packagesDirectories) { | 210 for (JavaFile packagesDirectory in _packagesDirectories) { |
| 203 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); | 211 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); |
| 204 if (resolvedFile.exists()) { | 212 if (resolvedFile.exists()) { |
| 205 JavaFile canonicalFile = getCanonicalFile(packagesDirectory, pkgName, re
lPath); | 213 JavaFile canonicalFile = getCanonicalFile(packagesDirectory, pkgName, re
lPath); |
| 206 UriKind uriKind = isSelfReference(packagesDirectory, canonicalFile) ? Ur
iKind.PACKAGE_SELF_URI : UriKind.PACKAGE_URI; | 214 UriKind uriKind = isSelfReference(packagesDirectory, canonicalFile) ? Ur
iKind.PACKAGE_SELF_URI : UriKind.PACKAGE_URI; |
| 207 return new FileBasedSource.con2(contentCache, canonicalFile, uriKind); | 215 return new FileBasedSource.con2(contentCache, canonicalFile, uriKind); |
| 208 } | 216 } |
| 209 } | 217 } |
| 210 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); | 218 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); |
| 211 } | 219 } |
| 220 |
| 212 Uri restoreAbsolute(Source source) { | 221 Uri restoreAbsolute(Source source) { |
| 213 if (source is FileBasedSource) { | 222 if (source is FileBasedSource) { |
| 214 String sourcePath = ((source as FileBasedSource)).file.getPath(); | 223 String sourcePath = (source as FileBasedSource).file.getPath(); |
| 215 for (JavaFile packagesDirectory in _packagesDirectories) { | 224 for (JavaFile packagesDirectory in _packagesDirectories) { |
| 216 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); | 225 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); |
| 217 if (pkgFolders != null) { | 226 if (pkgFolders != null) { |
| 218 for (JavaFile pkgFolder in pkgFolders) { | 227 for (JavaFile pkgFolder in pkgFolders) { |
| 219 try { | 228 try { |
| 220 String pkgCanonicalPath = pkgFolder.getCanonicalPath(); | 229 String pkgCanonicalPath = pkgFolder.getCanonicalPath(); |
| 221 if (sourcePath.startsWith(pkgCanonicalPath)) { | 230 if (sourcePath.startsWith(pkgCanonicalPath)) { |
| 222 String relPath = sourcePath.substring(pkgCanonicalPath.length); | 231 String relPath = sourcePath.substring(pkgCanonicalPath.length); |
| 223 return parseUriWithException("${PACKAGE_SCHEME}:${pkgFolder.getN
ame()}${relPath}"); | 232 return parseUriWithException("${PACKAGE_SCHEME}:${pkgFolder.getN
ame()}${relPath}"); |
| 224 } | 233 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 bool isSelfReference(JavaFile packagesDir, JavaFile file) { | 271 bool isSelfReference(JavaFile packagesDir, JavaFile file) { |
| 263 JavaFile rootDir = packagesDir.getParentFile(); | 272 JavaFile rootDir = packagesDir.getParentFile(); |
| 264 if (rootDir == null) { | 273 if (rootDir == null) { |
| 265 return false; | 274 return false; |
| 266 } | 275 } |
| 267 String rootPath = rootDir.getAbsolutePath(); | 276 String rootPath = rootDir.getAbsolutePath(); |
| 268 String filePath = file.getAbsolutePath(); | 277 String filePath = file.getAbsolutePath(); |
| 269 return filePath.startsWith("${rootPath}/lib"); | 278 return filePath.startsWith("${rootPath}/lib"); |
| 270 } | 279 } |
| 271 } | 280 } |
| 281 |
| 272 /** | 282 /** |
| 273 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that | 283 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that |
| 274 * contains all sources within a given directory. | 284 * contains all sources within a given directory. |
| 275 * | 285 * |
| 276 * @coverage dart.engine.source | 286 * @coverage dart.engine.source |
| 277 */ | 287 */ |
| 278 class DirectoryBasedSourceContainer implements SourceContainer { | 288 class DirectoryBasedSourceContainer implements SourceContainer { |
| 279 | |
| 280 /** | 289 /** |
| 281 * Append the system file separator to the given path unless the path already
ends with a | 290 * Append the system file separator to the given path unless the path already
ends with a |
| 282 * separator. | 291 * separator. |
| 283 * | 292 * |
| 284 * @param path the path to which the file separator is to be added | 293 * @param path the path to which the file separator is to be added |
| 285 * @return a path that ends with the system file separator | 294 * @return a path that ends with the system file separator |
| 286 */ | 295 */ |
| 287 static String appendFileSeparator(String path) { | 296 static String appendFileSeparator(String path) { |
| 288 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) ==
JavaFile.separatorChar) { | 297 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) ==
JavaFile.separatorChar) { |
| 289 return path; | 298 return path; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 308 | 317 |
| 309 /** | 318 /** |
| 310 * Construct a container representing the specified path and containing any so
urces whose | 319 * Construct a container representing the specified path and containing any so
urces whose |
| 311 * [Source#getFullName] starts with the specified path. | 320 * [Source#getFullName] starts with the specified path. |
| 312 * | 321 * |
| 313 * @param path the path (not `null` and not empty) | 322 * @param path the path (not `null` and not empty) |
| 314 */ | 323 */ |
| 315 DirectoryBasedSourceContainer.con2(String path) { | 324 DirectoryBasedSourceContainer.con2(String path) { |
| 316 this.path = appendFileSeparator(path); | 325 this.path = appendFileSeparator(path); |
| 317 } | 326 } |
| 327 |
| 318 bool contains(Source source) => source.fullName.startsWith(path); | 328 bool contains(Source source) => source.fullName.startsWith(path); |
| 319 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; | 329 |
| 330 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && (obj
as DirectoryBasedSourceContainer).path == path; |
| 331 |
| 320 int get hashCode => path.hashCode; | 332 int get hashCode => path.hashCode; |
| 333 |
| 321 String toString() => "SourceContainer[${path}]"; | 334 String toString() => "SourceContainer[${path}]"; |
| 322 } | 335 } |
| 336 |
| 323 /** | 337 /** |
| 324 * Instances of the class `FileUriResolver` resolve `file` URI's. | 338 * Instances of the class `FileUriResolver` resolve `file` URI's. |
| 325 * | 339 * |
| 326 * @coverage dart.engine.source | 340 * @coverage dart.engine.source |
| 327 */ | 341 */ |
| 328 class FileUriResolver extends UriResolver { | 342 class FileUriResolver extends UriResolver { |
| 329 | |
| 330 /** | 343 /** |
| 331 * The name of the `file` scheme. | 344 * The name of the `file` scheme. |
| 332 */ | 345 */ |
| 333 static String FILE_SCHEME = "file"; | 346 static String FILE_SCHEME = "file"; |
| 334 | 347 |
| 335 /** | 348 /** |
| 336 * Return `true` if the given URI is a `file` URI. | 349 * Return `true` if the given URI is a `file` URI. |
| 337 * | 350 * |
| 338 * @param uri the URI being tested | 351 * @param uri the URI being tested |
| 339 * @return `true` if the given URI is a `file` URI | 352 * @return `true` if the given URI is a `file` URI |
| 340 */ | 353 */ |
| 341 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; | 354 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; |
| 355 |
| 342 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { | 356 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { |
| 343 if (identical(kind, UriKind.FILE_URI)) { | 357 if (identical(kind, UriKind.FILE_URI)) { |
| 344 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); | 358 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); |
| 345 } | 359 } |
| 346 return null; | 360 return null; |
| 347 } | 361 } |
| 362 |
| 348 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 363 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 349 if (!isFileUri(uri)) { | 364 if (!isFileUri(uri)) { |
| 350 return null; | 365 return null; |
| 351 } | 366 } |
| 352 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); | 367 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); |
| 353 } | 368 } |
| 354 } | 369 } |
| OLD | NEW |