From 33e174084ac0e94ddd0a656d5b1254bb56253bd1 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 8 Feb 2022 21:38:57 +0000 Subject: [PATCH] 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 Commit-Queue: Nate Bosch --- .../lib/src/util/libraries_specification.dart | 4 +-- .../lib/src/util/resolve_input_uri.dart | 2 +- .../lib/js_interop_checks.dart | 2 +- .../lib/src/computer/computer_hover.dart | 2 +- .../completion/available_suggestions.dart | 2 +- .../dart/convert_to_package_import.dart | 4 +-- .../dart/convert_to_relative_import.dart | 4 +-- .../lib/src/services/correction/util.dart | 2 +- .../lib/src/file_system/file_system.dart | 2 +- pkg/analyzer/lib/src/generated/source.dart | 2 +- .../lib/src/source/package_map_resolver.dart | 2 +- .../lib/src/source/source_resource.dart | 2 +- pkg/analyzer/lib/src/workspace/bazel.dart | 4 +-- .../lib/src/workspace/package_build.dart | 2 +- pkg/analyzer/lib/src/workspace/workspace.dart | 2 +- pkg/analyzer/test/generated/test_support.dart | 4 +-- .../src/dart/analysis/file_state_test.dart | 2 +- pkg/analyzer_cli/lib/src/analyzer_impl.dart | 4 +-- .../lib/file_system/multi_root.dart | 2 +- .../lib/file_system/single_root.dart | 2 +- pkg/compiler/lib/src/compiler.dart | 2 +- pkg/compiler/lib/src/dart2js.dart | 2 +- .../lib/src/diagnostics/code_location.dart | 6 ++-- .../lib/src/elements/entity_utils.dart | 12 ++++---- pkg/compiler/lib/src/ir/util.dart | 2 +- .../lib/src/js_backend/annotations.dart | 2 +- .../lib/src/js_backend/backend_usage.dart | 2 +- .../lib/src/kernel/dart2js_target.dart | 4 +-- .../lib/src/kernel/front_end_adapter.dart | 2 +- pkg/compiler/lib/src/kernel/loader.dart | 2 +- pkg/compiler/lib/src/options.dart | 2 +- .../lib/src/source_file_provider.dart | 18 +++++------ .../test/analyses/analysis_helper.dart | 6 ++-- .../test/analyses/api_dynamic_test.dart | 2 +- .../test/end_to_end/modular_loader_test.dart | 2 +- .../equivalence/id_equivalence_helper.dart | 4 +-- .../test/equivalence/show_helper.dart | 2 +- pkg/compiler/test/helpers/element_lookup.dart | 8 ++--- .../helpers/memory_source_file_helper.dart | 2 +- .../test/model/cfe_annotations_test.dart | 2 +- .../test/model/receiver_type_test.dart | 2 +- .../tools/source_mapping_tester.dart | 2 +- .../tool/modular_test_suite_helper.dart | 2 +- .../bin/src/deferred_library_layout.dart | 2 +- .../lib/deferred_library_check.dart | 2 +- pkg/dart2js_info/lib/src/util.dart | 2 +- .../lib/deobfuscate_stack_trace.dart | 2 +- pkg/dart2js_tools/lib/src/util.dart | 2 +- pkg/dds/lib/dds.dart | 4 +-- .../lib/src/compiler/module_builder.dart | 4 +-- .../lib/src/compiler/shared_command.dart | 4 +-- .../lib/src/kernel/asset_file_system.dart | 2 +- pkg/dev_compiler/lib/src/kernel/command.dart | 6 ++-- pkg/dev_compiler/lib/src/kernel/compiler.dart | 26 ++++++++-------- .../kernel/expression_compiler_worker.dart | 4 +-- .../lib/src/kernel/kernel_helpers.dart | 6 ++-- .../lib/src/kernel/native_types.dart | 2 +- .../lib/src/kernel/nullable_inference.dart | 4 +-- pkg/dev_compiler/lib/src/kernel/target.dart | 4 +-- .../expression_compiler_test.dart | 2 +- .../test/nullable_inference_test.dart | 2 +- .../src/api_prototype/experimental_flags.dart | 12 ++++---- .../src/api_prototype/language_version.dart | 6 ++-- .../api_prototype/standard_file_system.dart | 8 ++--- .../lib/src/base/processed_options.dart | 4 +-- .../compute_platform_binaries_location.dart | 4 +-- .../lib/src/fasta/builder/class_builder.dart | 2 +- .../lib/src/fasta/compiler_context.dart | 2 +- .../lib/src/fasta/dill/dill_loader.dart | 4 +-- .../lib/src/fasta/hybrid_file_system.dart | 2 +- .../lib/src/fasta/incremental_compiler.dart | 20 ++++++------- .../lib/src/fasta/incremental_serializer.dart | 8 ++--- .../lib/src/fasta/kernel/body_builder.dart | 2 +- .../src/fasta/kernel/constant_evaluator.dart | 2 +- .../lib/src/fasta/kernel/kernel_target.dart | 2 +- .../lib/src/fasta/kernel/type_labeler.dart | 6 ++-- .../lib/src/fasta/kernel/verifier.dart | 8 ++--- .../fasta/source/source_class_builder.dart | 2 +- .../fasta/source/source_library_builder.dart | 16 +++++----- .../lib/src/fasta/source/source_loader.dart | 30 +++++++++---------- .../fasta/type_inference/type_inferrer.dart | 2 +- .../type_schema_elimination.dart | 2 +- .../lib/src/fasta/uri_translator.dart | 8 ++--- .../lib/src/fasta/util/outline_extractor.dart | 20 ++++++------- .../lib/src/testing/compiler_common.dart | 2 +- .../lib/src/testing/id_testing_helper.dart | 4 +-- .../test/ast_nodes_has_to_string_test.dart | 4 +-- .../comments_on_certain_arguments_tool.dart | 2 +- pkg/front_end/test/compile_benchmark.dart | 4 +-- .../crashing_test_case_minimizer_impl.dart | 6 ++-- .../enable_non_nullable_test.dart | 4 +-- pkg/front_end/test/fasta/testing/suite.dart | 12 ++++---- .../type_constraint_gatherer_nnbd_test.dart | 4 +-- .../type_constraint_gatherer_test.dart | 4 +-- .../type_schema_environment_nnbd_test.dart | 4 +-- .../type_schema_environment_test.dart | 4 +-- .../types/legacy_upper_bound_helper.dart | 4 +-- pkg/front_end/test/hot_reload_e2e_test.dart | 2 +- .../test/incremental_dart2js_tester.dart | 2 +- .../test/incremental_flutter_tester.dart | 2 +- pkg/front_end/test/incremental_suite.dart | 12 ++++---- pkg/front_end/test/incremental_utils.dart | 2 +- .../language_versioning_test.dart | 2 +- pkg/front_end/test/lint_suite.dart | 4 +-- pkg/front_end/test/macros/macro_test.dart | 4 +-- pkg/front_end/test/mock_file_system.dart | 3 +- .../test/static_types/analysis_helper.dart | 2 +- .../test/static_types/static_type_test.dart | 2 +- pkg/front_end/test/utils/kernel_chain.dart | 6 ++-- pkg/front_end/test/vm_service_coverage.dart | 4 +-- ...m_service_coverage_constant_evaluator.dart | 2 +- pkg/front_end/tool/_fasta/bench_maker.dart | 2 +- pkg/front_end/tool/_fasta/entry_points.dart | 6 ++-- pkg/front_end/tool/incremental_perf.dart | 6 ++-- pkg/frontend_server/lib/compute_kernel.dart | 2 +- pkg/frontend_server/lib/frontend_server.dart | 6 ++-- .../lib/src/javascript_bundle.dart | 6 ++-- .../lib/src/strong_components.dart | 2 +- pkg/kernel/lib/ast.dart | 2 +- pkg/kernel/lib/import_table.dart | 2 +- pkg/kernel/lib/library_index.dart | 2 +- pkg/kernel/lib/src/printer.dart | 2 +- pkg/kernel/lib/target/targets.dart | 4 +-- .../lib/testing/type_parser_environment.dart | 2 +- .../mixin_full_resolution.dart | 2 +- .../track_widget_constructor_locations.dart | 2 +- pkg/kernel/lib/type_checker.dart | 4 +-- pkg/nnbd_migration/lib/src/edge_builder.dart | 4 +-- pkg/nnbd_migration/lib/src/node_builder.dart | 2 +- pkg/test_runner/lib/src/utils.dart | 2 +- pkg/vm/bin/kernel_service.dart | 8 ++--- pkg/vm/bin/protobuf_aware_treeshaker.dart | 2 +- pkg/vm/lib/http_filesystem.dart | 2 +- pkg/vm/lib/incremental_compiler.dart | 2 +- .../lib/transformations/deferred_loading.dart | 2 +- pkg/vm/lib/transformations/ffi/common.dart | 2 +- .../type_flow/native_code.dart | 4 +-- pkg/vm/test/incremental_compiler_test.dart | 2 +- .../deferred_loading_test.dart | 2 +- pkg/vm/test/unlinked_ast_to_text_test.dart | 4 +-- .../enum_from_lib_used_as_type.dart.expect | 2 +- .../tree_shake_enum_from_lib.dart.expect | 2 +- pkg/vm_service/test/common/test_helper.dart | 2 +- runtime/observatory/bin/heap_snapshot.dart | 4 +-- .../lib/src/elements/script_inset.dart | 4 +-- runtime/observatory_2/bin/heap_snapshot.dart | 4 +-- .../lib/src/elements/script_inset.dart | 4 +-- sdk/lib/_http/http_impl.dart | 10 +++---- sdk/lib/_http/websocket_impl.dart | 4 +-- sdk/lib/_internal/vm/bin/builtin.dart | 16 +++++----- sdk/lib/core/uri.dart | 30 ++++++++++++++----- tests/corelib/uri_base_test.dart | 2 +- tests/corelib_2/uri_base_test.dart | 2 +- .../lib/mirrors/library_uri_package_test.dart | 2 +- tests/lib/mirrors/mirrors_test.dart | 2 +- .../mirrors/library_uri_package_test.dart | 2 +- tests/lib_2/mirrors/mirrors_test.dart | 2 +- .../io/web_socket_compression_test.dart | 2 +- .../io/web_socket_compression_test.dart | 27 ++++++++--------- tools/dom/src/native_DOMImplementation.dart | 20 ++++++++----- tools/package_deps/bin/package_deps.dart | 2 +- 161 files changed, 378 insertions(+), 358 deletions(-) diff --git a/pkg/_fe_analyzer_shared/lib/src/util/libraries_specification.dart b/pkg/_fe_analyzer_shared/lib/src/util/libraries_specification.dart index 4e453145c03..a25f8e88fb9 100644 --- a/pkg/_fe_analyzer_shared/lib/src/util/libraries_specification.dart +++ b/pkg/_fe_analyzer_shared/lib/src/util/libraries_specification.dart @@ -238,7 +238,7 @@ class LibrariesSpecification { _reportError(messageIncludePathIsNotAString(targetName, specUri)); } Uri uri = Uri.parse(path); - if (uri.scheme != '' && uri.scheme != 'file') { + if (uri.hasScheme && !uri.isScheme('file')) { return _reportError(messageUnsupportedUriScheme(path, specUri)); } LibrariesSpecification specification = @@ -269,7 +269,7 @@ class LibrariesSpecification { uriString, libraryName, targetName, specUri)); } Uri uri = Uri.parse(uriString); - if (uri.scheme != '' && uri.scheme != 'file') { + if (uri.hasScheme && !uri.isScheme('file')) { return _reportError( messageUnsupportedUriScheme(uriString, specUri)); } diff --git a/pkg/_fe_analyzer_shared/lib/src/util/resolve_input_uri.dart b/pkg/_fe_analyzer_shared/lib/src/util/resolve_input_uri.dart index 2600d6d0884..39ce9d4b1a7 100644 --- a/pkg/_fe_analyzer_shared/lib/src/util/resolve_input_uri.dart +++ b/pkg/_fe_analyzer_shared/lib/src/util/resolve_input_uri.dart @@ -18,7 +18,7 @@ Uri resolveInputUri(String path) { Uri parseUri(String path) { if (path.startsWith("file:")) { - if (Uri.base.scheme == "file") { + if (Uri.base.isScheme("file")) { // The Uri class doesn't handle relative file URIs correctly, the // following works around that issue. return new Uri(path: Uri.parse("x-$path").path); diff --git a/pkg/_js_interop_checks/lib/js_interop_checks.dart b/pkg/_js_interop_checks/lib/js_interop_checks.dart index e9f6fb0799b..6dab119649e 100644 --- a/pkg/_js_interop_checks/lib/js_interop_checks.dart +++ b/pkg/_js_interop_checks/lib/js_interop_checks.dart @@ -362,7 +362,7 @@ class JsInteropChecks extends RecursiveVisitor { /// or a from environment constructor. bool _isAllowedExternalUsage(Member member) { Uri uri = member.enclosingLibrary.importUri; - return uri.scheme == 'dart' && + return uri.isScheme('dart') && _pathsWithAllowedDartExternalUsage.contains(uri.path) || _allowedNativeTestPatterns.any((pattern) => uri.path.contains(pattern)); } diff --git a/pkg/analysis_server/lib/src/computer/computer_hover.dart b/pkg/analysis_server/lib/src/computer/computer_hover.dart index d51da0437cd..e16e30780fd 100644 --- a/pkg/analysis_server/lib/src/computer/computer_hover.dart +++ b/pkg/analysis_server/lib/src/computer/computer_hover.dart @@ -82,7 +82,7 @@ class DartUnitHoverComputer { if (library != null) { var uri = library.source.uri; var analysisSession = _unit.declaredElement?.session; - if (uri.scheme == 'file' && analysisSession != null) { + if (uri.isScheme('file') && analysisSession != null) { // for 'file:' URIs, use the path after the project root var context = analysisSession.resourceProvider.pathContext; var projectRootDir = diff --git a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart index 3c7bbac3264..bca280750db 100644 --- a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart +++ b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart @@ -173,7 +173,7 @@ protocol.ElementKind protocolElementKind(DeclarationKind kind) { /// Computes the best URI to import [what] into the [unit] library. String? _getRelativeFileUri(DartCompletionRequest request, Uri what) { - if (what.scheme == 'file') { + if (what.isScheme('file')) { var pathContext = request.analysisSession.resourceProvider.pathContext; var libraryPath = request.libraryElement.source.fullName; diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart index 93e64604c1d..7d3b150b99b 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_package_import.dart @@ -43,14 +43,14 @@ class ConvertToPackageImport extends CorrectionProducer { } var importUri = uriSource.uri; - if (importUri.scheme != 'package') { + if (!importUri.isScheme('package')) { return; } // Don't offer to convert a 'package:' URI to itself. try { var uriContent = importDirective.uriContent; - if (uriContent == null || Uri.parse(uriContent).scheme == 'package') { + if (uriContent == null || Uri.parse(uriContent).isScheme('package')) { return; } } on FormatException { diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart index 7acecb504f1..49bedd13534 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_relative_import.dart @@ -45,7 +45,7 @@ class ConvertToRelativeImport extends CorrectionProducer { // Ignore if the uri is not a package: uri. var sourceUri = resolvedResult.uri; - if (sourceUri.scheme != 'package') { + if (!sourceUri.isScheme('package')) { return; } @@ -61,7 +61,7 @@ class ConvertToRelativeImport extends CorrectionProducer { } // Ignore if import uri is not a package: uri. - if (importUri.scheme != 'package') { + if (!importUri.isScheme('package')) { return; } diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart index 906642943ed..f5935dd0bad 100644 --- a/pkg/analysis_server/lib/src/services/correction/util.dart +++ b/pkg/analysis_server/lib/src/services/correction/util.dart @@ -322,7 +322,7 @@ Map getImportNamespace(ImportElement imp) { /// Computes the best URI to import [what] into [from]. String getLibrarySourceUri( path.Context pathContext, LibraryElement from, Uri what) { - if (what.scheme == 'file') { + if (what.isScheme('file')) { var fromFolder = pathContext.dirname(from.source.fullName); var relativeFile = pathContext.relative(what.path, from: fromFolder); return pathContext.split(relativeFile).join('/'); diff --git a/pkg/analyzer/lib/src/file_system/file_system.dart b/pkg/analyzer/lib/src/file_system/file_system.dart index b7b4655490d..d7bfadfdbaf 100644 --- a/pkg/analyzer/lib/src/file_system/file_system.dart +++ b/pkg/analyzer/lib/src/file_system/file_system.dart @@ -37,5 +37,5 @@ class ResourceUriResolver extends UriResolver { Uri restoreAbsolute(Source source) => pathToUri(source.fullName); /// Return `true` if the given [uri] is a `file` URI. - static bool isFileUri(Uri uri) => uri.scheme == FILE_SCHEME; + static bool isFileUri(Uri uri) => uri.isScheme(FILE_SCHEME); } diff --git a/pkg/analyzer/lib/src/generated/source.dart b/pkg/analyzer/lib/src/generated/source.dart index ed375ffb231..77865a99002 100644 --- a/pkg/analyzer/lib/src/generated/source.dart +++ b/pkg/analyzer/lib/src/generated/source.dart @@ -31,7 +31,7 @@ abstract class BasicSource extends Source { @Deprecated('Use uri.isScheme("dart") instead') @override - bool get isInSystemLibrary => uri.scheme == 'dart'; + bool get isInSystemLibrary => uri.isScheme('dart'); @override String get shortName => pathos.basename(fullName); diff --git a/pkg/analyzer/lib/src/source/package_map_resolver.dart b/pkg/analyzer/lib/src/source/package_map_resolver.dart index 9b96f99d076..c1d3bf0add9 100644 --- a/pkg/analyzer/lib/src/source/package_map_resolver.dart +++ b/pkg/analyzer/lib/src/source/package_map_resolver.dart @@ -79,6 +79,6 @@ class PackageMapUriResolver extends UriResolver { /// Returns `true` if [uri] is a `package` URI. static bool isPackageUri(Uri uri) { - return uri.scheme == PACKAGE_SCHEME; + return uri.isScheme(PACKAGE_SCHEME); } } diff --git a/pkg/analyzer/lib/src/source/source_resource.dart b/pkg/analyzer/lib/src/source/source_resource.dart index 9334b31b586..3e4adf7d442 100644 --- a/pkg/analyzer/lib/src/source/source_resource.dart +++ b/pkg/analyzer/lib/src/source/source_resource.dart @@ -80,7 +80,7 @@ class FileSource extends Source { @Deprecated('Use uri.isScheme("dart") instead') @override - bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME; + bool get isInSystemLibrary => uri.isScheme(DartUriResolver.DART_SCHEME); @Deprecated('Not used anymore') @override diff --git a/pkg/analyzer/lib/src/workspace/bazel.dart b/pkg/analyzer/lib/src/workspace/bazel.dart index ae54e97a7e3..7350937500e 100644 --- a/pkg/analyzer/lib/src/workspace/bazel.dart +++ b/pkg/analyzer/lib/src/workspace/bazel.dart @@ -83,7 +83,7 @@ class BazelPackageUriResolver extends UriResolver { } Source? _resolveAbsolute(Uri uri) { - if (uri.scheme == 'file') { + if (uri.isScheme('file')) { var path = fileUriToNormalizedPath(_context, uri); var pathRelativeToRoot = _workspace._relativeToRoot(path); if (pathRelativeToRoot == null) return null; @@ -91,7 +91,7 @@ class BazelPackageUriResolver extends UriResolver { var file = _workspace.findFile(fullFilePath); return file?.createSource(uri); } - if (uri.scheme != 'package') { + if (!uri.isScheme('package')) { return null; } String uriPath = Uri.decodeComponent(uri.path); diff --git a/pkg/analyzer/lib/src/workspace/package_build.dart b/pkg/analyzer/lib/src/workspace/package_build.dart index 4e06f048d82..c30333ee0dd 100644 --- a/pkg/analyzer/lib/src/workspace/package_build.dart +++ b/pkg/analyzer/lib/src/workspace/package_build.dart @@ -73,7 +73,7 @@ class PackageBuildPackageUriResolver extends UriResolver { @override Source? resolveAbsolute(Uri uri) { - if (uri.scheme != 'package') { + if (!uri.isScheme('package')) { return null; } diff --git a/pkg/analyzer/lib/src/workspace/workspace.dart b/pkg/analyzer/lib/src/workspace/workspace.dart index 34ab9c12646..035744b0219 100644 --- a/pkg/analyzer/lib/src/workspace/workspace.dart +++ b/pkg/analyzer/lib/src/workspace/workspace.dart @@ -82,7 +82,7 @@ abstract class WorkspacePackage { /// example, the case of a [InSummarySource]). In this case, use /// [workspace]'s package URI resolver to fetch the file path. String? filePathFromSource(Source source) { - if (source.uri.scheme == 'package') { + if (source.uri.isScheme('package')) { return workspace.packageUriResolver.resolveAbsolute(source.uri)?.fullName; } else { return source.fullName; diff --git a/pkg/analyzer/test/generated/test_support.dart b/pkg/analyzer/test/generated/test_support.dart index 927a542a0b1..c170e15e0c1 100644 --- a/pkg/analyzer/test/generated/test_support.dart +++ b/pkg/analyzer/test/generated/test_support.dart @@ -530,9 +530,9 @@ class TestSourceWithUri extends TestSource { @Deprecated('Use Source.uri instead') @override UriKind get uriKind { - if (uri.scheme == 'dart') { + if (uri.isScheme('dart')) { return UriKind.DART_URI; - } else if (uri.scheme == 'package') { + } else if (uri.isScheme('package')) { return UriKind.PACKAGE_URI; } return UriKind.FILE_URI; diff --git a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart index 539ff590f29..996d5d5d6cd 100644 --- a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart +++ b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart @@ -783,7 +783,7 @@ part of 'a.dart'; if (file is LibraryCycle) { return !file.libraries.any((file) => file.uri.isScheme('dart')); } else if (file is FileState) { - return file.uri.scheme != 'dart'; + return !file.uri.isScheme('dart'); } else if (file == null) { return true; } else { diff --git a/pkg/analyzer_cli/lib/src/analyzer_impl.dart b/pkg/analyzer_cli/lib/src/analyzer_impl.dart index 19caf6dfa35..fff12521852 100644 --- a/pkg/analyzer_cli/lib/src/analyzer_impl.dart +++ b/pkg/analyzer_cli/lib/src/analyzer_impl.dart @@ -127,7 +127,7 @@ class AnalyzerImpl { files.clear(); errorsResults.clear(); var libraryUri = libraryFile.uri; - if (libraryUri.scheme == 'package' && libraryUri.pathSegments.isNotEmpty) { + if (libraryUri.isScheme('package') && libraryUri.pathSegments.isNotEmpty) { _selfPackageName = libraryUri.pathSegments[0]; } } @@ -177,7 +177,7 @@ class AnalyzerImpl { /// Determine whether the given URI refers to a package being analyzed. bool _isAnalyzedPackage(Uri uri) { - if (uri.scheme != 'package' || uri.pathSegments.isEmpty) { + if (!uri.isScheme('package') || uri.pathSegments.isEmpty) { return false; } var packageName = uri.pathSegments.first; diff --git a/pkg/build_integration/lib/file_system/multi_root.dart b/pkg/build_integration/lib/file_system/multi_root.dart index 14772ccc8b3..7fff8e7b44f 100644 --- a/pkg/build_integration/lib/file_system/multi_root.dart +++ b/pkg/build_integration/lib/file_system/multi_root.dart @@ -52,7 +52,7 @@ class MultiRootFileSystemEntity implements FileSystemEntity { _delegate ??= await _resolveEntity(); Future _resolveEntity() async { - if (uri.scheme == multiRootFileSystem.markerScheme) { + if (uri.isScheme(multiRootFileSystem.markerScheme)) { if (!uri.isAbsolute) { throw new FileSystemException( uri, "This MultiRootFileSystem only handles absolutes URIs: $uri"); diff --git a/pkg/build_integration/lib/file_system/single_root.dart b/pkg/build_integration/lib/file_system/single_root.dart index 30cbc6652f1..896dfc346fd 100644 --- a/pkg/build_integration/lib/file_system/single_root.dart +++ b/pkg/build_integration/lib/file_system/single_root.dart @@ -33,7 +33,7 @@ class SingleRootFileSystem implements FileSystem { @override FileSystemEntity entityForUri(Uri uri) { - if (uri.scheme != markerScheme) { + if (!uri.isScheme(markerScheme)) { throw new FileSystemException( uri, "This SingleRootFileSystem only handles URIs with the '$markerScheme'" diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart index 9bbada16105..4c636e3504c 100644 --- a/pkg/compiler/lib/src/compiler.dart +++ b/pkg/compiler/lib/src/compiler.dart @@ -726,7 +726,7 @@ abstract class Compiler { Uri getCanonicalUri(Entity element) { Uri libraryUri = _uriFromElement(element); if (libraryUri == null) return null; - if (libraryUri.scheme == 'package') { + if (libraryUri.isScheme('package')) { int slashPos = libraryUri.path.indexOf('/'); if (slashPos != -1) { String packageName = libraryUri.path.substring(0, slashPos); diff --git a/pkg/compiler/lib/src/dart2js.dart b/pkg/compiler/lib/src/dart2js.dart index a57892b86ff..7cb01734ba5 100644 --- a/pkg/compiler/lib/src/dart2js.dart +++ b/pkg/compiler/lib/src/dart2js.dart @@ -1102,7 +1102,7 @@ class AbortLeg { void writeString(Uri uri, String text) { if (!enableWriteString) return; - if (uri.scheme != 'file') { + if (!uri.isScheme('file')) { fail('Unhandled scheme ${uri.scheme}.'); } var file = (File(uri.toFilePath())..createSync(recursive: true)) diff --git a/pkg/compiler/lib/src/diagnostics/code_location.dart b/pkg/compiler/lib/src/diagnostics/code_location.dart index 58bc177e4e2..515f3592e3b 100644 --- a/pkg/compiler/lib/src/diagnostics/code_location.dart +++ b/pkg/compiler/lib/src/diagnostics/code_location.dart @@ -18,7 +18,7 @@ abstract class CodeLocation { String relativize(Uri baseUri); factory CodeLocation(Uri uri) { - if (uri.scheme == 'package') { + if (uri.isScheme('package')) { int slashPos = uri.path.indexOf('/'); if (slashPos != -1) { String packageName = uri.path.substring(0, slashPos); @@ -42,7 +42,7 @@ class SchemeLocation implements CodeLocation { @override bool inSameLocation(Uri uri) { - return this.uri.scheme == uri.scheme; + return this.uri.isScheme(uri.scheme); } @override @@ -62,7 +62,7 @@ class PackageLocation implements CodeLocation { @override bool inSameLocation(Uri uri) { - return uri.scheme == 'package' && uri.path.startsWith('$packageName/'); + return uri.isScheme('package') && uri.path.startsWith('$packageName/'); } @override diff --git a/pkg/compiler/lib/src/elements/entity_utils.dart b/pkg/compiler/lib/src/elements/entity_utils.dart index 2942392eba6..7e5813362a8 100644 --- a/pkg/compiler/lib/src/elements/entity_utils.dart +++ b/pkg/compiler/lib/src/elements/entity_utils.dart @@ -19,17 +19,17 @@ int compareLibrariesUris(Uri a, Uri b) { } // Order: platform < package < other. - if (a.scheme == 'dart') { - if (b.scheme == 'dart') return byCanonicalUriPath(); + if (a.isScheme('dart')) { + if (b.isScheme('dart')) return byCanonicalUriPath(); return -1; } - if (b.scheme == 'dart') return 1; + if (b.isScheme('dart')) return 1; - if (a.scheme == 'package') { - if (b.scheme == 'package') return byCanonicalUriPath(); + if (a.isScheme('package')) { + if (b.isScheme('package')) return byCanonicalUriPath(); return -1; } - if (b.scheme == 'package') return 1; + if (b.isScheme('package')) return 1; return _compareCanonicalUri(a, b); } diff --git a/pkg/compiler/lib/src/ir/util.dart b/pkg/compiler/lib/src/ir/util.dart index 27b00cb7515..e825b5246b2 100644 --- a/pkg/compiler/lib/src/ir/util.dart +++ b/pkg/compiler/lib/src/ir/util.dart @@ -251,7 +251,7 @@ bool containsFreeVariables(ir.DartType type) => /// Returns true if [importUri] corresponds to dart:html and related libraries. bool _isWebLibrary(Uri importUri) => - importUri.scheme == 'dart' && + importUri.isScheme('dart') && (importUri.path == 'html' || importUri.path == 'svg' || importUri.path == 'indexed_db' || diff --git a/pkg/compiler/lib/src/js_backend/annotations.dart b/pkg/compiler/lib/src/js_backend/annotations.dart index 7ae9894b8b3..cf4c0499e87 100644 --- a/pkg/compiler/lib/src/js_backend/annotations.dart +++ b/pkg/compiler/lib/src/js_backend/annotations.dart @@ -156,7 +156,7 @@ EnumSet processMemberAnnotations( Uri uri = member.enclosingLibrary.importUri; bool platformAnnotationsAllowed = - options.testMode || uri.scheme == 'dart' || maybeEnableNative(uri); + options.testMode || uri.isScheme('dart') || maybeEnableNative(uri); for (PragmaAnnotationData data in pragmaAnnotationData) { String name = data.name; diff --git a/pkg/compiler/lib/src/js_backend/backend_usage.dart b/pkg/compiler/lib/src/js_backend/backend_usage.dart index 23f8c735190..6f87f10831b 100644 --- a/pkg/compiler/lib/src/js_backend/backend_usage.dart +++ b/pkg/compiler/lib/src/js_backend/backend_usage.dart @@ -158,7 +158,7 @@ class BackendUsageBuilderImpl implements BackendUsageBuilder { bool _isValidBackendUse(Entity element, LibraryEntity library) { if (_isValidEntity(element)) return true; SourceSpan span = _frontendStrategy.spanFromSpannable(element, element); - if (library.canonicalUri.scheme == 'dart' && + if (library.canonicalUri.isScheme('dart') && span.uri.path.contains('_internal/js_runtime/lib/')) { // TODO(johnniwinther): We should be more precise about these. return true; diff --git a/pkg/compiler/lib/src/kernel/dart2js_target.dart b/pkg/compiler/lib/src/kernel/dart2js_target.dart index 156e7a4f6a0..c6e7a5e1911 100644 --- a/pkg/compiler/lib/src/kernel/dart2js_target.dart +++ b/pkg/compiler/lib/src/kernel/dart2js_target.dart @@ -55,7 +55,7 @@ bool allowedNativeTest(Uri uri) { bool maybeEnableNative(Uri uri) { bool allowedDartLibrary() { - if (uri.scheme != 'dart') return false; + if (!uri.isScheme('dart')) return false; return _allowedDartSchemePaths.contains(uri.path); } @@ -118,7 +118,7 @@ class Dart2jsTarget extends Target { bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) => super.allowPlatformPrivateLibraryAccess(importer, imported) || maybeEnableNative(importer) || - (importer.scheme == 'package' && + (importer.isScheme('package') && importer.path.startsWith('dart2js_runtime_metrics/')); @override diff --git a/pkg/compiler/lib/src/kernel/front_end_adapter.dart b/pkg/compiler/lib/src/kernel/front_end_adapter.dart index 9a542a8681b..605b3bddbd2 100644 --- a/pkg/compiler/lib/src/kernel/front_end_adapter.dart +++ b/pkg/compiler/lib/src/kernel/front_end_adapter.dart @@ -23,7 +23,7 @@ class CompilerFileSystem implements fe.FileSystem { @override fe.FileSystemEntity entityForUri(Uri uri) { - if (uri.scheme == 'data') { + if (uri.isScheme('data')) { return fe.DataFileSystemEntity(Uri.base.resolveUri(uri)); } else { return _CompilerFileSystemEntity(uri, this); diff --git a/pkg/compiler/lib/src/kernel/loader.dart b/pkg/compiler/lib/src/kernel/loader.dart index cdab490c821..aaf5016ddd4 100644 --- a/pkg/compiler/lib/src/kernel/loader.dart +++ b/pkg/compiler/lib/src/kernel/loader.dart @@ -269,7 +269,7 @@ class KernelLoaderTask extends CompilerTask { // Libraries dependencies do not show implicit imports to `dart:core`. var dartCore = component.libraries.firstWhere((lib) { - return lib.importUri.scheme == 'dart' && lib.importUri.path == 'core'; + return lib.importUri.isScheme('dart') && lib.importUri.path == 'core'; }); search(dartCore); diff --git a/pkg/compiler/lib/src/options.dart b/pkg/compiler/lib/src/options.dart index c2efa63cffc..c0c846893ba 100644 --- a/pkg/compiler/lib/src/options.dart +++ b/pkg/compiler/lib/src/options.dart @@ -826,7 +826,7 @@ class CompilerOptions implements DiagnosticOptions { return true; } if (shownPackageWarnings != null) { - return uri.scheme == 'package' && + return uri.isScheme('package') && shownPackageWarnings!.contains(uri.pathSegments.first); } return false; diff --git a/pkg/compiler/lib/src/source_file_provider.dart b/pkg/compiler/lib/src/source_file_provider.dart index 359fead1a42..c869d49b1a7 100644 --- a/pkg/compiler/lib/src/source_file_provider.dart +++ b/pkg/compiler/lib/src/source_file_provider.dart @@ -40,9 +40,9 @@ abstract class SourceFileProvider implements CompilerInput { } if (input != null) return Future.value(input); - if (resourceUri.scheme == 'file') { + if (resourceUri.isScheme('file')) { return _readFromFile(resourceUri, inputKind); - } else if (resourceUri.scheme == 'http' || resourceUri.scheme == 'https') { + } else if (resourceUri.isScheme('http') || resourceUri.isScheme('https')) { return _readFromHttp(resourceUri, inputKind); } else { throw ArgumentError("Unknown scheme in uri '$resourceUri'"); @@ -50,7 +50,7 @@ abstract class SourceFileProvider implements CompilerInput { } api.Input _readFromFileSync(Uri resourceUri, api.InputKind inputKind) { - assert(resourceUri.scheme == 'file'); + assert(resourceUri.isScheme('file')); List source; try { source = readAll(resourceUri.toFilePath(), @@ -99,7 +99,7 @@ abstract class SourceFileProvider implements CompilerInput { Future>> _readFromHttp( Uri resourceUri, api.InputKind inputKind) { - assert(resourceUri.scheme == 'http'); + assert(resourceUri.isScheme('http')); HttpClient client = HttpClient(); return client .getUrl(resourceUri) @@ -279,7 +279,7 @@ class FormattingDiagnosticHandler implements CompilerDiagnostics { api.Input file = provider.getUtf8SourceFile(uri); if (file == null && autoReadFileUri && - (uri.scheme == 'file' || !uri.isAbsolute) && + (uri.isScheme('file') || !uri.isAbsolute) && uri.path.endsWith('.dart')) { if (!uri.isAbsolute) { uri = provider.cwd.resolveUri(uri); @@ -379,7 +379,7 @@ class RandomAccessFileOutputProvider implements CompilerOutput { Uri uri = createUri(name, extension, type); bool isPrimaryOutput = uri == out; - if (uri.scheme != 'file') { + if (!uri.isScheme('file')) { onFailure('Unhandled scheme ${uri.scheme} in $uri.'); } @@ -428,7 +428,7 @@ class RandomAccessFileOutputProvider implements CompilerOutput { allOutputFiles.add(fe.relativizeUri(Uri.base, uri, Platform.isWindows)); - if (uri.scheme != 'file') { + if (!uri.isScheme('file')) { onFailure('Unhandled scheme ${uri.scheme} in $uri.'); } @@ -608,7 +608,7 @@ class MultiRootInputProvider extends SourceFileProvider { Future>> readFromUri(Uri uri, {InputKind inputKind = InputKind.UTF8}) async { var resolvedUri = uri; - if (resolvedUri.scheme == markerScheme) { + if (resolvedUri.isScheme(markerScheme)) { var path = resolvedUri.path; if (path.startsWith('/')) path = path.substring(1); for (var dir in roots) { @@ -634,7 +634,7 @@ class MultiRootInputProvider extends SourceFileProvider { @override api.Input autoReadFromFile(Uri resourceUri) { - if (resourceUri.scheme == markerScheme) { + if (resourceUri.isScheme(markerScheme)) { var path = resourceUri.path; for (var dir in roots) { var file = dir.resolve(path); diff --git a/pkg/compiler/test/analyses/analysis_helper.dart b/pkg/compiler/test/analyses/analysis_helper.dart index b104a00d58a..0d427c66125 100644 --- a/pkg/compiler/test/analyses/analysis_helper.dart +++ b/pkg/compiler/test/analyses/analysis_helper.dart @@ -40,7 +40,7 @@ main(List args) { Uri packageConfig = getPackages(argResults); List options = getOptions(argResults); run(entryPoint, null, - analyzedUrisFilter: (Uri uri) => uri.scheme != 'dart', + analyzedUrisFilter: (Uri uri) => !uri.isScheme('dart'), librariesSpecificationUri: librariesSpecificationUri, packageConfig: packageConfig, options: options); @@ -362,7 +362,7 @@ class DynamicVisitor extends StaticTypeVisitorBase { String reportAssertionFailure(ir.Node node, String message) { SourceSpan span = computeSourceSpanFromTreeNode(node); Uri uri = span.uri; - if (uri.scheme == 'org-dartlang-sdk') { + if (uri.isScheme('org-dartlang-sdk')) { span = new SourceSpan( Uri.base.resolve(uri.path.substring(1)), span.begin, span.end); } @@ -378,7 +378,7 @@ class DynamicVisitor extends StaticTypeVisitorBase { String uriString = relativizeUri(Uri.base, uri, Platform.isWindows); Map> actualMap = _actualMessages .putIfAbsent(uriString, () => >{}); - if (uri.scheme == 'org-dartlang-sdk') { + if (uri.isScheme('org-dartlang-sdk')) { span = new SourceSpan( Uri.base.resolve(uri.path.substring(1)), span.begin, span.end); } diff --git a/pkg/compiler/test/analyses/api_dynamic_test.dart b/pkg/compiler/test/analyses/api_dynamic_test.dart index 8119a4ee635..543cd862602 100644 --- a/pkg/compiler/test/analyses/api_dynamic_test.dart +++ b/pkg/compiler/test/analyses/api_dynamic_test.dart @@ -14,7 +14,7 @@ main(List args) { asyncTest(() async { await run( Uri.parse('memory:main.dart'), 'pkg/compiler/test/analyses/$goldenFile', - analyzedUrisFilter: (Uri uri) => uri.scheme == 'dart', + analyzedUrisFilter: (Uri uri) => uri.isScheme('dart'), memorySourceFiles: {'main.dart': 'main() {}'}, verbose: args.contains('-v'), generate: args.contains('-g')); diff --git a/pkg/compiler/test/end_to_end/modular_loader_test.dart b/pkg/compiler/test/end_to_end/modular_loader_test.dart index 6b5c88263d5..bc5995489b5 100644 --- a/pkg/compiler/test/end_to_end/modular_loader_test.dart +++ b/pkg/compiler/test/end_to_end/modular_loader_test.dart @@ -109,7 +109,7 @@ class TestFileSystem implements FileSystem { @override FileSystemEntity entityForUri(Uri uri) { - if (uri.scheme == 'file') return physical.entityForUri(uri); + if (uri.isScheme('file')) return physical.entityForUri(uri); return memory.entityForUri(uri); } } diff --git a/pkg/compiler/test/equivalence/id_equivalence_helper.dart b/pkg/compiler/test/equivalence/id_equivalence_helper.dart index 8a34cb9d213..30524c0235d 100644 --- a/pkg/compiler/test/equivalence/id_equivalence_helper.dart +++ b/pkg/compiler/test/equivalence/id_equivalence_helper.dart @@ -248,8 +248,8 @@ Future> computeData(String name, Uri entryPoint, bool excludeLibrary(LibraryEntity library) { return forUserLibrariesOnly && - (library.canonicalUri.scheme == 'dart' || - library.canonicalUri.scheme == 'package'); + (library.canonicalUri.isScheme('dart') || + library.canonicalUri.isScheme('package')); } ir.Library getIrLibrary(LibraryEntity library) { diff --git a/pkg/compiler/test/equivalence/show_helper.dart b/pkg/compiler/test/equivalence/show_helper.dart index ecc6257215b..4aa38503dc7 100644 --- a/pkg/compiler/test/equivalence/show_helper.dart +++ b/pkg/compiler/test/equivalence/show_helper.dart @@ -65,7 +65,7 @@ show(ArgResults argResults, DataComputer dataComputer, SourceFileProvider provider = data.compiler.provider; for (Uri uri in data.actualMaps.keys) { Uri fileUri = uri; - if (fileUri.scheme == 'org-dartlang-sdk') { + if (fileUri.isScheme('org-dartlang-sdk')) { fileUri = Uri.base.resolve(fileUri.path.substring(1)); } if (show != null && !show.any((f) => '$fileUri'.endsWith(f))) { diff --git a/pkg/compiler/test/helpers/element_lookup.dart b/pkg/compiler/test/helpers/element_lookup.dart index 0ff12c21456..ae8bfa22e7f 100644 --- a/pkg/compiler/test/helpers/element_lookup.dart +++ b/pkg/compiler/test/helpers/element_lookup.dart @@ -21,8 +21,8 @@ ClassEntity findClass(JClosedWorld closedWorld, String name) { closedWorld.commonElements.jsHelperLibrary, name); if (cls == null) { for (LibraryEntity library in elementEnvironment.libraries) { - if (library.canonicalUri.scheme != 'dart' && - library.canonicalUri.scheme != 'package') { + if (!library.canonicalUri.isScheme('dart') && + !library.canonicalUri.isScheme('package')) { cls = elementEnvironment.lookupClass(library, name); if (cls != null) { break; @@ -70,8 +70,8 @@ MemberEntity findMember(JClosedWorld closedWorld, String name) { setter: isSetter); if (member == null) { for (LibraryEntity library in elementEnvironment.libraries) { - if (library.canonicalUri.scheme != 'dart' && - library.canonicalUri.scheme != 'package') { + if (!library.canonicalUri.isScheme('dart') && + !library.canonicalUri.isScheme('package')) { member = elementEnvironment.lookupLibraryMember(library, name, setter: isSetter); if (member != null) { diff --git a/pkg/compiler/test/helpers/memory_source_file_helper.dart b/pkg/compiler/test/helpers/memory_source_file_helper.dart index 865d20e3f82..a15262bfbb7 100644 --- a/pkg/compiler/test/helpers/memory_source_file_helper.dart +++ b/pkg/compiler/test/helpers/memory_source_file_helper.dart @@ -31,7 +31,7 @@ class MemorySourceFileProvider extends SourceFileProvider { @override Future>> readBytesFromUri( Uri resourceUri, InputKind inputKind) { - if (resourceUri.scheme != 'memory') { + if (!resourceUri.isScheme('memory')) { return super.readBytesFromUri(resourceUri, inputKind); } // TODO(johnniwinther): We should use inputs already in the cache. Some diff --git a/pkg/compiler/test/model/cfe_annotations_test.dart b/pkg/compiler/test/model/cfe_annotations_test.dart index 9cb3b6e565f..e6e164a35e1 100644 --- a/pkg/compiler/test/model/cfe_annotations_test.dart +++ b/pkg/compiler/test/model/cfe_annotations_test.dart @@ -351,7 +351,7 @@ main(List args) { } for (ir.Library library in component.libraries) { - if (library.importUri.scheme == 'memory') { + if (library.importUri.isScheme('memory')) { String libraryId = library.importUri.path; LibraryEntity libraryEntity = elementMap.getLibrary(library); diff --git a/pkg/compiler/test/model/receiver_type_test.dart b/pkg/compiler/test/model/receiver_type_test.dart index d7567dc6206..7c73276d863 100644 --- a/pkg/compiler/test/model/receiver_type_test.dart +++ b/pkg/compiler/test/model/receiver_type_test.dart @@ -52,7 +52,7 @@ Future runTest() async { Selector callSelector = new Selector.callClosure(0); closedWorld.classHierarchy.forEachStrictSubclassOf( closedWorld.commonElements.objectClass, (ClassEntity cls) { - if (cls.library.canonicalUri.scheme != 'memory') + if (!cls.library.canonicalUri.isScheme('memory')) return IterationStep.CONTINUE; TypeMask mask = new TypeMask.nonNullSubclass(cls, closedWorld); diff --git a/pkg/compiler/test/sourcemaps/tools/source_mapping_tester.dart b/pkg/compiler/test/sourcemaps/tools/source_mapping_tester.dart index 6bca3c37f61..8f5e582b883 100644 --- a/pkg/compiler/test/sourcemaps/tools/source_mapping_tester.dart +++ b/pkg/compiler/test/sourcemaps/tools/source_mapping_tester.dart @@ -157,7 +157,7 @@ Future runTests( .process(['--csp', Flags.disableInlining, ...options], verbose: verbose); TestResult result = new TestResult(config, filename, processor); for (SourceMapInfo info in sourceMaps.elementSourceMapInfos.values) { - if (info.element.library.canonicalUri.scheme == 'dart') continue; + if (info.element.library.canonicalUri.isScheme('dart')) continue; result.userInfoList.add(info); Iterable missingCodePoints = info.codePoints.where((c) => c.isMissing); diff --git a/pkg/compiler/tool/modular_test_suite_helper.dart b/pkg/compiler/tool/modular_test_suite_helper.dart index cd583add86e..d4ff09e4f92 100644 --- a/pkg/compiler/tool/modular_test_suite_helper.dart +++ b/pkg/compiler/tool/modular_test_suite_helper.dart @@ -638,7 +638,7 @@ Future resolveScripts(Options options) async { String sourceUriOrPath, String relativeSnapshotPath) async { Uri sourceUri = sdkRoot.resolve(sourceUriOrPath); String result = - sourceUri.scheme == 'file' ? sourceUri.toFilePath() : sourceUriOrPath; + sourceUri.isScheme('file') ? sourceUri.toFilePath() : sourceUriOrPath; if (_options.useSdk) { String snapshot = Uri.file(Platform.resolvedExecutable) .resolve(relativeSnapshotPath) diff --git a/pkg/dart2js_info/bin/src/deferred_library_layout.dart b/pkg/dart2js_info/bin/src/deferred_library_layout.dart index 1c4f13ffb88..95f20a5c9aa 100644 --- a/pkg/dart2js_info/bin/src/deferred_library_layout.dart +++ b/pkg/dart2js_info/bin/src/deferred_library_layout.dart @@ -64,7 +64,7 @@ _showLayout(String file) async { print(' contains:'); map.forEach((lib, elements) { var uri = lib.uri; - var shortUri = (uri.scheme == 'file' && uri.path.startsWith(dir)) + var shortUri = (uri.isScheme('file') && uri.path.startsWith(dir)) ? uri.path.substring(dir.length + 1) : '$uri'; diff --git a/pkg/dart2js_info/lib/deferred_library_check.dart b/pkg/dart2js_info/lib/deferred_library_check.dart index ef35cec1709..3b5c365cbe8 100644 --- a/pkg/dart2js_info/lib/deferred_library_check.dart +++ b/pkg/dart2js_info/lib/deferred_library_check.dart @@ -133,7 +133,7 @@ LibraryInfo _getLibraryOf(Info info) { return current; } -bool _isPackageUri(Uri uri) => uri.scheme == 'package'; +bool _isPackageUri(Uri uri) => uri.isScheme('package'); String _getPackageName(Uri uri) { assert(_isPackageUri(uri)); diff --git a/pkg/dart2js_info/lib/src/util.dart b/pkg/dart2js_info/lib/src/util.dart index 9ee83cbcff2..874202c66bd 100644 --- a/pkg/dart2js_info/lib/src/util.dart +++ b/pkg/dart2js_info/lib/src/util.dart @@ -116,7 +116,7 @@ String packageName(Info info) { info = info.parent; } if (info is LibraryInfo) { - if (info.uri.scheme == 'package') { + if (info.uri.isScheme('package')) { return '${info.uri}'.split('/').first; } } diff --git a/pkg/dart2js_tools/lib/deobfuscate_stack_trace.dart b/pkg/dart2js_tools/lib/deobfuscate_stack_trace.dart index 4a43b6c19b7..c04c95127f3 100644 --- a/pkg/dart2js_tools/lib/deobfuscate_stack_trace.dart +++ b/pkg/dart2js_tools/lib/deobfuscate_stack_trace.dart @@ -31,7 +31,7 @@ String deobfuscateStackTrace(String obfuscatedTrace) { var provider = CachingFileProvider(); StackDeobfuscationResult result = deobfuscateStack(obfuscatedTrace, provider); Frame firstFrame = result.original.frames.first; - String translatedError = (firstFrame.uri.scheme == 'error' + String translatedError = (firstFrame.uri.isScheme('error') ? null : translate(error, provider.mappingFor(firstFrame.uri))) ?? ''; diff --git a/pkg/dart2js_tools/lib/src/util.dart b/pkg/dart2js_tools/lib/src/util.dart index 1a733ac211a..eb8c3662dc2 100644 --- a/pkg/dart2js_tools/lib/src/util.dart +++ b/pkg/dart2js_tools/lib/src/util.dart @@ -34,7 +34,7 @@ class CachingFileProvider implements FileProvider { /// deobfuscation locally for debugging purposes. class DownloadedFileProvider extends CachingFileProvider { _localize(uri) { - if (uri.scheme == 'http' || uri.scheme == 'https') { + if (uri.isScheme('http') || uri.isScheme('https')) { String filename = uri.path.substring(uri.path.lastIndexOf('/') + 1); return Uri.base.resolve(filename); } diff --git a/pkg/dds/lib/dds.dart b/pkg/dds/lib/dds.dart index f31e447e63b..4d8a5e7cac3 100644 --- a/pkg/dds/lib/dds.dart +++ b/pkg/dds/lib/dds.dart @@ -46,13 +46,13 @@ abstract class DartDevelopmentService { DevToolsConfiguration? devToolsConfiguration, bool logRequests = false, }) async { - if (remoteVmServiceUri.scheme != 'http') { + if (!remoteVmServiceUri.isScheme('http')) { throw ArgumentError( 'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}', ); } if (serviceUri != null) { - if (serviceUri.scheme != 'http') { + if (!serviceUri.isScheme('http')) { throw ArgumentError( 'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}', ); diff --git a/pkg/dev_compiler/lib/src/compiler/module_builder.dart b/pkg/dev_compiler/lib/src/compiler/module_builder.dart index 9761f01e984..14685a410d0 100644 --- a/pkg/dev_compiler/lib/src/compiler/module_builder.dart +++ b/pkg/dev_compiler/lib/src/compiler/module_builder.dart @@ -460,11 +460,11 @@ class AmdModuleBuilder extends _ModuleBuilder { } bool isSdkInternalRuntimeUri(Uri importUri) { - return importUri.scheme == 'dart' && importUri.path == '_runtime'; + return importUri.isScheme('dart') && importUri.path == '_runtime'; } String libraryUriToJsIdentifier(Uri importUri) { - if (importUri.scheme == 'dart') { + if (importUri.isScheme('dart')) { return isSdkInternalRuntimeUri(importUri) ? 'dart' : importUri.path; } return pathToJSIdentifier(p.withoutExtension(importUri.pathSegments.last)); diff --git a/pkg/dev_compiler/lib/src/compiler/shared_command.dart b/pkg/dev_compiler/lib/src/compiler/shared_command.dart index f70d35bfe00..02472f7353b 100644 --- a/pkg/dev_compiler/lib/src/compiler/shared_command.dart +++ b/pkg/dev_compiler/lib/src/compiler/shared_command.dart @@ -347,7 +347,7 @@ Uri sourcePathToUri(String source, {bool windows}) { Uri sourcePathToRelativeUri(String source, {bool windows}) { var uri = sourcePathToUri(source, windows: windows); - if (uri.scheme == 'file') { + if (uri.isScheme('file')) { var uriPath = uri.path; var root = Uri.base.path; if (uriPath.startsWith(root)) { @@ -400,7 +400,7 @@ Map placeSourceMap(Map sourceMap, String sourceMapPath, String multiRootScheme, return sourcePath; } - if (uri.scheme == 'http') return sourcePath; + if (uri.isScheme('http')) return sourcePath; // Convert to a local file path if it's not. sourcePath = sourcePathToUri(p.absolute(p.fromUri(uri))).path; diff --git a/pkg/dev_compiler/lib/src/kernel/asset_file_system.dart b/pkg/dev_compiler/lib/src/kernel/asset_file_system.dart index b2647e0f97d..33b64964f8f 100644 --- a/pkg/dev_compiler/lib/src/kernel/asset_file_system.dart +++ b/pkg/dev_compiler/lib/src/kernel/asset_file_system.dart @@ -32,7 +32,7 @@ class AssetFileSystem implements FileSystem { @override FileSystemEntity entityForUri(Uri uri) { - if (uri.scheme == 'file') { + if (uri.isScheme('file')) { return original.entityForUri(uri); } diff --git a/pkg/dev_compiler/lib/src/kernel/command.dart b/pkg/dev_compiler/lib/src/kernel/command.dart index 605c339bf9f..f6fc3a201a7 100644 --- a/pkg/dev_compiler/lib/src/kernel/command.dart +++ b/pkg/dev_compiler/lib/src/kernel/command.dart @@ -177,7 +177,7 @@ Future _compile(List args, options.multiRootScheme, multiRootPaths, fe.StandardFileSystem.instance); Uri toCustomUri(Uri uri) { - if (uri.scheme == '') { + if (!uri.hasScheme) { return Uri(scheme: options.multiRootScheme, path: '/' + uri.path); } return uri; @@ -486,7 +486,7 @@ Future _compile(List args, compilerState.incrementalCompiler.updateNeededDillLibrariesWithHierarchy( neededDillLibraries, result.classHierarchy); for (var lib in neededDillLibraries) { - if (lib.importUri.scheme == 'dart') continue; + if (lib.importUri.isScheme('dart')) continue; var uri = compilerState.libraryToInputDill[lib.importUri]; if (uri == null) { throw StateError('Library ${lib.importUri} was recorded as used, ' @@ -552,7 +552,7 @@ Future compileSdkFromDill(List args) async { var component = loadComponentFromBinary(inputs.single); var invalidLibraries = []; for (var library in component.libraries) { - if (library.importUri.scheme != 'dart') { + if (!library.importUri.isScheme('dart')) { invalidLibraries.add(library.importUri); } } diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index 3919691fa0f..f0a8fc75f06 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -496,10 +496,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor @override String jsLibraryAlias(Library library) { var uri = library.importUri.normalizePath(); - if (uri.scheme == 'dart') return null; + if (uri.isScheme('dart')) return null; Iterable segments; - if (uri.scheme == 'package') { + if (uri.isScheme('package')) { // Strip the package name. segments = uri.pathSegments.skip(1); } else { @@ -521,7 +521,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor /// True when [library] is the sdk internal library 'dart:_internal'. bool _isDartInternal(Library library) { var importUri = library.importUri; - return importUri.scheme == 'dart' && importUri.path == '_internal'; + return importUri.isScheme('dart') && importUri.path == '_internal'; } @override @@ -531,7 +531,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor @override String libraryToModule(Library library) { - if (library.importUri.scheme == 'dart') { + if (library.importUri.isScheme('dart')) { // TODO(jmesserly): we need to split out HTML. return js_ast.dartSdkModule; } @@ -1940,7 +1940,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor bool _isForwardingStub(Procedure member) { if (member.isForwardingStub || member.isForwardingSemiStub) { - if (_currentLibrary.importUri.scheme != 'dart') return true; + if (!_currentLibrary.importUri.isScheme('dart')) return true; // TODO(jmesserly): external methods in the SDK seem to get incorrectly // tagged as forwarding stubs even if they are patched. Perhaps there is // an ordering issue in CFE. So for now we pattern match to see if it @@ -2254,7 +2254,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor _hierarchy.getClassAsInstanceOf(c.superclass, _coreTypes.iterableClass); if (parentIterable != null) return null; - if (c.enclosingLibrary.importUri.scheme == 'dart' && + if (c.enclosingLibrary.importUri.isScheme('dart') && c.procedures.any((m) => _jsExportName(m) == 'Symbol.iterator')) { return null; } @@ -2764,7 +2764,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor var fn = _emitFunction(p.function, p.name.text) ..sourceInformation = _nodeEnd(p.fileEndOffset); - if (_currentLibrary.importUri.scheme == 'dart' && + if (_currentLibrary.importUri.isScheme('dart') && _isInlineJSFunction(p.function.body)) { fn = js_ast.simplifyPassThroughArrowFunCallBody(fn); } @@ -3737,7 +3737,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor bool _reifyGenericFunction(Member m) => m == null || - m.enclosingLibrary.importUri.scheme != 'dart' || + !m.enclosingLibrary.importUri.isScheme('dart') || !m.annotations .any((a) => isBuiltinAnnotation(a, '_js_helper', 'NoReifyGeneric')); @@ -5692,7 +5692,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor bool _isWebLibrary(Uri importUri) => importUri != null && - importUri.scheme == 'dart' && + importUri.isScheme('dart') && (importUri.path == 'html' || importUri.path == 'svg' || importUri.path == 'indexed_db' || @@ -5792,7 +5792,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor if (args.positional.isEmpty && args.named.isEmpty && - ctorClass.enclosingLibrary.importUri.scheme == 'dart') { + ctorClass.enclosingLibrary.importUri.isScheme('dart')) { // Skip the slow SDK factory constructors when possible. switch (ctorClass.name) { case 'Map': @@ -6308,7 +6308,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor ]); bool _reifyFunctionType(FunctionNode f) { - if (_currentLibrary.importUri.scheme != 'dart') return true; + if (!_currentLibrary.importUri.isScheme('dart')) return true; var parent = f.parent; // SDK libraries can skip reification if they request it. @@ -6337,7 +6337,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor /// under which functions are compiled and exported. String _jsExportName(NamedNode n) { var library = getLibrary(n); - if (library == null || library.importUri.scheme != 'dart') return null; + if (library == null || !library.importUri.isScheme('dart')) return null; return _annotationName(n, isJSExportNameAnnotation); } @@ -6363,7 +6363,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor js_ast.Expression visitConstant(Constant node) { if (node is StaticTearOffConstant) { // JS() or external JS consts should not be lazily loaded. - var isSdk = node.target.enclosingLibrary.importUri.scheme == 'dart'; + var isSdk = node.target.enclosingLibrary.importUri.isScheme('dart'); if (_isInForeignJS) { return _emitStaticTarget(node.target); } diff --git a/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart b/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart index 215ba19c6dc..4ba953c893b 100644 --- a/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart +++ b/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart @@ -299,7 +299,7 @@ class ExpressionCompilerWorker { var libraryUri = Uri.parse(request.libraryUri); var moduleName = request.moduleName; - if (libraryUri.scheme == 'dart') { + if (libraryUri.isScheme('dart')) { // compiling expressions inside the SDK currently fails because // SDK kernel outlines do not contain information that is needed // to detect the scope for expression evaluation - such as local @@ -329,7 +329,7 @@ class ExpressionCompilerWorker { var originalComponent = _moduleCache.componentForModuleName[moduleName]; var component = _sdkComponent; - if (libraryUri.scheme != 'dart') { + if (!libraryUri.isScheme('dart')) { _processedOptions.ticker.logMs('Collecting libraries for $moduleName'); var libraries = diff --git a/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart b/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart index 44fe33ab7aa..fa868d90d16 100644 --- a/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart +++ b/pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart @@ -92,7 +92,7 @@ bool isBuiltinAnnotation( var c = getAnnotationClass(value); if (c != null && c.name == className) { var uri = c.enclosingLibrary.importUri; - return uri.scheme == 'dart' && uri.path == libraryName; + return uri.isScheme('dart') && uri.path == libraryName; } return false; } @@ -223,7 +223,7 @@ bool isCovariantField(Field f) { /// /// `dart:html` has many of these. bool isUnsupportedFactoryConstructor(Procedure node) { - if (node.name.isPrivate && node.enclosingLibrary.importUri.scheme == 'dart') { + if (node.name.isPrivate && node.enclosingLibrary.importUri.isScheme('dart')) { var body = node.function.body; if (body is Block) { var statements = body.statements; @@ -365,4 +365,4 @@ bool _isNativeMarkerAnnotation(Expression annotation) { } bool _isDartInternal(Uri uri) => - uri.scheme == 'dart' && uri.path == '_internal'; + uri.isScheme('dart') && uri.path == '_internal'; diff --git a/pkg/dev_compiler/lib/src/kernel/native_types.dart b/pkg/dev_compiler/lib/src/kernel/native_types.dart index 665f722fa1c..6ff4cdf4217 100644 --- a/pkg/dev_compiler/lib/src/kernel/native_types.dart +++ b/pkg/dev_compiler/lib/src/kernel/native_types.dart @@ -170,5 +170,5 @@ bool _isNativeAnnotation(Expression annotation) { var c = getAnnotationClass(annotation); return c != null && (c.name == 'Native' || c.name == 'JsPeerInterface') && - c.enclosingLibrary.importUri.scheme == 'dart'; + c.enclosingLibrary.importUri.isScheme('dart'); } diff --git a/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart b/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart index 71aaed211bc..c1ec743f5e5 100644 --- a/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart +++ b/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart @@ -338,9 +338,9 @@ class NullableInference extends ExpressionVisitor { bool _isInternalSdkAnnotation(Library library) { var uri = library.importUri; - return uri.scheme == 'dart' && uri.pathSegments[0] == '_js_helper' || + return uri.isScheme('dart') && uri.pathSegments[0] == '_js_helper' || allowPackageMetaAnnotations && - uri.scheme == 'package' && + uri.isScheme('package') && uri.pathSegments[0] == 'meta'; } } diff --git a/pkg/dev_compiler/lib/src/kernel/target.dart b/pkg/dev_compiler/lib/src/kernel/target.dart index 90dc78ecd92..2fb1100500d 100644 --- a/pkg/dev_compiler/lib/src/kernel/target.dart +++ b/pkg/dev_compiler/lib/src/kernel/target.dart @@ -120,11 +120,11 @@ class DevCompilerTarget extends Target { /// test framework. bool _allowedTestLibrary(Uri uri) { // Multi-root scheme used by modular test framework. - if (uri.scheme == 'dev-dart-app') return true; + if (uri.isScheme('dev-dart-app')) return true; return allowedNativeTest(uri); } - bool _allowedDartLibrary(Uri uri) => uri.scheme == 'dart'; + bool _allowedDartLibrary(Uri uri) => uri.isScheme('dart'); @override bool enableNative(Uri uri) => diff --git a/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart b/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart index 8dc187d777f..e5e91cc22d9 100644 --- a/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart +++ b/pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart @@ -42,7 +42,7 @@ class Module { Module(this.importUri, this.fileUri) : name = libraryUriToJsIdentifier(importUri), - path = importUri.scheme == 'package' + path = importUri.isScheme('package') ? 'packages/${importUri.path}' : importUri.path; diff --git a/pkg/dev_compiler/test/nullable_inference_test.dart b/pkg/dev_compiler/test/nullable_inference_test.dart index 901ca216530..1c5d392beda 100644 --- a/pkg/dev_compiler/test/nullable_inference_test.dart +++ b/pkg/dev_compiler/test/nullable_inference_test.dart @@ -568,7 +568,7 @@ class _TestRecursiveVisitor extends RecursiveVisitor { void visitLibrary(Library node) { _staticTypeContext.enterLibrary(node); if (librariesFromDill.contains(node) || - node.importUri.scheme == 'package' && + node.importUri.isScheme('package') && node.importUri.pathSegments[0] == 'meta') { return; } diff --git a/pkg/front_end/lib/src/api_prototype/experimental_flags.dart b/pkg/front_end/lib/src/api_prototype/experimental_flags.dart index 379c5ac396f..aa49e7b934c 100644 --- a/pkg/front_end/lib/src/api_prototype/experimental_flags.dart +++ b/pkg/front_end/lib/src/api_prototype/experimental_flags.dart @@ -93,9 +93,9 @@ bool isExperimentEnabledInLibrary(ExperimentalFlag flag, Uri canonicalUri, if (!enabled!) { allowedExperimentalFlags ??= defaultAllowedExperimentalFlags; Set? allowedFlags; - if (canonicalUri.scheme == 'dart') { + if (canonicalUri.isScheme('dart')) { allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path); - } else if (canonicalUri.scheme == 'package') { + } else if (canonicalUri.isScheme('package')) { int index = canonicalUri.path.indexOf('/'); String packageName; if (index >= 0) { @@ -123,9 +123,9 @@ Version getExperimentEnabledVersionInLibrary(ExperimentalFlag flag, allowedExperimentalFlags ??= defaultAllowedExperimentalFlags; Set? allowedFlags; - if (canonicalUri.scheme == 'dart') { + if (canonicalUri.isScheme('dart')) { allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path); - } else if (canonicalUri.scheme == 'package') { + } else if (canonicalUri.isScheme('package')) { int index = canonicalUri.path.indexOf('/'); String packageName; if (index >= 0) { @@ -187,9 +187,9 @@ bool isExperimentEnabledInLibraryByVersion( Set? allowedFlags; bool enabledByAllowed = false; - if (canonicalUri.scheme == 'dart') { + if (canonicalUri.isScheme('dart')) { allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path); - } else if (canonicalUri.scheme == 'package') { + } else if (canonicalUri.isScheme('package')) { int index = canonicalUri.path.indexOf('/'); String packageName; if (index >= 0) { diff --git a/pkg/front_end/lib/src/api_prototype/language_version.dart b/pkg/front_end/lib/src/api_prototype/language_version.dart index 566c81607e0..94dcb51b170 100644 --- a/pkg/front_end/lib/src/api_prototype/language_version.dart +++ b/pkg/front_end/lib/src/api_prototype/language_version.dart @@ -57,7 +57,7 @@ Future languageVersionForUri( UriTranslator uriTranslator = await context.options.getUriTranslator(); Uri? fileUri; Package? package; - if (uri.scheme == "package") { + if (uri.isScheme("package")) { fileUri = uriTranslator.translate(uri); package = uriTranslator.getPackage(uri); } else { @@ -65,8 +65,8 @@ Future languageVersionForUri( package = uriTranslator.packages.packageOf(uri); } Uri packageUri = uri; - if (packageUri.scheme != 'dart' && - packageUri.scheme != 'package' && + if (!packageUri.isScheme('dart') && + !packageUri.isScheme('package') && package != null && // ignore: unnecessary_null_comparison package.name != null) { diff --git a/pkg/front_end/lib/src/api_prototype/standard_file_system.dart b/pkg/front_end/lib/src/api_prototype/standard_file_system.dart index e7fd2c5b469..d15af7204a1 100644 --- a/pkg/front_end/lib/src/api_prototype/standard_file_system.dart +++ b/pkg/front_end/lib/src/api_prototype/standard_file_system.dart @@ -23,12 +23,12 @@ class StandardFileSystem implements FileSystem { @override FileSystemEntity entityForUri(Uri uri) { - if (uri.scheme == 'file') { + if (uri.isScheme('file')) { return new _IoFileSystemEntity(uri); - } else if (uri.scheme == '') { + } else if (!uri.hasScheme) { // TODO(askesc): Empty schemes should have been handled elsewhere. return new _IoFileSystemEntity(Uri.base.resolveUri(uri)); - } else if (uri.scheme == 'data') { + } else if (uri.isScheme('data')) { return new DataFileSystemEntity(Uri.base.resolveUri(uri)); } else { throw new FileSystemException( @@ -125,7 +125,7 @@ class DataFileSystemEntity implements FileSystemEntity { final Uri uri; DataFileSystemEntity(this.uri) - : assert(uri.scheme == 'data'), + : assert(uri.isScheme('data')), assert(uri.data != null); @override diff --git a/pkg/front_end/lib/src/base/processed_options.dart b/pkg/front_end/lib/src/base/processed_options.dart index ea79f68b203..a91d6cbe966 100644 --- a/pkg/front_end/lib/src/base/processed_options.dart +++ b/pkg/front_end/lib/src/base/processed_options.dart @@ -563,7 +563,7 @@ class ProcessedOptions { } // When compiling the SDK the input files are normally `dart:` URIs. - if (inputs.every((uri) => uri.scheme == 'dart')) { + if (inputs.every((uri) => uri.isScheme('dart'))) { return _packages = PackageConfig.empty; } @@ -577,7 +577,7 @@ class ProcessedOptions { Uri input = inputs.first; - if (input.scheme == 'package') { + if (input.isScheme('package')) { report( messageCantInferPackagesFromPackageUri.withLocation( input, -1, noLength), diff --git a/pkg/front_end/lib/src/compute_platform_binaries_location.dart b/pkg/front_end/lib/src/compute_platform_binaries_location.dart index c849e08d9f4..e53340fd3cb 100644 --- a/pkg/front_end/lib/src/compute_platform_binaries_location.dart +++ b/pkg/front_end/lib/src/compute_platform_binaries_location.dart @@ -95,7 +95,7 @@ Uri computePlatformBinariesLocation({bool forceBuildDir: false}) { /// Translates an SDK URI ("org-dartlang-sdk:///...") to a file URI. Uri translateSdk(Uri uri) { if (CompilerContext.isActive) { - if (uri.scheme == "org-dartlang-sdk") { + if (uri.isScheme("org-dartlang-sdk")) { String path = uri.path; if (path.startsWith("/sdk/")) { CompilerContext context = CompilerContext.current; @@ -148,7 +148,7 @@ Uri translateSdk(Uri uri) { } bool isExistingFile(Uri uri) { - if (uri.scheme == "file") { + if (uri.isScheme("file")) { return new File.fromUri(uri).existsSync(); } else { return false; diff --git a/pkg/front_end/lib/src/fasta/builder/class_builder.dart b/pkg/front_end/lib/src/fasta/builder/class_builder.dart index 05653efab2b..758b0702dbf 100644 --- a/pkg/front_end/lib/src/fasta/builder/class_builder.dart +++ b/pkg/front_end/lib/src/fasta/builder/class_builder.dart @@ -326,7 +326,7 @@ abstract class ClassBuilderImpl extends DeclarationBuilderImpl } if (name == "FutureOr") { LibraryBuilder parentLibrary = parent as LibraryBuilder; - if (parentLibrary.importUri.scheme == "dart" && + if (parentLibrary.importUri.isScheme("dart") && parentLibrary.importUri.path == "async") { assert(arguments != null && arguments.length == 1); return new FutureOrType(arguments!.single, nullability); diff --git a/pkg/front_end/lib/src/fasta/compiler_context.dart b/pkg/front_end/lib/src/fasta/compiler_context.dart index 59605748f2e..9d86de301c7 100644 --- a/pkg/front_end/lib/src/fasta/compiler_context.dart +++ b/pkg/front_end/lib/src/fasta/compiler_context.dart @@ -86,7 +86,7 @@ class CompilerContext { } static void recordDependency(Uri uri) { - if (uri.scheme != "file" && uri.scheme != "http") { + if (!uri.isScheme("file") && !uri.isScheme("http")) { throw new ArgumentError("Expected a file or http URI, but got: '$uri'."); } CompilerContext? context = Zone.current[compilerContextKey]; diff --git a/pkg/front_end/lib/src/fasta/dill/dill_loader.dart b/pkg/front_end/lib/src/fasta/dill/dill_loader.dart index 9524f5b5bde..b53d4882e32 100644 --- a/pkg/front_end/lib/src/fasta/dill/dill_loader.dart +++ b/pkg/front_end/lib/src/fasta/dill/dill_loader.dart @@ -120,7 +120,7 @@ class DillLoader extends Loader { assert(libraryBuilder != null, "No library found for $uri."); _builders[uri] = libraryBuilder!; assert(libraryBuilder.loader == this); - if (uri.scheme == "dart") { + if (uri.isScheme("dart")) { if (uri.path == "core") { _coreLibrary = libraryBuilder; } @@ -352,7 +352,7 @@ severity: $severity void registerLibraryBuilder(DillLibraryBuilder libraryBuilder) { Uri importUri = libraryBuilder.importUri; libraryBuilder.loader = this; - if (importUri.scheme == "dart" && importUri.path == "core") { + if (importUri.isScheme("dart") && importUri.path == "core") { _coreLibrary = libraryBuilder; } _builders[importUri] = libraryBuilder; diff --git a/pkg/front_end/lib/src/fasta/hybrid_file_system.dart b/pkg/front_end/lib/src/fasta/hybrid_file_system.dart index d56e24f85b4..55f838176af 100644 --- a/pkg/front_end/lib/src/fasta/hybrid_file_system.dart +++ b/pkg/front_end/lib/src/fasta/hybrid_file_system.dart @@ -37,7 +37,7 @@ class HybridFileSystemEntity implements FileSystemEntity { Future get delegate async { if (_delegate != null) return _delegate!; FileSystemEntity entity = _fs.memory.entityForUri(uri); - if (((uri.scheme != 'file' && uri.scheme != 'data') && + if (((!uri.isScheme('file') && !uri.isScheme('data')) && _fs.physical is StandardFileSystem) || await entity.exists()) { _delegate = entity; diff --git a/pkg/front_end/lib/src/fasta/incremental_compiler.dart b/pkg/front_end/lib/src/fasta/incremental_compiler.dart index 5e0c376779a..3e10ccd295a 100644 --- a/pkg/front_end/lib/src/fasta/incremental_compiler.dart +++ b/pkg/front_end/lib/src/fasta/incremental_compiler.dart @@ -1272,7 +1272,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { _platformBuilders = []; for (DillLibraryBuilder builder in dillLoadedData.loader.libraryBuilders) { - if (builder.importUri.scheme == "dart") { + if (builder.importUri.isScheme("dart")) { _platformBuilders!.add(builder); } else { _userBuilders![builder.importUri] = builder; @@ -1425,7 +1425,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { _platformBuilders = []; for (DillLibraryBuilder builder in _dillLoadedData!.loader.libraryBuilders) { - if (builder.importUri.scheme == "dart") { + if (builder.importUri.isScheme("dart")) { _platformBuilders!.add(builder); } else { _userBuilders![builder.importUri] = builder; @@ -1492,7 +1492,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { partUriToLibraryImportUri[partUri] = library.importUri; } } - if (library.importUri.scheme == "dart") { + if (library.importUri.isScheme("dart")) { result.add(library); inputLibrariesFiltered?.add(library); } else { @@ -1501,7 +1501,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { } } for (LibraryBuilder libraryBuilder in reusedLibraries) { - if (libraryBuilder.importUri.scheme == "dart" && + if (libraryBuilder.importUri.isScheme("dart") && !libraryBuilder.isSynthetic) { continue; } @@ -1550,7 +1550,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { List removedLibraries = []; bool removedDillBuilders = false; for (Uri uri in potentiallyReferencedLibraries.keys) { - if (uri.scheme == "package") continue; + if (uri.isScheme("package")) continue; LibraryBuilder? builder = currentKernelTarget.loader.deregisterLibraryBuilder(uri); if (builder != null) { @@ -1913,7 +1913,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { if (importUri != fileUri && invalidatedUris.contains(fileUri)) { return true; } - if (_hasToCheckPackageUris && importUri.scheme == "package") { + if (_hasToCheckPackageUris && importUri.isScheme("package")) { // Get package name, check if the base URI has changed for the package, // if it has, translate the URI again, // otherwise the URI cannot have changed. @@ -1935,7 +1935,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator { } void addBuilderAndInvalidateUris(Uri uri, LibraryBuilder libraryBuilder) { - if (uri.scheme == "dart" && !libraryBuilder.isSynthetic) { + if (uri.isScheme("dart") && !libraryBuilder.isSynthetic) { if (seenUris.add(libraryBuilder.importUri)) { reusedLibraries.add(libraryBuilder); } @@ -2355,7 +2355,7 @@ class _InitializationFromComponent extends _InitializationStrategy { bool foundDartCore = false; for (int i = 0; i < component.libraries.length; i++) { Library library = component.libraries[i]; - if (library.importUri.scheme == "dart" && + if (library.importUri.isScheme("dart") && library.importUri.path == "core") { foundDartCore = true; break; @@ -2501,7 +2501,7 @@ class _InitializationFromUri extends _InitializationFromSdkSummary { // (e.g. the package still exists and hasn't been updated). // Also verify NNBD settings. for (Library lib in data.component!.libraries) { - if (lib.importUri.scheme == "package" && + if (lib.importUri.isScheme("package") && uriTranslator.translate(lib.importUri, false) != lib.fileUri) { // Package has been removed or updated. // This library should be thrown away. @@ -2649,7 +2649,7 @@ class _ComponentProblems { extension on UriTranslator { Uri? getPartFileUri(Uri parentFileUri, LibraryPart part) { Uri? fileUri = getPartUri(parentFileUri, part); - if (fileUri.scheme == "package") { + if (fileUri.isScheme("package")) { // Part was specified via package URI and the resolve above thus // did not go as expected. Translate the package URI to get the // actual file URI. diff --git a/pkg/front_end/lib/src/fasta/incremental_serializer.dart b/pkg/front_end/lib/src/fasta/incremental_serializer.dart index 7289a1107a8..bebdcd9149b 100644 --- a/pkg/front_end/lib/src/fasta/incremental_serializer.dart +++ b/pkg/front_end/lib/src/fasta/incremental_serializer.dart @@ -43,7 +43,7 @@ class IncrementalSerializer { Uri uri = lib.importUri; // Uris need to be unique. if (!uris.add(lib.fileUri)) return false; - if (uri.scheme == "package") { + if (uri.isScheme("package")) { String thisPackageName = uri.pathSegments.first; if (packageName == null) { packageName = thisPackageName; @@ -117,7 +117,7 @@ class IncrementalSerializer { List nonPackageLibraries = []; for (Library lib in component.libraries) { Uri uri = lib.importUri; - if (uri.scheme == "package") { + if (uri.isScheme("package")) { packageLibraries.add(lib); } else { nonPackageLibraries.add(lib); @@ -179,7 +179,7 @@ class IncrementalSerializer { for (Library lib in component.libraries) { for (LibraryDependency dependency in lib.dependencies) { if (!got.contains(dependency.targetLibrary)) { - if (dependency.targetLibrary.importUri.scheme == "dart") { + if (dependency.targetLibrary.importUri.isScheme("dart")) { continue; } return false; @@ -241,7 +241,7 @@ class IncrementalSerializer { for (Library lib in libraries) { for (LibraryDependency dep in lib.dependencies) { Library dependencyLibrary = dep.importedLibraryReference.asLibrary; - if (dependencyLibrary.importUri.scheme != "package") continue; + if (!dependencyLibrary.importUri.isScheme("package")) continue; Uri dependencyLibraryUri = dep.importedLibraryReference.asLibrary.fileUri; SerializationGroup? depGroup = uriToGroup[dependencyLibraryUri]; diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart index 89836a776e2..e04f3aaddd4 100644 --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart @@ -355,7 +355,7 @@ class BodyBuilder extends ScopeListener stringExpectedAfterNative = libraryBuilder .loader.target.backendTarget.nativeExtensionExpectsString, ignoreMainInGetMainClosure = - libraryBuilder.importUri.scheme == 'dart' && + libraryBuilder.importUri.isScheme('dart') && (libraryBuilder.importUri.path == "_builtin" || libraryBuilder.importUri.path == "ui"), needsImplicitSuperInitializer = diff --git a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart index 7d665b8d79c..9aca3e3689d 100644 --- a/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart +++ b/pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart @@ -965,7 +965,7 @@ class ConstantEvaluator implements ExpressionVisitor { Map _computeSupportedLibraries() { Map map = {}; for (Library library in component.libraries) { - if (library.importUri.scheme == 'dart') { + if (library.importUri.isScheme('dart')) { map[library.importUri.path] = DartLibrarySupport.getDartLibrarySupportValue( library.importUri.path, diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart index 6ac5ea02d9a..aa458b7748a 100644 --- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart +++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart @@ -1667,7 +1667,7 @@ class KernelTarget extends TargetImplementation { } void readPatchFiles(SourceLibraryBuilder library) { - assert(library.importUri.scheme == "dart"); + assert(library.importUri.isScheme("dart")); List? patches = uriTranslator.getDartPatches(library.importUri.path); if (patches != null) { SourceLibraryBuilder? first; diff --git a/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart b/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart index 79badb9ea8e..ec26f2aef1f 100644 --- a/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart +++ b/pkg/front_end/lib/src/fasta/kernel/type_labeler.dart @@ -66,7 +66,7 @@ class TypeLabeler implements DartTypeVisitor, ConstantVisitor { static bool isObject(DartType type) { if (type is InterfaceType && type.classNode.name == 'Object') { Uri importUri = type.classNode.enclosingLibrary.importUri; - return importUri.scheme == 'dart' && importUri.path == 'core'; + return importUri.isScheme('dart') && importUri.path == 'core'; } return false; } @@ -504,7 +504,7 @@ class LabeledNode { } String get originMessage { - if (importUri.scheme == 'dart' && importUri.path == 'core') { + if (importUri.isScheme('dart') && importUri.path == 'core') { if (node is Class && denylistedCoreClasses.contains(name)) { // Denylisted core class. Only print if ambiguous. List entityForName = typeLabeler.nameMap[name]!; @@ -521,7 +521,7 @@ class LabeledNode { return ""; } } - Message message = (importUri == fileUri || importUri.scheme == 'dart') + Message message = (importUri == fileUri || importUri.isScheme('dart')) ? templateTypeOrigin.withArguments(toString(), importUri) : templateTypeOriginWithFileUri.withArguments( toString(), importUri, fileUri); diff --git a/pkg/front_end/lib/src/fasta/kernel/verifier.dart b/pkg/front_end/lib/src/fasta/kernel/verifier.dart index ae560e29218..3c825f67ca5 100644 --- a/pkg/front_end/lib/src/fasta/kernel/verifier.dart +++ b/pkg/front_end/lib/src/fasta/kernel/verifier.dart @@ -241,7 +241,7 @@ class FastaVerifyingVisitor extends VerifyingVisitor { // 'dart:test' is used in the unit tests and isn't an actual part of the // platform. if (skipPlatform && - node.importUri.scheme == 'dart' && + node.importUri.isScheme('dart') && node.importUri.path != 'test') { return; } @@ -304,7 +304,7 @@ class FastaVerifyingVisitor extends VerifyingVisitor { bool isObjectClass(Class c) { return c.name == "Object" && - c.enclosingLibrary.importUri.scheme == "dart" && + c.enclosingLibrary.importUri.isScheme("dart") && c.enclosingLibrary.importUri.path == "core"; } @@ -435,7 +435,7 @@ class FastaVerifyingVisitor extends VerifyingVisitor { } void _checkConstructorTearOff(Node node, Member tearOffTarget) { - if (tearOffTarget.enclosingLibrary.importUri.scheme == 'dart') { + if (tearOffTarget.enclosingLibrary.importUri.isScheme('dart')) { // Platform libraries are not compilation with test flags and might // contain tear-offs not expected when testing lowerings. return; @@ -540,7 +540,7 @@ class FastaVerifyGetStaticType extends VerifyGetStaticType { // 'dart:test' is used in the unit tests and isn't an actual part of the // platform. if (skipPlatform && - node.importUri.scheme == 'dart' && + node.importUri.isScheme('dart') && node.importUri.path != "test") { return; } diff --git a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart index 4d8edadfe1d..7b40a7c4705 100644 --- a/pkg/front_end/lib/src/fasta/source/source_class_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_class_builder.dart @@ -714,7 +714,7 @@ class SourceClassBuilder extends ClassBuilderImpl this.charOffset, noLength); } else if (interface.cls.name == "FutureOr" && - interface.cls.enclosingLibrary.importUri.scheme == "dart" && + interface.cls.enclosingLibrary.importUri.isScheme("dart") && interface.cls.enclosingLibrary.importUri.path == "async") { addProblem(messageImplementsFutureOr, this.charOffset, noLength); } else if (implemented.contains(interface)) { diff --git a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart index dee61c4c909..a5a4d579f5f 100644 --- a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart @@ -289,12 +289,12 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { new Scope.top()) { assert( _packageUri == null || - importUri.scheme != 'package' || + !importUri.isScheme('package') || importUri.path.startsWith(_packageUri!.path), "Foreign package uri '$_packageUri' set on library with import uri " "'${importUri}'."); assert( - importUri.scheme != 'dart' || _packageUri == null, + !importUri.isScheme('dart') || _packageUri == null, "Package uri '$_packageUri' set on dart: library with import uri " "'${importUri}'."); } @@ -638,7 +638,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { return previous; } - bool uriIsValid(Uri uri) => uri.scheme != MALFORMED_URI_SCHEME; + bool uriIsValid(Uri uri) => !uri.isScheme(MALFORMED_URI_SCHEME); Uri resolve(Uri baseUri, String? uri, int uriOffset, {isPart: false}) { if (uri == null) { @@ -657,7 +657,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { return new Uri( scheme: MALFORMED_URI_SCHEME, query: Uri.encodeQueryComponent(uri)); } - if (isPart && baseUri.scheme == "dart") { + if (isPart && baseUri.isScheme("dart")) { // Resolve using special rules for dart: URIs return resolveRelativeUri(baseUri, parsedUri); } else { @@ -1668,7 +1668,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { if (className != "Function") { return; } - if (decType == "class" && importUri.scheme == "dart") { + if (decType == "class" && importUri.isScheme("dart")) { // Allow declaration of class Function in the sdk. return; } @@ -3158,9 +3158,9 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { preferred = declaration; } else if (other is LoadLibraryBuilder) { preferred = other; - } else if (otherUri.scheme == "dart" && uri.scheme != "dart") { + } else if (otherUri.isScheme("dart") && !uri.isScheme("dart")) { preferred = declaration; - } else if (uri.scheme == "dart" && otherUri.scheme != "dart") { + } else if (uri.isScheme("dart") && !otherUri.isScheme("dart")) { preferred = other; } } @@ -3901,7 +3901,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { } void exportMemberFromPatch(String name, Builder member) { - if (importUri.scheme != "dart" || !importUri.path.startsWith("_")) { + if (!importUri.isScheme("dart") || !importUri.path.startsWith("_")) { addProblem(templatePatchInjectionFailed.withArguments(name, importUri), member.charOffset, noLength, member.fileUri); } diff --git a/pkg/front_end/lib/src/fasta/source/source_loader.dart b/pkg/front_end/lib/src/fasta/source/source_loader.dart index 90ad778fe57..766d6310372 100644 --- a/pkg/front_end/lib/src/fasta/source/source_loader.dart +++ b/pkg/front_end/lib/src/fasta/source/source_loader.dart @@ -265,7 +265,7 @@ class SourceLoader extends Loader { void registerLibraryBuilder(LibraryBuilder libraryBuilder) { Uri uri = libraryBuilder.importUri; - if (uri.scheme == "dart" && uri.path == "core") { + if (uri.isScheme("dart") && uri.path == "core") { _coreLibrary = libraryBuilder; } _builders[uri] = libraryBuilder; @@ -326,7 +326,7 @@ class SourceLoader extends Loader { referencesFrom: referencesFrom, referenceIsPartOwner: referenceIsPartOwner, isUnsupported: origin?.library.isUnsupported ?? - importUri.scheme == 'dart' && + importUri.isScheme('dart') && !target.uriTranslator.isLibrarySupported(importUri.path)); } @@ -359,9 +359,9 @@ class SourceLoader extends Loader { Library? referencesFrom, bool? referenceIsPartOwner) { if (fileUri != null && - (fileUri.scheme == "dart" || - fileUri.scheme == "package" || - fileUri.scheme == "dart-ext")) { + (fileUri.isScheme("dart") || + fileUri.isScheme("package") || + fileUri.isScheme("dart-ext"))) { fileUri = null; } package_config.Package? packageForLanguageVersion; @@ -373,7 +373,7 @@ class SourceLoader extends Loader { new Uri( scheme: untranslatableUriScheme, path: Uri.encodeComponent("$uri")); - if (uri.scheme == "package") { + if (uri.isScheme("package")) { packageForLanguageVersion = target.uriTranslator.getPackage(uri); } else { packageForLanguageVersion = @@ -396,8 +396,8 @@ class SourceLoader extends Loader { Message? packageLanguageVersionProblem; if (packageForLanguageVersion != null) { Uri importUri = origin?.importUri ?? uri; - if (importUri.scheme != 'dart' && - importUri.scheme != 'package' && + if (!importUri.isScheme('dart') && + !importUri.isScheme('package') && // ignore: unnecessary_null_comparison packageForLanguageVersion.name != null) { packageUri = @@ -455,7 +455,7 @@ class SourceLoader extends Loader { if (target.backendTarget.mayDefineRestrictedType(libraryUri)) { libraryBuilder.mayImplementRestrictedTypes = true; } - if (uri.scheme == "dart") { + if (uri.isScheme("dart")) { target.readPatchFiles(libraryBuilder); } _unparsedLibraries.addLast(libraryBuilder); @@ -516,7 +516,7 @@ class SourceLoader extends Loader { } void _checkForDartCore(Uri uri, LibraryBuilder libraryBuilder) { - if (uri.scheme == "dart") { + if (uri.isScheme("dart")) { if (uri.path == "core") { _coreLibrary = libraryBuilder; } else if (uri.path == "typed_data") { @@ -595,7 +595,7 @@ class SourceLoader extends Loader { } bool _hasLibraryAccess({required Uri imported, required Uri? importer}) { - if (imported.scheme == "dart" && imported.path.startsWith("_")) { + if (imported.isScheme("dart") && imported.path.startsWith("_")) { if (importer == null) { return false; } else { @@ -810,7 +810,7 @@ severity: $severity if (bytes == null) { // Error recovery. - if (fileUri.scheme == untranslatableUriScheme) { + if (fileUri.isScheme(untranslatableUriScheme)) { Message message = templateUntranslatableUri.withArguments(library.importUri); library.addProblemAtAccessors(message); @@ -820,7 +820,7 @@ severity: $severity templateInternalProblemUriMissingScheme.withArguments(fileUri), -1, library.importUri); - } else if (fileUri.scheme == SourceLibraryBuilder.MALFORMED_URI_SCHEME) { + } else if (fileUri.isScheme(SourceLibraryBuilder.MALFORMED_URI_SCHEME)) { library.addProblemAtAccessors(messageExpectedUri); bytes = synthesizeSourceForMissingFile(library.importUri, null); } @@ -1027,7 +1027,7 @@ severity: $severity continue; } } - if (libraryBuilder.importUri.scheme == 'package') { + if (libraryBuilder.importUri.isScheme('package')) { (libraryByPackage[null] ??= []).add(libraryBuilder); } else { if (emitNonPackageErrors) { @@ -1965,7 +1965,7 @@ severity: $severity for (LibraryBuilder libraryBuilder in libraryBuilders) { if (!libraryBuilder.isPatch && (libraryBuilder.loader == this || - libraryBuilder.importUri.scheme == "dart" || + libraryBuilder.importUri.isScheme("dart") || libraryBuilder == this.first)) { if (libraries.add(libraryBuilder.library)) { workList.add(libraryBuilder.library); diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart index bdf3e385b27..5f7680bfd75 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart @@ -1064,7 +1064,7 @@ class TypeInferrerImpl implements TypeInferrer { onType, onTypeInstantiateToBounds, target, - isPlatform: extensionBuilder.library.importUri.scheme == 'dart'); + isPlatform: extensionBuilder.library.importUri.isScheme('dart')); if (noneMoreSpecific.isNotEmpty) { bool isMostSpecific = true; for (ExtensionAccessCandidate other in noneMoreSpecific) { diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart b/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart index 8927d8584ef..d1023db310b 100644 --- a/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart +++ b/pkg/front_end/lib/src/fasta/type_inference/type_schema_elimination.dart @@ -70,7 +70,7 @@ class _TypeSchemaEliminationVisitor extends ReplacementVisitor { assert(topType == const DynamicType() || topType is InterfaceType && topType.nullability == Nullability.nullable && - topType.classNode.enclosingLibrary.importUri.scheme == "dart" && + topType.classNode.enclosingLibrary.importUri.isScheme("dart") && topType.classNode.enclosingLibrary.importUri.path == "core" && topType.classNode.name == "Object"); assert( diff --git a/pkg/front_end/lib/src/fasta/uri_translator.dart b/pkg/front_end/lib/src/fasta/uri_translator.dart index dac88453a75..e4df37bf839 100644 --- a/pkg/front_end/lib/src/fasta/uri_translator.dart +++ b/pkg/front_end/lib/src/fasta/uri_translator.dart @@ -22,7 +22,7 @@ class UriTranslator { dartLibraries.libraryInfoFor(libraryName)?.patches; bool isPlatformImplementation(Uri uri) { - if (uri.scheme != "dart") return false; + if (!uri.isScheme("dart")) return false; String path = uri.path; return dartLibraries.libraryInfoFor(path) == null || path.startsWith("_"); } @@ -31,8 +31,8 @@ class UriTranslator { // callback, so we can provide an error location when one is available. For // example, if the error occurs in an `import`. Uri? translate(Uri uri, [bool reportMessage = true]) { - if (uri.scheme == "dart") return _translateDartUri(uri); - if (uri.scheme == "package") { + if (uri.isScheme("dart")) return _translateDartUri(uri); + if (uri.isScheme("package")) { return _translatePackageUri(uri, reportMessage); } return null; @@ -42,7 +42,7 @@ class UriTranslator { Package? getPackage(Uri uri) { // ignore: unnecessary_null_comparison if (packages == null) return null; - if (uri.scheme != "package") return null; + if (!uri.isScheme("package")) return null; int firstSlash = uri.path.indexOf('/'); if (firstSlash == -1) return null; String packageName = uri.path.substring(0, firstSlash); diff --git a/pkg/front_end/lib/src/fasta/util/outline_extractor.dart b/pkg/front_end/lib/src/fasta/util/outline_extractor.dart index ff65e376af0..d1f5d0a9e2c 100644 --- a/pkg/front_end/lib/src/fasta/util/outline_extractor.dart +++ b/pkg/front_end/lib/src/fasta/util/outline_extractor.dart @@ -116,7 +116,7 @@ class _Processor { Future preprocessUri(Uri importUri, {Uri? partOf}) async { if (verbosityLevel >= 20) log("$importUri =>"); Uri fileUri = importUri; - if (importUri.scheme == "package") { + if (importUri.isScheme("package")) { fileUri = uriTranslator.translate(importUri)!; } if (verbosityLevel >= 20) log("$fileUri"); @@ -202,14 +202,14 @@ class _Processor { worklist.add(new _TopLevelAndAstNode(entrypointish, child)); if (child is Part) { - if (child.uri.scheme != "dart") { + if (!child.uri.isScheme("dart")) { TopLevel partTopLevel = parsed[child.uri] ?? await preprocessUri(child.uri, partOf: entrypointish.uri); await _premarkTopLevel(worklist, closed, partTopLevel); } } else if (child is Export) { for (Uri importedUri in child.uris) { - if (importedUri.scheme != "dart") { + if (!importedUri.isScheme("dart")) { TopLevel exportTopLevel = parsed[importedUri] ?? await preprocessUri(importedUri); await _premarkTopLevel(worklist, closed, exportTopLevel); @@ -230,7 +230,7 @@ class _Processor { if (child is Import) { child.marked = Coloring.Marked; for (Uri importedUri in child.uris) { - if (importedUri.scheme != "dart") { + if (!importedUri.isScheme("dart")) { TopLevel importedTopLevel = parsed[importedUri] ?? await preprocessUri(importedUri); imported.add(importedTopLevel); @@ -238,7 +238,7 @@ class _Processor { } } else if (child is PartOf) { child.marked = Coloring.Marked; - if (child.partOfUri.scheme != "dart") { + if (!child.partOfUri.isScheme("dart")) { TopLevel part = parsed[child.partOfUri]!; List importsFromPart = await _preprocessImportsAsNeeded(imports, part); @@ -392,7 +392,7 @@ class _Processor { if (child is Part) { child.marked = Coloring.Marked; // do stuff to part. - if (child.uri.scheme != "dart") { + if (!child.uri.isScheme("dart")) { other = parsed[child.uri] ?? await preprocessUri(child.uri, partOf: topLevel.uri); } @@ -400,7 +400,7 @@ class _Processor { child.marked = Coloring.Marked; // do stuff to export. for (Uri importedUri in child.uris) { - if (importedUri.scheme != "dart") { + if (!importedUri.isScheme("dart")) { other = parsed[importedUri] ?? await preprocessUri(importedUri); } } @@ -468,7 +468,7 @@ class _Processor { } if (child is Import) { for (Uri importedUri in child.uris) { - if (importedUri.scheme != "dart") { + if (!importedUri.isScheme("dart")) { imported.add(importedUri); } } @@ -478,7 +478,7 @@ class _Processor { if (sb.isNotEmpty) count++; Uri uri = entry.key; Uri fileUri = uri; - if (uri.scheme == "package") { + if (uri.isScheme("package")) { fileUri = uriTranslator.translate(uri)!; } result[fileUri] = sb.toString(); @@ -489,7 +489,7 @@ class _Processor { // uri imports a file we haven't read. Check if it exists and include it // as an empty file if it does. Uri fileUri = uri; - if (uri.scheme == "package") { + if (uri.isScheme("package")) { fileUri = uriTranslator.translate(uri)!; } if (await fileSystem.entityForUri(fileUri).exists()) { diff --git a/pkg/front_end/lib/src/testing/compiler_common.dart b/pkg/front_end/lib/src/testing/compiler_common.dart index 0ee8f98aefd..6c2620b02d1 100644 --- a/pkg/front_end/lib/src/testing/compiler_common.dart +++ b/pkg/front_end/lib/src/testing/compiler_common.dart @@ -140,7 +140,7 @@ String _invalidLibrariesSpec = ''' '''; bool isDartCoreLibrary(Library lib) => isDartCore(lib.importUri); -bool isDartCore(Uri uri) => uri.scheme == 'dart' && uri.path == 'core'; +bool isDartCore(Uri uri) => uri.isScheme('dart') && uri.path == 'core'; /// Find a library in [component] whose Uri ends with the given [suffix] Library findLibrary(Component component, String suffix) { diff --git a/pkg/front_end/lib/src/testing/id_testing_helper.dart b/pkg/front_end/lib/src/testing/id_testing_helper.dart index b9a1a86e42e..48fe099f873 100644 --- a/pkg/front_end/lib/src/testing/id_testing_helper.dart +++ b/pkg/front_end/lib/src/testing/id_testing_helper.dart @@ -451,8 +451,8 @@ Future> runTestForConfig( bool excludeLibrary(Library library) { return forUserLibrariesOnly && - (library.importUri.scheme == 'dart' || - library.importUri.scheme == 'package'); + (library.importUri.isScheme('dart') || + library.importUri.isScheme('package')); } await dataComputer.inspectTestResultData(testResultData); diff --git a/pkg/front_end/test/ast_nodes_has_to_string_test.dart b/pkg/front_end/test/ast_nodes_has_to_string_test.dart index 0c27d6f5dfb..ea54f974e58 100644 --- a/pkg/front_end/test/ast_nodes_has_to_string_test.dart +++ b/pkg/front_end/test/ast_nodes_has_to_string_test.dart @@ -55,7 +55,7 @@ Future main(List args) async { .where((Member m) => !m.isAbstract && m.name.text == "toString" && - m.enclosingLibrary.importUri.scheme != "dart") + !m.enclosingLibrary.importUri.isScheme("dart")) .toList(); if (toStringList.length > 1) throw "What?"; if (toStringList.length == 1) { @@ -157,7 +157,7 @@ Future main(List args) async { .where((Member m) => !m.isAbstract && m.name.text == "toString" && - m.enclosingLibrary.importUri.scheme != "dart") + !m.enclosingLibrary.importUri.isScheme("dart")) .toList(); Member toString = toStringList.single; if (toString.fileUri != uri) continue; diff --git a/pkg/front_end/test/comments_on_certain_arguments_tool.dart b/pkg/front_end/test/comments_on_certain_arguments_tool.dart index 254ff7d74f8..3607cc250d9 100644 --- a/pkg/front_end/test/comments_on_certain_arguments_tool.dart +++ b/pkg/front_end/test/comments_on_certain_arguments_tool.dart @@ -88,7 +88,7 @@ Future main(List args) async { component = incrementalCompilerResult.component; for (Library library in component.libraries) { - if (library.importUri.scheme == "dart") continue; + if (library.importUri.isScheme("dart")) continue; // This isn't perfect because of parts, but (for now) it'll do. for (Uri uri in libUris) { if (library.fileUri.toString().startsWith(uri.toString())) { diff --git a/pkg/front_end/test/compile_benchmark.dart b/pkg/front_end/test/compile_benchmark.dart index c244da305e8..e6cea76e322 100644 --- a/pkg/front_end/test/compile_benchmark.dart +++ b/pkg/front_end/test/compile_benchmark.dart @@ -363,7 +363,7 @@ class RegisterCallTransformer extends RecursiveVisitor { @override void visitLibrary(Library node) { - if (node.importUri.scheme == "package" && + if (node.importUri.isScheme("package") && node.importUri.pathSegments.first == "front_end") { super.visitLibrary(node); } @@ -395,7 +395,7 @@ class RegisterTimeTransformer extends RecursiveVisitor { @override void visitLibrary(Library node) { - if (node.importUri.scheme == "package" && + if (node.importUri.isScheme("package") && node.importUri.pathSegments.first == "front_end") { super.visitLibrary(node); } diff --git a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart index 437c01020da..e6ffb2bd9ef 100644 --- a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart +++ b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart @@ -778,9 +778,9 @@ worlds: void _rewriteImportsExportsToUriInternal( Token uriToken, Uri oldUri, List<_Replacement> replacements, Uri newUri) { Uri tokenUri = _getUri(uriToken, oldUri, resolvePackage: false); - if (tokenUri.scheme == "package" || tokenUri.scheme == "dart") return; + if (tokenUri.isScheme("package") || tokenUri.isScheme("dart")) return; Uri asPackageUri = _getImportUri(tokenUri); - if (asPackageUri.scheme == "package") { + if (asPackageUri.isScheme("package")) { // Just replace with this package uri. replacements.add(new _Replacement( uriToken.offset - 1, @@ -803,7 +803,7 @@ worlds: String uriString = uriToken.lexeme; uriString = uriString.substring(1, uriString.length - 1); Uri uriTokenUri = uri.resolve(uriString); - if (resolvePackage && uriTokenUri.scheme == "package") { + if (resolvePackage && uriTokenUri.isScheme("package")) { Package package = _latestCrashingIncrementalCompiler! .getPackageForPackageName(uriTokenUri.pathSegments.first)!; uriTokenUri = package.packageUriRoot diff --git a/pkg/front_end/test/enable_non_nullable/enable_non_nullable_test.dart b/pkg/front_end/test/enable_non_nullable/enable_non_nullable_test.dart index a5f766e1faa..b2076acb15f 100644 --- a/pkg/front_end/test/enable_non_nullable/enable_non_nullable_test.dart +++ b/pkg/front_end/test/enable_non_nullable/enable_non_nullable_test.dart @@ -116,7 +116,7 @@ Future test( Expect.isFalse( hadDiagnostic, "Compilation had diagnostics (errors, warnings)!"); for (Library library in result.component!.libraries) { - if (library.importUri.scheme != 'dart') { + if (!library.importUri.isScheme('dart')) { bool usesLegacy = await uriUsesLegacyLanguageVersion(library.fileUri, options); VersionAndPackageUri versionAndPackageUri = @@ -143,7 +143,7 @@ Future test( "Expected library ${library.importUri} with version " "${library.languageVersion} to be opted in."); Expect.isTrue( - versionAndPackageUri.packageUri.scheme != 'package' || + !versionAndPackageUri.packageUri.isScheme('package') || !versionAndPackageUri.packageUri.path .startsWith('allowed_package') || library.languageVersion < versionOptsInAllowed || diff --git a/pkg/front_end/test/fasta/testing/suite.dart b/pkg/front_end/test/fasta/testing/suite.dart index 02231dd7358..2b3db8d1d71 100644 --- a/pkg/front_end/test/fasta/testing/suite.dart +++ b/pkg/front_end/test/fasta/testing/suite.dart @@ -598,7 +598,7 @@ class FastaContext extends ChainContext with MatchContext { } for (String argument in parsedOptions.arguments) { Uri uri = description.uri.resolve(argument); - if (uri.scheme != 'package') { + if (!uri.isScheme('package')) { File f = new File.fromUri(uri); if (!f.existsSync()) { throw new UnsupportedError("No file found: $f ($argument)"); @@ -1328,11 +1328,11 @@ class FuzzCompiles Map builders = {}; for (LibraryBuilder builder in incrementalCompiler.kernelTargetForTesting!.loader.libraryBuilders) { - if (builder.importUri.scheme == "dart" && !builder.isSynthetic) continue; + if (builder.importUri.isScheme("dart") && !builder.isSynthetic) continue; builders[builder.fileUri] = builder; for (LibraryPart part in builder.library.parts) { Uri thisPartUri = builder.importUri.resolve(part.partUri); - if (thisPartUri.scheme == "package") { + if (thisPartUri.isScheme("package")) { thisPartUri = incrementalCompiler .kernelTargetForTesting!.uriTranslator .translate(thisPartUri)!; @@ -1761,8 +1761,8 @@ Set createUserLibrariesImportUriSet( component.libraries.map((Library library) => library.importUri).toSet(); Set userLibraries = component.libraries .where((Library library) => - library.importUri.scheme != 'dart' && - library.importUri.scheme != 'package' && + !library.importUri.isScheme('dart') && + !library.importUri.isScheme('package') && !excludedLibraries.contains(library)) .map((Library library) => library.importUri) .toSet(); @@ -2171,7 +2171,7 @@ class MatchHierarchy ComponentResult result, FastaContext context) { Component component = result.component; Uri uri = - component.uriToSource.keys.firstWhere((uri) => uri.scheme == "file"); + component.uriToSource.keys.firstWhere((uri) => uri.isScheme("file")); KernelTarget target = result.sourceTarget; ClassHierarchyBuilder hierarchy = target.loader.hierarchyBuilder; StringBuffer sb = new StringBuffer(); diff --git a/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_nnbd_test.dart b/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_nnbd_test.dart index f037ae53bb7..6bb5a3298e9 100644 --- a/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_nnbd_test.dart +++ b/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_nnbd_test.dart @@ -48,13 +48,13 @@ class TypeConstraintGathererTest { "the core library and the test library."); Library firstLibrary = env.component.libraries.first; Library secondLibrary = env.component.libraries.last; - if (firstLibrary.importUri.scheme == "dart" && + if (firstLibrary.importUri.isScheme("dart") && firstLibrary.importUri.path == "core") { _coreLibrary = firstLibrary; _testLibrary = secondLibrary; } else { assert( - secondLibrary.importUri.scheme == "dart" && + secondLibrary.importUri.isScheme("dart") && secondLibrary.importUri.path == "core", "One of the libraries is expected to be 'dart:core'."); _coreLibrary == secondLibrary; diff --git a/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_test.dart b/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_test.dart index e42fc10e6c4..f0aa16d0bd4 100644 --- a/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_test.dart +++ b/pkg/front_end/test/fasta/type_inference/type_constraint_gatherer_test.dart @@ -48,13 +48,13 @@ class TypeConstraintGathererTest { "the core library and the test library."); Library firstLibrary = env.component.libraries.first; Library secondLibrary = env.component.libraries.last; - if (firstLibrary.importUri.scheme == "dart" && + if (firstLibrary.importUri.isScheme("dart") && firstLibrary.importUri.path == "core") { _coreLibrary = firstLibrary; _testLibrary = secondLibrary; } else { assert( - secondLibrary.importUri.scheme == "dart" && + secondLibrary.importUri.isScheme("dart") && secondLibrary.importUri.path == "core", "One of the libraries is expected to be 'dart:core'."); _coreLibrary == secondLibrary; diff --git a/pkg/front_end/test/fasta/type_inference/type_schema_environment_nnbd_test.dart b/pkg/front_end/test/fasta/type_inference/type_schema_environment_nnbd_test.dart index 182d44bd6bd..df6740e487a 100644 --- a/pkg/front_end/test/fasta/type_inference/type_schema_environment_nnbd_test.dart +++ b/pkg/front_end/test/fasta/type_inference/type_schema_environment_nnbd_test.dart @@ -46,13 +46,13 @@ class TypeSchemaEnvironmentTest { "the core library and the test library."); Library firstLibrary = typeParserEnvironment.component.libraries.first; Library secondLibrary = typeParserEnvironment.component.libraries.last; - if (firstLibrary.importUri.scheme == "dart" && + if (firstLibrary.importUri.isScheme("dart") && firstLibrary.importUri.path == "core") { _coreLibrary = firstLibrary; _testLibrary = secondLibrary; } else { assert( - secondLibrary.importUri.scheme == "dart" && + secondLibrary.importUri.isScheme("dart") && secondLibrary.importUri.path == "core", "One of the libraries is expected to be 'dart:core'."); _coreLibrary == secondLibrary; diff --git a/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart b/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart index 526e0618f92..cd094fe0f3b 100644 --- a/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart +++ b/pkg/front_end/test/fasta/type_inference/type_schema_environment_test.dart @@ -46,13 +46,13 @@ class TypeSchemaEnvironmentTest { "the core library and the test library."); Library firstLibrary = typeParserEnvironment.component.libraries.first; Library secondLibrary = typeParserEnvironment.component.libraries.last; - if (firstLibrary.importUri.scheme == "dart" && + if (firstLibrary.importUri.isScheme("dart") && firstLibrary.importUri.path == "core") { _coreLibrary = firstLibrary; _testLibrary = secondLibrary; } else { assert( - secondLibrary.importUri.scheme == "dart" && + secondLibrary.importUri.isScheme("dart") && secondLibrary.importUri.path == "core", "One of the libraries is expected to be 'dart:core'."); _coreLibrary == secondLibrary; diff --git a/pkg/front_end/test/fasta/types/legacy_upper_bound_helper.dart b/pkg/front_end/test/fasta/types/legacy_upper_bound_helper.dart index a47c4ee95f2..ecb36646742 100644 --- a/pkg/front_end/test/fasta/types/legacy_upper_bound_helper.dart +++ b/pkg/front_end/test/fasta/types/legacy_upper_bound_helper.dart @@ -28,13 +28,13 @@ abstract class LegacyUpperBoundTest { "the core library and the test library."); Library firstLibrary = env.component.libraries.first; Library secondLibrary = env.component.libraries.last; - if (firstLibrary.importUri.scheme == "dart" && + if (firstLibrary.importUri.isScheme("dart") && firstLibrary.importUri.path == "core") { coreLibrary = firstLibrary; testLibrary = secondLibrary; } else { assert( - secondLibrary.importUri.scheme == "dart" && + secondLibrary.importUri.isScheme("dart") && secondLibrary.importUri.path == "core", "One of the libraries is expected to be 'dart:core'."); coreLibrary = secondLibrary; diff --git a/pkg/front_end/test/hot_reload_e2e_test.dart b/pkg/front_end/test/hot_reload_e2e_test.dart index 86ddcb08d0b..07cf63b47b9 100644 --- a/pkg/front_end/test/hot_reload_e2e_test.dart +++ b/pkg/front_end/test/hot_reload_e2e_test.dart @@ -330,7 +330,7 @@ Future writeProgram(Component component, Uri outputUri) async { // TODO(sigmund): the incremental generator should always filter these // libraries instead. new BinaryPrinter(sink, - libraryFilter: (library) => library.importUri.scheme != 'dart') + libraryFilter: (library) => !library.importUri.isScheme('dart')) .writeComponentFile(component); await sink.close(); } diff --git a/pkg/front_end/test/incremental_dart2js_tester.dart b/pkg/front_end/test/incremental_dart2js_tester.dart index 59add482121..c3d76006b95 100644 --- a/pkg/front_end/test/incremental_dart2js_tester.dart +++ b/pkg/front_end/test/incremental_dart2js_tester.dart @@ -220,7 +220,7 @@ class Dart2jsTester { uris = c.uriToSource.values .map((s) => s.importUri) .whereType() - .where((u) => u.scheme != "dart") + .where((u) => !u.isScheme("dart")) .toSet() .toList(); diff --git a/pkg/front_end/test/incremental_flutter_tester.dart b/pkg/front_end/test/incremental_flutter_tester.dart index 4a745aa7255..7527279c164 100644 --- a/pkg/front_end/test/incremental_flutter_tester.dart +++ b/pkg/front_end/test/incremental_flutter_tester.dart @@ -120,7 +120,7 @@ Future main(List args) async { List uris = c.uriToSource.values .map((s) => s.importUri) .whereType() - .where((u) => u.scheme != "dart") + .where((u) => !u.isScheme("dart")) .toSet() .toList(); diff --git a/pkg/front_end/test/incremental_suite.dart b/pkg/front_end/test/incremental_suite.dart index 20ed53aef29..e72f3f268a7 100644 --- a/pkg/front_end/test/incremental_suite.dart +++ b/pkg/front_end/test/incremental_suite.dart @@ -789,7 +789,7 @@ class NewWorldTest { // null is always there, so allow it implicitly. // Dart scheme uris too. // ignore: unnecessary_null_comparison - if (uri == null || uri.scheme == "org-dartlang-sdk") continue; + if (uri == null || uri.isScheme("org-dartlang-sdk")) continue; if (!allowed.contains(uri)) { return new Result( data, @@ -1226,7 +1226,7 @@ Result? checkClassHierarchy(IncrementalCompilerResult compilerResult, Component component = compilerResult.component; StringBuffer sb = new StringBuffer(); for (Library library in component.libraries) { - if (library.importUri.scheme == "dart") continue; + if (library.importUri.isScheme("dart")) continue; sb.writeln("Library ${library.importUri}"); for (Class c in library.classes) { sb.writeln(" - Class ${c.name}"); @@ -1533,7 +1533,7 @@ void computeAllReachableLibrariesFor(Library lib, Set allLibraries) { while (workList.isNotEmpty) { Library library = workList.removeLast(); for (LibraryDependency dependency in library.dependencies) { - if (dependency.targetLibrary.importUri.scheme == "dart") continue; + if (dependency.targetLibrary.importUri.isScheme("dart")) continue; if (libraries.add(dependency.targetLibrary)) { workList.add(dependency.targetLibrary); allLibraries.add(dependency.targetLibrary); @@ -1607,7 +1607,7 @@ Result? checkNeededDillLibraries( if (world["neededDillLibraries"] != null) { List actualContent = []; for (Library lib in neededDillLibraries!) { - if (lib.importUri.scheme == "dart") continue; + if (lib.importUri.isScheme("dart")) continue; actualContent.add(lib.importUri); } @@ -1652,7 +1652,7 @@ String componentToStringSdkFiltered(Component component) { Component c = new Component(); List dartUris = []; for (Library lib in component.libraries) { - if (lib.importUri.scheme == "dart") { + if (lib.importUri.isScheme("dart")) { dartUris.add(lib.importUri); } else { c.libraries.add(lib); @@ -1686,7 +1686,7 @@ int countNonSyntheticLibraries(Component c) { int countNonSyntheticPlatformLibraries(Component c) { int result = 0; for (Library lib in c.libraries) { - if (!lib.isSynthetic && lib.importUri.scheme == "dart") result++; + if (!lib.isSynthetic && lib.importUri.isScheme("dart")) result++; } return result; } diff --git a/pkg/front_end/test/incremental_utils.dart b/pkg/front_end/test/incremental_utils.dart index 8a46cd6d53d..49c7663948b 100644 --- a/pkg/front_end/test/incremental_utils.dart +++ b/pkg/front_end/test/incremental_utils.dart @@ -77,7 +77,7 @@ Future throwOnInsufficientUriToSource(Component component, for (Uri uri in uris) { // ignore: unnecessary_null_comparison if (uri == null) continue; - if (uri.scheme != "org-dartlang-test") continue; + if (!uri.isScheme("org-dartlang-test")) continue; // The file system doesn't have the sources for any modules. // For now assume that that is always what's going on. if (!await fileSystem.entityForUri(uri).exists()) continue; diff --git a/pkg/front_end/test/language_versioning/language_versioning_test.dart b/pkg/front_end/test/language_versioning/language_versioning_test.dart index 5e886696d78..dabc98e10f5 100644 --- a/pkg/front_end/test/language_versioning/language_versioning_test.dart +++ b/pkg/front_end/test/language_versioning/language_versioning_test.dart @@ -85,7 +85,7 @@ class LanguageVersioningDataComputer extends DataComputer { CompilerOptions options = testResultData.customData; Component component = testResultData.compilerResult.component!; for (Library library in component.libraries) { - if (library.importUri.scheme == "dart") continue; + if (library.importUri.isScheme("dart")) continue; Version lvFile = (await lv.languageVersionForUri(library.fileUri, options)).version; Version lvImportUri = diff --git a/pkg/front_end/test/lint_suite.dart b/pkg/front_end/test/lint_suite.dart index d61759d4f3e..16bc5926837 100644 --- a/pkg/front_end/test/lint_suite.dart +++ b/pkg/front_end/test/lint_suite.dart @@ -315,7 +315,7 @@ class ImportsTwiceLintListener extends LintListener { importUri = importUri.substring(1, importUri.length - 1); } Uri resolved = uri.resolve(importUri); - if (resolved.scheme == "package") { + if (resolved.isScheme("package")) { if (description.cache.packages != null) { resolved = description.cache.packages!.resolve(resolved)!; } @@ -345,7 +345,7 @@ class ExportsLintListener extends LintListener { exportUri = exportUri.substring(1, exportUri.length - 1); } Uri resolved = uri.resolve(exportUri); - if (resolved.scheme == "package") { + if (resolved.isScheme("package")) { if (description.cache.packages != null) { resolved = description.cache.packages!.resolve(resolved)!; } diff --git a/pkg/front_end/test/macros/macro_test.dart b/pkg/front_end/test/macros/macro_test.dart index c4db33079e7..ce0398970b7 100644 --- a/pkg/front_end/test/macros/macro_test.dart +++ b/pkg/front_end/test/macros/macro_test.dart @@ -98,9 +98,9 @@ String constructorNameToString(String constructorName) { } String importUriToString(Uri importUri) { - if (importUri.scheme == 'package') { + if (importUri.isScheme('package')) { return importUri.toString(); - } else if (importUri.scheme == 'dart') { + } else if (importUri.isScheme('dart')) { return importUri.toString(); } else { return importUri.pathSegments.last; diff --git a/pkg/front_end/test/mock_file_system.dart b/pkg/front_end/test/mock_file_system.dart index 60e45be9259..fa674e1afcd 100644 --- a/pkg/front_end/test/mock_file_system.dart +++ b/pkg/front_end/test/mock_file_system.dart @@ -11,7 +11,8 @@ class MockFileSystem implements FileSystem { @override FileSystemEntity entityForUri(Uri uri) { - if (scheme != null && uri.scheme != scheme) throw "unsupported"; + final scheme = this.scheme; + if (scheme != null && !uri.isScheme(scheme)) throw "unsupported"; return new MockFileSystemEntity(uri, this); } } diff --git a/pkg/front_end/test/static_types/analysis_helper.dart b/pkg/front_end/test/static_types/analysis_helper.dart index 6564bd1ef82..ab60ab77c11 100644 --- a/pkg/front_end/test/static_types/analysis_helper.dart +++ b/pkg/front_end/test/static_types/analysis_helper.dart @@ -312,7 +312,7 @@ class DynamicVisitor extends StaticTypeVisitorBase { String uriString = relativizeUri(uri)!; Map> actualMap = _actualMessages.putIfAbsent( uriString, () => >{}); - if (uri.scheme == 'org-dartlang-sdk') { + if (uri.isScheme('org-dartlang-sdk')) { location = new Location(Uri.base.resolve(uri.path.substring(1)), location.line, location.column); } diff --git a/pkg/front_end/test/static_types/static_type_test.dart b/pkg/front_end/test/static_types/static_type_test.dart index 80a339d158b..41bc89cb53e 100644 --- a/pkg/front_end/test/static_types/static_type_test.dart +++ b/pkg/front_end/test/static_types/static_type_test.dart @@ -136,7 +136,7 @@ class StaticTypeDataExtractor extends CfeDataExtractor { if (object is ConstructorInvocation) { Class cls = object.target.enclosingClass; return cls.name == 'ReachabilityError' && - cls.enclosingLibrary.importUri.scheme == 'dart' && + cls.enclosingLibrary.importUri.isScheme('dart') && cls.enclosingLibrary.importUri.path == '_internal'; } return false; diff --git a/pkg/front_end/test/utils/kernel_chain.dart b/pkg/front_end/test/utils/kernel_chain.dart index 2c96443ec2c..d526f135126 100644 --- a/pkg/front_end/test/utils/kernel_chain.dart +++ b/pkg/front_end/test/utils/kernel_chain.dart @@ -384,8 +384,8 @@ class KernelTextSerialization TextSerializationVerifier verifier = new TextSerializationVerifier(root: component.root); for (Library library in component.libraries) { - if (library.importUri.scheme != "dart" && - library.importUri.scheme != "package") { + if (!library.importUri.isScheme("dart") && + !library.importUri.isScheme("package")) { verifier.verify(library); } } @@ -401,7 +401,7 @@ class KernelTextSerialization if (writeRoundTripStatus) { Uri uri = component.uriToSource.keys - .firstWhere((uri) => uri.scheme == "file"); + .firstWhere((uri) => uri.isScheme("file")); String filename = "${uri.toFilePath()}${suffix}"; uri = new File(filename).uri; StringBuffer buffer = new StringBuffer(); diff --git a/pkg/front_end/test/vm_service_coverage.dart b/pkg/front_end/test/vm_service_coverage.dart index 2112bd0035d..cb6736c9ddc 100644 --- a/pkg/front_end/test/vm_service_coverage.dart +++ b/pkg/front_end/test/vm_service_coverage.dart @@ -112,10 +112,10 @@ class CoverageHelper extends vmService.LaunchingVMServiceHelper { } bool includeCoverageFor(Uri uri) { - if (uri.scheme == "dart") { + if (uri.isScheme("dart")) { return false; } - if (uri.scheme == "package") { + if (uri.isScheme("package")) { return uri.pathSegments.first == "front_end" || uri.pathSegments.first == "_fe_analyzer_shared" || uri.pathSegments.first == "kernel"; diff --git a/pkg/front_end/test/vm_service_coverage_constant_evaluator.dart b/pkg/front_end/test/vm_service_coverage_constant_evaluator.dart index 3128758ffbf..70b7dad0bfd 100644 --- a/pkg/front_end/test/vm_service_coverage_constant_evaluator.dart +++ b/pkg/front_end/test/vm_service_coverage_constant_evaluator.dart @@ -23,7 +23,7 @@ class CoverageHelper extends helper.CoverageHelper { @override bool includeCoverageFor(Uri uri) { - if (uri.scheme != "package") return false; + if (!uri.isScheme("package")) return false; if (uri.path.startsWith("front_end/src/fasta/kernel/constant_")) { return true; } diff --git a/pkg/front_end/tool/_fasta/bench_maker.dart b/pkg/front_end/tool/_fasta/bench_maker.dart index 4e95837f8e2..58c45c97d3b 100644 --- a/pkg/front_end/tool/_fasta/bench_maker.dart +++ b/pkg/front_end/tool/_fasta/bench_maker.dart @@ -270,7 +270,7 @@ class BenchMaker implements DartTypeVisitor1 { } Uri clsImportUri = cls.enclosingLibrary.importUri; bool isNull = cls.name == "Null" && - clsImportUri.scheme == "dart" && + clsImportUri.isScheme("dart") && clsImportUri.path == "core"; if (!isNull) { writeNullability(node.nullability, sb); diff --git a/pkg/front_end/tool/_fasta/entry_points.dart b/pkg/front_end/tool/_fasta/entry_points.dart index 822fced563b..adc882636ea 100644 --- a/pkg/front_end/tool/_fasta/entry_points.dart +++ b/pkg/front_end/tool/_fasta/entry_points.dart @@ -421,7 +421,7 @@ class CompileTask { userCode.setMainMethodAndMode( outline.mainMethodName, true, outline.mode); for (Library library in outline.libraries) { - if (library.importUri.scheme != "dart") { + if (!library.importUri.isScheme("dart")) { userCode.libraries.add(library); } } @@ -465,13 +465,13 @@ class CompileTask { userCode.setMainMethodAndMode( component.mainMethodName, true, component.mode); for (Library library in component.libraries) { - if (library.importUri.scheme != "dart") { + if (!library.importUri.isScheme("dart")) { userCode.libraries.add(library); } } component = userCode; } - if (uri.scheme == "file") { + if (uri.isScheme("file")) { benchmarker?.enterPhase(BenchmarkPhases.writeComponent); await writeComponentToFile(component, uri); ticker.logMs("Wrote component to ${uri.toFilePath()}"); diff --git a/pkg/front_end/tool/incremental_perf.dart b/pkg/front_end/tool/incremental_perf.dart index afb0e813c7f..0a1186dbc22 100644 --- a/pkg/front_end/tool/incremental_perf.dart +++ b/pkg/front_end/tool/incremental_perf.dart @@ -168,7 +168,7 @@ Future applyEdits( print('edit $edit'); } var uri = edit.uri; - if (uri.scheme == 'package') uri = uriTranslator.translate(uri)!; + if (uri.isScheme('package')) uri = uriTranslator.translate(uri)!; generator.invalidate(uri); OverlayFileSystemEntity entity = fs.entityForUri(uri) as OverlayFileSystemEntity; @@ -212,9 +212,9 @@ class OverlayFileSystem implements FileSystem { @override FileSystemEntity entityForUri(Uri uri) { - if (uri.scheme == 'org-dartlang-overlay') { + if (uri.isScheme('org-dartlang-overlay')) { return new OverlayFileSystemEntity(uri, this); - } else if (uri.scheme == 'file') { + } else if (uri.isScheme('file')) { // The IKG compiler reads ".packages" which might contain absolute file // URIs (which it will then try to use on the FS). We therefore replace // them with overlay-fs URIs as usual. diff --git a/pkg/frontend_server/lib/compute_kernel.dart b/pkg/frontend_server/lib/compute_kernel.dart index 3fd7f05acfa..e9aac60e958 100644 --- a/pkg/frontend_server/lib/compute_kernel.dart +++ b/pkg/frontend_server/lib/compute_kernel.dart @@ -296,7 +296,7 @@ Future computeKernel(List args, if (recordUsedInputs) { Set usedOutlines = {}; for (Library lib in incrementalCompilerResult.neededDillLibraries) { - if (lib.importUri.scheme == "dart") continue; + if (lib.importUri.isScheme("dart")) continue; Uri uri = state.libraryToInputDill[lib.importUri]; if (uri == null) { throw new StateError("Library ${lib.importUri} was recorded as used, " diff --git a/pkg/frontend_server/lib/frontend_server.dart b/pkg/frontend_server/lib/frontend_server.dart index d68a4ecb64b..bcfd7995f2a 100644 --- a/pkg/frontend_server/lib/frontend_server.dart +++ b/pkg/frontend_server/lib/frontend_server.dart @@ -630,7 +630,7 @@ class FrontendCompiler implements CompilerInterface { Set uris = Set(); for (Uri uri in compiledSources) { // Skip empty or corelib dependencies. - if (uri == null || uri.scheme == 'org-dartlang-sdk') continue; + if (uri == null || uri.isScheme('org-dartlang-sdk')) continue; uris.add(uri); } for (Uri uri in uris) { @@ -986,7 +986,7 @@ class FrontendCompiler implements CompilerInterface { for (var lib in deltaProgram.libraries) { Uri uri = lib.importUri; - if (uri.scheme == "package") { + if (uri.isScheme("package")) { packageLibraries.add(lib); } else { libraries.add(lib); @@ -1040,7 +1040,7 @@ class FrontendCompiler implements CompilerInterface { for (Library lib in libraries) { for (LibraryDependency dep in lib.dependencies) { Library dependencyLibrary = dep.importedLibraryReference.asLibrary; - if (dependencyLibrary.importUri.scheme != "package") continue; + if (!dependencyLibrary.importUri.isScheme("package")) continue; Uri dependencyLibraryUri = dep.importedLibraryReference.asLibrary.fileUri; if (libraryUris.contains(dependencyLibraryUri)) continue; diff --git a/pkg/frontend_server/lib/src/javascript_bundle.dart b/pkg/frontend_server/lib/src/javascript_bundle.dart index a989fb1efc7..d39ee754190 100644 --- a/pkg/frontend_server/lib/src/javascript_bundle.dart +++ b/pkg/frontend_server/lib/src/javascript_bundle.dart @@ -110,7 +110,7 @@ class JavaScriptBundler { for (Library library in _originalComponent.libraries) { if (loadedLibraries.contains(library) || - library.importUri.scheme == 'dart') { + library.importUri.isScheme('dart')) { continue; } final Uri moduleUri = @@ -156,7 +156,7 @@ class JavaScriptBundler { final moduleUrl = urlForComponentUri(moduleUri); String sourceMapBase; - if (moduleUri.scheme == 'package') { + if (moduleUri.isScheme('package')) { // Source locations come through as absolute file uris. In order to // make relative paths in the source map we get the absolute uri for // the module and make them relative to that. @@ -218,7 +218,7 @@ class JavaScriptBundler { } } -String urlForComponentUri(Uri componentUri) => componentUri.scheme == 'package' +String urlForComponentUri(Uri componentUri) => componentUri.isScheme('package') ? '/packages/${componentUri.path}' : componentUri.path; diff --git a/pkg/frontend_server/lib/src/strong_components.dart b/pkg/frontend_server/lib/src/strong_components.dart index a631c309164..4c010a8eba8 100644 --- a/pkg/frontend_server/lib/src/strong_components.dart +++ b/pkg/frontend_server/lib/src/strong_components.dart @@ -103,7 +103,7 @@ class _LibraryGraph implements Graph { return [ for (LibraryDependency dependency in vertex.dependencies) if (!loadedLibraries.contains(dependency.targetLibrary) && - dependency.targetLibrary.importUri.scheme != 'dart') + !dependency.targetLibrary.importUri.isScheme('dart')) dependency.targetLibrary ]; } diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart index a2fce2fcbd6..cbf0d440532 100644 --- a/pkg/kernel/lib/ast.dart +++ b/pkg/kernel/lib/ast.dart @@ -10071,7 +10071,7 @@ class Catch extends TreeNode { type.className.node != null && type.classNode.name == 'Object') { Uri uri = type.classNode.enclosingLibrary.importUri; - return uri.scheme == 'dart' && + return uri.isScheme('dart') && uri.path == 'core' && type.nullability == Nullability.nonNullable; } diff --git a/pkg/kernel/lib/import_table.dart b/pkg/kernel/lib/import_table.dart index fd5f59f8cfd..eea2adbb569 100644 --- a/pkg/kernel/lib/import_table.dart +++ b/pkg/kernel/lib/import_table.dart @@ -89,7 +89,7 @@ class _ImportTableBuilder extends RecursiveVisitor { // whether the scheme is 'file:', but instead we check that is not 'dart:' // or 'package:'. bool isFileOrCustomScheme(Uri uri) => - uri.scheme != '' && uri.scheme != 'package' && uri.scheme != 'dart'; + uri.hasScheme && !uri.isScheme('package') && !uri.isScheme('dart'); bool isTargetSchemeFileOrCustom = isFileOrCustomScheme(targetUri); bool isReferenceSchemeFileOrCustom = isFileOrCustomScheme(referenceUri); if (isTargetSchemeFileOrCustom && isReferenceSchemeFileOrCustom) { diff --git a/pkg/kernel/lib/library_index.dart b/pkg/kernel/lib/library_index.dart index 5f231b44d5a..da1d0e78616 100644 --- a/pkg/kernel/lib/library_index.dart +++ b/pkg/kernel/lib/library_index.dart @@ -44,7 +44,7 @@ class LibraryIndex { /// Indexes `dart:` libraries. LibraryIndex.coreLibraries(Component component) { for (Library library in component.libraries) { - if (library.importUri.scheme == 'dart') { + if (library.importUri.isScheme('dart')) { _libraries['${library.importUri}'] = new _ClassTable(library); } } diff --git a/pkg/kernel/lib/src/printer.dart b/pkg/kernel/lib/src/printer.dart index 3d28d328be4..fc81e9ce8c7 100644 --- a/pkg/kernel/lib/src/printer.dart +++ b/pkg/kernel/lib/src/printer.dart @@ -266,7 +266,7 @@ class AstPrinter { type.className.node != null && type.classNode.name == 'Object') { Uri uri = type.classNode.enclosingLibrary.importUri; - return uri.scheme == 'dart' && + return uri.isScheme('dart') && uri.path == 'core' && (type.nullability == Nullability.legacy || type.nullability == Nullability.nullable); diff --git a/pkg/kernel/lib/target/targets.dart b/pkg/kernel/lib/target/targets.dart index 678cc332450..330d68308ca 100644 --- a/pkg/kernel/lib/target/targets.dart +++ b/pkg/kernel/lib/target/targets.dart @@ -368,8 +368,8 @@ abstract class Target { /// By default only `dart:*` libraries are allowed. May be overridden for /// testing purposes. bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) => - importer.scheme == "dart" || - (importer.scheme == "package" && + importer.isScheme("dart") || + (importer.isScheme("package") && importer.path.startsWith("dart_internal/")); /// Whether the `native` language extension is supported within [library]. diff --git a/pkg/kernel/lib/testing/type_parser_environment.dart b/pkg/kernel/lib/testing/type_parser_environment.dart index 6beaa677201..1f9fab5dac9 100644 --- a/pkg/kernel/lib/testing/type_parser_environment.dart +++ b/pkg/kernel/lib/testing/type_parser_environment.dart @@ -289,7 +289,7 @@ class _KernelFromParsedType implements Visitor { Nullability nullability = interpretParsedNullability(node.parsedNullability); if (declaration.name == 'Null' && - declaration.enclosingLibrary.importUri.scheme == 'dart' && + declaration.enclosingLibrary.importUri.isScheme('dart') && declaration.enclosingLibrary.importUri.path == 'core') { if (node.parsedNullability != ParsedNullability.omitted) { throw "Null type must be written without explicit nullability"; diff --git a/pkg/kernel/lib/transformations/mixin_full_resolution.dart b/pkg/kernel/lib/transformations/mixin_full_resolution.dart index fee20894237..5af547518b6 100644 --- a/pkg/kernel/lib/transformations/mixin_full_resolution.dart +++ b/pkg/kernel/lib/transformations/mixin_full_resolution.dart @@ -77,7 +77,7 @@ class MixinFullResolution { Library enclosingLibrary = class_.enclosingLibrary; if (!librariesToBeTransformed.contains(enclosingLibrary) && - enclosingLibrary.importUri.scheme == "dart") { + enclosingLibrary.importUri.isScheme("dart")) { // If we're not asked to transform the platform libraries then we expect // that they will be already transformed. return; diff --git a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart index 318b7205654..cb6601eb797 100644 --- a/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart +++ b/pkg/kernel/lib/transformations/track_widget_constructor_locations.dart @@ -298,7 +298,7 @@ class WidgetCreatorTracker { for (Library library in libraries) { final Uri importUri = library.importUri; // ignore: unnecessary_null_comparison - if (importUri != null && importUri.scheme == 'package') { + if (importUri != null && importUri.isScheme('package')) { if (importUri.path == 'flutter/src/widgets/framework.dart') { for (Class class_ in library.classes) { if (class_.name == 'Widget') { diff --git a/pkg/kernel/lib/type_checker.dart b/pkg/kernel/lib/type_checker.dart index e575a005b3d..e19ef36da70 100644 --- a/pkg/kernel/lib/type_checker.dart +++ b/pkg/kernel/lib/type_checker.dart @@ -27,7 +27,7 @@ abstract class TypeChecker { void checkComponent(Component component) { for (Library library in component.libraries) { - if (ignoreSdk && library.importUri.scheme == 'dart') continue; + if (ignoreSdk && library.importUri.isScheme('dart')) continue; for (Class class_ in library.classes) { hierarchy.forEachOverridePair(class_, (Member ownMember, Member superMember, bool isSetter) { @@ -39,7 +39,7 @@ abstract class TypeChecker { new TypeCheckingVisitor(this, environment, hierarchy); for (Library library in component.libraries) { currentLibrary = library; - if (ignoreSdk && library.importUri.scheme == 'dart') continue; + if (ignoreSdk && library.importUri.isScheme('dart')) continue; for (Class class_ in library.classes) { currentThisType = coreTypes.thisInterfaceType( class_, class_.enclosingLibrary.nonNullable); diff --git a/pkg/nnbd_migration/lib/src/edge_builder.dart b/pkg/nnbd_migration/lib/src/edge_builder.dart index 5ab9d265450..4b03467bf7e 100644 --- a/pkg/nnbd_migration/lib/src/edge_builder.dart +++ b/pkg/nnbd_migration/lib/src/edge_builder.dart @@ -3167,7 +3167,7 @@ class EdgeBuilder extends GeneralizingAstVisitor var calleeUri = callee?.library?.source.uri; var isQuiverCheckNull = callee?.name == 'checkNotNull' && calleeUri != null && - calleeUri.scheme == 'package' && + calleeUri.isScheme('package') && calleeUri.path.startsWith('quiver/'); if (isQuiverCheckNull && node.argumentList.arguments.isNotEmpty) { @@ -3215,7 +3215,7 @@ class EdgeBuilder extends GeneralizingAstVisitor if (enclosingInvocation.name == 'setUp') { var uri = enclosingInvocation.staticElement!.library?.source.uri; if (uri != null && - uri.scheme == 'package' && + uri.isScheme('package') && uri.path.startsWith('test_core/')) { return true; } diff --git a/pkg/nnbd_migration/lib/src/node_builder.dart b/pkg/nnbd_migration/lib/src/node_builder.dart index 0f1e8f4a839..9f7c8311add 100644 --- a/pkg/nnbd_migration/lib/src/node_builder.dart +++ b/pkg/nnbd_migration/lib/src/node_builder.dart @@ -969,7 +969,7 @@ class NodeBuilder extends GeneralizingAstVisitor /// Determines whether the given [uri] comes from the Angular package. bool _isAngularUri(Uri uri) { - if (uri.scheme != 'package') return false; + if (!uri.isScheme('package')) return false; var packageName = uri.pathSegments[0]; if (packageName == 'angular') return true; if (packageName == 'third_party.dart_src.angular.angular') { diff --git a/pkg/test_runner/lib/src/utils.dart b/pkg/test_runner/lib/src/utils.dart index fc27e18bd70..03d3f84335f 100644 --- a/pkg/test_runner/lib/src/utils.dart +++ b/pkg/test_runner/lib/src/utils.dart @@ -306,7 +306,7 @@ class LastModifiedCache { /// In case [uri] is not a local file, this method will always return /// the current date. DateTime getLastModified(Uri uri) { - if (uri.scheme == "file") { + if (uri.isScheme("file")) { if (_cache.containsKey(uri.path)) { return _cache[uri.path]; } diff --git a/pkg/vm/bin/kernel_service.dart b/pkg/vm/bin/kernel_service.dart index 8e3f7524552..a843655b51a 100644 --- a/pkg/vm/bin/kernel_service.dart +++ b/pkg/vm/bin/kernel_service.dart @@ -552,7 +552,7 @@ Future _processExpressionCompilationRequest(request) async { // If it does not, try to load from dart_platform_kernel or from file. bool foundDartCore = false; for (Library library in component.libraries) { - if (library.importUri.scheme == "dart" && + if (library.importUri.isScheme("dart") && library.importUri.path == "core" && !library.isSynthetic) { foundDartCore = true; @@ -665,12 +665,12 @@ void _recordDependencies( if (component != null) { for (var lib in component.libraries) { - if (lib.importUri.scheme == "dart") continue; + if (lib.importUri.isScheme("dart")) continue; dependencies.add(lib.fileUri); for (var part in lib.parts) { final fileUri = lib.fileUri.resolve(part.partUri); - if (fileUri.scheme != "" && fileUri.scheme != "file") { + if (fileUri.hasScheme && !fileUri.isScheme("file")) { // E.g. part 'package:foo/foo.dart'; // Maybe the front end should resolve this? continue; @@ -827,7 +827,7 @@ Future _processLoadRequest(request) async { if (packageConfigWithDefault != null) { packagesUri = Uri.parse(packageConfigWithDefault); } - if (packagesUri != null && packagesUri.scheme == '') { + if (packagesUri != null && !packagesUri.hasScheme) { // Script does not have a scheme, assume that it is a path, // resolve it against the working directory. packagesUri = Uri.directory(workingDirectory!).resolveUri(packagesUri); diff --git a/pkg/vm/bin/protobuf_aware_treeshaker.dart b/pkg/vm/bin/protobuf_aware_treeshaker.dart index 3af79b60176..bb746af3da2 100644 --- a/pkg/vm/bin/protobuf_aware_treeshaker.dart +++ b/pkg/vm/bin/protobuf_aware_treeshaker.dart @@ -185,5 +185,5 @@ bool isLibEmpty(Library lib) { } bool isCoreLibrary(Library library) { - return library.importUri.scheme == 'dart'; + return library.importUri.isScheme('dart'); } diff --git a/pkg/vm/lib/http_filesystem.dart b/pkg/vm/lib/http_filesystem.dart index 18ee3e1abb3..59664943056 100644 --- a/pkg/vm/lib/http_filesystem.dart +++ b/pkg/vm/lib/http_filesystem.dart @@ -14,7 +14,7 @@ class HttpAwareFileSystem implements FileSystem { @override FileSystemEntity entityForUri(Uri uri) { - if (uri.scheme == 'http' || uri.scheme == 'https') { + if (uri.isScheme('http') || uri.isScheme('https')) { return new HttpFileSystemEntity(this, uri); } else { return original.entityForUri(uri); diff --git a/pkg/vm/lib/incremental_compiler.dart b/pkg/vm/lib/incremental_compiler.dart index fdf6e5cfb87..6f109b36bf3 100644 --- a/pkg/vm/lib/incremental_compiler.dart +++ b/pkg/vm/lib/incremental_compiler.dart @@ -95,7 +95,7 @@ class IncrementalCompiler { uriToSource.addAll(delta.uriToSource); for (Library library in delta.libraries) { bool isPlatform = - library.importUri.scheme == "dart" && !library.isSynthetic; + library.importUri.isScheme("dart") && !library.isSynthetic; if (!includePlatform && isPlatform) continue; combined[library.importUri] = library; } diff --git a/pkg/vm/lib/transformations/deferred_loading.dart b/pkg/vm/lib/transformations/deferred_loading.dart index b7dd321417c..91beb11349b 100644 --- a/pkg/vm/lib/transformations/deferred_loading.dart +++ b/pkg/vm/lib/transformations/deferred_loading.dart @@ -54,7 +54,7 @@ List computeLoadingUnits(Component component) { // Fake imports from root library to every core library so they end up in // the same loading unit attributed to the user's root library. for (final vertex in map.values) { - if (vertex.library.importUri.scheme == "dart") { + if (vertex.library.importUri.isScheme("dart")) { root.successors.add(vertex); vertex.isLoadingRoot = false; } diff --git a/pkg/vm/lib/transformations/ffi/common.dart b/pkg/vm/lib/transformations/ffi/common.dart index 5c20ebfc4d6..22f21954129 100644 --- a/pkg/vm/lib/transformations/ffi/common.dart +++ b/pkg/vm/lib/transformations/ffi/common.dart @@ -992,7 +992,7 @@ Set _getAllRelevantLibraries( for (Library lib in component.libraries) { // Skip real dart: libraries. dart:core imports dart:ffi, but that doesn't // mean we have to transform anything. - if (lib.importUri.scheme == "dart" && !lib.isSynthetic) continue; + if (lib.importUri.isScheme("dart") && !lib.isSynthetic) continue; allLibs.add(lib); } return allLibs; diff --git a/pkg/vm/lib/transformations/type_flow/native_code.dart b/pkg/vm/lib/transformations/type_flow/native_code.dart index 8b96b9a5217..450233d7780 100644 --- a/pkg/vm/lib/transformations/type_flow/native_code.dart +++ b/pkg/vm/lib/transformations/type_flow/native_code.dart @@ -208,7 +208,7 @@ class NativeCodeOracle { for (var annotation in member.annotations) { ParsedPragma? pragma = _matcher.parsePragma(annotation); if (pragma is ParsedDisableUnboxedParameters) { - if (member.enclosingLibrary.importUri.scheme != "dart") { + if (!member.enclosingLibrary.importUri.isScheme("dart")) { throw "ERROR: Cannot use @pragma(vm:disable-unboxed-parameters) outside core libraries."; } return true; @@ -236,7 +236,7 @@ class NativeCodeOracle { // We can only use the 'vm:exact-result-type' pragma on methods in core // libraries for safety reasons. See 'result_type_pragma.md', detail 1.2 // for explanation. - if (member.enclosingLibrary.importUri.scheme != "dart") { + if (!member.enclosingLibrary.importUri.isScheme("dart")) { throw "ERROR: Cannot use $kVmExactResultTypePragmaName " "outside core libraries."; } diff --git a/pkg/vm/test/incremental_compiler_test.dart b/pkg/vm/test/incremental_compiler_test.dart index d44ca159d57..ef627acb68f 100644 --- a/pkg/vm/test/incremental_compiler_test.dart +++ b/pkg/vm/test/incremental_compiler_test.dart @@ -1707,7 +1707,7 @@ class LibraryReferenceCollector extends RecursiveVisitor { void defaultMemberReference(Member node) { Library lib = node.enclosingLibrary; - if (lib.importUri.scheme != "dart") { + if (!lib.importUri.isScheme("dart")) { librariesReferenced.add(lib); } return super.defaultMemberReference(node); diff --git a/pkg/vm/test/transformations/deferred_loading_test.dart b/pkg/vm/test/transformations/deferred_loading_test.dart index f36b610e790..5b7cce83b76 100644 --- a/pkg/vm/test/transformations/deferred_loading_test.dart +++ b/pkg/vm/test/transformations/deferred_loading_test.dart @@ -28,7 +28,7 @@ runTestCase(Uri source) async { // Remove core libraries so the expected output isn't enormous and broken by // core libraries changes. - component.libraries.removeWhere((lib) => lib.importUri.scheme == "dart"); + component.libraries.removeWhere((lib) => lib.importUri.isScheme("dart")); String actual = kernelComponentToString(component); diff --git a/pkg/vm/test/unlinked_ast_to_text_test.dart b/pkg/vm/test/unlinked_ast_to_text_test.dart index 8b03a2c8381..ecf80d05851 100644 --- a/pkg/vm/test/unlinked_ast_to_text_test.dart +++ b/pkg/vm/test/unlinked_ast_to_text_test.dart @@ -45,7 +45,7 @@ main() async { final component = loadComponentFromBinary(dillFile); final IOSink sink = new File(unlinkedDillFile).openWrite(); final printer = new BinaryPrinter(sink, - libraryFilter: (lib) => lib.importUri.scheme != 'dart'); + libraryFilter: (lib) => !lib.importUri.isScheme('dart')); printer.writeComponentFile(component); await sink.close(); @@ -54,7 +54,7 @@ main() async { final unlinkedComponent = loadComponentFromBinary(unlinkedDillFile); final coreLibraryCount = unlinkedComponent.libraries .where( - (lib) => lib.importUri.scheme == 'dart' && lib.members.isNotEmpty) + (lib) => lib.importUri.isScheme('dart') && lib.members.isNotEmpty) .length; Expect.equals(0, coreLibraryCount); diff --git a/pkg/vm/testcases/transformations/type_flow/transformer/enum_from_lib_used_as_type.dart.expect b/pkg/vm/testcases/transformations/type_flow/transformer/enum_from_lib_used_as_type.dart.expect index 950e802bb18..7777d7a05fd 100644 --- a/pkg/vm/testcases/transformations/type_flow/transformer/enum_from_lib_used_as_type.dart.expect +++ b/pkg/vm/testcases/transformations/type_flow/transformer/enum_from_lib_used_as_type.dart.expect @@ -22,6 +22,6 @@ class Class extends core::Object { synthetic constructor •() → self::Class : super core::Object::•() ; -[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3399,getterSelectorId:3400] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::Enum e) → core::int +[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3398,getterSelectorId:3399] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::Enum e) → core::int return [@vm.inferred-type.metadata=!] e.{core::_Enum::index}{core::int}; } diff --git a/pkg/vm/testcases/transformations/type_flow/transformer/tree_shake_enum_from_lib.dart.expect b/pkg/vm/testcases/transformations/type_flow/transformer/tree_shake_enum_from_lib.dart.expect index 5ccaefa84b6..5a63ba03d72 100644 --- a/pkg/vm/testcases/transformations/type_flow/transformer/tree_shake_enum_from_lib.dart.expect +++ b/pkg/vm/testcases/transformations/type_flow/transformer/tree_shake_enum_from_lib.dart.expect @@ -51,6 +51,6 @@ class ConstClass extends core::Object { synthetic constructor •() → self::ConstClass : super core::Object::•() ; -[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3403,getterSelectorId:3404] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::ConstEnum e) → core::int +[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3402,getterSelectorId:3403] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::ConstEnum e) → core::int return [@vm.inferred-type.metadata=!] e.{core::_Enum::index}{core::int}; } diff --git a/pkg/vm_service/test/common/test_helper.dart b/pkg/vm_service/test/common/test_helper.dart index a5001d0445b..4100c68e94a 100644 --- a/pkg/vm_service/test/common/test_helper.dart +++ b/pkg/vm_service/test/common/test_helper.dart @@ -32,7 +32,7 @@ bool _isTestee() { } Uri _getTestUri(String script) { - if (io.Platform.script.scheme == 'data') { + if (io.Platform.script.isScheme('data')) { // If running from pub we can assume that we're in the root of the package // directory. return Uri.parse('test/$script'); diff --git a/runtime/observatory/bin/heap_snapshot.dart b/runtime/observatory/bin/heap_snapshot.dart index b5aaf93fafd..382009667af 100644 --- a/runtime/observatory/bin/heap_snapshot.dart +++ b/runtime/observatory/bin/heap_snapshot.dart @@ -401,9 +401,9 @@ main(List args) async { } var uri = Uri.parse(args[0]); - if (uri.scheme == 'http') { + if (uri.isScheme('http')) { uri = uri.replace(scheme: 'ws'); - } else if (uri.scheme == 'https') { + } else if (uri.isScheme('https')) { uri = uri.replace(scheme: 'wss'); } if (!uri.path.endsWith('/ws')) { diff --git a/runtime/observatory/lib/src/elements/script_inset.dart b/runtime/observatory/lib/src/elements/script_inset.dart index 68dc829c080..ca74491a6ca 100644 --- a/runtime/observatory/lib/src/elements/script_inset.dart +++ b/runtime/observatory/lib/src/elements/script_inset.dart @@ -439,7 +439,7 @@ class ScriptInsetElement extends CustomElement implements Renderable { return l as S.Library; } } - if (targetUri.scheme == 'package') { + if (targetUri.isScheme('package')) { var targetUriString = "packages/${targetUri.path}"; for (M.Library l in script.isolate!.libraries) { if (targetUriString == l.uri) { @@ -482,7 +482,7 @@ class ScriptInsetElement extends CustomElement implements Renderable { S.Script? resolvePart(String relativeUri) { S.Script script = _loadedScript as S.Script; var rootUri = Uri.parse(script.library!.uri!); - if (rootUri.scheme == 'dart') { + if (rootUri.isScheme('dart')) { // The relative paths from dart:* libraries to their parts are not valid. rootUri = Uri.parse(script.library!.uri! + '/'); } diff --git a/runtime/observatory_2/bin/heap_snapshot.dart b/runtime/observatory_2/bin/heap_snapshot.dart index 495c77893a5..11e25eaefd9 100644 --- a/runtime/observatory_2/bin/heap_snapshot.dart +++ b/runtime/observatory_2/bin/heap_snapshot.dart @@ -401,9 +401,9 @@ main(List args) async { } var uri = Uri.parse(args[0]); - if (uri.scheme == 'http') { + if (uri.isScheme('http')) { uri = uri.replace(scheme: 'ws'); - } else if (uri.scheme == 'https') { + } else if (uri.isScheme('https')) { uri = uri.replace(scheme: 'wss'); } if (!uri.path.endsWith('/ws')) { diff --git a/runtime/observatory_2/lib/src/elements/script_inset.dart b/runtime/observatory_2/lib/src/elements/script_inset.dart index c4a00946428..70d2049217b 100644 --- a/runtime/observatory_2/lib/src/elements/script_inset.dart +++ b/runtime/observatory_2/lib/src/elements/script_inset.dart @@ -436,7 +436,7 @@ class ScriptInsetElement extends CustomElement implements Renderable { return l; } } - if (targetUri.scheme == 'package') { + if (targetUri.isScheme('package')) { var targetUriString = "packages/${targetUri.path}"; for (M.Library l in script.isolate.libraries) { if (targetUriString == l.uri) { @@ -479,7 +479,7 @@ class ScriptInsetElement extends CustomElement implements Renderable { M.Script resolvePart(String relativeUri) { S.Script script = _loadedScript as S.Script; var rootUri = Uri.parse(script.library.uri); - if (rootUri.scheme == 'dart') { + if (rootUri.isScheme('dart')) { // The relative paths from dart:* libraries to their parts are not valid. rootUri = Uri.parse(script.library.uri + '/'); } diff --git a/sdk/lib/_http/http_impl.dart b/sdk/lib/_http/http_impl.dart index 622c662e832..80ee3b5bf89 100644 --- a/sdk/lib/_http/http_impl.dart +++ b/sdk/lib/_http/http_impl.dart @@ -1094,7 +1094,7 @@ abstract class _HttpOutboundMessage extends _IOSinkImpl { {_HttpHeaders? initialHeaders}) : _uri = uri, headers = _HttpHeaders(protocolVersion, - defaultPortForScheme: uri.scheme == 'https' + defaultPortForScheme: uri.isScheme('https') ? HttpClient.defaultHttpsPort : HttpClient.defaultHttpPort, initialHeaders: initialHeaders), @@ -2665,7 +2665,7 @@ class _HttpClient implements HttpClient { if (method != "CONNECT") { if (uri.host.isEmpty) { throw ArgumentError("No host specified in URI $uri"); - } else if (uri.scheme != "http" && uri.scheme != "https") { + } else if (!uri.isScheme("http") && !uri.isScheme("https")) { throw ArgumentError("Unsupported scheme '${uri.scheme}' in URI $uri"); } } @@ -2717,7 +2717,7 @@ class _HttpClient implements HttpClient { } static bool _isSubdomain(Uri subdomain, Uri domain) { - return (subdomain.scheme == domain.scheme && + return (subdomain.isScheme(domain.scheme) && subdomain.port == domain.port && (subdomain.host == domain.host || subdomain.host.endsWith("." + domain.host))); @@ -2928,13 +2928,13 @@ class _HttpClient implements HttpClient { return proxyCfg; } - if (url.scheme == "http") { + if (url.isScheme("http")) { String? proxy = environment["http_proxy"] ?? environment["HTTP_PROXY"]; proxyCfg = checkProxy(proxy); if (proxyCfg != null) { return proxyCfg; } - } else if (url.scheme == "https") { + } else if (url.isScheme("https")) { String? proxy = environment["https_proxy"] ?? environment["HTTPS_PROXY"]; proxyCfg = checkProxy(proxy); if (proxyCfg != null) { diff --git a/sdk/lib/_http/websocket_impl.dart b/sdk/lib/_http/websocket_impl.dart index c7126c21444..fdafda89ce3 100644 --- a/sdk/lib/_http/websocket_impl.dart +++ b/sdk/lib/_http/websocket_impl.dart @@ -996,7 +996,7 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket { {CompressionOptions compression = CompressionOptions.compressionDefault, HttpClient? customClient}) { Uri uri = Uri.parse(url); - if (uri.scheme != "ws" && uri.scheme != "wss") { + if (!uri.isScheme("ws") && !uri.isScheme("wss")) { throw WebSocketException("Unsupported URL scheme '${uri.scheme}'"); } @@ -1011,7 +1011,7 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket { final callerStackTrace = StackTrace.current; uri = Uri( - scheme: uri.scheme == "wss" ? "https" : "http", + scheme: uri.isScheme("wss") ? "https" : "http", userInfo: uri.userInfo, host: uri.host, port: uri.port, diff --git a/sdk/lib/_internal/vm/bin/builtin.dart b/sdk/lib/_internal/vm/bin/builtin.dart index e39fa7fc008..2684e6fd4de 100644 --- a/sdk/lib/_internal/vm/bin/builtin.dart +++ b/sdk/lib/_internal/vm/bin/builtin.dart @@ -96,7 +96,7 @@ _sanitizeWindowsPath(path) { _setPackagesConfig(String packagesParam) { var packagesName = _sanitizeWindowsPath(packagesParam); var packagesUri = Uri.parse(packagesName); - if (packagesUri.scheme == '') { + if (!packagesUri.hasScheme) { // Script does not have a scheme, assume that it is a path, // resolve it against the working directory. packagesUri = _workingDirectory.resolveUri(packagesUri); @@ -107,7 +107,7 @@ _setPackagesConfig(String packagesParam) { // Given a uri with a 'package' scheme, return a Uri that is prefixed with // the package root or resolved relative to the package configuration. Uri _resolvePackageUri(Uri uri) { - assert(uri.scheme == "package"); + assert(uri.isScheme("package")); assert(_packagesReady); if (uri.host.isNotEmpty) { @@ -444,7 +444,7 @@ bool _isValidUtf8DataUrl(UriData data) { _handlePackagesRequest(bool traceLoading, int tag, Uri resource) { try { if (tag == -1) { - if (resource.scheme == '' || resource.scheme == 'file') { + if (!resource.hasScheme || resource.isScheme('file')) { return _findPackagesConfiguration(traceLoading, resource); } else { return "Unsupported scheme used to locate .packages file:'$resource'."; @@ -454,13 +454,13 @@ _handlePackagesRequest(bool traceLoading, int tag, Uri resource) { _log("Handling load of packages map: '$resource'."); } late Uint8List bytes; - if (resource.scheme == '' || resource.scheme == 'file') { + if (!resource.hasScheme || resource.isScheme('file')) { final file = File.fromUri(resource); if (!file.existsSync()) { return "Packages file '$resource' does not exit."; } bytes = file.readAsBytesSync(); - } else if (resource.scheme == 'data') { + } else if (resource.isScheme('data')) { final uriData = resource.data!; if (!_isValidUtf8DataUrl(uriData)) { return "The data resource '$resource' must have a 'text/plain' mime " @@ -543,7 +543,7 @@ String _setPackagesMap(String packagesParam) { } var packagesName = _sanitizeWindowsPath(packagesParam); var packagesUri = Uri.parse(packagesName); - if (packagesUri.scheme == '') { + if (!packagesUri.hasScheme) { // Script does not have a scheme, assume that it is a path, // resolve it against the working directory. packagesUri = _workingDirectory.resolveUri(packagesUri); @@ -569,7 +569,7 @@ String _resolveScriptUri(String scriptName) { scriptName = _sanitizeWindowsPath(scriptName); var scriptUri = Uri.parse(scriptName); - if (scriptUri.scheme == '') { + if (!scriptUri.hasScheme) { // Script does not have a scheme, assume that it is a path, // resolve it against the working directory. scriptUri = _workingDirectory.resolveUri(scriptUri); @@ -608,7 +608,7 @@ Future _resolvePackageUriFuture(Uri packageUri) { if (_traceLoading) { _log("Request for package Uri resolution from user code: $packageUri"); } - if (packageUri.scheme != "package") { + if (!packageUri.isScheme("package")) { if (_traceLoading) { _log("Non-package Uri, returning unmodified: $packageUri"); } diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart index cd386626693..d8ee831a5b4 100644 --- a/sdk/lib/core/uri.dart +++ b/sdk/lib/core/uri.dart @@ -2184,7 +2184,9 @@ class _Uri implements Uri { } } String slice = host.substring(sectionStart, index); - (buffer ??= StringBuffer())..write(slice)..write(_escapeChar(char)); + (buffer ??= StringBuffer()) + ..write(slice) + ..write(_escapeChar(char)); index += sourceLength; sectionStart = index; } @@ -2261,7 +2263,9 @@ class _Uri implements Uri { } String slice = host.substring(sectionStart, index); if (!isNormalized) slice = slice.toLowerCase(); - (buffer ??= StringBuffer())..write(slice)..write(_escapeChar(char)); + (buffer ??= StringBuffer()) + ..write(slice) + ..write(_escapeChar(char)); index += sourceLength; sectionStart = index; } @@ -2928,7 +2932,10 @@ class _Uri implements Uri { String _initializeText() { StringBuffer sb = StringBuffer(); - if (scheme.isNotEmpty) sb..write(scheme)..write(":"); + if (scheme.isNotEmpty) + sb + ..write(scheme) + ..write(":"); if (hasAuthority || (scheme == "file")) { // File URIS always have the authority, even if it is empty. // The empty URI means "localhost". @@ -2936,8 +2943,14 @@ class _Uri implements Uri { _writeAuthority(sb); } sb.write(path); - if (_query != null) sb..write("?")..write(_query); - if (_fragment != null) sb..write("#")..write(_fragment); + if (_query != null) + sb + ..write("?") + ..write(_query); + if (_fragment != null) + sb + ..write("#") + ..write(_fragment); return sb.toString(); } @@ -3439,7 +3452,7 @@ class UriData { /// and the path (concatenated with the query, if there is one) must be valid /// as data URI content with the same rules as [parse]. factory UriData.fromUri(Uri uri) { - if (uri.scheme != "data") { + if (!uri.isScheme("data")) { throw ArgumentError.value(uri, "uri", "Scheme must be 'data'"); } if (uri.hasAuthority) { @@ -3487,7 +3500,10 @@ class UriData { } if (charsetName != null) { // TODO(39209): Use ?.. when sequences are properly supported. - if (indices != null) indices..add(buffer.length)..add(buffer.length + 8); + if (indices != null) + indices + ..add(buffer.length) + ..add(buffer.length + 8); buffer.write(";charset="); buffer.write(_Uri._uriEncode(_tokenCharTable, charsetName, utf8, false)); } diff --git a/tests/corelib/uri_base_test.dart b/tests/corelib/uri_base_test.dart index a54a28774a5..51822c49b56 100644 --- a/tests/corelib/uri_base_test.dart +++ b/tests/corelib/uri_base_test.dart @@ -7,7 +7,7 @@ import "package:expect/expect.dart"; main() { try { Uri base = Uri.base; - Expect.isTrue(Uri.base.scheme == "file" || Uri.base.scheme == "http"); + Expect.isTrue(Uri.base.isScheme("file") || Uri.base.isScheme("http")); } on UnsupportedError catch (e) { Expect.isTrue(e.toString().contains("'Uri.base' is not supported")); } diff --git a/tests/corelib_2/uri_base_test.dart b/tests/corelib_2/uri_base_test.dart index 37175713de4..eb35e610806 100644 --- a/tests/corelib_2/uri_base_test.dart +++ b/tests/corelib_2/uri_base_test.dart @@ -9,7 +9,7 @@ import "package:expect/expect.dart"; main() { try { Uri base = Uri.base; - Expect.isTrue(Uri.base.scheme == "file" || Uri.base.scheme == "http"); + Expect.isTrue(Uri.base.isScheme("file") || Uri.base.isScheme("http")); } on UnsupportedError catch (e) { Expect.isTrue(e.toString().contains("'Uri.base' is not supported")); } diff --git a/tests/lib/mirrors/library_uri_package_test.dart b/tests/lib/mirrors/library_uri_package_test.dart index e546722f738..1ed7d66285f 100644 --- a/tests/lib/mirrors/library_uri_package_test.dart +++ b/tests/lib/mirrors/library_uri_package_test.dart @@ -15,7 +15,7 @@ testLibraryUri(var value, Uri expectedUri) { ClassMirror valueClass = valueMirror.type; LibraryMirror valueLibrary = valueClass.owner as LibraryMirror; Uri uri = valueLibrary.uri; - if (uri.scheme != "https" || + if (!uri.isScheme("https") || uri.host != "dartlang.org" || uri.path != "/dart2js-stripped-uri") { expect(uri, equals(expectedUri)); diff --git a/tests/lib/mirrors/mirrors_test.dart b/tests/lib/mirrors/mirrors_test.dart index e48269e70e1..a3e2a9ce473 100644 --- a/tests/lib/mirrors/mirrors_test.dart +++ b/tests/lib/mirrors/mirrors_test.dart @@ -199,7 +199,7 @@ testLibraryUri(var value, bool check(Uri uri)) { ClassMirror valueClass = valueMirror.type; LibraryMirror valueLibrary = valueClass.owner as LibraryMirror; Uri uri = valueLibrary.uri; - if (uri.scheme != "https" || + if (!uri.isScheme("https") || uri.host != "dartlang.org" || uri.path != "/dart2js-stripped-uri") { expect(check(uri), isTrue); diff --git a/tests/lib_2/mirrors/library_uri_package_test.dart b/tests/lib_2/mirrors/library_uri_package_test.dart index 38afa904595..8f55ead6bcc 100644 --- a/tests/lib_2/mirrors/library_uri_package_test.dart +++ b/tests/lib_2/mirrors/library_uri_package_test.dart @@ -17,7 +17,7 @@ testLibraryUri(var value, Uri expectedUri) { ClassMirror valueClass = valueMirror.type; LibraryMirror valueLibrary = valueClass.owner as LibraryMirror; Uri uri = valueLibrary.uri; - if (uri.scheme != "https" || + if (!uri.isScheme("https") || uri.host != "dartlang.org" || uri.path != "/dart2js-stripped-uri") { expect(uri, equals(expectedUri)); diff --git a/tests/lib_2/mirrors/mirrors_test.dart b/tests/lib_2/mirrors/mirrors_test.dart index 11f81ec0fe2..5c4ef4e9bf4 100644 --- a/tests/lib_2/mirrors/mirrors_test.dart +++ b/tests/lib_2/mirrors/mirrors_test.dart @@ -201,7 +201,7 @@ testLibraryUri(var value, bool check(Uri uri)) { ClassMirror valueClass = valueMirror.type; LibraryMirror valueLibrary = valueClass.owner as LibraryMirror; Uri uri = valueLibrary.uri; - if (uri.scheme != "https" || + if (!uri.isScheme("https") || uri.host != "dartlang.org" || uri.path != "/dart2js-stripped-uri") { expect(check(uri), isTrue); diff --git a/tests/standalone/io/web_socket_compression_test.dart b/tests/standalone/io/web_socket_compression_test.dart index 37b458e176f..56ada3377d0 100644 --- a/tests/standalone/io/web_socket_compression_test.dart +++ b/tests/standalone/io/web_socket_compression_test.dart @@ -55,7 +55,7 @@ class SecurityConfiguration { String nonce = base64.encode(nonceData); uri = new Uri( - scheme: uri.scheme == "wss" ? "https" : "http", + scheme: uri.isScheme("wss") ? "https" : "http", userInfo: uri.userInfo, host: uri.host, port: uri.port, diff --git a/tests/standalone_2/io/web_socket_compression_test.dart b/tests/standalone_2/io/web_socket_compression_test.dart index 59310623366..c62a5219d65 100644 --- a/tests/standalone_2/io/web_socket_compression_test.dart +++ b/tests/standalone_2/io/web_socket_compression_test.dart @@ -57,7 +57,7 @@ class SecurityConfiguration { String nonce = base64.encode(nonceData); uri = new Uri( - scheme: uri.scheme == "wss" ? "https" : "http", + scheme: uri.isScheme("wss") ? "https" : "http", userInfo: uri.userInfo, host: uri.host, port: uri.port, @@ -100,8 +100,7 @@ class SecurityConfiguration { createServer().then((server) { server.listen((request) { Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request)); - WebSocketTransformer - .upgrade(request, compression: serverOptions) + WebSocketTransformer.upgrade(request, compression: serverOptions) .then((webSocket) { webSocket.listen((message) { Expect.equals("Hello World", message); @@ -136,8 +135,7 @@ class SecurityConfiguration { createServer().then((server) { server.listen((request) { Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request)); - WebSocketTransformer - .upgrade(request, compression: serverOpts) + WebSocketTransformer.upgrade(request, compression: serverOpts) .then((webSocket) { webSocket.listen((message) { Expect.equals("Hello World", message); @@ -186,9 +184,9 @@ class SecurityConfiguration { ..headers.add( "Sec-WebSocket-Extensions", "permessage-deflate;" - // Test quoted values and space padded = - 'server_max_window_bits="10"; client_max_window_bits = 12' - 'client_no_context_takeover; server_no_context_takeover'); + // Test quoted values and space padded = + 'server_max_window_bits="10"; client_max_window_bits = 12' + 'client_no_context_takeover; server_no_context_takeover'); request.response.contentLength = 0; request.response.detachSocket().then((socket) { return new WebSocket.fromUpgradedSocket(socket, serverSide: true); @@ -218,8 +216,7 @@ class SecurityConfiguration { server.listen((request) { // Stuff Expect.isTrue(WebSocketTransformer.isUpgradeRequest(request)); - WebSocketTransformer - .upgrade(request, compression: serverCompression) + WebSocketTransformer.upgrade(request, compression: serverCompression) .then((webSocket) { webSocket.listen((message) { Expect.equals("Hello World", message); @@ -342,22 +339,22 @@ class SecurityConfiguration { testReturnHeaders( 'permessage-deflate; server_max_window_bits=10', "permessage-deflate;" - " server_max_window_bits=10;" - " client_max_window_bits=10"); + " server_max_window_bits=10;" + " client_max_window_bits=10"); // Don't provider context takeover if requested but not enabled. // Default is not enabled. testReturnHeaders( 'permessage-deflate; client_max_window_bits;' - 'client_no_context_takeover', + 'client_no_context_takeover', 'permessage-deflate; client_max_window_bits=15'); // Enable context Takeover and provide if requested. compression = new CompressionOptions( clientNoContextTakeover: true, serverNoContextTakeover: true); testReturnHeaders( 'permessage-deflate; client_max_window_bits; ' - 'client_no_context_takeover', + 'client_no_context_takeover', 'permessage-deflate; client_no_context_takeover; ' - 'client_max_window_bits=15', + 'client_max_window_bits=15', serverCompression: compression); // Enable context takeover and don't provide if not requested compression = new CompressionOptions( diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart index 79f5d049ecf..2400619e263 100644 --- a/tools/dom/src/native_DOMImplementation.dart +++ b/tools/dom/src/native_DOMImplementation.dart @@ -147,7 +147,9 @@ class _LibraryManager { ..group("Current library: $_currentLibrary") ..groupCollapsed("All libraries:"); _listLibraries(); - window.console..groupEnd()..groupEnd(); + window.console + ..groupEnd() + ..groupEnd(); return; } var matches = findMatches(name); @@ -169,9 +171,9 @@ class _LibraryManager { static List _sortUris(Iterable uris) { return (uris.toList()) ..sort((Uri a, Uri b) { - if (a.scheme != b.scheme) { - if (a.scheme == 'dart') return -1; - if (b.scheme == 'dart') return 1; + if (!a.isScheme(b.scheme)) { + if (a.isScheme('dart')) return -1; + if (b.isScheme('dart')) return 1; return a.scheme.compareTo(b.scheme); } return a.toString().compareTo(b.toString()); @@ -213,14 +215,18 @@ class _LibraryManager { if (index != -1) { // %c enables styling console log messages with css // specified at the end of the console. - sb..write(txt.substring(0, index))..write('%c'); + sb + ..write(txt.substring(0, index)) + ..write('%c'); var matchEnd = index + key.length; sb ..write(txt.substring(index, matchEnd)) ..write('%c') ..write(txt.substring(matchEnd)) ..write('\n'); - boldPairs..add('font-weight: bold')..add('font-weight: normal'); + boldPairs + ..add('font-weight: bold') + ..add('font-weight: normal'); } } _log([sb.toString()]..addAll(boldPairs)); @@ -738,7 +744,7 @@ class _Utils { // This matches JavaScript behavior. We should consider displaying // getters for all dart platform libraries rather than just the DOM // libraries. - return libraryMirror.uri.scheme == 'dart' && + return libraryMirror.uri.isScheme('dart') && SIDE_EFFECT_FREE_LIBRARIES.contains(libraryMirror.uri.toString()); } diff --git a/tools/package_deps/bin/package_deps.dart b/tools/package_deps/bin/package_deps.dart index 38cca341c4f..1bf3598ac7b 100644 --- a/tools/package_deps/bin/package_deps.dart +++ b/tools/package_deps/bin/package_deps.dart @@ -168,7 +168,7 @@ class Package implements Comparable { for (var import in _collectImports(file)) { try { var uri = Uri.parse(import); - if (uri.hasScheme && uri.scheme == 'package') { + if (uri.hasScheme && uri.isScheme('package')) { var packageName = path.split(uri.path).first; importedPackages.add(packageName); }