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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 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 | « packages/analyzer/lib/src/generated/ast.dart ('k') | packages/analyzer/lib/src/generated/constant.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/analyzer/lib/src/generated/bazel.dart
diff --git a/packages/analyzer/lib/src/generated/bazel.dart b/packages/analyzer/lib/src/generated/bazel.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fc85e29740b4a071bc86bc2fbd85cdc2cfb77c2d
--- /dev/null
+++ b/packages/analyzer/lib/src/generated/bazel.dart
@@ -0,0 +1,67 @@
+// 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';
+
+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) {
+ try {
+ return provider.pathContext.relative(provider.pathContext.fromUri(uri),
+ from: _workspaceDir.path);
+ } on Exception {
+ return '';
+ }
+ }
+}
« no previous file with comments | « packages/analyzer/lib/src/generated/ast.dart ('k') | packages/analyzer/lib/src/generated/constant.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698