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

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

Issue 2403733002: Implement BazelPackageUriResolver.restoreAbsolute(). (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/bazel_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/bazel.dart
diff --git a/pkg/analyzer/lib/src/generated/bazel.dart b/pkg/analyzer/lib/src/generated/bazel.dart
index ae493a744e270fa34e055f712ee30538e15bfcd8..b81a0c8aee07dbc0f8023b8548ff91b7b060c722 100644
--- a/pkg/analyzer/lib/src/generated/bazel.dart
+++ b/pkg/analyzer/lib/src/generated/bazel.dart
@@ -10,6 +10,7 @@ import 'dart:core';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
+import 'package:analyzer/src/util/fast_uri.dart';
import 'package:path/path.dart';
/**
@@ -86,6 +87,53 @@ class BazelPackageUriResolver extends UriResolver {
}
});
}
+
+ @override
+ Uri restoreAbsolute(Source source) {
+ Context context = _workspace.provider.pathContext;
+ String path = source.fullName;
+
+ Uri restore(String root, String path) {
+ if (root != null && context.isWithin(root, path)) {
+ String relative = context.relative(path, from: root);
+ List<String> components = context.split(relative);
+ if (components.length >= 1 && components[0] == 'third_party') {
+ if (components.length > 4 &&
+ components[1] == 'dart' &&
+ components[3] == 'lib') {
+ String packageName = components[2];
+ String pathInLib = components.skip(4).join('/');
+ return FastUri.parse('package:$packageName/$pathInLib');
+ }
+ } else {
+ for (int i = 2; i < components.length - 1; i++) {
+ String component = components[i];
+ if (component == 'lib') {
+ String packageName = components.getRange(0, i).join('.');
+ String pathInLib = components.skip(i + 1).join('/');
+ return FastUri.parse('package:$packageName/$pathInLib');
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ // Search in each root.
+ for (String root in [
+ _workspace.bin,
+ _workspace.genfiles,
+ _workspace.readonly,
+ _workspace.root
+ ]) {
+ Uri uri = restore(root, path);
+ if (uri != null) {
+ return uri;
+ }
+ }
+
+ return null;
+ }
}
/**
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/bazel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698