| 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 library engine.source.io; | 3 library engine.source.io; |
| 4 import 'source.dart'; | 4 import 'source.dart'; |
| 5 import 'java_core.dart'; | 5 import 'java_core.dart'; |
| 6 import 'java_io.dart'; | 6 import 'java_io.dart'; |
| 7 import 'engine.dart' show AnalysisContext, AnalysisEngine; | 7 import 'engine.dart' show AnalysisContext, AnalysisEngine; |
| 8 export 'source.dart'; | 8 export 'source.dart'; |
| 9 /** | 9 /** |
| 10 * Instances of the class `FileBasedSource` implement a source that represents a
file. | 10 * Instances of the class `FileBasedSource` implement a source that represents a
file. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 throw new IllegalArgumentException("Invalid source path: ${file}"); | 59 throw new IllegalArgumentException("Invalid source path: ${file}"); |
| 60 } on IllegalArgumentException catch (e) { | 60 } on IllegalArgumentException catch (e) { |
| 61 AnalysisEngine.instance.logger.logError3(e); | 61 AnalysisEngine.instance.logger.logError3(e); |
| 62 throw e; | 62 throw e; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && file == ((object as FileBasedSource)).file; | 66 bool operator ==(Object object) => object != null && this.runtimeType == objec
t.runtimeType && file == ((object as FileBasedSource)).file; |
| 67 bool exists() => _contentCache.getContents(this) != null || (file.exists() &&
!file.isDirectory()); | 67 bool exists() => _contentCache.getContents(this) != null || (file.exists() &&
!file.isDirectory()); |
| 68 void getContents(Source_ContentReceiver receiver) { | 68 void getContents(Source_ContentReceiver receiver) { |
| 69 { | 69 String contents = _contentCache.getContents(this); |
| 70 String contents = _contentCache.getContents(this); | 70 if (contents != null) { |
| 71 if (contents != null) { | 71 receiver.accept2(contents, _contentCache.getModificationStamp(this)); |
| 72 receiver.accept2(contents, _contentCache.getModificationStamp(this)); | 72 return; |
| 73 return; | |
| 74 } | |
| 75 } | 73 } |
| 76 receiver.accept2(file.readAsStringSync(), file.lastModified()); | 74 getContentsFromFile(receiver); |
| 77 } | 75 } |
| 78 String get encoding { | 76 String get encoding { |
| 79 if (_encoding == null) { | 77 if (_encoding == null) { |
| 80 _encoding = "${_uriKind.encoding}${file.toURI().toString()}"; | 78 _encoding = "${_uriKind.encoding}${file.toURI().toString()}"; |
| 81 } | 79 } |
| 82 return _encoding; | 80 return _encoding; |
| 83 } | 81 } |
| 84 String get fullName => file.getAbsolutePath(); | 82 String get fullName => file.getAbsolutePath(); |
| 85 int get modificationStamp { | 83 int get modificationStamp { |
| 86 int stamp = _contentCache.getModificationStamp(this); | 84 int stamp = _contentCache.getModificationStamp(this); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 } catch (exception) { | 98 } catch (exception) { |
| 101 } | 99 } |
| 102 return null; | 100 return null; |
| 103 } | 101 } |
| 104 String toString() { | 102 String toString() { |
| 105 if (file == null) { | 103 if (file == null) { |
| 106 return "<unknown source>"; | 104 return "<unknown source>"; |
| 107 } | 105 } |
| 108 return file.getAbsolutePath(); | 106 return file.getAbsolutePath(); |
| 109 } | 107 } |
| 108 |
| 109 /** |
| 110 * 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 |
| 112 * 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. |
| 114 * |
| 115 * @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 |
| 117 * @see #getContents(com.google.dart.engine.source.Source.ContentReceiver) |
| 118 */ |
| 119 void getContentsFromFile(Source_ContentReceiver receiver) { |
| 120 { |
| 121 } |
| 122 receiver.accept2(file.readAsStringSync(), file.lastModified()); |
| 123 } |
| 110 } | 124 } |
| 111 /** | 125 /** |
| 112 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co
ntext of | 126 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co
ntext of |
| 113 * an application. | 127 * an application. |
| 114 * | 128 * |
| 115 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory | 129 * For the purposes of sharing analysis, the path to each package under the "pac
kages" directory |
| 116 * should be canonicalized, but to preserve relative links within a package, the
remainder of the | 130 * should be canonicalized, but to preserve relative links within a package, the
remainder of the |
| 117 * path from the package directory to the leaf should not. | 131 * path from the package directory to the leaf should not. |
| 118 * | 132 * |
| 119 * @coverage dart.engine.source | 133 * @coverage dart.engine.source |
| (...skipping 30 matching lines...) Expand all Loading... |
| 150 * @param packagesDirectories the package directories that `package` URI's are
assumed to be | 164 * @param packagesDirectories the package directories that `package` URI's are
assumed to be |
| 151 * relative to | 165 * relative to |
| 152 */ | 166 */ |
| 153 PackageUriResolver(List<JavaFile> packagesDirectories) { | 167 PackageUriResolver(List<JavaFile> packagesDirectories) { |
| 154 if (packagesDirectories.length < 1) { | 168 if (packagesDirectories.length < 1) { |
| 155 throw new IllegalArgumentException("At least one package directory must be
provided"); | 169 throw new IllegalArgumentException("At least one package directory must be
provided"); |
| 156 } | 170 } |
| 157 this._packagesDirectories = packagesDirectories; | 171 this._packagesDirectories = packagesDirectories; |
| 158 } | 172 } |
| 159 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { | 173 Source fromEncoding(ContentCache contentCache, UriKind kind, Uri uri) { |
| 160 if (identical(kind, UriKind.PACKAGE_URI)) { | 174 if (identical(kind, UriKind.PACKAGE_SELF_URI) || identical(kind, UriKind.PAC
KAGE_URI)) { |
| 161 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); | 175 return new FileBasedSource.con2(contentCache, new JavaFile.fromUri(uri), k
ind); |
| 162 } | 176 } |
| 163 return null; | 177 return null; |
| 164 } | 178 } |
| 165 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 179 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 166 if (!isPackageUri(uri)) { | 180 if (!isPackageUri(uri)) { |
| 167 return null; | 181 return null; |
| 168 } | 182 } |
| 169 String path = uri.path; | 183 String path = uri.path; |
| 170 if (path == null) { | 184 if (path == null) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 181 relPath = ""; | 195 relPath = ""; |
| 182 } else if (index == 0) { | 196 } else if (index == 0) { |
| 183 return null; | 197 return null; |
| 184 } else { | 198 } else { |
| 185 pkgName = path.substring(0, index); | 199 pkgName = path.substring(0, index); |
| 186 relPath = path.substring(index + 1); | 200 relPath = path.substring(index + 1); |
| 187 } | 201 } |
| 188 for (JavaFile packagesDirectory in _packagesDirectories) { | 202 for (JavaFile packagesDirectory in _packagesDirectories) { |
| 189 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); | 203 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); |
| 190 if (resolvedFile.exists()) { | 204 if (resolvedFile.exists()) { |
| 191 return new FileBasedSource.con2(contentCache, getCanonicalFile(packagesD
irectory, pkgName, relPath), UriKind.PACKAGE_URI); | 205 JavaFile canonicalFile = getCanonicalFile(packagesDirectory, pkgName, re
lPath); |
| 206 UriKind uriKind = isSelfReference(packagesDirectory, canonicalFile) ? Ur
iKind.PACKAGE_SELF_URI : UriKind.PACKAGE_URI; |
| 207 return new FileBasedSource.con2(contentCache, canonicalFile, uriKind); |
| 192 } | 208 } |
| 193 } | 209 } |
| 194 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); | 210 return new FileBasedSource.con2(contentCache, getCanonicalFile(_packagesDire
ctories[0], pkgName, relPath), UriKind.PACKAGE_URI); |
| 195 } | 211 } |
| 196 Uri restoreAbsolute(Source source) { | 212 Uri restoreAbsolute(Source source) { |
| 197 if (source is FileBasedSource) { | 213 if (source is FileBasedSource) { |
| 198 String sourcePath = ((source as FileBasedSource)).file.getPath(); | 214 String sourcePath = ((source as FileBasedSource)).file.getPath(); |
| 199 for (JavaFile packagesDirectory in _packagesDirectories) { | 215 for (JavaFile packagesDirectory in _packagesDirectories) { |
| 200 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); | 216 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); |
| 201 if (pkgFolders != null) { | 217 if (pkgFolders != null) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 231 } on JavaIOException catch (e) { | 247 } on JavaIOException catch (e) { |
| 232 if (!e.toString().contains("Required key not available")) { | 248 if (!e.toString().contains("Required key not available")) { |
| 233 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}",
e); | 249 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}",
e); |
| 234 } else if (_CanLogRequiredKeyIoException) { | 250 } else if (_CanLogRequiredKeyIoException) { |
| 235 _CanLogRequiredKeyIoException = false; | 251 _CanLogRequiredKeyIoException = false; |
| 236 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}",
e); | 252 AnalysisEngine.instance.logger.logError2("Canonical failed: ${pkgDir}",
e); |
| 237 } | 253 } |
| 238 } | 254 } |
| 239 return new JavaFile.relative(pkgDir, relPath.replaceAll('/', new String.from
CharCode(JavaFile.separatorChar))); | 255 return new JavaFile.relative(pkgDir, relPath.replaceAll('/', new String.from
CharCode(JavaFile.separatorChar))); |
| 240 } | 256 } |
| 257 |
| 258 /** |
| 259 * @return `true` if "file" was found in "packagesDir", and it is part of the
"lib" folder |
| 260 * of the application that contains in this "packagesDir". |
| 261 */ |
| 262 bool isSelfReference(JavaFile packagesDir, JavaFile file) { |
| 263 JavaFile rootDir = packagesDir.getParentFile(); |
| 264 String rootPath = rootDir.getAbsolutePath(); |
| 265 String filePath = file.getAbsolutePath(); |
| 266 return filePath.startsWith("${rootPath}/lib"); |
| 267 } |
| 241 } | 268 } |
| 242 /** | 269 /** |
| 243 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that | 270 * Instances of the class [DirectoryBasedSourceContainer] represent a source con
tainer that |
| 244 * contains all sources within a given directory. | 271 * contains all sources within a given directory. |
| 245 * | 272 * |
| 246 * @coverage dart.engine.source | 273 * @coverage dart.engine.source |
| 247 */ | 274 */ |
| 248 class DirectoryBasedSourceContainer implements SourceContainer { | 275 class DirectoryBasedSourceContainer implements SourceContainer { |
| 249 | 276 |
| 250 /** | 277 /** |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 342 } |
| 316 return null; | 343 return null; |
| 317 } | 344 } |
| 318 Source resolveAbsolute(ContentCache contentCache, Uri uri) { | 345 Source resolveAbsolute(ContentCache contentCache, Uri uri) { |
| 319 if (!isFileUri(uri)) { | 346 if (!isFileUri(uri)) { |
| 320 return null; | 347 return null; |
| 321 } | 348 } |
| 322 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); | 349 return new FileBasedSource.con1(contentCache, new JavaFile.fromUri(uri)); |
| 323 } | 350 } |
| 324 } | 351 } |
| OLD | NEW |