| 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; | 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 source factory that created this source and that should be used to reso
lve URI's against | 21 * The content cache used to access the contents of this source if they have b
een overridden from |
| 22 * this source. | 22 * what is on disk or cached. |
| 23 */ | 23 */ |
| 24 SourceFactory _factory; | 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}. |
| 31 */ |
| 32 String _fileUriString; |
| 33 /** |
| 30 * A flag indicating whether this source is in one of the system libraries. | 34 * A flag indicating whether this source is in one of the system libraries. |
| 31 */ | 35 */ |
| 32 bool _inSystemLibrary = false; | 36 bool _inSystemLibrary = false; |
| 33 /** | 37 /** |
| 34 * 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 |
| 35 * library. | 39 * library. |
| 36 * @param factory the source factory that created this source | 40 * @param contentCache the content cache used to access the contents of this s
ource |
| 37 * @param file the file represented by this source | 41 * @param file the file represented by this source |
| 38 */ | 42 */ |
| 39 FileBasedSource.con1(SourceFactory factory, JavaFile file) { | 43 FileBasedSource.con1(ContentCache contentCache, JavaFile file) { |
| 40 _jtd_constructor_302_impl(factory, file); | 44 _jtd_constructor_328_impl(contentCache, file); |
| 41 } | 45 } |
| 42 _jtd_constructor_302_impl(SourceFactory factory, JavaFile file) { | 46 _jtd_constructor_328_impl(ContentCache contentCache, JavaFile file) { |
| 43 _jtd_constructor_303_impl(factory, file, false); | 47 _jtd_constructor_329_impl(contentCache, file, false); |
| 44 } | 48 } |
| 45 /** | 49 /** |
| 46 * Initialize a newly created source object. | 50 * Initialize a newly created source object. |
| 47 * @param factory the source factory that created this source | 51 * @param contentCache the content cache used to access the contents of this s
ource |
| 48 * @param file the file represented by this source | 52 * @param file the file represented by this source |
| 49 * @param inSystemLibrary {@code true} if this source is in one of the system
libraries | 53 * @param inSystemLibrary {@code true} if this source is in one of the system
libraries |
| 50 */ | 54 */ |
| 51 FileBasedSource.con2(SourceFactory factory2, JavaFile file3, bool inSystemLibr
ary2) { | 55 FileBasedSource.con2(ContentCache contentCache2, JavaFile file3, bool inSystem
Library2) { |
| 52 _jtd_constructor_303_impl(factory2, file3, inSystemLibrary2); | 56 _jtd_constructor_329_impl(contentCache2, file3, inSystemLibrary2); |
| 53 } | 57 } |
| 54 _jtd_constructor_303_impl(SourceFactory factory2, JavaFile file3, bool inSyste
mLibrary2) { | 58 _jtd_constructor_329_impl(ContentCache contentCache2, JavaFile file3, bool inS
ystemLibrary2) { |
| 55 this._factory = factory2; | 59 this._contentCache = contentCache2; |
| 56 this._file = file3; | 60 this._file = file3; |
| 57 this._inSystemLibrary = inSystemLibrary2; | 61 this._inSystemLibrary = inSystemLibrary2; |
| 62 this._fileUriString = file3.toURI().toString(); |
| 58 } | 63 } |
| 59 bool operator ==(Object object) => object != null && identical(this.runtimeTyp
e, object.runtimeType) && _file == ((object as FileBasedSource))._file; | 64 bool operator ==(Object object) => object != null && identical(this.runtimeTyp
e, object.runtimeType) && _file == ((object as FileBasedSource))._file; |
| 60 bool exists() => _factory.getContents(this) != null || (_file.exists() && !_fi
le.isDirectory()); | 65 bool exists() => _contentCache.getContents(this) != null || (_file.exists() &&
!_file.isDirectory()); |
| 61 void getContents(Source_ContentReceiver receiver) { | 66 void getContents(Source_ContentReceiver receiver) { |
| 62 { | 67 { |
| 63 String contents = _factory.getContents(this); | 68 String contents = _contentCache.getContents(this); |
| 64 if (contents != null) { | 69 if (contents != null) { |
| 65 receiver.accept2(contents); | 70 receiver.accept2(contents, _contentCache.getModificationStamp(this)); |
| 66 return; | 71 return; |
| 67 } | 72 } |
| 68 } | 73 } |
| 69 receiver.accept2(_file.readAsStringSync()); | 74 receiver.accept2(_file.readAsStringSync(), _file.lastModified()); |
| 70 } | 75 } |
| 71 AnalysisContext get context => _factory.context; | 76 String get encoding => _fileUriString; |
| 72 String get encoding => _file.toURI().toString(); | |
| 73 String get fullName => _file.getAbsolutePath(); | 77 String get fullName => _file.getAbsolutePath(); |
| 74 int get modificationStamp { | 78 int get modificationStamp { |
| 75 int stamp = _factory.getModificationStamp(this); | 79 int stamp = _contentCache.getModificationStamp(this); |
| 76 if (stamp != null) { | 80 if (stamp != null) { |
| 77 return stamp; | 81 return stamp; |
| 78 } | 82 } |
| 79 return _file.lastModified(); | 83 return _file.lastModified(); |
| 80 } | 84 } |
| 81 String get shortName => _file.getName(); | 85 String get shortName => _file.getName(); |
| 82 int get hashCode => _file.hashCode; | 86 int get hashCode => _file.hashCode; |
| 83 bool isInSystemLibrary() => _inSystemLibrary; | 87 bool isInSystemLibrary() => _inSystemLibrary; |
| 84 Source resolve(String uri) => _factory.resolveUri(this, uri); | |
| 85 Source resolveRelative(Uri containedUri) { | 88 Source resolveRelative(Uri containedUri) { |
| 86 try { | 89 try { |
| 87 Uri resolvedUri = file.toURI().resolveUri(containedUri); | 90 Uri resolvedUri = file.toURI().resolveUri(containedUri); |
| 88 return new FileBasedSource.con1(_factory, new JavaFile.fromUri(resolvedUri
)); | 91 return new FileBasedSource.con2(_contentCache, new JavaFile.fromUri(resolv
edUri), isInSystemLibrary()); |
| 89 } catch (exception) { | 92 } catch (exception) { |
| 90 } | 93 } |
| 91 return null; | 94 return null; |
| 92 } | 95 } |
| 93 String toString() { | 96 String toString() { |
| 94 if (_file == null) { | 97 if (_file == null) { |
| 95 return "<unknown source>"; | 98 return "<unknown source>"; |
| 96 } | 99 } |
| 97 return _file.getAbsolutePath(); | 100 return _file.getAbsolutePath(); |
| 98 } | 101 } |
| 99 /** | 102 /** |
| 100 * Return the file represented by this source. This is an internal method that
is only intended to | 103 * Return the file represented by this source. This is an internal method that
is only intended to |
| 101 * be used by {@link UriResolver}. | 104 * be used by {@link UriResolver}. |
| 102 * @return the file represented by this source | 105 * @return the file represented by this source |
| 103 */ | 106 */ |
| 104 JavaFile get file => _file; | 107 JavaFile get file => _file; |
| 105 } | 108 } |
| 106 /** | 109 /** |
| 107 * Instances of the class {@code DartUriResolver} resolve {@code dart} URI's. | |
| 108 * @coverage dart.engine.source | |
| 109 */ | |
| 110 class DartUriResolver extends UriResolver { | |
| 111 /** | |
| 112 * The Dart SDK against which URI's are to be resolved. | |
| 113 */ | |
| 114 DartSdk _sdk; | |
| 115 /** | |
| 116 * The name of the {@code dart} scheme. | |
| 117 */ | |
| 118 static String _DART_SCHEME = "dart"; | |
| 119 /** | |
| 120 * Return {@code true} if the given URI is a {@code dart:} URI. | |
| 121 * @param uri the URI being tested | |
| 122 * @return {@code true} if the given URI is a {@code dart:} URI | |
| 123 */ | |
| 124 static bool isDartUri(Uri uri) => uri.scheme == _DART_SCHEME; | |
| 125 /** | |
| 126 * Initialize a newly created resolver to resolve Dart URI's against the given
platform within the | |
| 127 * given Dart SDK. | |
| 128 * @param sdk the Dart SDK against which URI's are to be resolved | |
| 129 */ | |
| 130 DartUriResolver(DartSdk sdk) { | |
| 131 this._sdk = sdk; | |
| 132 } | |
| 133 Source resolveAbsolute(SourceFactory factory, Uri uri) { | |
| 134 if (!isDartUri(uri)) { | |
| 135 return null; | |
| 136 } | |
| 137 JavaFile resolvedFile = _sdk.mapDartUri(uri.toString()); | |
| 138 if (resolvedFile == null) { | |
| 139 return null; | |
| 140 } | |
| 141 return new FileBasedSource.con2(factory, resolvedFile, true); | |
| 142 } | |
| 143 } | |
| 144 /** | |
| 145 * Instances of the class {@code PackageUriResolver} resolve {@code package} URI
's in the context of | 110 * Instances of the class {@code PackageUriResolver} resolve {@code package} URI
's in the context of |
| 146 * an application. | 111 * an application. |
| 112 * <p> |
| 113 * 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 |
| 115 * path from the package directory to the leaf should not. |
| 147 * @coverage dart.engine.source | 116 * @coverage dart.engine.source |
| 148 */ | 117 */ |
| 149 class PackageUriResolver extends UriResolver { | 118 class PackageUriResolver extends UriResolver { |
| 150 /** | 119 /** |
| 151 * The package directories that {@code package} URI's are assumed to be relati
ve to. | 120 * The package directories that {@code package} URI's are assumed to be relati
ve to. |
| 152 */ | 121 */ |
| 153 List<JavaFile> _packagesDirectories; | 122 List<JavaFile> _packagesDirectories; |
| 154 /** | 123 /** |
| 155 * The name of the {@code package} scheme. | 124 * The name of the {@code package} scheme. |
| 156 */ | 125 */ |
| 157 static String _PACKAGE_SCHEME = "package"; | 126 static String _PACKAGE_SCHEME = "package"; |
| 158 /** | 127 /** |
| 159 * Return {@code true} if the given URI is a {@code package} URI. | 128 * Return {@code true} if the given URI is a {@code package} URI. |
| 160 * @param uri the URI being tested | 129 * @param uri the URI being tested |
| 161 * @return {@code true} if the given URI is a {@code package} URI | 130 * @return {@code true} if the given URI is a {@code package} URI |
| 162 */ | 131 */ |
| 163 static bool isPackageUri(Uri uri) => uri.scheme == _PACKAGE_SCHEME; | 132 static bool isPackageUri(Uri uri) => uri.scheme == _PACKAGE_SCHEME; |
| 164 /** | 133 /** |
| 165 * Initialize a newly created resolver to resolve {@code package} URI's relati
ve to the given | 134 * Initialize a newly created resolver to resolve {@code package} URI's relati
ve to the given |
| 166 * package directories. | 135 * package directories. |
| 167 * @param packagesDirectories the package directories that {@code package} URI
's are assumed to be | 136 * @param packagesDirectories the package directories that {@code package} URI
's are assumed to be |
| 168 * relative to | 137 * relative to |
| 169 */ | 138 */ |
| 170 PackageUriResolver(List<JavaFile> packagesDirectories) { | 139 PackageUriResolver(List<JavaFile> packagesDirectories) { |
| 171 if (packagesDirectories.length < 1) { | 140 if (packagesDirectories.length < 1) { |
| 172 throw new IllegalArgumentException("At least one package directory must be
provided"); | 141 throw new IllegalArgumentException("At least one package directory must be
provided"); |
| 173 } | 142 } |
| 174 this._packagesDirectories = packagesDirectories; | 143 this._packagesDirectories = packagesDirectories; |
| 175 } | 144 } |
| 176 Source resolveAbsolute(SourceFactory factory, Uri uri) { | 145 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 177 if (!isPackageUri(uri)) { | 146 if (!isPackageUri(uri)) { |
| 178 return null; | 147 return null; |
| 179 } | 148 } |
| 180 String path4 = uri.path; | 149 String path4 = uri.path; |
| 181 if (path4 == null) { | 150 if (path4 == null) { |
| 182 path4 = uri.path; | 151 path4 = uri.path; |
| 183 if (path4 == null) { | 152 if (path4 == null) { |
| 184 return null; | 153 return null; |
| 185 } | 154 } |
| 186 } | 155 } |
| 156 String pkgName; |
| 157 String relPath; |
| 158 int index = path4.indexOf('/'); |
| 159 if (index == -1) { |
| 160 pkgName = path4; |
| 161 relPath = ""; |
| 162 } else if (index == 0) { |
| 163 return null; |
| 164 } else { |
| 165 pkgName = path4.substring(0, index); |
| 166 relPath = path4.substring(index + 1); |
| 167 } |
| 187 for (JavaFile packagesDirectory in _packagesDirectories) { | 168 for (JavaFile packagesDirectory in _packagesDirectories) { |
| 188 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path4); | 169 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path4); |
| 189 if (resolvedFile.exists()) { | 170 if (resolvedFile.exists()) { |
| 190 return new FileBasedSource.con1(factory, resolvedFile); | 171 return new FileBasedSource.con1(contentCache, getCanonicalFile(packagesD
irectory, pkgName, relPath)); |
| 191 } | 172 } |
| 192 } | 173 } |
| 193 return new FileBasedSource.con1(factory, new JavaFile.relative(_packagesDire
ctories[0], path4)); | 174 return new FileBasedSource.con1(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath)); |
| 175 } |
| 176 /** |
| 177 * Answer the canonical file for the specified package. |
| 178 * @param packagesDirectory the "packages" directory (not {@code null}) |
| 179 * @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, |
| 181 * but may be empty string) |
| 182 * @return the file (not {@code null}) |
| 183 */ |
| 184 JavaFile getCanonicalFile(JavaFile packagesDirectory, String pkgName, String r
elPath) { |
| 185 JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName); |
| 186 try { |
| 187 pkgDir = pkgDir.getCanonicalFile(); |
| 188 } on IOException catch (e) { |
| 189 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}", e)
; |
| 190 } |
| 191 return new JavaFile.relative(pkgDir, relPath.replaceAll(0x2F, JavaFile.separ
atorChar)); |
| 194 } | 192 } |
| 195 } | 193 } |
| 196 /** | 194 /** |
| 197 * Instances of the class {@link DirectoryBasedSourceContainer} represent a sour
ce container that | 195 * Instances of the class {@link DirectoryBasedSourceContainer} represent a sour
ce container that |
| 198 * contains all sources within a given directory. | 196 * contains all sources within a given directory. |
| 199 * @coverage dart.engine.source | 197 * @coverage dart.engine.source |
| 200 */ | 198 */ |
| 201 class DirectoryBasedSourceContainer implements SourceContainer { | 199 class DirectoryBasedSourceContainer implements SourceContainer { |
| 202 /** | 200 /** |
| 203 * Append the system file separator to the given path unless the path already
ends with a | 201 * Append the system file separator to the given path unless the path already
ends with a |
| (...skipping 10 matching lines...) Expand all Loading... |
| 214 /** | 212 /** |
| 215 * The container's path (not {@code null}). | 213 * The container's path (not {@code null}). |
| 216 */ | 214 */ |
| 217 String _path; | 215 String _path; |
| 218 /** | 216 /** |
| 219 * 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, | 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, |
| 220 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour
ceContainer(String)}. | 218 * fully equivalent to {@link DirectoryBasedSourceContainer#DirectoryBasedSour
ceContainer(String)}. |
| 221 * @param directory the directory (not {@code null}) | 219 * @param directory the directory (not {@code null}) |
| 222 */ | 220 */ |
| 223 DirectoryBasedSourceContainer.con1(JavaFile directory) { | 221 DirectoryBasedSourceContainer.con1(JavaFile directory) { |
| 224 _jtd_constructor_300_impl(directory); | 222 _jtd_constructor_326_impl(directory); |
| 225 } | 223 } |
| 226 _jtd_constructor_300_impl(JavaFile directory) { | 224 _jtd_constructor_326_impl(JavaFile directory) { |
| 227 _jtd_constructor_301_impl(directory.getPath()); | 225 _jtd_constructor_327_impl(directory.getPath()); |
| 228 } | 226 } |
| 229 /** | 227 /** |
| 230 * Construct a container representing the specified path and containing any so
urces whose{@link Source#getFullName()} starts with the specified path. | 228 * Construct a container representing the specified path and containing any so
urces whose{@link Source#getFullName()} starts with the specified path. |
| 231 * @param path the path (not {@code null} and not empty) | 229 * @param path the path (not {@code null} and not empty) |
| 232 */ | 230 */ |
| 233 DirectoryBasedSourceContainer.con2(String path3) { | 231 DirectoryBasedSourceContainer.con2(String path3) { |
| 234 _jtd_constructor_301_impl(path3); | 232 _jtd_constructor_327_impl(path3); |
| 235 } | 233 } |
| 236 _jtd_constructor_301_impl(String path3) { | 234 _jtd_constructor_327_impl(String path3) { |
| 237 this._path = appendFileSeparator(path3); | 235 this._path = appendFileSeparator(path3); |
| 238 } | 236 } |
| 239 bool contains(Source source) => source.fullName.startsWith(_path); | 237 bool contains(Source source) => source.fullName.startsWith(_path); |
| 240 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; | 238 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && ((ob
j as DirectoryBasedSourceContainer)).path == path; |
| 241 /** | 239 /** |
| 242 * Answer the receiver's path, used to determine if a source is contained in t
he receiver. | 240 * Answer the receiver's path, used to determine if a source is contained in t
he receiver. |
| 243 * @return the path (not {@code null}, not empty) | 241 * @return the path (not {@code null}, not empty) |
| 244 */ | 242 */ |
| 245 String get path => _path; | 243 String get path => _path; |
| 246 int get hashCode => _path.hashCode; | 244 int get hashCode => _path.hashCode; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 259 * @param uri the URI being tested | 257 * @param uri the URI being tested |
| 260 * @return {@code true} if the given URI is a {@code file} URI | 258 * @return {@code true} if the given URI is a {@code file} URI |
| 261 */ | 259 */ |
| 262 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; | 260 static bool isFileUri(Uri uri) => uri.scheme == _FILE_SCHEME; |
| 263 /** | 261 /** |
| 264 * Initialize a newly created resolver to resolve {@code file} URI's relative
to the given root | 262 * Initialize a newly created resolver to resolve {@code file} URI's relative
to the given root |
| 265 * directory. | 263 * directory. |
| 266 */ | 264 */ |
| 267 FileUriResolver() : super() { | 265 FileUriResolver() : super() { |
| 268 } | 266 } |
| 269 Source resolveAbsolute(SourceFactory factory, Uri uri) { | 267 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 270 if (!isFileUri(uri)) { | 268 if (!isFileUri(uri)) { |
| 271 return null; | 269 return null; |
| 272 } | 270 } |
| 273 return new FileBasedSource.con1(factory, new JavaFile.fromUri(uri)); | 271 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); |
| 274 } | 272 } |
| 275 } | 273 } |
| OLD | NEW |