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

Unified Diff: pkg/analyzer/lib/src/generated/source.dart

Issue 257773008: New analyzer snapshot, based on r35422. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update pubspec.yaml Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
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 c38eb08fce848b268c2bc65e612e467ff2636be2..767ff56495cfff0e57facaefecf8e615d409afcf 100644
--- a/pkg/analyzer/lib/src/generated/source.dart
+++ b/pkg/analyzer/lib/src/generated/source.dart
@@ -12,224 +12,6 @@ import 'sdk.dart' show DartSdk;
import 'engine.dart' show AnalysisContext, TimestampedData;
/**
- * Instances of interface `LocalSourcePredicate` are used to determine if the given
- * [Source] is "local" in some sense, so can be updated.
- */
-abstract class LocalSourcePredicate {
- /**
- * Instance of [LocalSourcePredicate] that always returns `false`.
- */
- static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE();
-
- /**
- * Instance of [LocalSourcePredicate] that always returns `true`.
- */
- static final LocalSourcePredicate TRUE = new LocalSourcePredicate_TRUE();
-
- /**
- * Instance of [LocalSourcePredicate] that returns `true` for all [Source]s
- * except of SDK.
- */
- static final LocalSourcePredicate NOT_SDK = new LocalSourcePredicate_NOT_SDK();
-
- /**
- * Determines if the given [Source] is local.
- *
- * @param source the [Source] to analyze
- * @return `true` if the given [Source] is local
- */
- bool isLocal(Source source);
-}
-
-class LocalSourcePredicate_FALSE implements LocalSourcePredicate {
- @override
- bool isLocal(Source source) => false;
-}
-
-class LocalSourcePredicate_TRUE implements LocalSourcePredicate {
- @override
- bool isLocal(Source source) => true;
-}
-
-class LocalSourcePredicate_NOT_SDK implements LocalSourcePredicate {
- @override
- bool isLocal(Source source) => source.uriKind != UriKind.DART_URI;
-}
-
-/**
- * Instances of the class `SourceFactory` resolve possibly relative URI's against an existing
- * [Source].
- */
-class SourceFactory {
- /**
- * The analysis context that this source factory is associated with.
- */
- AnalysisContext context;
-
- /**
- * The resolvers used to resolve absolute URI's.
- */
- final List<UriResolver> _resolvers;
-
- /**
- * The predicate to determine is [Source] is local.
- */
- LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK;
-
- /**
- * Initialize a newly created source factory.
- *
- * @param resolvers the resolvers used to resolve absolute URI's
- */
- SourceFactory(this._resolvers);
-
- /**
- * 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);
- }
- } on URISyntaxException catch (exception) {
- }
- return null;
- }
-
- /**
- * 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#getEncoding()
- */
- Source fromEncoding(String encoding) {
- if (encoding.length < 2) {
- throw new IllegalArgumentException("Invalid encoding length");
- }
- UriKind kind = UriKind.fromEncoding(encoding.codeUnitAt(0));
- if (kind == null) {
- throw new IllegalArgumentException("Invalid source kind in encoding: ${kind}");
- }
- try {
- Uri uri = parseUriWithException(encoding.substring(1));
- for (UriResolver resolver in _resolvers) {
- Source result = resolver.fromEncoding(kind, uri);
- if (result != null) {
- return result;
- }
- }
- throw new IllegalArgumentException("No resolver for kind: ${kind}");
- } on JavaException catch (exception) {
- throw new IllegalArgumentException("Invalid URI in encoding");
- }
- }
-
- /**
- * 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;
- }
-
- /**
- * Determines if the given [Source] is local.
- *
- * @param source the [Source] to analyze
- * @return `true` if the given [Source] is local
- */
- bool isLocalSource(Source source) => _localSourcePredicate.isLocal(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
- */
- 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));
- } on URISyntaxException catch (exception) {
- return null;
- }
- }
-
- /**
- * 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) {
- for (UriResolver resolver in _resolvers) {
- Uri uri = resolver.restoreAbsolute(source);
- if (uri != null) {
- return uri;
- }
- }
- return null;
- }
-
- /**
- * Sets the [LocalSourcePredicate].
- *
- * @param localSourcePredicate the predicate to determine is [Source] is local
- */
- void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) {
- this._localSourcePredicate = localSourcePredicate;
- }
-
- /**
- * 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.
- *
- * @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
- */
- Source _internalResolveUri(Source containingSource, Uri containedUri) {
- if (containedUri.isAbsolute) {
- for (UriResolver resolver in _resolvers) {
- Source result = resolver.resolveAbsolute(containedUri);
- if (result != null) {
- return result;
- }
- }
- return null;
- } else {
- return containingSource.resolveRelative(containedUri);
- }
- }
-}
-
-/**
* The abstract class `UriResolver` defines the behavior of objects that are used to resolve
* URI's for a source factory. Subclasses of this class are expected to resolve a single scheme of
* absolute URI.
@@ -429,99 +211,439 @@ abstract class Source_ContentReceiver {
}
/**
- * The enumeration `SourceKind` defines the different kinds of sources that are known to the
- * analysis engine.
+ * Instances of interface `LocalSourcePredicate` are used to determine if the given
+ * [Source] is "local" in some sense, so can be updated.
*/
-class SourceKind extends Enum<SourceKind> {
+abstract class LocalSourcePredicate {
/**
- * A source containing HTML. The HTML might or might not contain Dart scripts.
+ * Instance of [LocalSourcePredicate] that always returns `false`.
*/
- static const SourceKind HTML = const SourceKind('HTML', 0);
+ static final LocalSourcePredicate FALSE = new LocalSourcePredicate_FALSE();
/**
- * A Dart compilation unit that is not a part of another library. Libraries might or might not
- * contain any directives, including a library directive.
+ * Instance of [LocalSourcePredicate] that always returns `true`.
*/
- static const SourceKind LIBRARY = const SourceKind('LIBRARY', 1);
+ static final LocalSourcePredicate TRUE = new LocalSourcePredicate_TRUE();
/**
- * A Dart compilation unit that is part of another library. Parts contain a part-of directive.
+ * Instance of [LocalSourcePredicate] that returns `true` for all [Source]s
+ * except of SDK.
*/
- static const SourceKind PART = const SourceKind('PART', 2);
+ static final LocalSourcePredicate NOT_SDK = new LocalSourcePredicate_NOT_SDK();
/**
- * 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.
+ * Determines if the given [Source] is local.
+ *
+ * @param source the [Source] to analyze
+ * @return `true` if the given [Source] is local
*/
- static const SourceKind UNKNOWN = const SourceKind('UNKNOWN', 3);
-
- static const List<SourceKind> values = const [HTML, LIBRARY, PART, UNKNOWN];
+ bool isLocal(Source source);
+}
- const SourceKind(String name, int ordinal) : super(name, ordinal);
+class LocalSourcePredicate_FALSE implements LocalSourcePredicate {
+ @override
+ bool isLocal(Source source) => false;
}
-/**
- * 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 LocalSourcePredicate_TRUE implements LocalSourcePredicate {
+ @override
+ bool isLocal(Source source) => true;
+}
+
+class LocalSourcePredicate_NOT_SDK implements LocalSourcePredicate {
+ @override
+ bool isLocal(Source source) => source.uriKind != UriKind.DART_URI;
+}
+
+/**
+ * Instances of the class `LineInfo` encapsulate information about line and column information
+ * within a source file.
*/
-class UriKind extends Enum<UriKind> {
+class LineInfo {
/**
- * A 'dart:' URI.
+ * An array containing the offsets of the first character of each line in the source code.
*/
- static const UriKind DART_URI = const UriKind('DART_URI', 0, 0x64);
+ final List<int> _lineStarts;
/**
- * A 'file:' URI.
+ * 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
*/
- static const UriKind FILE_URI = const UriKind('FILE_URI', 1, 0x66);
+ 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");
+ }
+ }
/**
- * A 'package:' URI referencing source package itself.
+ * 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
*/
- static const UriKind PACKAGE_SELF_URI = const UriKind('PACKAGE_SELF_URI', 2, 0x73);
+ LineInfo_Location getLocation(int offset) {
+ int lineCount = _lineStarts.length;
+ for (int i = 1; i < lineCount; i++) {
+ if (offset < _lineStarts[i]) {
+ return new LineInfo_Location(i, offset - _lineStarts[i - 1] + 1);
+ }
+ }
+ return new LineInfo_Location(lineCount, offset - _lineStarts[lineCount - 1] + 1);
+ }
+}
+/**
+ * Instances of the class `Location` represent the location of a character as a line and
+ * column pair.
+ */
+class LineInfo_Location {
/**
- * A 'package:' URI.
+ * The one-based index of the line containing the character.
*/
- static const UriKind PACKAGE_URI = const UriKind('PACKAGE_URI', 3, 0x70);
+ final int lineNumber;
- static const List<UriKind> values = const [DART_URI, FILE_URI, PACKAGE_SELF_URI, PACKAGE_URI];
+ /**
+ * The one-based index of the column containing the character.
+ */
+ final int columnNumber;
/**
- * Return the URI kind represented by the given encoding, or `null` if there is no kind with
- * the given encoding.
+ * Initialize a newly created location to represent the location of the character at the given
+ * line and column position.
*
- * @param encoding the single character encoding used to identify the URI kind to be returned
- * @return the URI kind represented by the given encoding
+ * @param lineNumber the one-based index of the line containing the character
+ * @param columnNumber the one-based index of the column containing the character
*/
- static UriKind fromEncoding(int encoding) {
- while (true) {
- if (encoding == 0x64) {
- return DART_URI;
- } else if (encoding == 0x66) {
- return FILE_URI;
- } else if (encoding == 0x73) {
- return PACKAGE_SELF_URI;
- } else if (encoding == 0x70) {
- return PACKAGE_URI;
+ LineInfo_Location(this.lineNumber, this.columnNumber);
+}
+
+/**
+ * Instances of class `ContentCache` hold content used to override the default content of a
+ * [Source].
+ */
+class ContentCache {
+ /**
+ * A table mapping sources to the contents of those sources. This is used to override the default
+ * contents of a source.
+ */
+ Map<Source, String> _contentMap = new Map<Source, String>();
+
+ /**
+ * A table mapping sources to the modification stamps of those sources. This is used when the
+ * default contents of a source has been overridden.
+ */
+ Map<Source, int> _stampMap = new Map<Source, int>();
+
+ /**
+ * Return the contents of the given source, or `null` if this cache does not override the
+ * contents of the source.
+ *
+ * <b>Note:</b> This method is not intended to be used except by
+ * [AnalysisContext#getContents].
+ *
+ * @param source the source whose content is to be returned
+ * @return the contents of the given source
+ */
+ String getContents(Source source) => _contentMap[source];
+
+ /**
+ * Return the modification stamp of the given source, or `null` if this cache does not
+ * override the contents of the source.
+ *
+ * <b>Note:</b> This method is not intended to be used except by
+ * [AnalysisContext#getModificationStamp].
+ *
+ * @param source the source whose modification stamp is to be returned
+ * @return the modification stamp of the given source
+ */
+ int getModificationStamp(Source source) => _stampMap[source];
+
+ /**
+ * Set the contents of the given source to the given contents. This has the effect of overriding
+ * the default contents of the source. If the contents are `null` the override is removed so
+ * that the default contents will be returned.
+ *
+ * @param source the source whose contents are being overridden
+ * @param contents the new contents of the source
+ * @return the original cached contents or `null` if none
+ */
+ String setContents(Source source, String contents) {
+ if (contents == null) {
+ _stampMap.remove(source);
+ return _contentMap.remove(source);
+ } else {
+ int newStamp = JavaSystem.currentTimeMillis();
+ int oldStamp = javaMapPut(_stampMap, source, newStamp);
+ // Occasionally, if this method is called in rapid succession, the timestamps are equal.
+ // Guard against this by artificially incrementing the new timestamp
+ if (newStamp == oldStamp) {
+ _stampMap[source] = newStamp + 1;
+ }
+ return javaMapPut(_contentMap, source, contents);
+ }
+ }
+}
+
+/**
+ * Instances of the class `DartUriResolver` resolve `dart` URI's.
+ */
+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.
+ */
+ final DartSdk _sdk;
+
+ /**
+ * The name of the `dart` scheme.
+ */
+ 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
+ * @return `true` if the given URI is a `dart:` URI
+ */
+ static bool isDartUri(Uri uri) => _DART_SCHEME == uri.scheme;
+
+ /**
+ * Initialize a newly created resolver to resolve Dart URI's against the given platform within the
+ * given Dart SDK.
+ *
+ * @param sdk the Dart SDK against which URI's are to be resolved
+ */
+ DartUriResolver(this._sdk);
+
+ @override
+ Source fromEncoding(UriKind kind, Uri uri) {
+ if (kind == UriKind.DART_URI) {
+ return _sdk.fromEncoding(kind, uri);
+ }
+ return null;
+ }
+
+ /**
+ * Return the [DartSdk] against which URIs are to be resolved.
+ *
+ * @return the [DartSdk] against which URIs are to be resolved.
+ */
+ DartSdk get dartSdk => _sdk;
+
+ @override
+ Source resolveAbsolute(Uri uri) {
+ if (!isDartUri(uri)) {
+ return null;
+ }
+ return _sdk.mapDartUri(uri.toString());
+ }
+}
+
+/**
+ * Instances of the class `SourceFactory` resolve possibly relative URI's against an existing
+ * [Source].
+ */
+class SourceFactory {
+ /**
+ * The analysis context that this source factory is associated with.
+ */
+ AnalysisContext context;
+
+ /**
+ * The resolvers used to resolve absolute URI's.
+ */
+ final List<UriResolver> _resolvers;
+
+ /**
+ * The predicate to determine is [Source] is local.
+ */
+ LocalSourcePredicate _localSourcePredicate = LocalSourcePredicate.NOT_SDK;
+
+ /**
+ * Initialize a newly created source factory.
+ *
+ * @param resolvers the resolvers used to resolve absolute URI's
+ */
+ SourceFactory(this._resolvers);
+
+ /**
+ * 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);
+ }
+ } on URISyntaxException catch (exception) {
+ }
+ return null;
+ }
+
+ /**
+ * 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#getEncoding()
+ */
+ Source fromEncoding(String encoding) {
+ if (encoding.length < 2) {
+ throw new IllegalArgumentException("Invalid encoding length");
+ }
+ UriKind kind = UriKind.fromEncoding(encoding.codeUnitAt(0));
+ if (kind == null) {
+ throw new IllegalArgumentException("Invalid source kind in encoding: ${kind}");
+ }
+ try {
+ Uri uri = parseUriWithException(encoding.substring(1));
+ for (UriResolver resolver in _resolvers) {
+ Source result = resolver.fromEncoding(kind, uri);
+ if (result != null) {
+ return result;
+ }
+ }
+ throw new IllegalArgumentException("No resolver for kind: ${kind}");
+ } on JavaException catch (exception) {
+ throw new IllegalArgumentException("Invalid URI in encoding");
+ }
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Determines if the given [Source] is local.
+ *
+ * @param source the [Source] to analyze
+ * @return `true` if the given [Source] is local
+ */
+ bool isLocalSource(Source source) => _localSourcePredicate.isLocal(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
+ */
+ 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));
+ } on URISyntaxException catch (exception) {
+ return null;
+ }
+ }
+
+ /**
+ * 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) {
+ for (UriResolver resolver in _resolvers) {
+ Uri uri = resolver.restoreAbsolute(source);
+ if (uri != null) {
+ return uri;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Sets the [LocalSourcePredicate].
+ *
+ * @param localSourcePredicate the predicate to determine is [Source] is local
+ */
+ void set localSourcePredicate(LocalSourcePredicate localSourcePredicate) {
+ this._localSourcePredicate = localSourcePredicate;
+ }
+
+ /**
+ * 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.
+ *
+ * @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
+ */
+ Source _internalResolveUri(Source containingSource, Uri containedUri) {
+ if (containedUri.isAbsolute) {
+ for (UriResolver resolver in _resolvers) {
+ Source result = resolver.resolveAbsolute(containedUri);
+ if (result != null) {
+ return result;
+ }
}
- break;
+ return null;
+ } else {
+ return containingSource.resolveRelative(containedUri);
}
- return null;
}
+}
+/**
+ * The interface `SourceContainer` is used by clients to define a collection of sources
+ *
+ * Source containers are not used within analysis engine, but can be used by clients to group
+ * sources for the purposes of accessing composite dependency information. For example, the Eclipse
+ * client uses source containers to represent Eclipse projects, which allows it to easily compute
+ * project-level dependencies.
+ */
+abstract class SourceContainer {
/**
- * The single character encoding used to identify this kind of URI.
- */
- final int encoding;
-
- /**
- * Initialize a newly created URI kind to have the given encoding.
+ * Determine if the specified source is part of the receiver's collection of sources.
*
- * @param encoding the single character encoding used to identify this kind of URI.
+ * @param source the source in question
+ * @return `true` if the receiver contains the source, else `false`
*/
- const UriKind(String name, int ordinal, this.encoding) : super(name, ordinal);
+ bool contains(Source source);
}
/**
@@ -657,219 +779,97 @@ class SourceRange {
}
/**
- * The interface `SourceContainer` is used by clients to define a collection of sources
- *
- * Source containers are not used within analysis engine, but can be used by clients to group
- * sources for the purposes of accessing composite dependency information. For example, the Eclipse
- * client uses source containers to represent Eclipse projects, which allows it to easily compute
- * project-level dependencies.
- */
-abstract class SourceContainer {
- /**
- * Determine if the specified source is part of the receiver's collection of sources.
- *
- * @param source the source in question
- * @return `true` if the receiver contains the source, else `false`
- */
- bool contains(Source source);
-}
-
-/**
- * Instances of the class `DartUriResolver` resolve `dart` URI's.
+ * The enumeration `SourceKind` defines the different kinds of sources that are known to the
+ * analysis engine.
*/
-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.
- */
- final DartSdk _sdk;
-
- /**
- * The name of the `dart` scheme.
- */
- 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:";
-
+class SourceKind extends Enum<SourceKind> {
/**
- * Return `true` if the given URI is a `dart:` URI.
- *
- * @param uri the URI being tested
- * @return `true` if the given URI is a `dart:` URI
+ * A source containing HTML. The HTML might or might not contain Dart scripts.
*/
- static bool isDartUri(Uri uri) => _DART_SCHEME == uri.scheme;
+ static const SourceKind HTML = const SourceKind('HTML', 0);
/**
- * Initialize a newly created resolver to resolve Dart URI's against the given platform within the
- * given Dart SDK.
- *
- * @param sdk the Dart SDK against which URI's are to be resolved
+ * A Dart compilation unit that is not a part of another library. Libraries might or might not
+ * contain any directives, including a library directive.
*/
- DartUriResolver(this._sdk);
-
- @override
- Source fromEncoding(UriKind kind, Uri uri) {
- if (kind == UriKind.DART_URI) {
- return _sdk.fromEncoding(kind, uri);
- }
- return null;
- }
+ static const SourceKind LIBRARY = const SourceKind('LIBRARY', 1);
/**
- * Return the [DartSdk] against which URIs are to be resolved.
- *
- * @return the [DartSdk] against which URIs are to be resolved.
+ * A Dart compilation unit that is part of another library. Parts contain a part-of directive.
*/
- DartSdk get dartSdk => _sdk;
-
- @override
- Source resolveAbsolute(Uri uri) {
- if (!isDartUri(uri)) {
- return null;
- }
- return _sdk.mapDartUri(uri.toString());
- }
-}
+ static const SourceKind PART = const SourceKind('PART', 2);
-/**
- * Instances of the class `LineInfo` encapsulate 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.
+ * 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.
*/
- final List<int> _lineStarts;
+ static const SourceKind UNKNOWN = const SourceKind('UNKNOWN', 3);
- /**
- * 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
- */
- 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");
- }
- }
+ static const List<SourceKind> values = const [HTML, LIBRARY, PART, UNKNOWN];
- /**
- * 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
- */
- LineInfo_Location getLocation(int offset) {
- int lineCount = _lineStarts.length;
- for (int i = 1; i < lineCount; i++) {
- if (offset < _lineStarts[i]) {
- return new LineInfo_Location(i, offset - _lineStarts[i - 1] + 1);
- }
- }
- return new LineInfo_Location(lineCount, offset - _lineStarts[lineCount - 1] + 1);
- }
+ const SourceKind(String name, int ordinal) : super(name, ordinal);
}
/**
- * Instances of the class `Location` represent the location of a character as a line and
- * column pair.
+ * 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 LineInfo_Location {
+class UriKind extends Enum<UriKind> {
/**
- * The one-based index of the line containing the character.
+ * A 'dart:' URI.
*/
- final int lineNumber;
+ static const UriKind DART_URI = const UriKind('DART_URI', 0, 0x64);
/**
- * The one-based index of the column containing the character.
+ * A 'file:' URI.
*/
- final int columnNumber;
+ static const UriKind FILE_URI = const UriKind('FILE_URI', 1, 0x66);
/**
- * Initialize a newly created location to represent the location of the character at the given
- * line and column position.
- *
- * @param lineNumber the one-based index of the line containing the character
- * @param columnNumber the one-based index of the column containing the character
+ * A 'package:' URI referencing source package itself.
*/
- LineInfo_Location(this.lineNumber, this.columnNumber);
-}
+ static const UriKind PACKAGE_SELF_URI = const UriKind('PACKAGE_SELF_URI', 2, 0x73);
-/**
- * Instances of class `ContentCache` hold content used to override the default content of a
- * [Source].
- */
-class ContentCache {
/**
- * A table mapping sources to the contents of those sources. This is used to override the default
- * contents of a source.
+ * A 'package:' URI.
*/
- Map<Source, String> _contentMap = new Map<Source, String>();
+ static const UriKind PACKAGE_URI = const UriKind('PACKAGE_URI', 3, 0x70);
- /**
- * A table mapping sources to the modification stamps of those sources. This is used when the
- * default contents of a source has been overridden.
- */
- Map<Source, int> _stampMap = new Map<Source, int>();
+ static const List<UriKind> values = const [DART_URI, FILE_URI, PACKAGE_SELF_URI, PACKAGE_URI];
/**
- * Return the contents of the given source, or `null` if this cache does not override the
- * contents of the source.
- *
- * <b>Note:</b> This method is not intended to be used except by
- * [AnalysisContext#getContents].
+ * Return the URI kind represented by the given encoding, or `null` if there is no kind with
+ * the given encoding.
*
- * @param source the source whose content is to be returned
- * @return the contents of the given source
+ * @param encoding the single character encoding used to identify the URI kind to be returned
+ * @return the URI kind represented by the given encoding
*/
- String getContents(Source source) => _contentMap[source];
+ static UriKind fromEncoding(int encoding) {
+ while (true) {
+ if (encoding == 0x64) {
+ return DART_URI;
+ } else if (encoding == 0x66) {
+ return FILE_URI;
+ } else if (encoding == 0x73) {
+ return PACKAGE_SELF_URI;
+ } else if (encoding == 0x70) {
+ return PACKAGE_URI;
+ }
+ break;
+ }
+ return null;
+ }
/**
- * Return the modification stamp of the given source, or `null` if this cache does not
- * override the contents of the source.
- *
- * <b>Note:</b> This method is not intended to be used except by
- * [AnalysisContext#getModificationStamp].
- *
- * @param source the source whose modification stamp is to be returned
- * @return the modification stamp of the given source
+ * The single character encoding used to identify this kind of URI.
*/
- int getModificationStamp(Source source) => _stampMap[source];
+ final int encoding;
/**
- * Set the contents of the given source to the given contents. This has the effect of overriding
- * the default contents of the source. If the contents are `null` the override is removed so
- * that the default contents will be returned.
+ * Initialize a newly created URI kind to have the given encoding.
*
- * @param source the source whose contents are being overridden
- * @param contents the new contents of the source
- * @return the original cached contents or `null` if none
+ * @param encoding the single character encoding used to identify this kind of URI.
*/
- String setContents(Source source, String contents) {
- if (contents == null) {
- _stampMap.remove(source);
- return _contentMap.remove(source);
- } else {
- int newStamp = JavaSystem.currentTimeMillis();
- int oldStamp = javaMapPut(_stampMap, source, newStamp);
- // Occasionally, if this method is called in rapid succession, the timestamps are equal.
- // Guard against this by artificially incrementing the new timestamp
- if (newStamp == oldStamp) {
- _stampMap[source] = newStamp + 1;
- }
- return javaMapPut(_contentMap, source, contents);
- }
- }
+ const UriKind(String name, int ordinal, this.encoding) : super(name, ordinal);
}

Powered by Google App Engine
This is Rietveld 408576698