Skip to content

Commit 33e1740

Browse files
nateboschCommit Bot
authored andcommitted
Replace Uri.scheme == with Uri.isScheme
Use `hasScheme` in place of comparing against the empty string, and `isScheme` to compare against all other schemes. TEST=No behavior changes. Change-Id: Ifc9fd13c6cf37933ebd4a754c4b500dedbcb291b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231185 Reviewed-by: Kevin Moore <[email protected]> Commit-Queue: Nate Bosch <[email protected]>
1 parent 7282a40 commit 33e1740

File tree

161 files changed

+378
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+378
-358
lines changed

pkg/_fe_analyzer_shared/lib/src/util/libraries_specification.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class LibrariesSpecification {
238238
_reportError(messageIncludePathIsNotAString(targetName, specUri));
239239
}
240240
Uri uri = Uri.parse(path);
241-
if (uri.scheme != '' && uri.scheme != 'file') {
241+
if (uri.hasScheme && !uri.isScheme('file')) {
242242
return _reportError(messageUnsupportedUriScheme(path, specUri));
243243
}
244244
LibrariesSpecification specification =
@@ -269,7 +269,7 @@ class LibrariesSpecification {
269269
uriString, libraryName, targetName, specUri));
270270
}
271271
Uri uri = Uri.parse(uriString);
272-
if (uri.scheme != '' && uri.scheme != 'file') {
272+
if (uri.hasScheme && !uri.isScheme('file')) {
273273
return _reportError(
274274
messageUnsupportedUriScheme(uriString, specUri));
275275
}

pkg/_fe_analyzer_shared/lib/src/util/resolve_input_uri.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Uri resolveInputUri(String path) {
1818

1919
Uri parseUri(String path) {
2020
if (path.startsWith("file:")) {
21-
if (Uri.base.scheme == "file") {
21+
if (Uri.base.isScheme("file")) {
2222
// The Uri class doesn't handle relative file URIs correctly, the
2323
// following works around that issue.
2424
return new Uri(path: Uri.parse("x-$path").path);

pkg/_js_interop_checks/lib/js_interop_checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class JsInteropChecks extends RecursiveVisitor {
362362
/// or a from environment constructor.
363363
bool _isAllowedExternalUsage(Member member) {
364364
Uri uri = member.enclosingLibrary.importUri;
365-
return uri.scheme == 'dart' &&
365+
return uri.isScheme('dart') &&
366366
_pathsWithAllowedDartExternalUsage.contains(uri.path) ||
367367
_allowedNativeTestPatterns.any((pattern) => uri.path.contains(pattern));
368368
}

pkg/analysis_server/lib/src/computer/computer_hover.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DartUnitHoverComputer {
8282
if (library != null) {
8383
var uri = library.source.uri;
8484
var analysisSession = _unit.declaredElement?.session;
85-
if (uri.scheme == 'file' && analysisSession != null) {
85+
if (uri.isScheme('file') && analysisSession != null) {
8686
// for 'file:' URIs, use the path after the project root
8787
var context = analysisSession.resourceProvider.pathContext;
8888
var projectRootDir =

pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ protocol.ElementKind protocolElementKind(DeclarationKind kind) {
173173

174174
/// Computes the best URI to import [what] into the [unit] library.
175175
String? _getRelativeFileUri(DartCompletionRequest request, Uri what) {
176-
if (what.scheme == 'file') {
176+
if (what.isScheme('file')) {
177177
var pathContext = request.analysisSession.resourceProvider.pathContext;
178178

179179
var libraryPath = request.libraryElement.source.fullName;

pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ class ConvertToPackageImport extends CorrectionProducer {
4343
}
4444

4545
var importUri = uriSource.uri;
46-
if (importUri.scheme != 'package') {
46+
if (!importUri.isScheme('package')) {
4747
return;
4848
}
4949

5050
// Don't offer to convert a 'package:' URI to itself.
5151
try {
5252
var uriContent = importDirective.uriContent;
53-
if (uriContent == null || Uri.parse(uriContent).scheme == 'package') {
53+
if (uriContent == null || Uri.parse(uriContent).isScheme('package')) {
5454
return;
5555
}
5656
} on FormatException {

pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ConvertToRelativeImport extends CorrectionProducer {
4545

4646
// Ignore if the uri is not a package: uri.
4747
var sourceUri = resolvedResult.uri;
48-
if (sourceUri.scheme != 'package') {
48+
if (!sourceUri.isScheme('package')) {
4949
return;
5050
}
5151

@@ -61,7 +61,7 @@ class ConvertToRelativeImport extends CorrectionProducer {
6161
}
6262

6363
// Ignore if import uri is not a package: uri.
64-
if (importUri.scheme != 'package') {
64+
if (!importUri.isScheme('package')) {
6565
return;
6666
}
6767

pkg/analysis_server/lib/src/services/correction/util.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Map<String, Element> getImportNamespace(ImportElement imp) {
322322
/// Computes the best URI to import [what] into [from].
323323
String getLibrarySourceUri(
324324
path.Context pathContext, LibraryElement from, Uri what) {
325-
if (what.scheme == 'file') {
325+
if (what.isScheme('file')) {
326326
var fromFolder = pathContext.dirname(from.source.fullName);
327327
var relativeFile = pathContext.relative(what.path, from: fromFolder);
328328
return pathContext.split(relativeFile).join('/');

pkg/analyzer/lib/src/file_system/file_system.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ class ResourceUriResolver extends UriResolver {
3737
Uri restoreAbsolute(Source source) => pathToUri(source.fullName);
3838

3939
/// Return `true` if the given [uri] is a `file` URI.
40-
static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME;
40+
static bool isFileUri(Uri uri) => uri.isScheme(FILE_SCHEME);
4141
}

pkg/analyzer/lib/src/generated/source.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class BasicSource extends Source {
3131

3232
@Deprecated('Use uri.isScheme("dart") instead')
3333
@override
34-
bool get isInSystemLibrary => uri.scheme == 'dart';
34+
bool get isInSystemLibrary => uri.isScheme('dart');
3535

3636
@override
3737
String get shortName => pathos.basename(fullName);

0 commit comments

Comments
 (0)