Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: packages/analyzer/lib/src/generated/source_io.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 library engine.source.io; 5 library analyzer.src.generated.source_io;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'engine.dart'; 9 import 'package:analyzer/exception/exception.dart';
10 import 'java_core.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
11 import 'java_engine.dart'; 11 import 'package:analyzer/src/generated/java_io.dart';
12 import 'java_io.dart'; 12 import 'package:analyzer/src/generated/source.dart';
13 import 'source.dart'; 13 import 'package:path/path.dart' as path;
14 14
15 export 'source.dart'; 15 export 'package:analyzer/src/generated/source.dart';
16 16
17 /** 17 /**
18 * Instances of the class [DirectoryBasedSourceContainer] represent a source con tainer that 18 * Instances of the class [DirectoryBasedSourceContainer] represent a source con tainer that
19 * contains all sources within a given directory. 19 * contains all sources within a given directory.
20 */ 20 */
21 @deprecated
21 class DirectoryBasedSourceContainer implements SourceContainer { 22 class DirectoryBasedSourceContainer implements SourceContainer {
22 /** 23 /**
23 * The container's path (not `null`). 24 * The container's path (not `null`).
24 */ 25 */
25 String _path; 26 String _path;
26 27
27 /** 28 /**
28 * Construct a container representing the specified directory and containing a ny sources whose 29 * Construct a container representing the specified directory and containing a ny sources whose
29 * [Source.fullName] starts with the directory's path. This is a convenience m ethod, 30 * [Source.fullName] starts with the directory's path. This is a convenience m ethod,
30 * fully equivalent to [DirectoryBasedSourceContainer.con2]. 31 * fully equivalent to [DirectoryBasedSourceContainer.con2].
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (path == null || 76 if (path == null ||
76 path.length <= 0 || 77 path.length <= 0 ||
77 path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) { 78 path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) {
78 return path; 79 return path;
79 } 80 }
80 return "$path${JavaFile.separator}"; 81 return "$path${JavaFile.separator}";
81 } 82 }
82 } 83 }
83 84
84 /** 85 /**
86 * Instances of the class [ExplicitSourceResolver] map URIs to files on disk
87 * using a fixed mapping provided at construction time.
88 */
89 @deprecated
90 class ExplicitSourceResolver extends UriResolver {
91 final Map<Uri, JavaFile> uriToFileMap;
92 final Map<String, Uri> pathToUriMap;
93
94 /**
95 * Construct an [ExplicitSourceResolver] based on the given [uriToFileMap].
96 */
97 ExplicitSourceResolver(Map<Uri, JavaFile> uriToFileMap)
98 : uriToFileMap = uriToFileMap,
99 pathToUriMap = _computePathToUriMap(uriToFileMap);
100
101 @override
102 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
103 JavaFile file = uriToFileMap[uri];
104 actualUri ??= uri;
105 if (file == null) {
106 return new NonExistingSource(
107 uri.toString(), actualUri, UriKind.fromScheme(actualUri.scheme));
108 } else {
109 return new FileBasedSource(file, actualUri);
110 }
111 }
112
113 @override
114 Uri restoreAbsolute(Source source) {
115 return pathToUriMap[source.fullName];
116 }
117
118 /**
119 * Build the inverse mapping of [uriToSourceMap].
120 */
121 static Map<String, Uri> _computePathToUriMap(
122 Map<Uri, JavaFile> uriToSourceMap) {
123 Map<String, Uri> pathToUriMap = <String, Uri>{};
124 uriToSourceMap.forEach((Uri uri, JavaFile file) {
125 pathToUriMap[file.getAbsolutePath()] = uri;
126 });
127 return pathToUriMap;
128 }
129 }
130
131 /**
85 * Instances of the class `FileBasedSource` implement a source that represents a file. 132 * Instances of the class `FileBasedSource` implement a source that represents a file.
86 */ 133 */
87 class FileBasedSource extends Source { 134 class FileBasedSource extends Source {
88 /** 135 /**
89 * A function that changes the way that files are read off of disk. 136 * A function that changes the way that files are read off of disk.
90 */ 137 */
91 static Function fileReadMode = (String s) => s; 138 static Function fileReadMode = (String s) => s;
92 139
93 /** 140 /**
94 * Map from encoded URI/filepath pair to a unique integer identifier. This 141 * Map from encoded URI/filepath pair to a unique integer identifier. This
95 * identifier is used for equality tests and hash codes. 142 * identifier is used for equality tests and hash codes.
96 * 143 *
97 * The URI and filepath are joined into a pair by separating them with an '@' 144 * The URI and filepath are joined into a pair by separating them with an '@'
98 * character. 145 * character.
99 */ 146 */
100 static final Map<String, int> _idTable = new HashMap<String, int>(); 147 static final Map<String, int> _idTable = new HashMap<String, int>();
101 148
102 /** 149 /**
103 * The URI from which this source was originally derived. 150 * The URI from which this source was originally derived.
104 */ 151 */
152 @override
105 final Uri uri; 153 final Uri uri;
106 154
107 /** 155 /**
108 * The unique ID associated with this [FileBasedSource]. 156 * The unique ID associated with this [FileBasedSource].
109 */ 157 */
110 final int id; 158 final int id;
111 159
112 /** 160 /**
113 * The file represented by this source. 161 * The file represented by this source.
114 */ 162 */
115 final JavaFile file; 163 final JavaFile file;
116 164
117 /** 165 /**
118 * The cached absolute path of this source. 166 * The cached absolute path of this source.
119 */ 167 */
120 String _absolutePath; 168 String _absolutePath;
121 169
122 /** 170 /**
123 * The cached encoding for this source. 171 * The cached encoding for this source.
124 */ 172 */
125 String _encoding; 173 String _encoding;
126 174
127 /** 175 /**
128 * Initialize a newly created source object to represent the given [file]. If 176 * Initialize a newly created source object to represent the given [file]. If
129 * a [uri] is given, then it will be used as the URI from which the source was 177 * a [uri] is given, then it will be used as the URI from which the source was
130 * derived, otherwise a `file:` URI will be created based on the [file]. 178 * derived, otherwise a `file:` URI will be created based on the [file].
131 */ 179 */
132 FileBasedSource(JavaFile file, [Uri uri]) 180 FileBasedSource(JavaFile file, [Uri uri])
133 : this.uri = (uri == null ? file.toURI() : uri), 181 : this.uri = uri ?? file.toURI(),
134 this.file = file, 182 this.file = file,
135 id = _idTable.putIfAbsent( 183 id = _idTable.putIfAbsent(
136 '${uri == null ? file.toURI() : uri}@${file.getPath()}', 184 '${uri ?? file.toURI()}@${file.getPath()}', () => _idTable.length);
137 () => _idTable.length);
138
139 /**
140 * Initialize a newly created source object.
141 *
142 * @param file the file represented by this source
143 */
144 @deprecated // Use new FileBasedSource(file)
145 FileBasedSource.con1(JavaFile file) : this(file);
146
147 /**
148 * Initialize a newly created source object.
149 *
150 * @param file the file represented by this source
151 * @param uri the URI from which this source was originally derived
152 */
153 @deprecated // Use new FileBasedSource(file, uri)
154 FileBasedSource.con2(Uri uri, JavaFile file)
155 : uri = uri,
156 file = file,
157 id = _idTable.putIfAbsent(
158 '$uri@${file.getPath()}', () => _idTable.length);
159 185
160 @override 186 @override
161 TimestampedData<String> get contents { 187 TimestampedData<String> get contents {
162 return PerformanceStatistics.io.makeCurrentWhile(() { 188 return PerformanceStatistics.io.makeCurrentWhile(() {
163 return contentsFromFile; 189 return contentsFromFile;
164 }); 190 });
165 } 191 }
166 192
167 /** 193 /**
168 * Get the contents and timestamp of the underlying file. 194 * Get the contents and timestamp of the underlying file.
169 * 195 *
170 * Clients should consider using the the method [AnalysisContext.getContents] 196 * Clients should consider using the method [AnalysisContext.getContents]
171 * because contexts can have local overrides of the content of a source that t he source is not 197 * because contexts can have local overrides of the content of a source that t he source is not
172 * aware of. 198 * aware of.
173 * 199 *
174 * @return the contents of the source paired with the modification stamp of th e source 200 * @return the contents of the source paired with the modification stamp of th e source
175 * @throws Exception if the contents of this source could not be accessed 201 * @throws Exception if the contents of this source could not be accessed
176 * See [contents]. 202 * See [contents].
177 */ 203 */
178 TimestampedData<String> get contentsFromFile { 204 TimestampedData<String> get contentsFromFile {
179 return new TimestampedData<String>( 205 return new TimestampedData<String>(
180 file.lastModified(), fileReadMode(file.readAsStringSync())); 206 file.lastModified(), fileReadMode(file.readAsStringSync()));
181 } 207 }
182 208
183 @override 209 @override
184 String get encoding { 210 String get encoding {
185 if (_encoding == null) { 211 if (_encoding == null) {
186 _encoding = uri.toString(); 212 _encoding = uri.toString();
187 } 213 }
188 return _encoding; 214 return _encoding;
189 } 215 }
190 216
191 @override 217 @override
192 String get fullName { 218 String get fullName {
193 if (_absolutePath == null) { 219 if (_absolutePath == null) {
194 _absolutePath = file.getAbsolutePath(); 220 _absolutePath = file.getAbsolutePath();
195 } 221 }
196 return _absolutePath; 222 return _absolutePath;
197 } 223 }
198 224
199 @override 225 @override
200 int get hashCode => id; 226 int get hashCode => uri.hashCode;
201 227
202 @override 228 @override
203 bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME; 229 bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME;
204 230
205 @override 231 @override
206 int get modificationStamp => file.lastModified(); 232 int get modificationStamp => file.lastModified();
207 233
208 @override 234 @override
209 String get shortName => file.getName(); 235 String get shortName => file.getName();
210 236
211 @override 237 @override
212 UriKind get uriKind { 238 UriKind get uriKind {
213 String scheme = uri.scheme; 239 String scheme = uri.scheme;
214 if (scheme == PackageUriResolver.PACKAGE_SCHEME) { 240 return UriKind.fromScheme(scheme);
215 return UriKind.PACKAGE_URI;
216 } else if (scheme == DartUriResolver.DART_SCHEME) {
217 return UriKind.DART_URI;
218 } else if (scheme == FileUriResolver.FILE_SCHEME) {
219 return UriKind.FILE_URI;
220 }
221 return UriKind.FILE_URI;
222 } 241 }
223 242
224 @override 243 @override
225 bool operator ==(Object object) => 244 bool operator ==(Object object) {
226 object is FileBasedSource && id == object.id; 245 if (object is FileBasedSource) {
246 return id == object.id;
247 } else if (object is Source) {
248 return uri == object.uri;
249 }
250 return false;
251 }
227 252
228 @override 253 @override
229 bool exists() => file.isFile(); 254 bool exists() => file.isFile();
230 255
231 @override 256 @override
232 Uri resolveRelativeUri(Uri containedUri) {
233 try {
234 Uri baseUri = uri;
235 bool isOpaque = uri.isAbsolute && !uri.path.startsWith('/');
236 if (isOpaque) {
237 String scheme = uri.scheme;
238 String part = uri.path;
239 if (scheme == DartUriResolver.DART_SCHEME && part.indexOf('/') < 0) {
240 part = "$part/$part.dart";
241 }
242 baseUri = parseUriWithException("$scheme:/$part");
243 }
244 Uri result = baseUri.resolveUri(containedUri);
245 if (isOpaque) {
246 result = parseUriWithException(
247 "${result.scheme}:${result.path.substring(1)}");
248 }
249 return result;
250 } catch (exception, stackTrace) {
251 throw new AnalysisException(
252 "Could not resolve URI ($containedUri) relative to source ($uri)",
253 new CaughtException(exception, stackTrace));
254 }
255 }
256
257 @override
258 String toString() { 257 String toString() {
259 if (file == null) { 258 if (file == null) {
260 return "<unknown source>"; 259 return "<unknown source>";
261 } 260 }
262 return file.getAbsolutePath(); 261 return file.getAbsolutePath();
263 } 262 }
264 } 263 }
265 264
266 /** 265 /**
267 * Instances of the class `FileUriResolver` resolve `file` URI's. 266 * Instances of the class `FileUriResolver` resolve `file` URI's.
267 *
268 * This class is now deprecated, 'new FileUriResolver()' is equivalent to
269 * 'new ResourceUriResolver(PhysicalResourceProvider.INSTANCE)'.
268 */ 270 */
271 @deprecated
269 class FileUriResolver extends UriResolver { 272 class FileUriResolver extends UriResolver {
270 /** 273 /**
271 * The name of the `file` scheme. 274 * The name of the `file` scheme.
272 */ 275 */
273 static String FILE_SCHEME = "file"; 276 static String FILE_SCHEME = "file";
274 277
275 @override 278 @override
276 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 279 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
277 if (!isFileUri(uri)) { 280 if (!isFileUri(uri)) {
278 return null; 281 return null;
279 } 282 }
280 return new FileBasedSource( 283 return new FileBasedSource(new JavaFile.fromUri(uri), actualUri ?? uri);
281 new JavaFile.fromUri(uri), actualUri != null ? actualUri : uri);
282 } 284 }
283 285
284 @override 286 @override
285 Uri restoreAbsolute(Source source) { 287 Uri restoreAbsolute(Source source) {
286 return new Uri.file(source.fullName); 288 return new Uri.file(source.fullName);
287 } 289 }
288 290
289 /** 291 /**
290 * Return `true` if the given URI is a `file` URI. 292 * Return `true` if the given URI is a `file` URI.
291 * 293 *
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 344 }
343 345
344 /** 346 /**
345 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of 347 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of
346 * an application. 348 * an application.
347 * 349 *
348 * For the purposes of sharing analysis, the path to each package under the "pac kages" directory 350 * For the purposes of sharing analysis, the path to each package under the "pac kages" directory
349 * should be canonicalized, but to preserve relative links within a package, the remainder of the 351 * should be canonicalized, but to preserve relative links within a package, the remainder of the
350 * path from the package directory to the leaf should not. 352 * path from the package directory to the leaf should not.
351 */ 353 */
354 @deprecated
352 class PackageUriResolver extends UriResolver { 355 class PackageUriResolver extends UriResolver {
353 /** 356 /**
354 * The name of the `package` scheme. 357 * The name of the `package` scheme.
355 */ 358 */
356 static String PACKAGE_SCHEME = "package"; 359 static String PACKAGE_SCHEME = "package";
357 360
358 /** 361 /**
359 * Log exceptions thrown with the message "Required key not available" only on ce. 362 * Log exceptions thrown with the message "Required key not available" only on ce.
360 */ 363 */
361 static bool _CanLogRequiredKeyIoException = true; 364 static bool _CanLogRequiredKeyIoException = true;
362 365
363 /** 366 /**
364 * The package directories that `package` URI's are assumed to be relative to. 367 * The package directories that `package` URI's are assumed to be relative to.
365 */ 368 */
366 final List<JavaFile> _packagesDirectories; 369 final List<JavaFile> _packagesDirectories;
367 370
368 /** 371 /**
369 * Initialize a newly created resolver to resolve `package` URI's relative to the given 372 * Initialize a newly created resolver to resolve `package` URI's relative to the given
370 * package directories. 373 * package directories.
371 * 374 *
372 * @param packagesDirectories the package directories that `package` URI's are assumed to be 375 * @param packagesDirectories the package directories that `package` URI's are assumed to be
373 * relative to 376 * relative to
374 */ 377 */
375 PackageUriResolver(this._packagesDirectories) { 378 PackageUriResolver(this._packagesDirectories) {
376 if (_packagesDirectories.length < 1) { 379 if (_packagesDirectories.length < 1) {
377 throw new IllegalArgumentException( 380 throw new ArgumentError(
378 "At least one package directory must be provided"); 381 "At least one package directory must be provided");
379 } 382 }
380 } 383 }
381 384
382 /** 385 /**
383 * If the list of package directories contains one element, return it. 386 * If the list of package directories contains one element, return it.
384 * Otherwise raise an exception. Intended for testing. 387 * Otherwise raise an exception. Intended for testing.
385 */ 388 */
386 String get packagesDirectory_forTesting { 389 String get packagesDirectory_forTesting {
387 int length = _packagesDirectories.length; 390 int length = _packagesDirectories.length;
(...skipping 10 matching lines...) Expand all
398 * @param pkgName the package name (not `null`, not empty) 401 * @param pkgName the package name (not `null`, not empty)
399 * @param relPath the path relative to the package directory (not `null`, no l eading slash, 402 * @param relPath the path relative to the package directory (not `null`, no l eading slash,
400 * but may be empty string) 403 * but may be empty string)
401 * @return the file (not `null`) 404 * @return the file (not `null`)
402 */ 405 */
403 JavaFile getCanonicalFile( 406 JavaFile getCanonicalFile(
404 JavaFile packagesDirectory, String pkgName, String relPath) { 407 JavaFile packagesDirectory, String pkgName, String relPath) {
405 JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName); 408 JavaFile pkgDir = new JavaFile.relative(packagesDirectory, pkgName);
406 try { 409 try {
407 pkgDir = pkgDir.getCanonicalFile(); 410 pkgDir = pkgDir.getCanonicalFile();
408 } on JavaIOException catch (exception, stackTrace) { 411 } catch (exception, stackTrace) {
409 if (!exception.toString().contains("Required key not available")) { 412 if (!exception.toString().contains("Required key not available")) {
410 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir", 413 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir",
411 new CaughtException(exception, stackTrace)); 414 new CaughtException(exception, stackTrace));
412 } else if (_CanLogRequiredKeyIoException) { 415 } else if (_CanLogRequiredKeyIoException) {
413 _CanLogRequiredKeyIoException = false; 416 _CanLogRequiredKeyIoException = false;
414 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir", 417 AnalysisEngine.instance.logger.logError("Canonical failed: $pkgDir",
415 new CaughtException(exception, stackTrace)); 418 new CaughtException(exception, stackTrace));
416 } 419 }
417 } 420 }
418 return new JavaFile.relative( 421 return new JavaFile.relative(
(...skipping 27 matching lines...) Expand all
446 } else { 449 } else {
447 // <pkgName>/<relPath> 450 // <pkgName>/<relPath>
448 pkgName = path.substring(0, index); 451 pkgName = path.substring(0, index);
449 relPath = path.substring(index + 1); 452 relPath = path.substring(index + 1);
450 } 453 }
451 for (JavaFile packagesDirectory in _packagesDirectories) { 454 for (JavaFile packagesDirectory in _packagesDirectories) {
452 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path); 455 JavaFile resolvedFile = new JavaFile.relative(packagesDirectory, path);
453 if (resolvedFile.exists()) { 456 if (resolvedFile.exists()) {
454 JavaFile canonicalFile = 457 JavaFile canonicalFile =
455 getCanonicalFile(packagesDirectory, pkgName, relPath); 458 getCanonicalFile(packagesDirectory, pkgName, relPath);
459 if (actualUri != null) {
460 return new FileBasedSource(canonicalFile, actualUri);
461 }
456 if (_isSelfReference(packagesDirectory, canonicalFile)) { 462 if (_isSelfReference(packagesDirectory, canonicalFile)) {
457 uri = canonicalFile.toURI(); 463 uri = canonicalFile.toURI();
458 } 464 }
459 return new FileBasedSource( 465 return new FileBasedSource(canonicalFile, uri);
460 canonicalFile, actualUri != null ? actualUri : uri);
461 } 466 }
462 } 467 }
463 return new FileBasedSource( 468 return new FileBasedSource(
464 getCanonicalFile(_packagesDirectories[0], pkgName, relPath), 469 getCanonicalFile(_packagesDirectories[0], pkgName, relPath),
465 actualUri != null ? actualUri : uri); 470 actualUri ?? uri);
466 } 471 }
467 472
468 @override 473 @override
469 Uri restoreAbsolute(Source source) { 474 Uri restoreAbsolute(Source source) {
470 String sourcePath = source.fullName; 475 String sourceUri = _toFileUri(source.fullName);
471 for (JavaFile packagesDirectory in _packagesDirectories) { 476 for (JavaFile packagesDirectory in _packagesDirectories) {
472 List<JavaFile> pkgFolders = packagesDirectory.listFiles(); 477 List<JavaFile> pkgFolders = packagesDirectory.listFiles();
473 if (pkgFolders != null) { 478 if (pkgFolders != null) {
474 for (JavaFile pkgFolder in pkgFolders) { 479 for (JavaFile pkgFolder in pkgFolders) {
475 try { 480 try {
476 String pkgCanonicalPath = pkgFolder.getCanonicalPath(); 481 String pkgCanonicalUri = _toFileUri(pkgFolder.getCanonicalPath());
477 if (sourcePath.startsWith(pkgCanonicalPath)) { 482 if (sourceUri.startsWith(pkgCanonicalUri)) {
478 String relPath = sourcePath.substring(pkgCanonicalPath.length); 483 String relPath = sourceUri.substring(pkgCanonicalUri.length);
479 return parseUriWithException( 484 return Uri
480 "$PACKAGE_SCHEME:${pkgFolder.getName()}$relPath"); 485 .parse("$PACKAGE_SCHEME:${pkgFolder.getName()}$relPath");
481 } 486 }
482 } catch (e) {} 487 } catch (e) {}
483 } 488 }
484 } 489 }
485 } 490 }
486 return null; 491 return null;
487 } 492 }
488 493
489 /** 494 /**
490 * @return `true` if "file" was found in "packagesDir", and it is part of the "lib" folder 495 * @return `true` if "file" was found in "packagesDir", and it is part of the "lib" folder
491 * of the application that contains in this "packagesDir". 496 * of the application that contains in this "packagesDir".
492 */ 497 */
493 bool _isSelfReference(JavaFile packagesDir, JavaFile file) { 498 bool _isSelfReference(JavaFile packagesDir, JavaFile file) {
494 JavaFile rootDir = packagesDir.getParentFile(); 499 JavaFile rootDir = packagesDir.getParentFile();
495 if (rootDir == null) { 500 if (rootDir == null) {
496 return false; 501 return false;
497 } 502 }
498 String rootPath = rootDir.getAbsolutePath(); 503 String rootPath = rootDir.getAbsolutePath();
499 String filePath = file.getAbsolutePath(); 504 String filePath = file.getAbsolutePath();
500 return filePath.startsWith("$rootPath/lib"); 505 return filePath.startsWith("$rootPath/lib");
501 } 506 }
502 507
503 /** 508 /**
509 * Convert the given file path to a "file:" URI. On Windows, this transforms
510 * backslashes to forward slashes.
511 */
512 String _toFileUri(String filePath) => path.context.toUri(filePath).toString();
513
514 /**
504 * Return `true` if the given URI is a `package` URI. 515 * Return `true` if the given URI is a `package` URI.
505 * 516 *
506 * @param uri the URI being tested 517 * @param uri the URI being tested
507 * @return `true` if the given URI is a `package` URI 518 * @return `true` if the given URI is a `package` URI
508 */ 519 */
509 static bool isPackageUri(Uri uri) => PACKAGE_SCHEME == uri.scheme; 520 static bool isPackageUri(Uri uri) => PACKAGE_SCHEME == uri.scheme;
510 } 521 }
511 522
512 /** 523 /**
513 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's. 524 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's.
525 *
526 * This class is now deprecated, file URI resolution should be done with
527 * ResourceUriResolver, i.e.
528 * 'new ResourceUriResolver(PhysicalResourceProvider.INSTANCE)'.
514 */ 529 */
530 @deprecated
515 class RelativeFileUriResolver extends UriResolver { 531 class RelativeFileUriResolver extends UriResolver {
516 /** 532 /**
517 * The name of the `file` scheme. 533 * The name of the `file` scheme.
518 */ 534 */
519 static String FILE_SCHEME = "file"; 535 static String FILE_SCHEME = "file";
520 536
521 /** 537 /**
522 * The directories for the relatvie URI's 538 * The directories for the relatvie URI's
523 */ 539 */
524 final List<JavaFile> _relativeDirectories; 540 final List<JavaFile> _relativeDirectories;
(...skipping 12 matching lines...) Expand all
537 553
538 @override 554 @override
539 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 555 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
540 String rootPath = _rootDirectory.toURI().path; 556 String rootPath = _rootDirectory.toURI().path;
541 String uriPath = uri.path; 557 String uriPath = uri.path;
542 if (uriPath != null && uriPath.startsWith(rootPath)) { 558 if (uriPath != null && uriPath.startsWith(rootPath)) {
543 String filePath = uri.path.substring(rootPath.length); 559 String filePath = uri.path.substring(rootPath.length);
544 for (JavaFile dir in _relativeDirectories) { 560 for (JavaFile dir in _relativeDirectories) {
545 JavaFile file = new JavaFile.relative(dir, filePath); 561 JavaFile file = new JavaFile.relative(dir, filePath);
546 if (file.exists()) { 562 if (file.exists()) {
547 return new FileBasedSource(file, actualUri != null ? actualUri : uri); 563 return new FileBasedSource(file, actualUri ?? uri);
548 } 564 }
549 } 565 }
550 } 566 }
551 return null; 567 return null;
552 } 568 }
553 569
554 /** 570 /**
555 * Return `true` if the given URI is a `file` URI. 571 * Return `true` if the given URI is a `file` URI.
556 * 572 *
557 * @param uri the URI being tested 573 * @param uri the URI being tested
558 * @return `true` if the given URI is a `file` URI 574 * @return `true` if the given URI is a `file` URI
559 */ 575 */
560 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; 576 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
561 } 577 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/src/generated/source.dart ('k') | packages/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698