| Index: packages/analyzer/lib/src/generated/source.dart
|
| diff --git a/packages/analyzer/lib/src/generated/source.dart b/packages/analyzer/lib/src/generated/source.dart
|
| index 1a4751678597008be0e04437eaa118bd5e69fd35..7f95c0177dcd8a16619a8f50284fc48fd57f77d2 100644
|
| --- a/packages/analyzer/lib/src/generated/source.dart
|
| +++ b/packages/analyzer/lib/src/generated/source.dart
|
| @@ -2,26 +2,23 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -library engine.source;
|
| +library analyzer.src.generated.source;
|
|
|
| import 'dart:collection';
|
| import "dart:math" as math;
|
|
|
| import 'package:analyzer/file_system/file_system.dart';
|
| -import 'package:analyzer/file_system/physical_file_system.dart';
|
| import 'package:analyzer/source/package_map_resolver.dart';
|
| -import 'package:analyzer/src/generated/utilities_dart.dart' as utils;
|
| +import 'package:analyzer/src/context/source.dart';
|
| +import 'package:analyzer/src/generated/engine.dart';
|
| +import 'package:analyzer/src/generated/java_engine.dart';
|
| +import 'package:analyzer/src/generated/java_io.dart' show JavaFile;
|
| +import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
|
| +import 'package:analyzer/src/generated/source_io.dart' show FileBasedSource;
|
| import 'package:analyzer/task/model.dart';
|
| import 'package:package_config/packages.dart';
|
| import 'package:path/path.dart' as pathos;
|
|
|
| -import 'engine.dart';
|
| -import 'java_core.dart';
|
| -import 'java_engine.dart';
|
| -import 'java_io.dart' show JavaFile;
|
| -import 'sdk.dart' show DartSdk;
|
| -import 'source_io.dart' show FileBasedSource;
|
| -
|
| /**
|
| * A function that is used to visit [ContentCache] entries.
|
| */
|
| @@ -44,6 +41,8 @@ class ContentCache {
|
| */
|
| HashMap<String, int> _stampMap = new HashMap<String, int>();
|
|
|
| + int _nextStamp = 0;
|
| +
|
| /**
|
| * Visit all entries of this cache.
|
| */
|
| @@ -84,7 +83,7 @@ class ContentCache {
|
| _stampMap.remove(fullName);
|
| return _contentMap.remove(fullName);
|
| } else {
|
| - int newStamp = JavaSystem.currentTimeMillis();
|
| + int newStamp = _nextStamp++;
|
| int oldStamp = _stampMap[fullName];
|
| _stampMap[fullName] = newStamp;
|
| // Occasionally, if this method is called in rapid succession, the
|
| @@ -100,6 +99,7 @@ class ContentCache {
|
| }
|
| }
|
|
|
| +@deprecated
|
| class CustomUriResolver extends UriResolver {
|
| final Map<String, String> _urlMappings;
|
|
|
| @@ -114,7 +114,7 @@ class CustomUriResolver extends UriResolver {
|
| if (!fileUri.isAbsolute) return null;
|
|
|
| JavaFile javaFile = new JavaFile.fromUri(fileUri);
|
| - return new FileBasedSource(javaFile, actualUri != null ? actualUri : uri);
|
| + return new FileBasedSource(javaFile, actualUri ?? uri);
|
| }
|
| }
|
|
|
| @@ -179,56 +179,69 @@ class DartUriResolver extends UriResolver {
|
| }
|
|
|
| /**
|
| - * Instances of the class `LineInfo` encapsulate information about line and column information
|
| - * within a source file.
|
| + * Information about line and column information within a source file.
|
| */
|
| class LineInfo {
|
| /**
|
| - * An array containing the offsets of the first character of each line in the source code.
|
| + * A list containing the offsets of the first character of each line in the
|
| + * source code.
|
| */
|
| - final List<int> _lineStarts;
|
| + final List<int> lineStarts;
|
|
|
| /**
|
| - * The zero-based [_lineStarts] index resulting from the last call to
|
| + * The zero-based [lineStarts] index resulting from the last call to
|
| * [getLocation].
|
| */
|
| int _previousLine = 0;
|
|
|
| /**
|
| - * Initialize a newly created set of line information to represent the data encoded in the given
|
| - * array.
|
| - *
|
| - * @param lineStarts the offsets of the first character of each line in the source code
|
| + * Initialize a newly created set of line information to represent the data
|
| + * encoded in the given list of [lineStarts].
|
| + */
|
| + factory LineInfo(List<int> lineStarts) => new LineInfoWithCount(lineStarts);
|
| +
|
| + /**
|
| + * Initialize a newly created set of line information corresponding to the
|
| + * given file [content].
|
| */
|
| - LineInfo(this._lineStarts) {
|
| - if (_lineStarts == null) {
|
| - throw new IllegalArgumentException("lineStarts must be non-null");
|
| - } else if (_lineStarts.length < 1) {
|
| - throw new IllegalArgumentException("lineStarts must be non-empty");
|
| + factory LineInfo.fromContent(String content) =>
|
| + new LineInfoWithCount(StringUtilities.computeLineStarts(content));
|
| +
|
| + /**
|
| + * Initialize a newly created set of line information to represent the data
|
| + * encoded in the given list of [lineStarts].
|
| + */
|
| + LineInfo._(this.lineStarts) {
|
| + if (lineStarts == null) {
|
| + throw new ArgumentError("lineStarts must be non-null");
|
| + } else if (lineStarts.length < 1) {
|
| + throw new ArgumentError("lineStarts must be non-empty");
|
| }
|
| }
|
|
|
| /**
|
| - * Return the location information for the character at the given offset.
|
| - *
|
| - * @param offset the offset of the character for which location information is to be returned
|
| - * @return the location information for the character at the given offset
|
| + * The number of lines.
|
| + */
|
| + int get lineCount => lineStarts.length;
|
| +
|
| + /**
|
| + * Return the location information for the character at the given [offset].
|
| */
|
| LineInfo_Location getLocation(int offset) {
|
| var min = 0;
|
| - var max = _lineStarts.length - 1;
|
| + var max = lineStarts.length - 1;
|
|
|
| // Subsequent calls to [getLocation] are often for offsets near each other.
|
| // To take advantage of that, we cache the index of the line start we found
|
| // when this was last called. If the current offset is on that line or
|
| // later, we'll skip those early indices completely when searching.
|
| - if (offset >= _lineStarts[_previousLine]) {
|
| + if (offset >= lineStarts[_previousLine]) {
|
| min = _previousLine;
|
|
|
| // Before kicking off a full binary search, do a quick check here to see
|
| // if the new offset is on that exact line.
|
| - if (min == _lineStarts.length - 1 || offset < _lineStarts[min + 1]) {
|
| - return new LineInfo_Location(min + 1, offset - _lineStarts[min] + 1);
|
| + if (min == lineStarts.length - 1 || offset < lineStarts[min + 1]) {
|
| + return new LineInfo_Location(min + 1, offset - lineStarts[min] + 1);
|
| }
|
| }
|
|
|
| @@ -236,7 +249,7 @@ class LineInfo {
|
| while (min < max) {
|
| var midpoint = (max - min + 1) ~/ 2 + min;
|
|
|
| - if (_lineStarts[midpoint] > offset) {
|
| + if (lineStarts[midpoint] > offset) {
|
| max = midpoint - 1;
|
| } else {
|
| min = midpoint;
|
| @@ -245,7 +258,19 @@ class LineInfo {
|
|
|
| _previousLine = min;
|
|
|
| - return new LineInfo_Location(min + 1, offset - _lineStarts[min] + 1);
|
| + return new LineInfo_Location(min + 1, offset - lineStarts[min] + 1);
|
| + }
|
| +
|
| + /**
|
| + * Return the offset of the first character on the line with the given
|
| + * [lineNumber].
|
| + */
|
| + int getOffsetOfLine(int lineNumber) {
|
| + if (lineNumber < 0 || lineNumber >= lineCount) {
|
| + throw new ArgumentError(
|
| + 'Invalid line number: $lineNumber; must be between 0 and ${lineCount - 1}');
|
| + }
|
| + return lineStarts[lineNumber];
|
| }
|
| }
|
|
|
| @@ -277,6 +302,21 @@ class LineInfo_Location {
|
| String toString() => '$lineNumber:$columnNumber';
|
| }
|
|
|
| +/**
|
| + * Information about line and column information within a source file,
|
| + * including a count of the total number of lines.
|
| + *
|
| + * TODO(paulberry): in the next major version roll of analyzer, merge this
|
| + * class into [LineInfo].
|
| + */
|
| +class LineInfoWithCount extends LineInfo {
|
| + /**
|
| + * Initialize a newly created set of line information to represent the data
|
| + * encoded in the given list of [lineStarts].
|
| + */
|
| + LineInfoWithCount(List<int> lineStarts) : super._(lineStarts);
|
| +}
|
| +
|
| /**
|
| * Instances of interface `LocalSourcePredicate` are used to determine if the given
|
| * [Source] is "local" in some sense, so can be updated.
|
| @@ -333,19 +373,18 @@ class NonExistingSource extends Source {
|
| @override
|
| final Uri uri;
|
|
|
| + @override
|
| final UriKind uriKind;
|
|
|
| NonExistingSource(this.fullName, this.uri, this.uriKind);
|
|
|
| @override
|
| TimestampedData<String> get contents {
|
| - throw new UnsupportedOperationException('$fullName does not exist.');
|
| + throw new UnsupportedError('$fullName does not exist.');
|
| }
|
|
|
| @override
|
| - String get encoding {
|
| - throw new UnsupportedOperationException('$fullName does not exist.');
|
| - }
|
| + String get encoding => uri.toString();
|
|
|
| @override
|
| int get hashCode => fullName.hashCode;
|
| @@ -369,11 +408,6 @@ class NonExistingSource extends Source {
|
|
|
| @override
|
| bool exists() => false;
|
| -
|
| - @override
|
| - Uri resolveRelativeUri(Uri relativeUri) {
|
| - throw new UnsupportedOperationException('$fullName does not exist.');
|
| - }
|
| }
|
|
|
| /**
|
| @@ -397,12 +431,6 @@ class NonExistingSource extends Source {
|
| * those files will know that they now exist.
|
| */
|
| abstract class Source implements AnalysisTarget {
|
| - /**
|
| - * An empty list of sources.
|
| - */
|
| - @deprecated // Use Source.EMPTY_LIST
|
| - static const List<Source> EMPTY_ARRAY = EMPTY_LIST;
|
| -
|
| /**
|
| * An empty list of sources.
|
| */
|
| @@ -411,7 +439,7 @@ abstract class Source implements AnalysisTarget {
|
| /**
|
| * Get the contents and timestamp of this source.
|
| *
|
| - * Clients should consider using the the method [AnalysisContext.getContents]
|
| + * Clients should consider using the method [AnalysisContext.getContents]
|
| * because contexts can have local overrides of the content of a source that the source is not
|
| * aware of.
|
| *
|
| @@ -454,6 +482,9 @@ abstract class Source implements AnalysisTarget {
|
| */
|
| bool get isInSystemLibrary;
|
|
|
| + @override
|
| + Source get librarySource => null;
|
| +
|
| /**
|
| * Return the modification stamp for this source, or a negative value if the
|
| * source does not exist. A modification stamp is a non-negative integer with
|
| @@ -462,7 +493,7 @@ abstract class Source implements AnalysisTarget {
|
| * will be returned, but if the contents of the source have been modified one
|
| * or more times (even if the net change is zero) the stamps will be different.
|
| *
|
| - * Clients should consider using the the method
|
| + * Clients should consider using the method
|
| * [AnalysisContext.getModificationStamp] because contexts can have local
|
| * overrides of the content of a source that the source is not aware of.
|
| */
|
| @@ -511,28 +542,13 @@ abstract class Source implements AnalysisTarget {
|
| /**
|
| * Return `true` if this source exists.
|
| *
|
| - * Clients should consider using the the method [AnalysisContext.exists] because
|
| + * Clients should consider using the method [AnalysisContext.exists] because
|
| * contexts can have local overrides of the content of a source that the source is not aware of
|
| * and a source with local content is considered to exist even if there is no file on disk.
|
| *
|
| * @return `true` if this source exists
|
| */
|
| bool exists();
|
| -
|
| - /**
|
| - * Resolve the relative URI against the URI associated with this source object.
|
| - *
|
| - * Note: This method is not intended for public use, it is only visible out of necessity. It is
|
| - * only intended to be invoked by a [SourceFactory]. Source factories will
|
| - * only invoke this method if the URI is relative, so implementations of this method are not
|
| - * required to, and generally do not, verify the argument. The result of invoking this method with
|
| - * an absolute URI is intentionally left unspecified.
|
| - *
|
| - * @param relativeUri the relative URI to be resolved against this source
|
| - * @return the URI to which given URI was resolved
|
| - * @throws AnalysisException if the relative URI could not be resolved
|
| - */
|
| - Uri resolveRelativeUri(Uri relativeUri);
|
| }
|
|
|
| /**
|
| @@ -571,148 +587,74 @@ abstract class SourceContainer {
|
| * Instances of the class `SourceFactory` resolve possibly relative URI's against an existing
|
| * [Source].
|
| */
|
| -class SourceFactory {
|
| +abstract class SourceFactory {
|
| /**
|
| * The analysis context that this source factory is associated with.
|
| */
|
| AnalysisContext context;
|
|
|
| /**
|
| - * URI processor used to find mappings for `package:` URIs found in a `.packages` config
|
| - * file.
|
| - */
|
| - final Packages _packages;
|
| -
|
| - /**
|
| - * Resource provider used in working with package maps.
|
| - */
|
| - final ResourceProvider _resourceProvider;
|
| -
|
| - /**
|
| - * The resolvers used to resolve absolute URI's.
|
| + * Initialize a newly created source factory with the given absolute URI
|
| + * [resolvers] and optional [packages] resolution helper.
|
| */
|
| - final List<UriResolver> _resolvers;
|
| + factory SourceFactory(List<UriResolver> resolvers,
|
| + [Packages packages,
|
| + ResourceProvider resourceProvider]) = SourceFactoryImpl;
|
|
|
| /**
|
| - * The predicate to determine is [Source] is local.
|
| - */
|
| - LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK;
|
| -
|
| - /**
|
| - * Initialize a newly created source factory with the given absolute URI [resolvers] and
|
| - * optional [packages] resolution helper.
|
| - */
|
| - SourceFactory(this._resolvers,
|
| - [this._packages, ResourceProvider resourceProvider])
|
| - : _resourceProvider = resourceProvider != null
|
| - ? resourceProvider
|
| - : PhysicalResourceProvider.INSTANCE;
|
| -
|
| - /**
|
| - * Return the [DartSdk] associated with this [SourceFactory], or `null` if there
|
| - * is no such SDK.
|
| + * Return the [DartSdk] associated with this [SourceFactory], or `null` if
|
| + * there is no such SDK.
|
| *
|
| * @return the [DartSdk] associated with this [SourceFactory], or `null` if
|
| * there is no such SDK
|
| */
|
| - DartSdk get dartSdk {
|
| - for (UriResolver resolver in _resolvers) {
|
| - if (resolver is DartUriResolver) {
|
| - DartUriResolver dartUriResolver = resolver;
|
| - return dartUriResolver.dartSdk;
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| + DartSdk get dartSdk;
|
|
|
| /**
|
| * Sets the [LocalSourcePredicate].
|
| *
|
| * @param localSourcePredicate the predicate to determine is [Source] is local
|
| */
|
| - void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) {
|
| - this._localSourcePredicate = localSourcePredicate;
|
| - }
|
| + void set localSourcePredicate(LocalSourcePredicate localSourcePredicate);
|
|
|
| /// A table mapping package names to paths of directories containing
|
| /// the package (or [null] if there is no registered package URI resolver).
|
| - Map<String, List<Folder>> get packageMap {
|
| - // Start by looking in .packages.
|
| - if (_packages != null) {
|
| - Map<String, List<Folder>> packageMap = <String, List<Folder>>{};
|
| - _packages.asMap().forEach((String name, Uri uri) {
|
| - if (uri.scheme == 'file' || uri.scheme == '' /* unspecified */) {
|
| - packageMap[name] = <Folder>[
|
| - _resourceProvider.getFolder(uri.toFilePath())
|
| - ];
|
| - }
|
| - });
|
| - return packageMap;
|
| - }
|
| + Map<String, List<Folder>> get packageMap;
|
|
|
| - // Default to the PackageMapUriResolver.
|
| - PackageMapUriResolver resolver = _resolvers
|
| - .firstWhere((r) => r is PackageMapUriResolver, orElse: () => null);
|
| - return resolver != null ? resolver.packageMap : null;
|
| - }
|
| + /**
|
| + * Return a source factory that will resolve URI's in the same way that this
|
| + * source factory does.
|
| + */
|
| + SourceFactory clone();
|
|
|
| /**
|
| - * Return a source object representing the given absolute URI, or `null` if the URI is not a
|
| - * valid URI or if it is not an absolute URI.
|
| + * Return a source object representing the given absolute URI, or `null` if
|
| + * the URI is not a valid URI or if it is not an absolute URI.
|
| *
|
| * @param absoluteUri the absolute URI to be resolved
|
| * @return a source object representing the absolute URI
|
| */
|
| - Source forUri(String absoluteUri) {
|
| - try {
|
| - Uri uri = parseUriWithException(absoluteUri);
|
| - if (uri.isAbsolute) {
|
| - return _internalResolveUri(null, uri);
|
| - }
|
| - } catch (exception, stackTrace) {
|
| - AnalysisEngine.instance.logger.logError(
|
| - "Could not resolve URI: $absoluteUri",
|
| - new CaughtException(exception, stackTrace));
|
| - }
|
| - return null;
|
| - }
|
| + Source forUri(String absoluteUri);
|
|
|
| /**
|
| - * Return a source object representing the given absolute URI, or `null` if the URI is not
|
| - * an absolute URI.
|
| + * Return a source object representing the given absolute URI, or `null` if
|
| + * the URI is not an absolute URI.
|
| *
|
| * @param absoluteUri the absolute URI to be resolved
|
| * @return a source object representing the absolute URI
|
| */
|
| - Source forUri2(Uri absoluteUri) {
|
| - if (absoluteUri.isAbsolute) {
|
| - try {
|
| - return _internalResolveUri(null, absoluteUri);
|
| - } on AnalysisException catch (exception, stackTrace) {
|
| - AnalysisEngine.instance.logger.logError(
|
| - "Could not resolve URI: $absoluteUri",
|
| - new CaughtException(exception, stackTrace));
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| + Source forUri2(Uri absoluteUri);
|
|
|
| /**
|
| - * Return a source object that is equal to the source object used to obtain the given encoding.
|
| + * Return a source object that is equal to the source object used to obtain
|
| + * the given encoding.
|
| *
|
| * @param encoding the encoding of a source object
|
| * @return a source object that is described by the given encoding
|
| * @throws IllegalArgumentException if the argument is not a valid encoding
|
| * See [Source.encoding].
|
| */
|
| - Source fromEncoding(String encoding) {
|
| - Source source = forUri(encoding);
|
| - if (source == null) {
|
| - throw new IllegalArgumentException(
|
| - "Invalid source encoding: '$encoding'");
|
| - }
|
| - return source;
|
| - }
|
| + Source fromEncoding(String encoding);
|
|
|
| /**
|
| * Determines if the given [Source] is local.
|
| @@ -720,160 +662,79 @@ class SourceFactory {
|
| * @param source the [Source] to analyze
|
| * @return `true` if the given [Source] is local
|
| */
|
| - bool isLocalSource(Source source) => _localSourcePredicate.isLocal(source);
|
| + bool isLocalSource(Source source);
|
|
|
| /**
|
| - * 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, 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
|
| - * @return the source representing the contained URI
|
| + * Return a source representing the URI that results from resolving the given
|
| + * (possibly relative) [containedUri] against the URI associated with the
|
| + * [containingSource], whether or not the resulting source exists, or `null`
|
| + * if either the [containedUri] is invalid or if it cannot be resolved against
|
| + * the [containingSource]'s URI.
|
| */
|
| - Source resolveUri(Source containingSource, String containedUri) {
|
| - if (containedUri == null || containedUri.isEmpty) {
|
| - return null;
|
| - }
|
| - try {
|
| - // Force the creation of an escaped URI to deal with spaces, etc.
|
| - return _internalResolveUri(
|
| - containingSource, parseUriWithException(containedUri));
|
| - } catch (exception, stackTrace) {
|
| - String containingFullName =
|
| - containingSource != null ? containingSource.fullName : '<null>';
|
| - AnalysisEngine.instance.logger.logError(
|
| - "Could not resolve URI ($containedUri) relative to source ($containingFullName)",
|
| - new CaughtException(exception, stackTrace));
|
| - return null;
|
| - }
|
| - }
|
| + Source resolveUri(Source containingSource, String containedUri);
|
|
|
| /**
|
| - * Return an absolute URI that represents the given source, or `null` if a valid URI cannot
|
| - * be computed.
|
| + * 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
|
| */
|
| - Uri restoreUri(Source source) {
|
| - // First see if a resolver can restore the URI.
|
| - for (UriResolver resolver in _resolvers) {
|
| - Uri uri = resolver.restoreAbsolute(source);
|
| - if (uri != null) {
|
| - // Now see if there's a package mapping.
|
| - Uri packageMappedUri = _getPackageMapping(uri);
|
| - if (packageMappedUri != null) {
|
| - return packageMappedUri;
|
| - }
|
| - // Fall back to the resolver's computed URI.
|
| - return uri;
|
| - }
|
| - }
|
| -
|
| - return null;
|
| - }
|
| -
|
| - Uri _getPackageMapping(Uri sourceUri) {
|
| - if (_packages == null) {
|
| - return null;
|
| - }
|
| - if (sourceUri.scheme != 'file') {
|
| - //TODO(pquitslund): verify this works for non-file URIs.
|
| - return null;
|
| - }
|
| -
|
| - Uri packageUri;
|
| - _packages.asMap().forEach((String name, Uri uri) {
|
| - if (packageUri == null) {
|
| - if (utils.startsWith(sourceUri, uri)) {
|
| - packageUri = Uri.parse(
|
| - 'package:$name/${sourceUri.path.substring(uri.path.length)}');
|
| - }
|
| - }
|
| - });
|
| - return packageUri;
|
| - }
|
| -
|
| - /**
|
| - * 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 the URI could not be resolved.
|
| - *
|
| - * @param containingSource the source containing the given URI
|
| - * @param containedUri the (possibly relative) URI to be resolved against the containing source
|
| - * @return the source representing the contained URI
|
| - * @throws AnalysisException if either the contained URI is invalid or if it cannot be resolved
|
| - * against the source object's URI
|
| - */
|
| - Source _internalResolveUri(Source containingSource, Uri containedUri) {
|
| - if (!containedUri.isAbsolute) {
|
| - if (containingSource == null) {
|
| - throw new AnalysisException(
|
| - "Cannot resolve a relative URI without a containing source: $containedUri");
|
| - }
|
| - containedUri = containingSource.resolveRelativeUri(containedUri);
|
| - }
|
| -
|
| - Uri actualUri = containedUri;
|
| -
|
| - // Check .packages and update target and actual URIs as appropriate.
|
| - if (_packages != null && containedUri.scheme == 'package') {
|
| - Uri packageUri =
|
| - _packages.resolve(containedUri, notFound: (Uri packageUri) => null);
|
| -
|
| - if (packageUri != null) {
|
| - // Ensure scheme is set.
|
| - if (packageUri.scheme == '') {
|
| - packageUri = packageUri.replace(scheme: 'file');
|
| - }
|
| - containedUri = packageUri;
|
| - }
|
| - }
|
| -
|
| - for (UriResolver resolver in _resolvers) {
|
| - Source result = resolver.resolveAbsolute(containedUri, actualUri);
|
| - if (result != null) {
|
| - return result;
|
| - }
|
| - }
|
| -
|
| - return null;
|
| - }
|
| + Uri restoreUri(Source source);
|
| }
|
|
|
| /**
|
| - * The enumeration `SourceKind` defines the different kinds of sources that are known to the
|
| - * analysis engine.
|
| + * The enumeration `SourceKind` defines the different kinds of sources that are
|
| + * known to the analysis engine.
|
| */
|
| -class SourceKind extends Enum<SourceKind> {
|
| +class SourceKind implements Comparable<SourceKind> {
|
| /**
|
| * A source containing HTML. The HTML might or might not contain Dart scripts.
|
| */
|
| 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.
|
| + * 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 const SourceKind LIBRARY = const SourceKind('LIBRARY', 1);
|
|
|
| /**
|
| - * A Dart compilation unit that is part of another library. Parts contain a part-of directive.
|
| + * A Dart compilation unit that is part of another library. Parts contain a
|
| + * part-of directive.
|
| */
|
| 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.
|
| + * 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 const SourceKind UNKNOWN = const SourceKind('UNKNOWN', 3);
|
|
|
| static const List<SourceKind> values = const [HTML, LIBRARY, PART, UNKNOWN];
|
|
|
| - const SourceKind(String name, int ordinal) : super(name, ordinal);
|
| + /**
|
| + * The name of this source kind.
|
| + */
|
| + final String name;
|
| +
|
| + /**
|
| + * The ordinal value of the source kind.
|
| + */
|
| + final int ordinal;
|
| +
|
| + const SourceKind(this.name, this.ordinal);
|
| +
|
| + @override
|
| + int get hashCode => ordinal;
|
| +
|
| + @override
|
| + int compareTo(SourceKind other) => ordinal - other.ordinal;
|
| +
|
| + @override
|
| + String toString() => name;
|
| }
|
|
|
| /**
|
| @@ -915,12 +776,10 @@ class SourceRange {
|
| int get hashCode => 31 * offset + length;
|
|
|
| @override
|
| - bool operator ==(Object obj) {
|
| - if (obj is! SourceRange) {
|
| - return false;
|
| - }
|
| - SourceRange sourceRange = obj as SourceRange;
|
| - return sourceRange.offset == offset && sourceRange.length == length;
|
| + bool operator ==(Object other) {
|
| + return other is SourceRange &&
|
| + other.offset == offset &&
|
| + other.length == length;
|
| }
|
|
|
| /**
|
| @@ -1007,7 +866,7 @@ class SourceRange {
|
| * The enumeration `UriKind` defines the different kinds of URI's that are known to the
|
| * analysis engine. These are used to keep track of the kind of URI associated with a given source.
|
| */
|
| -class UriKind extends Enum<UriKind> {
|
| +class UriKind implements Comparable<UriKind> {
|
| /**
|
| * A 'dart:' URI.
|
| */
|
| @@ -1025,6 +884,16 @@ class UriKind extends Enum<UriKind> {
|
|
|
| static const List<UriKind> values = const [DART_URI, FILE_URI, PACKAGE_URI];
|
|
|
| + /**
|
| + * The name of this URI kind.
|
| + */
|
| + final String name;
|
| +
|
| + /**
|
| + * The ordinal value of the URI kind.
|
| + */
|
| + final int ordinal;
|
| +
|
| /**
|
| * The single character encoding used to identify this kind of URI.
|
| */
|
| @@ -1032,17 +901,21 @@ class UriKind extends Enum<UriKind> {
|
|
|
| /**
|
| * Initialize a newly created URI kind to have the given encoding.
|
| - *
|
| - * @param encoding the single character encoding used to identify this kind of URI.
|
| */
|
| - const UriKind(String name, int ordinal, this.encoding) : super(name, ordinal);
|
| + const UriKind(this.name, this.ordinal, this.encoding);
|
| +
|
| + @override
|
| + int get hashCode => ordinal;
|
| +
|
| + @override
|
| + int compareTo(UriKind other) => ordinal - other.ordinal;
|
| +
|
| + @override
|
| + String toString() => name;
|
|
|
| /**
|
| - * Return the URI kind represented by the given encoding, or `null` if there is no kind with
|
| - * the given encoding.
|
| - *
|
| - * @param encoding the single character encoding used to identify the URI kind to be returned
|
| - * @return the URI kind represented by the given encoding
|
| + * Return the URI kind represented by the given [encoding], or `null` if there
|
| + * is no kind with the given encoding.
|
| */
|
| static UriKind fromEncoding(int encoding) {
|
| while (true) {
|
| @@ -1057,6 +930,20 @@ class UriKind extends Enum<UriKind> {
|
| }
|
| return null;
|
| }
|
| +
|
| + /**
|
| + * Return the URI kind corresponding to the given scheme string.
|
| + */
|
| + static UriKind fromScheme(String scheme) {
|
| + if (scheme == PackageMapUriResolver.PACKAGE_SCHEME) {
|
| + return UriKind.PACKAGE_URI;
|
| + } else if (scheme == DartUriResolver.DART_SCHEME) {
|
| + return UriKind.DART_URI;
|
| + } else if (scheme == ResourceUriResolver.FILE_SCHEME) {
|
| + return UriKind.FILE_URI;
|
| + }
|
| + return UriKind.FILE_URI;
|
| + }
|
| }
|
|
|
| /**
|
|
|