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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.source_io; 5 library analyzer.src.generated.source_io;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (path == null || 75 if (path == null ||
76 path.length <= 0 || 76 path.length <= 0 ||
77 path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) { 77 path.codeUnitAt(path.length - 1) == JavaFile.separatorChar) {
78 return path; 78 return path;
79 } 79 }
80 return "$path${JavaFile.separator}"; 80 return "$path${JavaFile.separator}";
81 } 81 }
82 } 82 }
83 83
84 /** 84 /**
85 * Instances of the class [ExplicitSourceResolver] map URIs to files on disk
86 * using a fixed mapping provided at construction time.
87 */
88 class ExplicitSourceResolver extends UriResolver {
89 final Map<Uri, JavaFile> uriToFileMap;
90 final Map<String, Uri> pathToUriMap;
91
92 /**
93 * Construct an [ExplicitSourceResolver] based on the given [uriToFileMap].
94 */
95 ExplicitSourceResolver(Map<Uri, JavaFile> uriToFileMap)
96 : uriToFileMap = uriToFileMap,
97 pathToUriMap = _computePathToUriMap(uriToFileMap);
98
99 @override
100 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
101 return new FileBasedSource(uriToFileMap[uri], actualUri ?? uri);
102 }
103
104 @override
105 Uri restoreAbsolute(Source source) {
106 return pathToUriMap[source.fullName];
107 }
108
109 /**
110 * Build the inverse mapping of [uriToSourceMap].
111 */
112 static Map<String, Uri> _computePathToUriMap(
113 Map<Uri, JavaFile> uriToSourceMap) {
114 Map<String, Uri> pathToUriMap = <String, Uri>{};
115 uriToSourceMap.forEach((Uri uri, JavaFile file) {
116 pathToUriMap[file.getAbsolutePath()] = uri;
117 });
118 return pathToUriMap;
119 }
120 }
121
122 /**
85 * Instances of the class `FileBasedSource` implement a source that represents a file. 123 * Instances of the class `FileBasedSource` implement a source that represents a file.
86 */ 124 */
87 class FileBasedSource extends Source { 125 class FileBasedSource extends Source {
88 /** 126 /**
89 * A function that changes the way that files are read off of disk. 127 * A function that changes the way that files are read off of disk.
90 */ 128 */
91 static Function fileReadMode = (String s) => s; 129 static Function fileReadMode = (String s) => s;
92 130
93 /** 131 /**
94 * Map from encoded URI/filepath pair to a unique integer identifier. This 132 * Map from encoded URI/filepath pair to a unique integer identifier. This
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 579 }
542 580
543 /** 581 /**
544 * Return `true` if the given URI is a `file` URI. 582 * Return `true` if the given URI is a `file` URI.
545 * 583 *
546 * @param uri the URI being tested 584 * @param uri the URI being tested
547 * @return `true` if the given URI is a `file` URI 585 * @return `true` if the given URI is a `file` URI
548 */ 586 */
549 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; 587 static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
550 } 588 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698