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

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

Issue 1830463002: Change analyzer_cli's "package mode" into a "build mode". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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_io.dart
diff --git a/pkg/analyzer/lib/src/generated/source_io.dart b/pkg/analyzer/lib/src/generated/source_io.dart
index 56db0e4d4d240ed1dbbc39f653a1cd3bf3b0c189..b27e3a195e8764539925840efe34b612d6d54ab3 100644
--- a/pkg/analyzer/lib/src/generated/source_io.dart
+++ b/pkg/analyzer/lib/src/generated/source_io.dart
@@ -82,6 +82,44 @@ class DirectoryBasedSourceContainer implements SourceContainer {
}
/**
+ * Instances of the class [ExplicitSourceResolver] map URIs to files on disk
+ * using a fixed mapping provided at construction time.
+ */
+class ExplicitSourceResolver extends UriResolver {
+ final Map<Uri, JavaFile> uriToFileMap;
+ final Map<String, Uri> pathToUriMap;
+
+ /**
+ * Construct an [ExplicitSourceResolver] based on the given [uriToFileMap].
+ */
+ ExplicitSourceResolver(Map<Uri, JavaFile> uriToFileMap)
+ : uriToFileMap = uriToFileMap,
+ pathToUriMap = _computePathToUriMap(uriToFileMap);
+
+ @override
+ Source resolveAbsolute(Uri uri, [Uri actualUri]) {
+ return new FileBasedSource(uriToFileMap[uri], actualUri ?? uri);
+ }
+
+ @override
+ Uri restoreAbsolute(Source source) {
+ return pathToUriMap[source.fullName];
+ }
+
+ /**
+ * Build the inverse mapping of [uriToSourceMap].
+ */
+ static Map<String, Uri> _computePathToUriMap(
+ Map<Uri, JavaFile> uriToSourceMap) {
+ Map<String, Uri> pathToUriMap = <String, Uri>{};
+ uriToSourceMap.forEach((Uri uri, JavaFile file) {
+ pathToUriMap[file.getAbsolutePath()] = uri;
+ });
+ return pathToUriMap;
+ }
+}
+
+/**
* Instances of the class `FileBasedSource` implement a source that represents a file.
*/
class FileBasedSource extends Source {

Powered by Google App Engine
This is Rietveld 408576698