Skip to content

Commit 33e1740

Browse files
nateboschCommit Bot
authored and
Commit Bot
committed
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);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ class PackageMapUriResolver extends UriResolver {
7979

8080
/// Returns `true` if [uri] is a `package` URI.
8181
static bool isPackageUri(Uri uri) {
82-
return uri.scheme == PACKAGE_SCHEME;
82+
return uri.isScheme(PACKAGE_SCHEME);
8383
}
8484
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class FileSource extends Source {
8080

8181
@Deprecated('Use uri.isScheme("dart") instead')
8282
@override
83-
bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME;
83+
bool get isInSystemLibrary => uri.isScheme(DartUriResolver.DART_SCHEME);
8484

8585
@Deprecated('Not used anymore')
8686
@override

pkg/analyzer/lib/src/workspace/bazel.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ class BazelPackageUriResolver extends UriResolver {
8383
}
8484

8585
Source? _resolveAbsolute(Uri uri) {
86-
if (uri.scheme == 'file') {
86+
if (uri.isScheme('file')) {
8787
var path = fileUriToNormalizedPath(_context, uri);
8888
var pathRelativeToRoot = _workspace._relativeToRoot(path);
8989
if (pathRelativeToRoot == null) return null;
9090
var fullFilePath = _context.join(_workspace.root, pathRelativeToRoot);
9191
var file = _workspace.findFile(fullFilePath);
9292
return file?.createSource(uri);
9393
}
94-
if (uri.scheme != 'package') {
94+
if (!uri.isScheme('package')) {
9595
return null;
9696
}
9797
String uriPath = Uri.decodeComponent(uri.path);

pkg/analyzer/lib/src/workspace/package_build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class PackageBuildPackageUriResolver extends UriResolver {
7373

7474
@override
7575
Source? resolveAbsolute(Uri uri) {
76-
if (uri.scheme != 'package') {
76+
if (!uri.isScheme('package')) {
7777
return null;
7878
}
7979

pkg/analyzer/lib/src/workspace/workspace.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ abstract class WorkspacePackage {
8282
/// example, the case of a [InSummarySource]). In this case, use
8383
/// [workspace]'s package URI resolver to fetch the file path.
8484
String? filePathFromSource(Source source) {
85-
if (source.uri.scheme == 'package') {
85+
if (source.uri.isScheme('package')) {
8686
return workspace.packageUriResolver.resolveAbsolute(source.uri)?.fullName;
8787
} else {
8888
return source.fullName;

pkg/analyzer/test/generated/test_support.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ class TestSourceWithUri extends TestSource {
530530
@Deprecated('Use Source.uri instead')
531531
@override
532532
UriKind get uriKind {
533-
if (uri.scheme == 'dart') {
533+
if (uri.isScheme('dart')) {
534534
return UriKind.DART_URI;
535-
} else if (uri.scheme == 'package') {
535+
} else if (uri.isScheme('package')) {
536536
return UriKind.PACKAGE_URI;
537537
}
538538
return UriKind.FILE_URI;

pkg/analyzer/test/src/dart/analysis/file_state_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ part of 'a.dart';
783783
if (file is LibraryCycle) {
784784
return !file.libraries.any((file) => file.uri.isScheme('dart'));
785785
} else if (file is FileState) {
786-
return file.uri.scheme != 'dart';
786+
return !file.uri.isScheme('dart');
787787
} else if (file == null) {
788788
return true;
789789
} else {

pkg/analyzer_cli/lib/src/analyzer_impl.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class AnalyzerImpl {
127127
files.clear();
128128
errorsResults.clear();
129129
var libraryUri = libraryFile.uri;
130-
if (libraryUri.scheme == 'package' && libraryUri.pathSegments.isNotEmpty) {
130+
if (libraryUri.isScheme('package') && libraryUri.pathSegments.isNotEmpty) {
131131
_selfPackageName = libraryUri.pathSegments[0];
132132
}
133133
}
@@ -177,7 +177,7 @@ class AnalyzerImpl {
177177

178178
/// Determine whether the given URI refers to a package being analyzed.
179179
bool _isAnalyzedPackage(Uri uri) {
180-
if (uri.scheme != 'package' || uri.pathSegments.isEmpty) {
180+
if (!uri.isScheme('package') || uri.pathSegments.isEmpty) {
181181
return false;
182182
}
183183
var packageName = uri.pathSegments.first;

pkg/build_integration/lib/file_system/multi_root.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class MultiRootFileSystemEntity implements FileSystemEntity {
5252
_delegate ??= await _resolveEntity();
5353

5454
Future<FileSystemEntity> _resolveEntity() async {
55-
if (uri.scheme == multiRootFileSystem.markerScheme) {
55+
if (uri.isScheme(multiRootFileSystem.markerScheme)) {
5656
if (!uri.isAbsolute) {
5757
throw new FileSystemException(
5858
uri, "This MultiRootFileSystem only handles absolutes URIs: $uri");

pkg/build_integration/lib/file_system/single_root.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SingleRootFileSystem implements FileSystem {
3333

3434
@override
3535
FileSystemEntity entityForUri(Uri uri) {
36-
if (uri.scheme != markerScheme) {
36+
if (!uri.isScheme(markerScheme)) {
3737
throw new FileSystemException(
3838
uri,
3939
"This SingleRootFileSystem only handles URIs with the '$markerScheme'"

pkg/compiler/lib/src/compiler.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ abstract class Compiler {
726726
Uri getCanonicalUri(Entity element) {
727727
Uri libraryUri = _uriFromElement(element);
728728
if (libraryUri == null) return null;
729-
if (libraryUri.scheme == 'package') {
729+
if (libraryUri.isScheme('package')) {
730730
int slashPos = libraryUri.path.indexOf('/');
731731
if (slashPos != -1) {
732732
String packageName = libraryUri.path.substring(0, slashPos);

pkg/compiler/lib/src/dart2js.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ class AbortLeg {
11021102

11031103
void writeString(Uri uri, String text) {
11041104
if (!enableWriteString) return;
1105-
if (uri.scheme != 'file') {
1105+
if (!uri.isScheme('file')) {
11061106
fail('Unhandled scheme ${uri.scheme}.');
11071107
}
11081108
var file = (File(uri.toFilePath())..createSync(recursive: true))

pkg/compiler/lib/src/diagnostics/code_location.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class CodeLocation {
1818
String relativize(Uri baseUri);
1919

2020
factory CodeLocation(Uri uri) {
21-
if (uri.scheme == 'package') {
21+
if (uri.isScheme('package')) {
2222
int slashPos = uri.path.indexOf('/');
2323
if (slashPos != -1) {
2424
String packageName = uri.path.substring(0, slashPos);
@@ -42,7 +42,7 @@ class SchemeLocation implements CodeLocation {
4242

4343
@override
4444
bool inSameLocation(Uri uri) {
45-
return this.uri.scheme == uri.scheme;
45+
return this.uri.isScheme(uri.scheme);
4646
}
4747

4848
@override
@@ -62,7 +62,7 @@ class PackageLocation implements CodeLocation {
6262

6363
@override
6464
bool inSameLocation(Uri uri) {
65-
return uri.scheme == 'package' && uri.path.startsWith('$packageName/');
65+
return uri.isScheme('package') && uri.path.startsWith('$packageName/');
6666
}
6767

6868
@override

pkg/compiler/lib/src/elements/entity_utils.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ int compareLibrariesUris(Uri a, Uri b) {
1919
}
2020

2121
// Order: platform < package < other.
22-
if (a.scheme == 'dart') {
23-
if (b.scheme == 'dart') return byCanonicalUriPath();
22+
if (a.isScheme('dart')) {
23+
if (b.isScheme('dart')) return byCanonicalUriPath();
2424
return -1;
2525
}
26-
if (b.scheme == 'dart') return 1;
26+
if (b.isScheme('dart')) return 1;
2727

28-
if (a.scheme == 'package') {
29-
if (b.scheme == 'package') return byCanonicalUriPath();
28+
if (a.isScheme('package')) {
29+
if (b.isScheme('package')) return byCanonicalUriPath();
3030
return -1;
3131
}
32-
if (b.scheme == 'package') return 1;
32+
if (b.isScheme('package')) return 1;
3333

3434
return _compareCanonicalUri(a, b);
3535
}

pkg/compiler/lib/src/ir/util.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool containsFreeVariables(ir.DartType type) =>
251251

252252
/// Returns true if [importUri] corresponds to dart:html and related libraries.
253253
bool _isWebLibrary(Uri importUri) =>
254-
importUri.scheme == 'dart' &&
254+
importUri.isScheme('dart') &&
255255
(importUri.path == 'html' ||
256256
importUri.path == 'svg' ||
257257
importUri.path == 'indexed_db' ||

pkg/compiler/lib/src/js_backend/annotations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ EnumSet<PragmaAnnotation> processMemberAnnotations(
156156

157157
Uri uri = member.enclosingLibrary.importUri;
158158
bool platformAnnotationsAllowed =
159-
options.testMode || uri.scheme == 'dart' || maybeEnableNative(uri);
159+
options.testMode || uri.isScheme('dart') || maybeEnableNative(uri);
160160

161161
for (PragmaAnnotationData data in pragmaAnnotationData) {
162162
String name = data.name;

pkg/compiler/lib/src/js_backend/backend_usage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class BackendUsageBuilderImpl implements BackendUsageBuilder {
158158
bool _isValidBackendUse(Entity element, LibraryEntity library) {
159159
if (_isValidEntity(element)) return true;
160160
SourceSpan span = _frontendStrategy.spanFromSpannable(element, element);
161-
if (library.canonicalUri.scheme == 'dart' &&
161+
if (library.canonicalUri.isScheme('dart') &&
162162
span.uri.path.contains('_internal/js_runtime/lib/')) {
163163
// TODO(johnniwinther): We should be more precise about these.
164164
return true;

pkg/compiler/lib/src/kernel/dart2js_target.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool allowedNativeTest(Uri uri) {
5555

5656
bool maybeEnableNative(Uri uri) {
5757
bool allowedDartLibrary() {
58-
if (uri.scheme != 'dart') return false;
58+
if (!uri.isScheme('dart')) return false;
5959
return _allowedDartSchemePaths.contains(uri.path);
6060
}
6161

@@ -118,7 +118,7 @@ class Dart2jsTarget extends Target {
118118
bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) =>
119119
super.allowPlatformPrivateLibraryAccess(importer, imported) ||
120120
maybeEnableNative(importer) ||
121-
(importer.scheme == 'package' &&
121+
(importer.isScheme('package') &&
122122
importer.path.startsWith('dart2js_runtime_metrics/'));
123123

124124
@override

pkg/compiler/lib/src/kernel/front_end_adapter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CompilerFileSystem implements fe.FileSystem {
2323

2424
@override
2525
fe.FileSystemEntity entityForUri(Uri uri) {
26-
if (uri.scheme == 'data') {
26+
if (uri.isScheme('data')) {
2727
return fe.DataFileSystemEntity(Uri.base.resolveUri(uri));
2828
} else {
2929
return _CompilerFileSystemEntity(uri, this);

pkg/compiler/lib/src/kernel/loader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class KernelLoaderTask extends CompilerTask {
269269

270270
// Libraries dependencies do not show implicit imports to `dart:core`.
271271
var dartCore = component.libraries.firstWhere((lib) {
272-
return lib.importUri.scheme == 'dart' && lib.importUri.path == 'core';
272+
return lib.importUri.isScheme('dart') && lib.importUri.path == 'core';
273273
});
274274
search(dartCore);
275275

pkg/compiler/lib/src/options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ class CompilerOptions implements DiagnosticOptions {
826826
return true;
827827
}
828828
if (shownPackageWarnings != null) {
829-
return uri.scheme == 'package' &&
829+
return uri.isScheme('package') &&
830830
shownPackageWarnings!.contains(uri.pathSegments.first);
831831
}
832832
return false;

0 commit comments

Comments
 (0)