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

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

Issue 259773005: New analyzer snapshot. Sorted unit members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.source.io; 8 library engine.source.io;
9 9
10 import 'source.dart'; 10 import 'source.dart';
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'java_io.dart'; 12 import 'java_io.dart';
13 import 'utilities_general.dart'; 13 import 'utilities_general.dart';
14 import 'engine.dart'; 14 import 'engine.dart';
15 export 'source.dart'; 15 export 'source.dart';
16 16
17 /** 17 /**
18 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's. 18 * Instances of the class [DirectoryBasedSourceContainer] represent a source con tainer that
19 * contains all sources within a given directory.
19 */ 20 */
20 class RelativeFileUriResolver extends UriResolver { 21 class DirectoryBasedSourceContainer implements SourceContainer {
21 /** 22 /**
22 * The name of the `file` scheme. 23 * Append the system file separator to the given path unless the path already ends with a
24 * separator.
25 *
26 * @param path the path to which the file separator is to be added
27 * @return a path that ends with the system file separator
23 */ 28 */
24 static String FILE_SCHEME = "file"; 29 static String _appendFileSeparator(String path) {
30 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) {
31 return path;
32 }
33 return "${path}${JavaFile.separator}";
34 }
25 35
26 /** 36 /**
27 * Return `true` if the given URI is a `file` URI. 37 * The container's path (not `null`).
28 *
29 * @param uri the URI being tested
30 * @return `true` if the given URI is a `file` URI
31 */ 38 */
32 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; 39 String _path;
33 40
34 /** 41 /**
35 * The directories for the relatvie URI's 42 * Construct a container representing the specified directory and containing a ny sources whose
43 * [Source#getFullName] starts with the directory's path. This is a convenienc e method,
44 * fully equivalent to [DirectoryBasedSourceContainer#DirectoryBasedSourceCont ainer]
45 * .
46 *
47 * @param directory the directory (not `null`)
36 */ 48 */
37 final List<JavaFile> _relativeDirectories; 49 DirectoryBasedSourceContainer.con1(JavaFile directory) : this.con2(directory.g etPath());
38 50
39 /** 51 /**
40 * The root directory for all the source trees 52 * Construct a container representing the specified path and containing any so urces whose
53 * [Source#getFullName] starts with the specified path.
54 *
55 * @param path the path (not `null` and not empty)
41 */ 56 */
42 final JavaFile _rootDirectory; 57 DirectoryBasedSourceContainer.con2(String path) {
43 58 this._path = _appendFileSeparator(path);
44 /**
45 * Initialize a newly created resolver to resolve `file` URI's relative to the given root
46 * directory.
47 */
48 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories) : supe r();
49
50 @override
51 Source fromEncoding(UriKind kind, Uri uri) {
52 if (kind == UriKind.FILE_URI) {
53 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind);
54 }
55 return null;
56 } 59 }
57 60
58 @override 61 @override
59 Source resolveAbsolute(Uri uri) { 62 bool contains(Source source) => source.fullName.startsWith(_path);
60 String rootPath = _rootDirectory.toURI().path; 63
61 String uriPath = uri.path; 64 @override
62 if (uriPath != null && uriPath.startsWith(rootPath)) { 65 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && obj. path == path;
63 String filePath = uri.path.substring(rootPath.length); 66
64 for (JavaFile dir in _relativeDirectories) { 67 /**
65 JavaFile file = new JavaFile.relative(dir, filePath); 68 * Answer the receiver's path, used to determine if a source is contained in t he receiver.
66 if (file.exists()) { 69 *
67 return new FileBasedSource.con2(file, UriKind.FILE_URI); 70 * @return the path (not `null`, not empty)
68 } 71 */
69 } 72 String get path => _path;
70 } 73
71 return null; 74 @override
72 } 75 int get hashCode => _path.hashCode;
76
77 @override
78 String toString() => "SourceContainer[${_path}]";
73 } 79 }
74 80
75 /** 81 /**
76 * Instances of the class `FileBasedSource` implement a source that represents a file. 82 * Instances of the class `FileBasedSource` implement a source that represents a file.
77 */ 83 */
78 class FileBasedSource implements Source { 84 class FileBasedSource implements Source {
79 /** 85 /**
80 * The file represented by this source. 86 * The file represented by this source.
81 */ 87 */
82 final JavaFile file; 88 final JavaFile file;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 @override 214 @override
209 Source resolveAbsolute(Uri uri) { 215 Source resolveAbsolute(Uri uri) {
210 if (!isFileUri(uri)) { 216 if (!isFileUri(uri)) {
211 return null; 217 return null;
212 } 218 }
213 return new FileBasedSource.con1(new JavaFile.fromUri(uri)); 219 return new FileBasedSource.con1(new JavaFile.fromUri(uri));
214 } 220 }
215 } 221 }
216 222
217 /** 223 /**
218 * An implementation of an non-existing [Source].
219 */
220 class NonExistingSource implements Source {
221 final String _name;
222
223 final UriKind uriKind;
224
225 NonExistingSource(this._name, this.uriKind);
226
227 @override
228 bool exists() => false;
229
230 @override
231 TimestampedData<String> get contents {
232 throw new UnsupportedOperationException("${_name}does not exist.");
233 }
234
235 @override
236 String get encoding {
237 throw new UnsupportedOperationException("${_name}does not exist.");
238 }
239
240 @override
241 String get fullName => _name;
242
243 @override
244 int get modificationStamp => 0;
245
246 @override
247 String get shortName => _name;
248
249 @override
250 bool get isInSystemLibrary => false;
251
252 @override
253 Source resolveRelative(Uri relativeUri) {
254 throw new UnsupportedOperationException("${_name}does not exist.");
255 }
256 }
257
258 /**
259 * Instances of interface `LocalSourcePredicate` are used to determine if the gi ven 224 * Instances of interface `LocalSourcePredicate` are used to determine if the gi ven
260 * [Source] is "local" in some sense, so can be updated. 225 * [Source] is "local" in some sense, so can be updated.
261 */ 226 */
262 abstract class LocalSourcePredicate { 227 abstract class LocalSourcePredicate {
263 /** 228 /**
264 * Instance of [LocalSourcePredicate] that always returns `false`. 229 * Instance of [LocalSourcePredicate] that always returns `false`.
265 */ 230 */
266 static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE(); 231 static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE();
267 232
268 /** 233 /**
(...skipping 14 matching lines...) Expand all
283 * @return `true` if the given [Source] is local 248 * @return `true` if the given [Source] is local
284 */ 249 */
285 bool isLocal(Source source); 250 bool isLocal(Source source);
286 } 251 }
287 252
288 class LocalSourcePredicate_FALSE implements LocalSourcePredicate { 253 class LocalSourcePredicate_FALSE implements LocalSourcePredicate {
289 @override 254 @override
290 bool isLocal(Source source) => false; 255 bool isLocal(Source source) => false;
291 } 256 }
292 257
258 class LocalSourcePredicate_NOT_SDK implements LocalSourcePredicate {
259 @override
260 bool isLocal(Source source) => source.uriKind != UriKind.DART_URI;
261 }
262
293 class LocalSourcePredicate_TRUE implements LocalSourcePredicate { 263 class LocalSourcePredicate_TRUE implements LocalSourcePredicate {
294 @override 264 @override
295 bool isLocal(Source source) => true; 265 bool isLocal(Source source) => true;
296 } 266 }
297 267
298 class LocalSourcePredicate_NOT_SDK implements LocalSourcePredicate { 268 /**
269 * An implementation of an non-existing [Source].
270 */
271 class NonExistingSource implements Source {
272 final String _name;
273
274 final UriKind uriKind;
275
276 NonExistingSource(this._name, this.uriKind);
277
299 @override 278 @override
300 bool isLocal(Source source) => source.uriKind != UriKind.DART_URI; 279 bool exists() => false;
280
281 @override
282 TimestampedData<String> get contents {
283 throw new UnsupportedOperationException("${_name}does not exist.");
284 }
285
286 @override
287 String get encoding {
288 throw new UnsupportedOperationException("${_name}does not exist.");
289 }
290
291 @override
292 String get fullName => _name;
293
294 @override
295 int get modificationStamp => 0;
296
297 @override
298 String get shortName => _name;
299
300 @override
301 bool get isInSystemLibrary => false;
302
303 @override
304 Source resolveRelative(Uri relativeUri) {
305 throw new UnsupportedOperationException("${_name}does not exist.");
306 }
301 } 307 }
302 308
303 /** 309 /**
304 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of 310 * Instances of the class `PackageUriResolver` resolve `package` URI's in the co ntext of
305 * an application. 311 * an application.
306 * 312 *
307 * For the purposes of sharing analysis, the path to each package under the "pac kages" directory 313 * For the purposes of sharing analysis, the path to each package under the "pac kages" directory
308 * should be canonicalized, but to preserve relative links within a package, the remainder of the 314 * should be canonicalized, but to preserve relative links within a package, the remainder of the
309 * path from the package directory to the leaf should not. 315 * path from the package directory to the leaf should not.
310 */ 316 */
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (rootDir == null) { 453 if (rootDir == null) {
448 return false; 454 return false;
449 } 455 }
450 String rootPath = rootDir.getAbsolutePath(); 456 String rootPath = rootDir.getAbsolutePath();
451 String filePath = file.getAbsolutePath(); 457 String filePath = file.getAbsolutePath();
452 return filePath.startsWith("${rootPath}/lib"); 458 return filePath.startsWith("${rootPath}/lib");
453 } 459 }
454 } 460 }
455 461
456 /** 462 /**
457 * Instances of the class [DirectoryBasedSourceContainer] represent a source con tainer that 463 * Instances of the class `RelativeFileUriResolver` resolve `file` URI's.
458 * contains all sources within a given directory.
459 */ 464 */
460 class DirectoryBasedSourceContainer implements SourceContainer { 465 class RelativeFileUriResolver extends UriResolver {
461 /** 466 /**
462 * Append the system file separator to the given path unless the path already ends with a 467 * The name of the `file` scheme.
463 * separator.
464 *
465 * @param path the path to which the file separator is to be added
466 * @return a path that ends with the system file separator
467 */ 468 */
468 static String _appendFileSeparator(String path) { 469 static String FILE_SCHEME = "file";
469 if (path == null || path.length <= 0 || path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) {
470 return path;
471 }
472 return "${path}${JavaFile.separator}";
473 }
474 470
475 /** 471 /**
476 * The container's path (not `null`). 472 * Return `true` if the given URI is a `file` URI.
473 *
474 * @param uri the URI being tested
475 * @return `true` if the given URI is a `file` URI
477 */ 476 */
478 String _path; 477 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
479 478
480 /** 479 /**
481 * Construct a container representing the specified directory and containing a ny sources whose 480 * The directories for the relatvie URI's
482 * [Source#getFullName] starts with the directory's path. This is a convenienc e method,
483 * fully equivalent to [DirectoryBasedSourceContainer#DirectoryBasedSourceCont ainer]
484 * .
485 *
486 * @param directory the directory (not `null`)
487 */ 481 */
488 DirectoryBasedSourceContainer.con1(JavaFile directory) : this.con2(directory.g etPath()); 482 final List<JavaFile> _relativeDirectories;
489 483
490 /** 484 /**
491 * Construct a container representing the specified path and containing any so urces whose 485 * The root directory for all the source trees
492 * [Source#getFullName] starts with the specified path.
493 *
494 * @param path the path (not `null` and not empty)
495 */ 486 */
496 DirectoryBasedSourceContainer.con2(String path) { 487 final JavaFile _rootDirectory;
497 this._path = _appendFileSeparator(path); 488
489 /**
490 * Initialize a newly created resolver to resolve `file` URI's relative to the given root
491 * directory.
492 */
493 RelativeFileUriResolver(this._rootDirectory, this._relativeDirectories) : supe r();
494
495 @override
496 Source fromEncoding(UriKind kind, Uri uri) {
497 if (kind == UriKind.FILE_URI) {
498 return new FileBasedSource.con2(new JavaFile.fromUri(uri), kind);
499 }
500 return null;
498 } 501 }
499 502
500 @override 503 @override
501 bool contains(Source source) => source.fullName.startsWith(_path); 504 Source resolveAbsolute(Uri uri) {
502 505 String rootPath = _rootDirectory.toURI().path;
503 @override 506 String uriPath = uri.path;
504 bool operator ==(Object obj) => (obj is DirectoryBasedSourceContainer) && obj. path == path; 507 if (uriPath != null && uriPath.startsWith(rootPath)) {
505 508 String filePath = uri.path.substring(rootPath.length);
506 /** 509 for (JavaFile dir in _relativeDirectories) {
507 * Answer the receiver's path, used to determine if a source is contained in t he receiver. 510 JavaFile file = new JavaFile.relative(dir, filePath);
508 * 511 if (file.exists()) {
509 * @return the path (not `null`, not empty) 512 return new FileBasedSource.con2(file, UriKind.FILE_URI);
510 */ 513 }
511 String get path => _path; 514 }
512 515 }
513 @override 516 return null;
514 int get hashCode => _path.hashCode; 517 }
515
516 @override
517 String toString() => "SourceContainer[${_path}]";
518 } 518 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/source.dart ('k') | pkg/analyzer/lib/src/generated/utilities_collection.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698