| Index: pkg/analyzer/lib/src/generated/source.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/source.dart b/pkg/analyzer/lib/src/generated/source.dart
|
| index 446c8eaa27ded1992da4d0430b85ebc73958f686..7dbcacd11e3e4018dbf86032e4a02395c35bc848 100644
|
| --- a/pkg/analyzer/lib/src/generated/source.dart
|
| +++ b/pkg/analyzer/lib/src/generated/source.dart
|
| @@ -69,7 +69,7 @@ class SourceFactory {
|
| /**
|
| * The resolvers used to resolve absolute URI's.
|
| */
|
| - List<UriResolver> _resolvers;
|
| + final List<UriResolver> _resolvers;
|
|
|
| /**
|
| * The predicate to determine is [Source] is local.
|
| @@ -81,9 +81,7 @@ class SourceFactory {
|
| *
|
| * @param resolvers the resolvers used to resolve absolute URI's
|
| */
|
| - SourceFactory(List<UriResolver> resolvers) {
|
| - this._resolvers = resolvers;
|
| - }
|
| + SourceFactory(this._resolvers);
|
|
|
| /**
|
| * Return a source object representing the given absolute URI, or `null` if the URI is not a
|
| @@ -160,9 +158,9 @@ class SourceFactory {
|
|
|
| /**
|
| * Return a source object representing the URI that results from resolving the given (possibly
|
| - * relative) contained URI against the URI associated with an existing source object, or
|
| - * `null` if either the contained URI is invalid or if it cannot be resolved against the
|
| - * source object's URI.
|
| + * relative) contained URI against the URI associated with an existing source object, whether or
|
| + * not the resulting source exists, or `null` if either the contained URI is invalid or if
|
| + * it cannot be resolved against the source object's URI.
|
| *
|
| * @param containingSource the source containing the given URI
|
| * @param containedUri the (possibly relative) URI to be resolved against the containing source
|
| @@ -181,10 +179,11 @@ class SourceFactory {
|
| }
|
|
|
| /**
|
| - * Return an absolute URI that represents the given source.
|
| + * Return an absolute URI that represents the given source, or `null` if a valid URI cannot
|
| + * be computed.
|
| *
|
| * @param source the source to get URI for
|
| - * @return the absolute URI representing the given source, may be `null`
|
| + * @return the absolute URI representing the given source
|
| */
|
| Uri restoreUri(Source source) {
|
| for (UriResolver resolver in _resolvers) {
|
| @@ -239,8 +238,9 @@ abstract class UriResolver {
|
| /**
|
| * If this resolver should be used for URI's of the given kind, resolve the given absolute URI.
|
| * The URI does not need to have the scheme handled by this resolver if the kind matches. Return a
|
| - * [Source] representing the file to which it was resolved, or `null` if it
|
| - * could not be resolved.
|
| + * [Source] representing the file to which it was resolved, whether or not the
|
| + * resulting source exists, or `null` if it could not be resolved because the URI is
|
| + * invalid.
|
| *
|
| * @param kind the kind of URI that was originally resolved in order to produce an encoding with
|
| * the given URI
|
| @@ -251,7 +251,8 @@ abstract class UriResolver {
|
|
|
| /**
|
| * Resolve the given absolute URI. Return a [Source] representing the file to which
|
| - * it was resolved, or `null` if it could not be resolved.
|
| + * it was resolved, whether or not the resulting source exists, or `null` if it could not be
|
| + * resolved because the URI is invalid.
|
| *
|
| * @param uri the URI to be resolved
|
| * @return a [Source] representing the file to which given URI was resolved
|
| @@ -259,17 +260,34 @@ abstract class UriResolver {
|
| Source resolveAbsolute(Uri uri);
|
|
|
| /**
|
| - * Return an absolute URI that represents the given source.
|
| + * Return an absolute URI that represents the given source, or `null` if a valid URI cannot
|
| + * be computed.
|
| *
|
| * @param source the source to get URI for
|
| - * @return the absolute URI representing the given source, may be `null`
|
| + * @return the absolute URI representing the given source
|
| */
|
| Uri restoreAbsolute(Source source) => null;
|
| }
|
|
|
| /**
|
| * The interface `Source` defines the behavior of objects representing source code that can be
|
| - * compiled.
|
| + * analyzed by the analysis engine.
|
| + *
|
| + * Implementations of this interface need to be aware of some assumptions made by the analysis
|
| + * engine concerning sources:
|
| + * * Sources are not required to be unique. That is, there can be multiple instances representing
|
| + * the same source.
|
| + * * Sources are long lived. That is, the engine is allowed to hold on to a source for an extended
|
| + * period of time and that source must continue to report accurate and up-to-date information.
|
| + * Because of these assumptions, most implementations will not maintain any state but will delegate
|
| + * to an authoritative system of record in order to implement this API. For example, a source that
|
| + * represents files on disk would typically query the file system to determine the state of the
|
| + * file.
|
| + *
|
| + * If the instances that implement this API are the system of record, then they will typically be
|
| + * unique. In that case, sources that are created that represent non-existent files must also be
|
| + * retained so that if those files are created at a later date the long-lived sources representing
|
| + * those files will know that they now exist.
|
| */
|
| abstract class Source {
|
| /**
|
| @@ -418,29 +436,29 @@ class SourceKind extends Enum<SourceKind> {
|
| /**
|
| * A source containing HTML. The HTML might or might not contain Dart scripts.
|
| */
|
| - static final SourceKind HTML = new SourceKind('HTML', 0);
|
| + static const SourceKind HTML = const SourceKind('HTML', 0);
|
|
|
| /**
|
| * A Dart compilation unit that is not a part of another library. Libraries might or might not
|
| * contain any directives, including a library directive.
|
| */
|
| - static final SourceKind LIBRARY = new SourceKind('LIBRARY', 1);
|
| + static const SourceKind LIBRARY = const SourceKind('LIBRARY', 1);
|
|
|
| /**
|
| * A Dart compilation unit that is part of another library. Parts contain a part-of directive.
|
| */
|
| - static final SourceKind PART = new SourceKind('PART', 2);
|
| + static const SourceKind PART = const SourceKind('PART', 2);
|
|
|
| /**
|
| * An unknown kind of source. Used both when it is not possible to identify the kind of a source
|
| * and also when the kind of a source is not known without performing a computation and the client
|
| * does not want to spend the time to identify the kind.
|
| */
|
| - static final SourceKind UNKNOWN = new SourceKind('UNKNOWN', 3);
|
| + static const SourceKind UNKNOWN = const SourceKind('UNKNOWN', 3);
|
|
|
| - static final List<SourceKind> values = [HTML, LIBRARY, PART, UNKNOWN];
|
| + static const List<SourceKind> values = const [HTML, LIBRARY, PART, UNKNOWN];
|
|
|
| - SourceKind(String name, int ordinal) : super(name, ordinal);
|
| + const SourceKind(String name, int ordinal) : super(name, ordinal);
|
| }
|
|
|
| /**
|
| @@ -451,24 +469,24 @@ class UriKind extends Enum<UriKind> {
|
| /**
|
| * A 'dart:' URI.
|
| */
|
| - static final UriKind DART_URI = new UriKind('DART_URI', 0, 0x64);
|
| + static const UriKind DART_URI = const UriKind('DART_URI', 0, 0x64);
|
|
|
| /**
|
| * A 'file:' URI.
|
| */
|
| - static final UriKind FILE_URI = new UriKind('FILE_URI', 1, 0x66);
|
| + static const UriKind FILE_URI = const UriKind('FILE_URI', 1, 0x66);
|
|
|
| /**
|
| * A 'package:' URI referencing source package itself.
|
| */
|
| - static final UriKind PACKAGE_SELF_URI = new UriKind('PACKAGE_SELF_URI', 2, 0x73);
|
| + static const UriKind PACKAGE_SELF_URI = const UriKind('PACKAGE_SELF_URI', 2, 0x73);
|
|
|
| /**
|
| * A 'package:' URI.
|
| */
|
| - static final UriKind PACKAGE_URI = new UriKind('PACKAGE_URI', 3, 0x70);
|
| + static const UriKind PACKAGE_URI = const UriKind('PACKAGE_URI', 3, 0x70);
|
|
|
| - static final List<UriKind> values = [DART_URI, FILE_URI, PACKAGE_SELF_URI, PACKAGE_URI];
|
| + static const List<UriKind> values = const [DART_URI, FILE_URI, PACKAGE_SELF_URI, PACKAGE_URI];
|
|
|
| /**
|
| * Return the URI kind represented by the given encoding, or `null` if there is no kind with
|
| @@ -496,16 +514,14 @@ class UriKind extends Enum<UriKind> {
|
| /**
|
| * The single character encoding used to identify this kind of URI.
|
| */
|
| - int encoding = 0;
|
| + final int encoding;
|
|
|
| /**
|
| * Initialize a newly created URI kind to have the given encoding.
|
| *
|
| * @param encoding the single character encoding used to identify this kind of URI.
|
| */
|
| - UriKind(String name, int ordinal, int encoding) : super(name, ordinal) {
|
| - this.encoding = encoding;
|
| - }
|
| + const UriKind(String name, int ordinal, this.encoding) : super(name, ordinal);
|
| }
|
|
|
| /**
|
| @@ -521,13 +537,13 @@ class SourceRange {
|
| * The 0-based index of the first character of the source code for this element, relative to the
|
| * source buffer in which this element is contained.
|
| */
|
| - int offset = 0;
|
| + final int offset;
|
|
|
| /**
|
| * The number of characters of the source code for this element, relative to the source buffer in
|
| * which this element is contained.
|
| */
|
| - int length = 0;
|
| + final int length;
|
|
|
| /**
|
| * Initialize a newly created source range using the given offset and the given length.
|
| @@ -535,10 +551,7 @@ class SourceRange {
|
| * @param offset the given offset
|
| * @param length the given length
|
| */
|
| - SourceRange(int offset, int length) {
|
| - this.offset = offset;
|
| - this.length = length;
|
| - }
|
| + SourceRange(this.offset, this.length);
|
|
|
| /**
|
| * @return `true` if <code>x</code> is in [offset, offset + length) interval.
|
| @@ -657,9 +670,17 @@ abstract class SourceContainer {
|
| */
|
| class DartUriResolver extends UriResolver {
|
| /**
|
| + * Return `true` if the given URI is a `dart-ext:` URI.
|
| + *
|
| + * @param uriContent the textual representation of the URI being tested
|
| + * @return `true` if the given URI is a `dart-ext:` URI
|
| + */
|
| + static bool isDartExtUri(String uriContent) => uriContent != null && uriContent.startsWith(_DART_EXT_SCHEME);
|
| +
|
| + /**
|
| * The Dart SDK against which URI's are to be resolved.
|
| */
|
| - DartSdk _sdk;
|
| + final DartSdk _sdk;
|
|
|
| /**
|
| * The name of the `dart` scheme.
|
| @@ -667,6 +688,11 @@ class DartUriResolver extends UriResolver {
|
| static String _DART_SCHEME = "dart";
|
|
|
| /**
|
| + * The prefix of a URI using the dart-ext scheme to reference a native code library.
|
| + */
|
| + static String _DART_EXT_SCHEME = "dart-ext:";
|
| +
|
| + /**
|
| * Return `true` if the given URI is a `dart:` URI.
|
| *
|
| * @param uri the URI being tested
|
| @@ -680,13 +706,11 @@ class DartUriResolver extends UriResolver {
|
| *
|
| * @param sdk the Dart SDK against which URI's are to be resolved
|
| */
|
| - DartUriResolver(DartSdk sdk) {
|
| - this._sdk = sdk;
|
| - }
|
| + DartUriResolver(this._sdk);
|
|
|
| @override
|
| Source fromEncoding(UriKind kind, Uri uri) {
|
| - if (identical(kind, UriKind.DART_URI)) {
|
| + if (kind == UriKind.DART_URI) {
|
| return _sdk.fromEncoding(kind, uri);
|
| }
|
| return null;
|
| @@ -716,7 +740,7 @@ class LineInfo {
|
| /**
|
| * An array containing the offsets of the first character of each line in the source code.
|
| */
|
| - List<int> _lineStarts;
|
| + final List<int> _lineStarts;
|
|
|
| /**
|
| * Initialize a newly created set of line information to represent the data encoded in the given
|
| @@ -724,13 +748,12 @@ class LineInfo {
|
| *
|
| * @param lineStarts the offsets of the first character of each line in the source code
|
| */
|
| - LineInfo(List<int> lineStarts) {
|
| - if (lineStarts == null) {
|
| + LineInfo(this._lineStarts) {
|
| + if (_lineStarts == null) {
|
| throw new IllegalArgumentException("lineStarts must be non-null");
|
| - } else if (lineStarts.length < 1) {
|
| + } else if (_lineStarts.length < 1) {
|
| throw new IllegalArgumentException("lineStarts must be non-empty");
|
| }
|
| - this._lineStarts = lineStarts;
|
| }
|
|
|
| /**
|
| @@ -758,12 +781,12 @@ class LineInfo_Location {
|
| /**
|
| * The one-based index of the line containing the character.
|
| */
|
| - int lineNumber = 0;
|
| + final int lineNumber;
|
|
|
| /**
|
| * The one-based index of the column containing the character.
|
| */
|
| - int columnNumber = 0;
|
| + final int columnNumber;
|
|
|
| /**
|
| * Initialize a newly created location to represent the location of the character at the given
|
| @@ -772,10 +795,7 @@ class LineInfo_Location {
|
| * @param lineNumber the one-based index of the line containing the character
|
| * @param columnNumber the one-based index of the column containing the character
|
| */
|
| - LineInfo_Location(int lineNumber, int columnNumber) {
|
| - this.lineNumber = lineNumber;
|
| - this.columnNumber = columnNumber;
|
| - }
|
| + LineInfo_Location(this.lineNumber, this.columnNumber);
|
| }
|
|
|
| /**
|
|
|