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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer.src.generated.bazel;
6
7 import 'dart:core' hide Resource;
8
9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/src/generated/source.dart';
11 import 'package:analyzer/src/generated/source_io.dart';
12
13 /**
14 * Instances of the class `BazelFileUriResolver` resolve `file` URI's by first
15 * resolving file uri's in the expected way, and then by looking in the
16 * corresponding generated directories.
17 */
18 class BazelFileUriResolver extends ResourceUriResolver {
19 /**
20 * The Bazel workspace directory.
21 */
22 final Folder _workspaceDir;
23
24 /**
25 * The build directories that relative `file` URI's should use to resolve
26 * relative URIs.
27 */
28 final List<Folder> _buildDirectories;
29
30 BazelFileUriResolver(
31 ResourceProvider provider, this._workspaceDir, this._buildDirectories)
32 : super(provider);
33
34 @override
35 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
36 if (!ResourceUriResolver.isFileUri(uri)) {
37 return null;
38 }
39
40 File uriFile = provider.getFile(provider.pathContext.fromUri(uri));
41 if (uriFile.exists) {
42 return uriFile.createSource(actualUri ?? uri);
43 }
44
45 String relativeFromWorkspaceDir = _getPathFromWorkspaceDir(uri);
46 if (_buildDirectories.isEmpty || relativeFromWorkspaceDir.isEmpty) {
47 return null;
48 }
49
50 for (Folder buildDir in _buildDirectories) {
51 File file = buildDir.getChildAssumingFile(relativeFromWorkspaceDir);
52 if (file.exists) {
53 return file.createSource(actualUri ?? uri);
54 }
55 }
56 return null;
57 }
58
59 String _getPathFromWorkspaceDir(Uri uri) {
60 String uriPath = uri.path;
61 String workspacePath = _workspaceDir.path;
62
63 if (uriPath.startsWith(workspacePath) &&
64 workspacePath.length < uriPath.length) {
65 return uriPath.substring(workspacePath.length + 1);
66 }
67 return '';
68 }
69 }
OLDNEW
« 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