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

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

Issue 428303004: Breaking changes in 'analyzer' package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename Source.resolveRelative to resolveRelativeUri, soften version constraints Created 6 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 | 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; 8 library engine.source;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'sdk.dart' show DartSdk; 12 import 'sdk.dart' show DartSdk;
13 import 'engine.dart' show AnalysisContext, TimestampedData; 13 import 'engine.dart';
14 import 'java_engine.dart';
14 15
15 /** 16 /**
16 * Instances of class `ContentCache` hold content used to override the default c ontent of a 17 * Instances of class `ContentCache` hold content used to override the default c ontent of a
17 * [Source]. 18 * [Source].
18 */ 19 */
19 class ContentCache { 20 class ContentCache {
20 /** 21 /**
21 * A table mapping sources to the contents of those sources. This is used to o verride the default 22 * A table mapping sources to the contents of those sources. This is used to o verride the default
22 * contents of a source. 23 * contents of a source.
23 */ 24 */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 static bool isDartExtUri(String uriContent) => uriContent != null && uriConten t.startsWith(_DART_EXT_SCHEME); 93 static bool isDartExtUri(String uriContent) => uriContent != null && uriConten t.startsWith(_DART_EXT_SCHEME);
93 94
94 /** 95 /**
95 * The Dart SDK against which URI's are to be resolved. 96 * The Dart SDK against which URI's are to be resolved.
96 */ 97 */
97 final DartSdk _sdk; 98 final DartSdk _sdk;
98 99
99 /** 100 /**
100 * The name of the `dart` scheme. 101 * The name of the `dart` scheme.
101 */ 102 */
102 static String _DART_SCHEME = "dart"; 103 static String DART_SCHEME = "dart";
103 104
104 /** 105 /**
105 * The prefix of a URI using the dart-ext scheme to reference a native code li brary. 106 * The prefix of a URI using the dart-ext scheme to reference a native code li brary.
106 */ 107 */
107 static String _DART_EXT_SCHEME = "dart-ext:"; 108 static String _DART_EXT_SCHEME = "dart-ext:";
108 109
109 /** 110 /**
110 * Return `true` if the given URI is a `dart:` URI. 111 * Return `true` if the given URI is a `dart:` URI.
111 * 112 *
112 * @param uri the URI being tested 113 * @param uri the URI being tested
113 * @return `true` if the given URI is a `dart:` URI 114 * @return `true` if the given URI is a `dart:` URI
114 */ 115 */
115 static bool isDartUri(Uri uri) => _DART_SCHEME == uri.scheme; 116 static bool isDartUri(Uri uri) => DART_SCHEME == uri.scheme;
116 117
117 /** 118 /**
118 * Initialize a newly created resolver to resolve Dart URI's against the given platform within the 119 * Initialize a newly created resolver to resolve Dart URI's against the given platform within the
119 * given Dart SDK. 120 * given Dart SDK.
120 * 121 *
121 * @param sdk the Dart SDK against which URI's are to be resolved 122 * @param sdk the Dart SDK against which URI's are to be resolved
122 */ 123 */
123 DartUriResolver(this._sdk); 124 DartUriResolver(this._sdk);
124 125
125 @override
126 Source fromEncoding(UriKind kind, Uri uri) {
127 if (kind == UriKind.DART_URI) {
128 return _sdk.fromEncoding(kind, uri);
129 }
130 return null;
131 }
132
133 /** 126 /**
134 * Return the [DartSdk] against which URIs are to be resolved. 127 * Return the [DartSdk] against which URIs are to be resolved.
135 * 128 *
136 * @return the [DartSdk] against which URIs are to be resolved. 129 * @return the [DartSdk] against which URIs are to be resolved.
137 */ 130 */
138 DartSdk get dartSdk => _sdk; 131 DartSdk get dartSdk => _sdk;
139 132
140 @override 133 @override
141 Source resolveAbsolute(Uri uri) { 134 Source resolveAbsolute(Uri uri) {
142 if (!isDartUri(uri)) { 135 if (!isDartUri(uri)) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 @override 285 @override
293 String get fullName => _name; 286 String get fullName => _name;
294 287
295 @override 288 @override
296 int get modificationStamp => 0; 289 int get modificationStamp => 0;
297 290
298 @override 291 @override
299 String get shortName => _name; 292 String get shortName => _name;
300 293
301 @override 294 @override
295 Uri get uri => null;
296
297 @override
302 int get hashCode => _name.hashCode; 298 int get hashCode => _name.hashCode;
303 299
304 @override 300 @override
305 bool get isInSystemLibrary => false; 301 bool get isInSystemLibrary => false;
306 302
307 @override 303 @override
308 Source resolveRelative(Uri relativeUri) { 304 Uri resolveRelativeUri(Uri relativeUri) {
309 throw new UnsupportedOperationException("${_name}does not exist."); 305 throw new UnsupportedOperationException("${_name}does not exist.");
310 } 306 }
311 } 307 }
312 308
313 /** 309 /**
314 * The interface `Source` defines the behavior of objects representing source co de that can be 310 * The interface `Source` defines the behavior of objects representing source co de that can be
315 * analyzed by the analysis engine. 311 * analyzed by the analysis engine.
316 * 312 *
317 * Implementations of this interface need to be aware of some assumptions made b y the analysis 313 * Implementations of this interface need to be aware of some assumptions made b y the analysis
318 * engine concerning sources: 314 * engine concerning sources:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 402
407 /** 403 /**
408 * Return a short version of the name that can be displayed to the user to den ote this source. For 404 * Return a short version of the name that can be displayed to the user to den ote this source. For
409 * example, for a source representing a file this would typically be the name of the file. 405 * example, for a source representing a file this would typically be the name of the file.
410 * 406 *
411 * @return a name that can be displayed to the user to denote this source 407 * @return a name that can be displayed to the user to denote this source
412 */ 408 */
413 String get shortName; 409 String get shortName;
414 410
415 /** 411 /**
412 * Return the URI from which this source was originally derived.
413 *
414 * @return the URI from which this source was originally derived
415 */
416 Uri get uri;
417
418 /**
416 * Return the kind of URI from which this source was originally derived. If th is source was 419 * Return the kind of URI from which this source was originally derived. If th is source was
417 * created from an absolute URI, then the returned kind will reflect the schem e of the absolute 420 * created from an absolute URI, then the returned kind will reflect the schem e of the absolute
418 * URI. If it was created from a relative URI, then the returned kind will be the same as the kind 421 * URI. If it was created from a relative URI, then the returned kind will be the same as the kind
419 * of the source against which the relative URI was resolved. 422 * of the source against which the relative URI was resolved.
420 * 423 *
421 * @return the kind of URI from which this source was originally derived 424 * @return the kind of URI from which this source was originally derived
422 */ 425 */
423 UriKind get uriKind; 426 UriKind get uriKind;
424 427
425 /** 428 /**
426 * Return a hash code for this source. 429 * Return a hash code for this source.
427 * 430 *
428 * @return a hash code for this source 431 * @return a hash code for this source
429 * @see Object#hashCode() 432 * @see Object#hashCode()
430 */ 433 */
431 @override 434 @override
432 int get hashCode; 435 int get hashCode;
433 436
434 /** 437 /**
435 * Return `true` if this source is in one of the system libraries. 438 * Return `true` if this source is in one of the system libraries.
436 * 439 *
437 * @return `true` if this is in a system library 440 * @return `true` if this is in a system library
438 */ 441 */
439 bool get isInSystemLibrary; 442 bool get isInSystemLibrary;
440 443
441 /** 444 /**
442 * Resolve the relative URI against the URI associated with this source object . Return a 445 * Resolve the relative URI against the URI associated with this source object .
443 * [Source] representing the URI to which it was resolved, or `null` if it
444 * could not be resolved.
445 * 446 *
446 * Note: This method is not intended for public use, it is only visible out of necessity. It is 447 * Note: This method is not intended for public use, it is only visible out of necessity. It is
447 * only intended to be invoked by a [SourceFactory]. Source factories will 448 * only intended to be invoked by a [SourceFactory]. Source factories will
448 * only invoke this method if the URI is relative, so implementations of this method are not 449 * only invoke this method if the URI is relative, so implementations of this method are not
449 * required to, and generally do not, verify the argument. The result of invok ing this method with 450 * required to, and generally do not, verify the argument. The result of invok ing this method with
450 * an absolute URI is intentionally left unspecified. 451 * an absolute URI is intentionally left unspecified.
451 * 452 *
452 * @param relativeUri the relative URI to be resolved against the containing s ource 453 * @param relativeUri the relative URI to be resolved against this source
453 * @return a [Source] representing the URI to which given URI was resolved 454 * @return the URI to which given URI was resolved
455 * @throws AnalysisException if the relative URI could not be resolved
454 */ 456 */
455 Source resolveRelative(Uri relativeUri); 457 Uri resolveRelativeUri(Uri relativeUri);
456 } 458 }
457 459
458 /** 460 /**
459 * The interface `SourceContainer` is used by clients to define a collection of sources 461 * The interface `SourceContainer` is used by clients to define a collection of sources
460 * 462 *
461 * Source containers are not used within analysis engine, but can be used by cli ents to group 463 * Source containers are not used within analysis engine, but can be used by cli ents to group
462 * sources for the purposes of accessing composite dependency information. For e xample, the Eclipse 464 * sources for the purposes of accessing composite dependency information. For e xample, the Eclipse
463 * client uses source containers to represent Eclipse projects, which allows it to easily compute 465 * client uses source containers to represent Eclipse projects, which allows it to easily compute
464 * project-level dependencies. 466 * project-level dependencies.
465 */ 467 */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 * 508 *
507 * @param absoluteUri the absolute URI to be resolved 509 * @param absoluteUri the absolute URI to be resolved
508 * @return a source object representing the absolute URI 510 * @return a source object representing the absolute URI
509 */ 511 */
510 Source forUri(String absoluteUri) { 512 Source forUri(String absoluteUri) {
511 try { 513 try {
512 Uri uri = parseUriWithException(absoluteUri); 514 Uri uri = parseUriWithException(absoluteUri);
513 if (uri.isAbsolute) { 515 if (uri.isAbsolute) {
514 return _internalResolveUri(null, uri); 516 return _internalResolveUri(null, uri);
515 } 517 }
516 } on URISyntaxException catch (exception) { 518 } catch (exception) {
519 AnalysisEngine.instance.logger.logError2("Could not resolve URI: ${absolut eUri}", exception);
517 } 520 }
518 return null; 521 return null;
519 } 522 }
523
524 /**
525 * Return a source object representing the given absolute URI, or `null` if th e URI is not
526 * an absolute URI.
527 *
528 * @param absoluteUri the absolute URI to be resolved
529 * @return a source object representing the absolute URI
530 */
531 Source forUri2(Uri absoluteUri) {
532 if (absoluteUri.isAbsolute) {
533 try {
534 return _internalResolveUri(null, absoluteUri);
535 } on AnalysisException catch (exception, stackTrace) {
536 AnalysisEngine.instance.logger.logError2("Could not resolve URI: ${absol uteUri}", new CaughtException(exception, stackTrace));
537 }
538 }
539 return null;
540 }
520 541
521 /** 542 /**
522 * Return a source object that is equal to the source object used to obtain th e given encoding. 543 * Return a source object that is equal to the source object used to obtain th e given encoding.
523 * 544 *
524 * @param encoding the encoding of a source object 545 * @param encoding the encoding of a source object
525 * @return a source object that is described by the given encoding 546 * @return a source object that is described by the given encoding
526 * @throws IllegalArgumentException if the argument is not a valid encoding 547 * @throws IllegalArgumentException if the argument is not a valid encoding
527 * @see Source#getEncoding() 548 * @see Source#getEncoding()
528 */ 549 */
529 Source fromEncoding(String encoding) { 550 Source fromEncoding(String encoding) {
530 if (encoding.length < 2) { 551 Source source = forUri(encoding);
531 throw new IllegalArgumentException("Invalid encoding length"); 552 if (source == null) {
553 throw new IllegalArgumentException("Invalid source encoding: ${encoding}") ;
532 } 554 }
533 UriKind kind = UriKind.fromEncoding(encoding.codeUnitAt(0)); 555 return source;
534 if (kind == null) {
535 throw new IllegalArgumentException("Invalid source kind in encoding: ${kin d}");
536 }
537 try {
538 Uri uri = parseUriWithException(encoding.substring(1));
539 for (UriResolver resolver in _resolvers) {
540 Source result = resolver.fromEncoding(kind, uri);
541 if (result != null) {
542 return result;
543 }
544 }
545 throw new IllegalArgumentException("No resolver for kind: ${kind}");
546 } catch (exception) {
547 throw new IllegalArgumentException("Invalid URI in encoding");
548 }
549 } 556 }
550 557
551 /** 558 /**
552 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re 559 * Return the [DartSdk] associated with this [SourceFactory], or `null` if the re
553 * is no such SDK. 560 * is no such SDK.
554 * 561 *
555 * @return the [DartSdk] associated with this [SourceFactory], or `null` if 562 * @return the [DartSdk] associated with this [SourceFactory], or `null` if
556 * there is no such SDK 563 * there is no such SDK
557 */ 564 */
558 DartSdk get dartSdk { 565 DartSdk get dartSdk {
(...skipping 24 matching lines...) Expand all
583 * @param containedUri the (possibly relative) URI to be resolved against the containing source 590 * @param containedUri the (possibly relative) URI to be resolved against the containing source
584 * @return the source representing the contained URI 591 * @return the source representing the contained URI
585 */ 592 */
586 Source resolveUri(Source containingSource, String containedUri) { 593 Source resolveUri(Source containingSource, String containedUri) {
587 if (containedUri == null || containedUri.isEmpty) { 594 if (containedUri == null || containedUri.isEmpty) {
588 return null; 595 return null;
589 } 596 }
590 try { 597 try {
591 // Force the creation of an escaped URI to deal with spaces, etc. 598 // Force the creation of an escaped URI to deal with spaces, etc.
592 return _internalResolveUri(containingSource, parseUriWithException(contain edUri)); 599 return _internalResolveUri(containingSource, parseUriWithException(contain edUri));
593 } on URISyntaxException catch (exception) { 600 } catch (exception) {
601 AnalysisEngine.instance.logger.logError2("Could not resolve URI (${contain edUri}) relative to source (${containingSource.fullName})", exception);
594 return null; 602 return null;
595 } 603 }
596 } 604 }
597 605
598 /** 606 /**
599 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 607 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
600 * be computed. 608 * be computed.
601 * 609 *
602 * @param source the source to get URI for 610 * @param source the source to get URI for
603 * @return the absolute URI representing the given source 611 * @return the absolute URI representing the given source
(...skipping 13 matching lines...) Expand all
617 * 625 *
618 * @param localSourcePredicate the predicate to determine is [Source] is local 626 * @param localSourcePredicate the predicate to determine is [Source] is local
619 */ 627 */
620 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) { 628 void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) {
621 this._localSourcePredicate = localSourcePredicate; 629 this._localSourcePredicate = localSourcePredicate;
622 } 630 }
623 631
624 /** 632 /**
625 * Return a source object representing the URI that results from resolving the given (possibly 633 * Return a source object representing the URI that results from resolving the given (possibly
626 * relative) contained URI against the URI associated with an existing source object, or 634 * relative) contained URI against the URI associated with an existing source object, or
627 * `null` if either the contained URI is invalid or if it cannot be resolved a gainst the 635 * `null` if the URI could not be resolved.
628 * source object's URI.
629 * 636 *
630 * @param containingSource the source containing the given URI 637 * @param containingSource the source containing the given URI
631 * @param containedUri the (possibly relative) URI to be resolved against the containing source 638 * @param containedUri the (possibly relative) URI to be resolved against the containing source
632 * @return the source representing the contained URI 639 * @return the source representing the contained URI
640 * @throws AnalysisException if either the contained URI is invalid or if it c annot be resolved
641 * against the source object's URI
633 */ 642 */
634 Source _internalResolveUri(Source containingSource, Uri containedUri) { 643 Source _internalResolveUri(Source containingSource, Uri containedUri) {
635 if (containedUri.isAbsolute) { 644 if (!containedUri.isAbsolute) {
636 for (UriResolver resolver in _resolvers) { 645 if (containingSource == null) {
637 Source result = resolver.resolveAbsolute(containedUri); 646 throw new AnalysisException("Cannot resolve a relative URI without a con taining source: ${containedUri}");
638 if (result != null) {
639 return result;
640 }
641 } 647 }
642 return null; 648 containedUri = containingSource.resolveRelativeUri(containedUri);
643 } else {
644 return containingSource.resolveRelative(containedUri);
645 } 649 }
650 for (UriResolver resolver in _resolvers) {
651 Source result = resolver.resolveAbsolute(containedUri);
652 if (result != null) {
653 return result;
654 }
655 }
656 return null;
646 } 657 }
647 } 658 }
648 659
649 /** 660 /**
650 * The enumeration `SourceKind` defines the different kinds of sources that are known to the 661 * The enumeration `SourceKind` defines the different kinds of sources that are known to the
651 * analysis engine. 662 * analysis engine.
652 */ 663 */
653 class SourceKind extends Enum<SourceKind> { 664 class SourceKind extends Enum<SourceKind> {
654 /** 665 /**
655 * A source containing HTML. The HTML might or might not contain Dart scripts. 666 * A source containing HTML. The HTML might or might not contain Dart scripts.
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 const UriKind(String name, int ordinal, this.encoding) : super(name, ordinal); 892 const UriKind(String name, int ordinal, this.encoding) : super(name, ordinal);
882 } 893 }
883 894
884 /** 895 /**
885 * The abstract class `UriResolver` defines the behavior of objects that are use d to resolve 896 * The abstract class `UriResolver` defines the behavior of objects that are use d to resolve
886 * URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of 897 * URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of
887 * absolute URI. 898 * absolute URI.
888 */ 899 */
889 abstract class UriResolver { 900 abstract class UriResolver {
890 /** 901 /**
891 * If this resolver should be used for URI's of the given kind, resolve the gi ven absolute URI.
892 * The URI does not need to have the scheme handled by this resolver if the ki nd matches. Return a
893 * [Source] representing the file to which it was resolved, whether or not the
894 * resulting source exists, or `null` if it could not be resolved because the URI is
895 * invalid.
896 *
897 * @param kind the kind of URI that was originally resolved in order to produc e an encoding with
898 * the given URI
899 * @param uri the URI to be resolved
900 * @return a [Source] representing the file to which given URI was resolved
901 */
902 Source fromEncoding(UriKind kind, Uri uri);
903
904 /**
905 * Resolve the given absolute URI. Return a [Source] representing the file to which 902 * Resolve the given absolute URI. Return a [Source] representing the file to which
906 * it was resolved, whether or not the resulting source exists, or `null` if i t could not be 903 * it was resolved, whether or not the resulting source exists, or `null` if i t could not be
907 * resolved because the URI is invalid. 904 * resolved because the URI is invalid.
908 * 905 *
909 * @param uri the URI to be resolved 906 * @param uri the URI to be resolved
910 * @return a [Source] representing the file to which given URI was resolved 907 * @return a [Source] representing the file to which given URI was resolved
911 */ 908 */
912 Source resolveAbsolute(Uri uri); 909 Source resolveAbsolute(Uri uri);
913 910
914 /** 911 /**
915 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot 912 * Return an absolute URI that represents the given source, or `null` if a val id URI cannot
916 * be computed. 913 * be computed.
917 * 914 *
918 * @param source the source to get URI for 915 * @param source the source to get URI for
919 * @return the absolute URI representing the given source 916 * @return the absolute URI representing the given source
920 */ 917 */
921 Uri restoreAbsolute(Source source) => null; 918 Uri restoreAbsolute(Source source) => null;
922 } 919 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/sdk_io.dart ('k') | pkg/analyzer/lib/src/generated/source_io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698