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

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

Issue 2079873002: Initial Bazel file resolver support. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rebase Created 4 years, 6 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 | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.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
new file mode 100644
index 0000000000000000000000000000000000000000..8198f46a2f8490cc407af3414184c91cbad68342
--- /dev/null
+++ b/pkg/analyzer/lib/src/generated/bazel.dart
@@ -0,0 +1,69 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// 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 analyzer.src.generated.bazel;
+
+import 'dart:core' hide Resource;
+
+import 'package:analyzer/file_system/file_system.dart';
+import 'package:analyzer/src/generated/source.dart';
+import 'package:analyzer/src/generated/source_io.dart';
+
+/**
+ * Instances of the class `BazelFileUriResolver` resolve `file` URI's by first
+ * resolving file uri's in the expected way, and then by looking in the
+ * corresponding generated directories.
+ */
+class BazelFileUriResolver extends ResourceUriResolver {
+ /**
+ * The Bazel workspace directory.
+ */
+ final Folder _workspaceDir;
+
+ /**
+ * The build directories that relative `file` URI's should use to resolve
+ * relative URIs.
+ */
+ final List<Folder> _buildDirectories;
+
+ BazelFileUriResolver(
+ ResourceProvider provider, this._workspaceDir, this._buildDirectories)
+ : super(provider);
+
+ @override
+ Source resolveAbsolute(Uri uri, [Uri actualUri]) {
+ if (!ResourceUriResolver.isFileUri(uri)) {
+ return null;
+ }
+
+ File uriFile = provider.getFile(provider.pathContext.fromUri(uri));
+ if (uriFile.exists) {
+ return uriFile.createSource(actualUri ?? uri);
+ }
+
+ String relativeFromWorkspaceDir = _getPathFromWorkspaceDir(uri);
+ if (_buildDirectories.isEmpty || relativeFromWorkspaceDir.isEmpty) {
+ return null;
+ }
+
+ for (Folder buildDir in _buildDirectories) {
+ File file = buildDir.getChildAssumingFile(relativeFromWorkspaceDir);
+ if (file.exists) {
+ return file.createSource(actualUri ?? uri);
+ }
+ }
+ return null;
+ }
+
+ String _getPathFromWorkspaceDir(Uri uri) {
+ String uriPath = uri.path;
+ String workspacePath = _workspaceDir.path;
+
+ if (uriPath.startsWith(workspacePath) &&
+ workspacePath.length < uriPath.length) {
+ return uriPath.substring(workspacePath.length + 1);
+ }
+ return '';
+ }
+}
« no previous file with comments | « pkg/analyzer/lib/src/context/context.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698