| 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 'dart:uri'; | 8 import 'dart:uri'; |
| 9 import 'java_core.dart'; | 9 import 'java_core.dart'; |
| 10 import 'java_io.dart'; | 10 import 'java_io.dart'; |
| 11 import 'sdk.dart' show DartSdk; | 11 import 'sdk.dart' show DartSdk; |
| 12 import 'engine.dart' show AnalysisContext, AnalysisEngine; | 12 import 'engine.dart' show AnalysisContext, AnalysisEngine; |
| 13 export 'source.dart'; | 13 export 'source.dart'; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * 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. |
| 17 * @coverage dart.engine.source | 17 * @coverage dart.engine.source |
| 18 */ | 18 */ |
| 19 class FileBasedSource implements Source { | 19 class FileBasedSource implements Source { |
| 20 /** | 20 /** |
| 21 * The content cache used to access the contents of this source if they have b
een overridden from | 21 * The content cache used to access the contents of this source if they have b
een overridden from |
| 22 * what is on disk or cached. | 22 * what is on disk or cached. |
| 23 */ | 23 */ |
| 24 ContentCache _contentCache; | 24 ContentCache _contentCache; |
| 25 /** | 25 /** |
| 26 * The file represented by this source. | 26 * The file represented by this source. |
| 27 */ | 27 */ |
| 28 JavaFile _file; | 28 JavaFile _file; |
| 29 /** | 29 /** |
| 30 * The cached URI of the {@link #file}. | 30 * The cached encoding for this source. |
| 31 */ | 31 */ |
| 32 String _fileUriString; | 32 String _encoding; |
| 33 /** | 33 /** |
| 34 * A flag indicating whether this source is in one of the system libraries. | 34 * The kind of URI from which this source was originally derived. |
| 35 */ | 35 */ |
| 36 bool _inSystemLibrary = false; | 36 UriKind _uriKind; |
| 37 /** | 37 /** |
| 38 * Initialize a newly created source object. The source object is assumed to n
ot be in a system | 38 * Initialize a newly created source object. The source object is assumed to n
ot be in a system |
| 39 * library. | 39 * library. |
| 40 * @param contentCache the content cache used to access the contents of this s
ource | 40 * @param contentCache the content cache used to access the contents of this s
ource |
| 41 * @param file the file represented by this source | 41 * @param file the file represented by this source |
| 42 */ | 42 */ |
| 43 FileBasedSource.con1(ContentCache contentCache, JavaFile file) { | 43 FileBasedSource.con1(ContentCache contentCache, JavaFile file) { |
| 44 _jtd_constructor_328_impl(contentCache, file); | 44 _jtd_constructor_329_impl(contentCache, file); |
| 45 } | 45 } |
| 46 _jtd_constructor_328_impl(ContentCache contentCache, JavaFile file) { | 46 _jtd_constructor_329_impl(ContentCache contentCache, JavaFile file) { |
| 47 _jtd_constructor_329_impl(contentCache, file, false); | 47 _jtd_constructor_330_impl(contentCache, file, UriKind.FILE_URI); |
| 48 } | 48 } |
| 49 /** | 49 /** |
| 50 * Initialize a newly created source object. | 50 * Initialize a newly created source object. |
| 51 * @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 |
| 52 * @param file the file represented by this source | 52 * @param file the file represented by this source |
| 53 * @param inSystemLibrary {@code true} if this source is in one of the system
libraries | 53 * @param flags {@code true} if this source is in one of the system libraries |
| 54 */ | 54 */ |
| 55 FileBasedSource.con2(ContentCache contentCache2, JavaFile file2, bool inSystem
Library2) { | 55 FileBasedSource.con2(ContentCache contentCache2, JavaFile file2, UriKind uriKi
nd2) { |
| 56 _jtd_constructor_329_impl(contentCache2, file2, inSystemLibrary2); | 56 _jtd_constructor_330_impl(contentCache2, file2, uriKind2); |
| 57 } | 57 } |
| 58 _jtd_constructor_329_impl(ContentCache contentCache2, JavaFile file2, bool inS
ystemLibrary2) { | 58 _jtd_constructor_330_impl(ContentCache contentCache2, JavaFile file2, UriKind
uriKind2) { |
| 59 this._contentCache = contentCache2; | 59 this._contentCache = contentCache2; |
| 60 this._file = file2; | 60 this._file = file2; |
| 61 this._inSystemLibrary = inSystemLibrary2; | 61 this._uriKind = uriKind2; |
| 62 this._fileUriString = file2.toURI().toString(); | 62 this._encoding = "${uriKind2.encoding}${file2.toURI().toString()}"; |
| 63 } | 63 } |
| 64 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && _file == ((object as FileBasedSource))._file; | 64 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && _file == ((object as FileBasedSource))._file; |
| 65 bool exists() => _contentCache.getContents(this) != null || (_file.exists() &&
!_file.isDirectory()); | 65 bool exists() => _contentCache.getContents(this) != null || (_file.exists() &&
!_file.isDirectory()); |
| 66 void getContents(Source_ContentReceiver receiver) { | 66 void getContents(Source_ContentReceiver receiver) { |
| 67 { | 67 { |
| 68 String contents = _contentCache.getContents(this); | 68 String contents = _contentCache.getContents(this); |
| 69 if (contents != null) { | 69 if (contents != null) { |
| 70 receiver.accept2(contents, _contentCache.getModificationStamp(this)); | 70 receiver.accept2(contents, _contentCache.getModificationStamp(this)); |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 receiver.accept2(_file.readAsStringSync(), _file.lastModified()); | 74 receiver.accept2(_file.readAsStringSync(), _file.lastModified()); |
| 75 } | 75 } |
| 76 String get encoding => _fileUriString; | 76 String get encoding => _encoding; |
| 77 String get fullName => _file.getAbsolutePath(); | 77 String get fullName => _file.getAbsolutePath(); |
| 78 int get modificationStamp { | 78 int get modificationStamp { |
| 79 int stamp = _contentCache.getModificationStamp(this); | 79 int stamp = _contentCache.getModificationStamp(this); |
| 80 if (stamp != null) { | 80 if (stamp != null) { |
| 81 return stamp; | 81 return stamp; |
| 82 } | 82 } |
| 83 return _file.lastModified(); | 83 return _file.lastModified(); |
| 84 } | 84 } |
| 85 String get shortName => _file.getName(); | 85 String get shortName => _file.getName(); |
| 86 UriKind get uriKind => _uriKind; |
| 86 int get hashCode => _file.hashCode; | 87 int get hashCode => _file.hashCode; |
| 87 bool isInSystemLibrary() => _inSystemLibrary; | 88 bool isInSystemLibrary() => identical(_uriKind, UriKind.DART_URI); |
| 88 Source resolveRelative(Uri containedUri) { | 89 Source resolveRelative(Uri containedUri) { |
| 89 try { | 90 try { |
| 90 Uri resolvedUri = file.toURI().resolveUri(containedUri); | 91 Uri resolvedUri = file.toURI().resolveUri(containedUri); |
| 91 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv
edUri), isInSystemLibrary()); | 92 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv
edUri), _uriKind); |
| 92 } catch (exception) { | 93 } catch (exception) { |
| 93 } | 94 } |
| 94 return null; | 95 return null; |
| 95 } | 96 } |
| 96 String toString() { | 97 String toString() { |
| 97 if (_file == null) { | 98 if (_file == null) { |
| 98 return "<unknown source>"; | 99 return "<unknown source>"; |
| 99 } | 100 } |
| 100 return _file.getAbsolutePath(); | 101 return _file.getAbsolutePath(); |
| 101 } | 102 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 * package directories. | 136 * package directories. |
| 136 * @param packagesDirectories the package directories that {@code package} URI
's are assumed to be | 137 * @param packagesDirectories the package directories that {@code package} URI
's are assumed to be |
| 137 * relative to | 138 * relative to |
| 138 */ | 139 */ |
| 139 PackageUriResolver(List<JavaFile> packagesDirectories) { | 140 PackageUriResolver(List<JavaFile> packagesDirectories) { |
| 140 if (packagesDirectories.length < 1) { | 141 if (packagesDirectories.length < 1) { |
| 141 throw new IllegalArgumentException("At least one package directory must be
provided"); | 142 throw new IllegalArgumentException("At least one package directory must be
provided"); |
| 142 } | 143 } |
| 143 this._packagesDirectories = packagesDirectories; | 144 this._packagesDirectories = packagesDirectories; |
| 144 } | 145 } |
| 146 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { |
| 147 if (identical(kind, UriKind.PACKAGE_URI)) { |
| 148 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); |
| 149 } |
| 150 return null; |
| 151 } |
| 145 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 152 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 146 if (!isPackageUri(uri)) { | 153 if (!isPackageUri(uri)) { |
| 147 return null; | 154 return null; |
| 148 } | 155 } |
| 149 String path2 = uri.path; | 156 String path2 = uri.path; |
| 150 if (path2 == null) { | 157 if (path2 == null) { |
| 151 path2 = uri.path; | 158 path2 = uri.path; |
| 152 if (path2 == null) { | 159 if (path2 == null) { |
| 153 return null; | 160 return null; |
| 154 } | 161 } |
| 155 } | 162 } |
| 156 String pkgName; | 163 String pkgName; |
| 157 String relPath; | 164 String relPath; |
| 158 int index = path2.indexOf('/'); | 165 int index = path2.indexOf('/'); |
| 159 if (index == -1) { | 166 if (index == -1) { |
| 160 pkgName = path2; | 167 pkgName = path2; |
| 161 relPath = ""; | 168 relPath = ""; |
| 162 } else if (index == 0) { | 169 } else if (index == 0) { |
| 163 return null; | 170 return null; |
| 164 } else { | 171 } else { |
| 165 pkgName = path2.substring(0, index); | 172 pkgName = path2.substring(0, index); |
| 166 relPath = path2.substring(index + 1); | 173 relPath = path2.substring(index + 1); |
| 167 } | 174 } |
| 168 for (JavaFile packagesDirectory in _packagesDirectories) { | 175 for (JavaFile packagesDirectory in _packagesDirectories) { |
| 169 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path2); | 176 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path2); |
| 170 if (resolvedFile.exists()) { | 177 if (resolvedFile.exists()) { |
| 171 return new FileBasedSource.con1(contentCache, getCanonicalFile(packagesD
irectory, pkgName, relPath)); | 178 return new FileBasedSource.con2(contentCache, getCanonicalFile(packagesD
irectory, pkgName, relPath), UriKind.PACKAGE_URI); |
| 172 } | 179 } |
| 173 } | 180 } |
| 174 return new FileBasedSource.con1(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath)); | 181 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); |
| 175 } | 182 } |
| 176 /** | 183 /** |
| 177 * Answer the canonical file for the specified package. | 184 * Answer the canonical file for the specified package. |
| 178 * @param packagesDirectory the "packages" directory (not {@code null}) | 185 * @param packagesDirectory the "packages" directory (not {@code null}) |
| 179 * @param pkgName the package name (not {@code null}, not empty) | 186 * @param pkgName the package name (not {@code null}, not empty) |
| 180 * @param relPath the path relative to the package directory (not {@code null}
, no leading slash, | 187 * @param relPath the path relative to the package directory (not {@code null}
, no leading slash, |
| 181 * but may be empty string) | 188 * but may be empty string) |
| 182 * @return the file (not {@code null}) | 189 * @return the file (not {@code null}) |
| 183 */ | 190 */ |
| 184 JavaFile getCanonicalFile(JavaFile packagesDirectory, String pkgName, String r
elPath) { | 191 JavaFile getCanonicalFile(JavaFile packagesDirectory, String pkgName, String r
elPath) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 212 /** | 219 /** |
| 213 * The container's path (not {@code null}). | 220 * The container's path (not {@code null}). |
| 214 */ | 221 */ |
| 215 String _path; | 222 String _path; |
| 216 /** | 223 /** |
| 217 * 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 * 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, |
| 218 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour
ceContainer(String)}. | 225 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour
ceContainer(String)}. |
| 219 * @param directory the directory (not {@code null}) | 226 * @param directory the directory (not {@code null}) |
| 220 */ | 227 */ |
| 221 DirectoryBasedSourceContainer.con1(JavaFile directory) { | 228 DirectoryBasedSourceContainer.con1(JavaFile directory) { |
| 222 _jtd_constructor_326_impl(directory); | 229 _jtd_constructor_327_impl(directory); |
| 223 } | 230 } |
| 224 _jtd_constructor_326_impl(JavaFile directory) { | 231 _jtd_constructor_327_impl(JavaFile directory) { |
| 225 _jtd_constructor_327_impl(directory.getPath()); | 232 _jtd_constructor_328_impl(directory.getPath()); |
| 226 } | 233 } |
| 227 /** | 234 /** |
| 228 * Construct a container representing the specified path and containing any so
urces whose{@link Source#getFullName()} starts with the specified path. | 235 * Construct a container representing the specified path and containing any so
urces whose{@link Source#getFullName()} starts with the specified path. |
| 229 * @param path the path (not {@code null} and not empty) | 236 * @param path the path (not {@code null} and not empty) |
| 230 */ | 237 */ |
| 231 DirectoryBasedSourceContainer.con2(String path2) { | 238 DirectoryBasedSourceContainer.con2(String path2) { |
| 232 _jtd_constructor_327_impl(path2); | 239 _jtd_constructor_328_impl(path2); |
| 233 } | 240 } |
| 234 _jtd_constructor_327_impl(String path2) { | 241 _jtd_constructor_328_impl(String path2) { |
| 235 this._path = appendFileSeparator(path2); | 242 this._path = appendFileSeparator(path2); |
| 236 } | 243 } |
| 237 bool contains(Source source) => source.fullName.startsWith(_path); | 244 bool contains(Source source) => source.fullName.startsWith(_path); |
| 238 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; | 245 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; |
| 239 /** | 246 /** |
| 240 * Answer the receiver's path, used to determine if a source is contained in t
he receiver. | 247 * Answer the receiver's path, used to determine if a source is contained in t
he receiver. |
| 241 * @return the path (not {@code null}, not empty) | 248 * @return the path (not {@code null}, not empty) |
| 242 */ | 249 */ |
| 243 String get path => _path; | 250 String get path => _path; |
| 244 int get hashCode => _path.hashCode; | 251 int get hashCode => _path.hashCode; |
| 252 String toString() => "SourceContainer[${_path}]"; |
| 245 } | 253 } |
| 246 /** | 254 /** |
| 247 * Instances of the class {@code FileUriResolver} resolve {@code file} URI's. | 255 * Instances of the class {@code FileUriResolver} resolve {@code file} URI's. |
| 248 * @coverage dart.engine.source | 256 * @coverage dart.engine.source |
| 249 */ | 257 */ |
| 250 class FileUriResolver extends UriResolver { | 258 class FileUriResolver extends UriResolver { |
| 251 /** | 259 /** |
| 252 * The name of the {@code file} scheme. | 260 * The name of the {@code file} scheme. |
| 253 */ | 261 */ |
| 254 static String _FILE_SCHEME = "file"; | 262 static String _FILE_SCHEME = "file"; |
| 255 /** | 263 /** |
| 256 * Return {@code true} if the given URI is a {@code file} URI. | 264 * Return {@code true} if the given URI is a {@code file} URI. |
| 257 * @param uri the URI being tested | 265 * @param uri the URI being tested |
| 258 * @return {@code true} if the given URI is a {@code file} URI | 266 * @return {@code true} if the given URI is a {@code file} URI |
| 259 */ | 267 */ |
| 260 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; | 268 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; |
| 261 /** | 269 /** |
| 262 * Initialize a newly created resolver to resolve {@code file} URI's relative
to the given root | 270 * Initialize a newly created resolver to resolve {@code file} URI's relative
to the given root |
| 263 * directory. | 271 * directory. |
| 264 */ | 272 */ |
| 265 FileUriResolver() : super() { | 273 FileUriResolver() : super() { |
| 266 } | 274 } |
| 275 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { |
| 276 if (identical(kind, UriKind.FILE_URI)) { |
| 277 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); |
| 278 } |
| 279 return null; |
| 280 } |
| 267 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 281 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 268 if (!isFileUri(uri)) { | 282 if (!isFileUri(uri)) { |
| 269 return null; | 283 return null; |
| 270 } | 284 } |
| 271 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); | 285 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); |
| 272 } | 286 } |
| 273 } | 287 } |
| OLD | NEW |