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 <kevmoo@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
This commit is contained in:
Nate Bosch 2022-02-08 21:38:57 +00:00 committed by Commit Bot
parent 7282a40c49
commit 33e174084a
161 changed files with 378 additions and 358 deletions

View file

@ -238,7 +238,7 @@ class LibrariesSpecification {
_reportError(messageIncludePathIsNotAString(targetName, specUri)); _reportError(messageIncludePathIsNotAString(targetName, specUri));
} }
Uri uri = Uri.parse(path); Uri uri = Uri.parse(path);
if (uri.scheme != '' && uri.scheme != 'file') { if (uri.hasScheme && !uri.isScheme('file')) {
return _reportError(messageUnsupportedUriScheme(path, specUri)); return _reportError(messageUnsupportedUriScheme(path, specUri));
} }
LibrariesSpecification specification = LibrariesSpecification specification =
@ -269,7 +269,7 @@ class LibrariesSpecification {
uriString, libraryName, targetName, specUri)); uriString, libraryName, targetName, specUri));
} }
Uri uri = Uri.parse(uriString); Uri uri = Uri.parse(uriString);
if (uri.scheme != '' && uri.scheme != 'file') { if (uri.hasScheme && !uri.isScheme('file')) {
return _reportError( return _reportError(
messageUnsupportedUriScheme(uriString, specUri)); messageUnsupportedUriScheme(uriString, specUri));
} }

View file

@ -18,7 +18,7 @@ Uri resolveInputUri(String path) {
Uri parseUri(String path) { Uri parseUri(String path) {
if (path.startsWith("file:")) { 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 // The Uri class doesn't handle relative file URIs correctly, the
// following works around that issue. // following works around that issue.
return new Uri(path: Uri.parse("x-$path").path); return new Uri(path: Uri.parse("x-$path").path);

View file

@ -362,7 +362,7 @@ class JsInteropChecks extends RecursiveVisitor {
/// or a from environment constructor. /// or a from environment constructor.
bool _isAllowedExternalUsage(Member member) { bool _isAllowedExternalUsage(Member member) {
Uri uri = member.enclosingLibrary.importUri; Uri uri = member.enclosingLibrary.importUri;
return uri.scheme == 'dart' && return uri.isScheme('dart') &&
_pathsWithAllowedDartExternalUsage.contains(uri.path) || _pathsWithAllowedDartExternalUsage.contains(uri.path) ||
_allowedNativeTestPatterns.any((pattern) => uri.path.contains(pattern)); _allowedNativeTestPatterns.any((pattern) => uri.path.contains(pattern));
} }

View file

@ -82,7 +82,7 @@ class DartUnitHoverComputer {
if (library != null) { if (library != null) {
var uri = library.source.uri; var uri = library.source.uri;
var analysisSession = _unit.declaredElement?.session; 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 // for 'file:' URIs, use the path after the project root
var context = analysisSession.resourceProvider.pathContext; var context = analysisSession.resourceProvider.pathContext;
var projectRootDir = var projectRootDir =

View file

@ -173,7 +173,7 @@ protocol.ElementKind protocolElementKind(DeclarationKind kind) {
/// Computes the best URI to import [what] into the [unit] library. /// Computes the best URI to import [what] into the [unit] library.
String? _getRelativeFileUri(DartCompletionRequest request, Uri what) { String? _getRelativeFileUri(DartCompletionRequest request, Uri what) {
if (what.scheme == 'file') { if (what.isScheme('file')) {
var pathContext = request.analysisSession.resourceProvider.pathContext; var pathContext = request.analysisSession.resourceProvider.pathContext;
var libraryPath = request.libraryElement.source.fullName; var libraryPath = request.libraryElement.source.fullName;

View file

@ -43,14 +43,14 @@ class ConvertToPackageImport extends CorrectionProducer {
} }
var importUri = uriSource.uri; var importUri = uriSource.uri;
if (importUri.scheme != 'package') { if (!importUri.isScheme('package')) {
return; return;
} }
// Don't offer to convert a 'package:' URI to itself. // Don't offer to convert a 'package:' URI to itself.
try { try {
var uriContent = importDirective.uriContent; var uriContent = importDirective.uriContent;
if (uriContent == null || Uri.parse(uriContent).scheme == 'package') { if (uriContent == null || Uri.parse(uriContent).isScheme('package')) {
return; return;
} }
} on FormatException { } on FormatException {

View file

@ -45,7 +45,7 @@ class ConvertToRelativeImport extends CorrectionProducer {
// Ignore if the uri is not a package: uri. // Ignore if the uri is not a package: uri.
var sourceUri = resolvedResult.uri; var sourceUri = resolvedResult.uri;
if (sourceUri.scheme != 'package') { if (!sourceUri.isScheme('package')) {
return; return;
} }
@ -61,7 +61,7 @@ class ConvertToRelativeImport extends CorrectionProducer {
} }
// Ignore if import uri is not a package: uri. // Ignore if import uri is not a package: uri.
if (importUri.scheme != 'package') { if (!importUri.isScheme('package')) {
return; return;
} }

View file

@ -322,7 +322,7 @@ Map<String, Element> getImportNamespace(ImportElement imp) {
/// Computes the best URI to import [what] into [from]. /// Computes the best URI to import [what] into [from].
String getLibrarySourceUri( String getLibrarySourceUri(
path.Context pathContext, LibraryElement from, Uri what) { path.Context pathContext, LibraryElement from, Uri what) {
if (what.scheme == 'file') { if (what.isScheme('file')) {
var fromFolder = pathContext.dirname(from.source.fullName); var fromFolder = pathContext.dirname(from.source.fullName);
var relativeFile = pathContext.relative(what.path, from: fromFolder); var relativeFile = pathContext.relative(what.path, from: fromFolder);
return pathContext.split(relativeFile).join('/'); return pathContext.split(relativeFile).join('/');

View file

@ -37,5 +37,5 @@ class ResourceUriResolver extends UriResolver {
Uri restoreAbsolute(Source source) => pathToUri(source.fullName); Uri restoreAbsolute(Source source) => pathToUri(source.fullName);
/// Return `true` if the given [uri] is a `file` URI. /// 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);
} }

View file

@ -31,7 +31,7 @@ abstract class BasicSource extends Source {
@Deprecated('Use uri.isScheme("dart") instead') @Deprecated('Use uri.isScheme("dart") instead')
@override @override
bool get isInSystemLibrary => uri.scheme == 'dart'; bool get isInSystemLibrary => uri.isScheme('dart');
@override @override
String get shortName => pathos.basename(fullName); String get shortName => pathos.basename(fullName);

View file

@ -79,6 +79,6 @@ class PackageMapUriResolver extends UriResolver {
/// Returns `true` if [uri] is a `package` URI. /// Returns `true` if [uri] is a `package` URI.
static bool isPackageUri(Uri uri) { static bool isPackageUri(Uri uri) {
return uri.scheme == PACKAGE_SCHEME; return uri.isScheme(PACKAGE_SCHEME);
} }
} }

View file

@ -80,7 +80,7 @@ class FileSource extends Source {
@Deprecated('Use uri.isScheme("dart") instead') @Deprecated('Use uri.isScheme("dart") instead')
@override @override
bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME; bool get isInSystemLibrary => uri.isScheme(DartUriResolver.DART_SCHEME);
@Deprecated('Not used anymore') @Deprecated('Not used anymore')
@override @override

View file

@ -83,7 +83,7 @@ class BazelPackageUriResolver extends UriResolver {
} }
Source? _resolveAbsolute(Uri uri) { Source? _resolveAbsolute(Uri uri) {
if (uri.scheme == 'file') { if (uri.isScheme('file')) {
var path = fileUriToNormalizedPath(_context, uri); var path = fileUriToNormalizedPath(_context, uri);
var pathRelativeToRoot = _workspace._relativeToRoot(path); var pathRelativeToRoot = _workspace._relativeToRoot(path);
if (pathRelativeToRoot == null) return null; if (pathRelativeToRoot == null) return null;
@ -91,7 +91,7 @@ class BazelPackageUriResolver extends UriResolver {
var file = _workspace.findFile(fullFilePath); var file = _workspace.findFile(fullFilePath);
return file?.createSource(uri); return file?.createSource(uri);
} }
if (uri.scheme != 'package') { if (!uri.isScheme('package')) {
return null; return null;
} }
String uriPath = Uri.decodeComponent(uri.path); String uriPath = Uri.decodeComponent(uri.path);

View file

@ -73,7 +73,7 @@ class PackageBuildPackageUriResolver extends UriResolver {
@override @override
Source? resolveAbsolute(Uri uri) { Source? resolveAbsolute(Uri uri) {
if (uri.scheme != 'package') { if (!uri.isScheme('package')) {
return null; return null;
} }

View file

@ -82,7 +82,7 @@ abstract class WorkspacePackage {
/// example, the case of a [InSummarySource]). In this case, use /// example, the case of a [InSummarySource]). In this case, use
/// [workspace]'s package URI resolver to fetch the file path. /// [workspace]'s package URI resolver to fetch the file path.
String? filePathFromSource(Source source) { String? filePathFromSource(Source source) {
if (source.uri.scheme == 'package') { if (source.uri.isScheme('package')) {
return workspace.packageUriResolver.resolveAbsolute(source.uri)?.fullName; return workspace.packageUriResolver.resolveAbsolute(source.uri)?.fullName;
} else { } else {
return source.fullName; return source.fullName;

View file

@ -530,9 +530,9 @@ class TestSourceWithUri extends TestSource {
@Deprecated('Use Source.uri instead') @Deprecated('Use Source.uri instead')
@override @override
UriKind get uriKind { UriKind get uriKind {
if (uri.scheme == 'dart') { if (uri.isScheme('dart')) {
return UriKind.DART_URI; return UriKind.DART_URI;
} else if (uri.scheme == 'package') { } else if (uri.isScheme('package')) {
return UriKind.PACKAGE_URI; return UriKind.PACKAGE_URI;
} }
return UriKind.FILE_URI; return UriKind.FILE_URI;

View file

@ -783,7 +783,7 @@ part of 'a.dart';
if (file is LibraryCycle) { if (file is LibraryCycle) {
return !file.libraries.any((file) => file.uri.isScheme('dart')); return !file.libraries.any((file) => file.uri.isScheme('dart'));
} else if (file is FileState) { } else if (file is FileState) {
return file.uri.scheme != 'dart'; return !file.uri.isScheme('dart');
} else if (file == null) { } else if (file == null) {
return true; return true;
} else { } else {

View file

@ -127,7 +127,7 @@ class AnalyzerImpl {
files.clear(); files.clear();
errorsResults.clear(); errorsResults.clear();
var libraryUri = libraryFile.uri; var libraryUri = libraryFile.uri;
if (libraryUri.scheme == 'package' && libraryUri.pathSegments.isNotEmpty) { if (libraryUri.isScheme('package') && libraryUri.pathSegments.isNotEmpty) {
_selfPackageName = libraryUri.pathSegments[0]; _selfPackageName = libraryUri.pathSegments[0];
} }
} }
@ -177,7 +177,7 @@ class AnalyzerImpl {
/// Determine whether the given URI refers to a package being analyzed. /// Determine whether the given URI refers to a package being analyzed.
bool _isAnalyzedPackage(Uri uri) { bool _isAnalyzedPackage(Uri uri) {
if (uri.scheme != 'package' || uri.pathSegments.isEmpty) { if (!uri.isScheme('package') || uri.pathSegments.isEmpty) {
return false; return false;
} }
var packageName = uri.pathSegments.first; var packageName = uri.pathSegments.first;

View file

@ -52,7 +52,7 @@ class MultiRootFileSystemEntity implements FileSystemEntity {
_delegate ??= await _resolveEntity(); _delegate ??= await _resolveEntity();
Future<FileSystemEntity> _resolveEntity() async { Future<FileSystemEntity> _resolveEntity() async {
if (uri.scheme == multiRootFileSystem.markerScheme) { if (uri.isScheme(multiRootFileSystem.markerScheme)) {
if (!uri.isAbsolute) { if (!uri.isAbsolute) {
throw new FileSystemException( throw new FileSystemException(
uri, "This MultiRootFileSystem only handles absolutes URIs: $uri"); uri, "This MultiRootFileSystem only handles absolutes URIs: $uri");

View file

@ -33,7 +33,7 @@ class SingleRootFileSystem implements FileSystem {
@override @override
FileSystemEntity entityForUri(Uri uri) { FileSystemEntity entityForUri(Uri uri) {
if (uri.scheme != markerScheme) { if (!uri.isScheme(markerScheme)) {
throw new FileSystemException( throw new FileSystemException(
uri, uri,
"This SingleRootFileSystem only handles URIs with the '$markerScheme'" "This SingleRootFileSystem only handles URIs with the '$markerScheme'"

View file

@ -726,7 +726,7 @@ abstract class Compiler {
Uri getCanonicalUri(Entity element) { Uri getCanonicalUri(Entity element) {
Uri libraryUri = _uriFromElement(element); Uri libraryUri = _uriFromElement(element);
if (libraryUri == null) return null; if (libraryUri == null) return null;
if (libraryUri.scheme == 'package') { if (libraryUri.isScheme('package')) {
int slashPos = libraryUri.path.indexOf('/'); int slashPos = libraryUri.path.indexOf('/');
if (slashPos != -1) { if (slashPos != -1) {
String packageName = libraryUri.path.substring(0, slashPos); String packageName = libraryUri.path.substring(0, slashPos);

View file

@ -1102,7 +1102,7 @@ class AbortLeg {
void writeString(Uri uri, String text) { void writeString(Uri uri, String text) {
if (!enableWriteString) return; if (!enableWriteString) return;
if (uri.scheme != 'file') { if (!uri.isScheme('file')) {
fail('Unhandled scheme ${uri.scheme}.'); fail('Unhandled scheme ${uri.scheme}.');
} }
var file = (File(uri.toFilePath())..createSync(recursive: true)) var file = (File(uri.toFilePath())..createSync(recursive: true))

View file

@ -18,7 +18,7 @@ abstract class CodeLocation {
String relativize(Uri baseUri); String relativize(Uri baseUri);
factory CodeLocation(Uri uri) { factory CodeLocation(Uri uri) {
if (uri.scheme == 'package') { if (uri.isScheme('package')) {
int slashPos = uri.path.indexOf('/'); int slashPos = uri.path.indexOf('/');
if (slashPos != -1) { if (slashPos != -1) {
String packageName = uri.path.substring(0, slashPos); String packageName = uri.path.substring(0, slashPos);
@ -42,7 +42,7 @@ class SchemeLocation implements CodeLocation {
@override @override
bool inSameLocation(Uri uri) { bool inSameLocation(Uri uri) {
return this.uri.scheme == uri.scheme; return this.uri.isScheme(uri.scheme);
} }
@override @override
@ -62,7 +62,7 @@ class PackageLocation implements CodeLocation {
@override @override
bool inSameLocation(Uri uri) { bool inSameLocation(Uri uri) {
return uri.scheme == 'package' && uri.path.startsWith('$packageName/'); return uri.isScheme('package') && uri.path.startsWith('$packageName/');
} }
@override @override

View file

@ -19,17 +19,17 @@ int compareLibrariesUris(Uri a, Uri b) {
} }
// Order: platform < package < other. // Order: platform < package < other.
if (a.scheme == 'dart') { if (a.isScheme('dart')) {
if (b.scheme == 'dart') return byCanonicalUriPath(); if (b.isScheme('dart')) return byCanonicalUriPath();
return -1; return -1;
} }
if (b.scheme == 'dart') return 1; if (b.isScheme('dart')) return 1;
if (a.scheme == 'package') { if (a.isScheme('package')) {
if (b.scheme == 'package') return byCanonicalUriPath(); if (b.isScheme('package')) return byCanonicalUriPath();
return -1; return -1;
} }
if (b.scheme == 'package') return 1; if (b.isScheme('package')) return 1;
return _compareCanonicalUri(a, b); return _compareCanonicalUri(a, b);
} }

View file

@ -251,7 +251,7 @@ bool containsFreeVariables(ir.DartType type) =>
/// Returns true if [importUri] corresponds to dart:html and related libraries. /// Returns true if [importUri] corresponds to dart:html and related libraries.
bool _isWebLibrary(Uri importUri) => bool _isWebLibrary(Uri importUri) =>
importUri.scheme == 'dart' && importUri.isScheme('dart') &&
(importUri.path == 'html' || (importUri.path == 'html' ||
importUri.path == 'svg' || importUri.path == 'svg' ||
importUri.path == 'indexed_db' || importUri.path == 'indexed_db' ||

View file

@ -156,7 +156,7 @@ EnumSet<PragmaAnnotation> processMemberAnnotations(
Uri uri = member.enclosingLibrary.importUri; Uri uri = member.enclosingLibrary.importUri;
bool platformAnnotationsAllowed = bool platformAnnotationsAllowed =
options.testMode || uri.scheme == 'dart' || maybeEnableNative(uri); options.testMode || uri.isScheme('dart') || maybeEnableNative(uri);
for (PragmaAnnotationData data in pragmaAnnotationData) { for (PragmaAnnotationData data in pragmaAnnotationData) {
String name = data.name; String name = data.name;

View file

@ -158,7 +158,7 @@ class BackendUsageBuilderImpl implements BackendUsageBuilder {
bool _isValidBackendUse(Entity element, LibraryEntity library) { bool _isValidBackendUse(Entity element, LibraryEntity library) {
if (_isValidEntity(element)) return true; if (_isValidEntity(element)) return true;
SourceSpan span = _frontendStrategy.spanFromSpannable(element, element); SourceSpan span = _frontendStrategy.spanFromSpannable(element, element);
if (library.canonicalUri.scheme == 'dart' && if (library.canonicalUri.isScheme('dart') &&
span.uri.path.contains('_internal/js_runtime/lib/')) { span.uri.path.contains('_internal/js_runtime/lib/')) {
// TODO(johnniwinther): We should be more precise about these. // TODO(johnniwinther): We should be more precise about these.
return true; return true;

View file

@ -55,7 +55,7 @@ bool allowedNativeTest(Uri uri) {
bool maybeEnableNative(Uri uri) { bool maybeEnableNative(Uri uri) {
bool allowedDartLibrary() { bool allowedDartLibrary() {
if (uri.scheme != 'dart') return false; if (!uri.isScheme('dart')) return false;
return _allowedDartSchemePaths.contains(uri.path); return _allowedDartSchemePaths.contains(uri.path);
} }
@ -118,7 +118,7 @@ class Dart2jsTarget extends Target {
bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) => bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) =>
super.allowPlatformPrivateLibraryAccess(importer, imported) || super.allowPlatformPrivateLibraryAccess(importer, imported) ||
maybeEnableNative(importer) || maybeEnableNative(importer) ||
(importer.scheme == 'package' && (importer.isScheme('package') &&
importer.path.startsWith('dart2js_runtime_metrics/')); importer.path.startsWith('dart2js_runtime_metrics/'));
@override @override

View file

@ -23,7 +23,7 @@ class CompilerFileSystem implements fe.FileSystem {
@override @override
fe.FileSystemEntity entityForUri(Uri uri) { fe.FileSystemEntity entityForUri(Uri uri) {
if (uri.scheme == 'data') { if (uri.isScheme('data')) {
return fe.DataFileSystemEntity(Uri.base.resolveUri(uri)); return fe.DataFileSystemEntity(Uri.base.resolveUri(uri));
} else { } else {
return _CompilerFileSystemEntity(uri, this); return _CompilerFileSystemEntity(uri, this);

View file

@ -269,7 +269,7 @@ class KernelLoaderTask extends CompilerTask {
// Libraries dependencies do not show implicit imports to `dart:core`. // Libraries dependencies do not show implicit imports to `dart:core`.
var dartCore = component.libraries.firstWhere((lib) { 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); search(dartCore);

View file

@ -826,7 +826,7 @@ class CompilerOptions implements DiagnosticOptions {
return true; return true;
} }
if (shownPackageWarnings != null) { if (shownPackageWarnings != null) {
return uri.scheme == 'package' && return uri.isScheme('package') &&
shownPackageWarnings!.contains(uri.pathSegments.first); shownPackageWarnings!.contains(uri.pathSegments.first);
} }
return false; return false;

View file

@ -40,9 +40,9 @@ abstract class SourceFileProvider implements CompilerInput {
} }
if (input != null) return Future.value(input); if (input != null) return Future.value(input);
if (resourceUri.scheme == 'file') { if (resourceUri.isScheme('file')) {
return _readFromFile(resourceUri, inputKind); return _readFromFile(resourceUri, inputKind);
} else if (resourceUri.scheme == 'http' || resourceUri.scheme == 'https') { } else if (resourceUri.isScheme('http') || resourceUri.isScheme('https')) {
return _readFromHttp(resourceUri, inputKind); return _readFromHttp(resourceUri, inputKind);
} else { } else {
throw ArgumentError("Unknown scheme in uri '$resourceUri'"); throw ArgumentError("Unknown scheme in uri '$resourceUri'");
@ -50,7 +50,7 @@ abstract class SourceFileProvider implements CompilerInput {
} }
api.Input _readFromFileSync(Uri resourceUri, api.InputKind inputKind) { api.Input _readFromFileSync(Uri resourceUri, api.InputKind inputKind) {
assert(resourceUri.scheme == 'file'); assert(resourceUri.isScheme('file'));
List<int> source; List<int> source;
try { try {
source = readAll(resourceUri.toFilePath(), source = readAll(resourceUri.toFilePath(),
@ -99,7 +99,7 @@ abstract class SourceFileProvider implements CompilerInput {
Future<api.Input<List<int>>> _readFromHttp( Future<api.Input<List<int>>> _readFromHttp(
Uri resourceUri, api.InputKind inputKind) { Uri resourceUri, api.InputKind inputKind) {
assert(resourceUri.scheme == 'http'); assert(resourceUri.isScheme('http'));
HttpClient client = HttpClient(); HttpClient client = HttpClient();
return client return client
.getUrl(resourceUri) .getUrl(resourceUri)
@ -279,7 +279,7 @@ class FormattingDiagnosticHandler implements CompilerDiagnostics {
api.Input file = provider.getUtf8SourceFile(uri); api.Input file = provider.getUtf8SourceFile(uri);
if (file == null && if (file == null &&
autoReadFileUri && autoReadFileUri &&
(uri.scheme == 'file' || !uri.isAbsolute) && (uri.isScheme('file') || !uri.isAbsolute) &&
uri.path.endsWith('.dart')) { uri.path.endsWith('.dart')) {
if (!uri.isAbsolute) { if (!uri.isAbsolute) {
uri = provider.cwd.resolveUri(uri); uri = provider.cwd.resolveUri(uri);
@ -379,7 +379,7 @@ class RandomAccessFileOutputProvider implements CompilerOutput {
Uri uri = createUri(name, extension, type); Uri uri = createUri(name, extension, type);
bool isPrimaryOutput = uri == out; bool isPrimaryOutput = uri == out;
if (uri.scheme != 'file') { if (!uri.isScheme('file')) {
onFailure('Unhandled scheme ${uri.scheme} in $uri.'); onFailure('Unhandled scheme ${uri.scheme} in $uri.');
} }
@ -428,7 +428,7 @@ class RandomAccessFileOutputProvider implements CompilerOutput {
allOutputFiles.add(fe.relativizeUri(Uri.base, uri, Platform.isWindows)); allOutputFiles.add(fe.relativizeUri(Uri.base, uri, Platform.isWindows));
if (uri.scheme != 'file') { if (!uri.isScheme('file')) {
onFailure('Unhandled scheme ${uri.scheme} in $uri.'); onFailure('Unhandled scheme ${uri.scheme} in $uri.');
} }
@ -608,7 +608,7 @@ class MultiRootInputProvider extends SourceFileProvider {
Future<api.Input<List<int>>> readFromUri(Uri uri, Future<api.Input<List<int>>> readFromUri(Uri uri,
{InputKind inputKind = InputKind.UTF8}) async { {InputKind inputKind = InputKind.UTF8}) async {
var resolvedUri = uri; var resolvedUri = uri;
if (resolvedUri.scheme == markerScheme) { if (resolvedUri.isScheme(markerScheme)) {
var path = resolvedUri.path; var path = resolvedUri.path;
if (path.startsWith('/')) path = path.substring(1); if (path.startsWith('/')) path = path.substring(1);
for (var dir in roots) { for (var dir in roots) {
@ -634,7 +634,7 @@ class MultiRootInputProvider extends SourceFileProvider {
@override @override
api.Input autoReadFromFile(Uri resourceUri) { api.Input autoReadFromFile(Uri resourceUri) {
if (resourceUri.scheme == markerScheme) { if (resourceUri.isScheme(markerScheme)) {
var path = resourceUri.path; var path = resourceUri.path;
for (var dir in roots) { for (var dir in roots) {
var file = dir.resolve(path); var file = dir.resolve(path);

View file

@ -40,7 +40,7 @@ main(List<String> args) {
Uri packageConfig = getPackages(argResults); Uri packageConfig = getPackages(argResults);
List<String> options = getOptions(argResults); List<String> options = getOptions(argResults);
run(entryPoint, null, run(entryPoint, null,
analyzedUrisFilter: (Uri uri) => uri.scheme != 'dart', analyzedUrisFilter: (Uri uri) => !uri.isScheme('dart'),
librariesSpecificationUri: librariesSpecificationUri, librariesSpecificationUri: librariesSpecificationUri,
packageConfig: packageConfig, packageConfig: packageConfig,
options: options); options: options);
@ -362,7 +362,7 @@ class DynamicVisitor extends StaticTypeVisitorBase {
String reportAssertionFailure(ir.Node node, String message) { String reportAssertionFailure(ir.Node node, String message) {
SourceSpan span = computeSourceSpanFromTreeNode(node); SourceSpan span = computeSourceSpanFromTreeNode(node);
Uri uri = span.uri; Uri uri = span.uri;
if (uri.scheme == 'org-dartlang-sdk') { if (uri.isScheme('org-dartlang-sdk')) {
span = new SourceSpan( span = new SourceSpan(
Uri.base.resolve(uri.path.substring(1)), span.begin, span.end); 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); String uriString = relativizeUri(Uri.base, uri, Platform.isWindows);
Map<String, List<DiagnosticMessage>> actualMap = _actualMessages Map<String, List<DiagnosticMessage>> actualMap = _actualMessages
.putIfAbsent(uriString, () => <String, List<DiagnosticMessage>>{}); .putIfAbsent(uriString, () => <String, List<DiagnosticMessage>>{});
if (uri.scheme == 'org-dartlang-sdk') { if (uri.isScheme('org-dartlang-sdk')) {
span = new SourceSpan( span = new SourceSpan(
Uri.base.resolve(uri.path.substring(1)), span.begin, span.end); Uri.base.resolve(uri.path.substring(1)), span.begin, span.end);
} }

View file

@ -14,7 +14,7 @@ main(List<String> args) {
asyncTest(() async { asyncTest(() async {
await run( await run(
Uri.parse('memory:main.dart'), 'pkg/compiler/test/analyses/$goldenFile', 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() {}'}, memorySourceFiles: {'main.dart': 'main() {}'},
verbose: args.contains('-v'), verbose: args.contains('-v'),
generate: args.contains('-g')); generate: args.contains('-g'));

View file

@ -109,7 +109,7 @@ class TestFileSystem implements FileSystem {
@override @override
FileSystemEntity entityForUri(Uri uri) { FileSystemEntity entityForUri(Uri uri) {
if (uri.scheme == 'file') return physical.entityForUri(uri); if (uri.isScheme('file')) return physical.entityForUri(uri);
return memory.entityForUri(uri); return memory.entityForUri(uri);
} }
} }

View file

@ -248,8 +248,8 @@ Future<CompiledData<T>> computeData<T>(String name, Uri entryPoint,
bool excludeLibrary(LibraryEntity library) { bool excludeLibrary(LibraryEntity library) {
return forUserLibrariesOnly && return forUserLibrariesOnly &&
(library.canonicalUri.scheme == 'dart' || (library.canonicalUri.isScheme('dart') ||
library.canonicalUri.scheme == 'package'); library.canonicalUri.isScheme('package'));
} }
ir.Library getIrLibrary(LibraryEntity library) { ir.Library getIrLibrary(LibraryEntity library) {

View file

@ -65,7 +65,7 @@ show<T>(ArgResults argResults, DataComputer<T> dataComputer,
SourceFileProvider provider = data.compiler.provider; SourceFileProvider provider = data.compiler.provider;
for (Uri uri in data.actualMaps.keys) { for (Uri uri in data.actualMaps.keys) {
Uri fileUri = uri; Uri fileUri = uri;
if (fileUri.scheme == 'org-dartlang-sdk') { if (fileUri.isScheme('org-dartlang-sdk')) {
fileUri = Uri.base.resolve(fileUri.path.substring(1)); fileUri = Uri.base.resolve(fileUri.path.substring(1));
} }
if (show != null && !show.any((f) => '$fileUri'.endsWith(f))) { if (show != null && !show.any((f) => '$fileUri'.endsWith(f))) {

View file

@ -21,8 +21,8 @@ ClassEntity findClass(JClosedWorld closedWorld, String name) {
closedWorld.commonElements.jsHelperLibrary, name); closedWorld.commonElements.jsHelperLibrary, name);
if (cls == null) { if (cls == null) {
for (LibraryEntity library in elementEnvironment.libraries) { for (LibraryEntity library in elementEnvironment.libraries) {
if (library.canonicalUri.scheme != 'dart' && if (!library.canonicalUri.isScheme('dart') &&
library.canonicalUri.scheme != 'package') { !library.canonicalUri.isScheme('package')) {
cls = elementEnvironment.lookupClass(library, name); cls = elementEnvironment.lookupClass(library, name);
if (cls != null) { if (cls != null) {
break; break;
@ -70,8 +70,8 @@ MemberEntity findMember(JClosedWorld closedWorld, String name) {
setter: isSetter); setter: isSetter);
if (member == null) { if (member == null) {
for (LibraryEntity library in elementEnvironment.libraries) { for (LibraryEntity library in elementEnvironment.libraries) {
if (library.canonicalUri.scheme != 'dart' && if (!library.canonicalUri.isScheme('dart') &&
library.canonicalUri.scheme != 'package') { !library.canonicalUri.isScheme('package')) {
member = elementEnvironment.lookupLibraryMember(library, name, member = elementEnvironment.lookupLibraryMember(library, name,
setter: isSetter); setter: isSetter);
if (member != null) { if (member != null) {

View file

@ -31,7 +31,7 @@ class MemorySourceFileProvider extends SourceFileProvider {
@override @override
Future<Input<List<int>>> readBytesFromUri( Future<Input<List<int>>> readBytesFromUri(
Uri resourceUri, InputKind inputKind) { Uri resourceUri, InputKind inputKind) {
if (resourceUri.scheme != 'memory') { if (!resourceUri.isScheme('memory')) {
return super.readBytesFromUri(resourceUri, inputKind); return super.readBytesFromUri(resourceUri, inputKind);
} }
// TODO(johnniwinther): We should use inputs already in the cache. Some // TODO(johnniwinther): We should use inputs already in the cache. Some

View file

@ -351,7 +351,7 @@ main(List<String> args) {
} }
for (ir.Library library in component.libraries) { for (ir.Library library in component.libraries) {
if (library.importUri.scheme == 'memory') { if (library.importUri.isScheme('memory')) {
String libraryId = library.importUri.path; String libraryId = library.importUri.path;
LibraryEntity libraryEntity = elementMap.getLibrary(library); LibraryEntity libraryEntity = elementMap.getLibrary(library);

View file

@ -52,7 +52,7 @@ Future runTest() async {
Selector callSelector = new Selector.callClosure(0); Selector callSelector = new Selector.callClosure(0);
closedWorld.classHierarchy.forEachStrictSubclassOf( closedWorld.classHierarchy.forEachStrictSubclassOf(
closedWorld.commonElements.objectClass, (ClassEntity cls) { closedWorld.commonElements.objectClass, (ClassEntity cls) {
if (cls.library.canonicalUri.scheme != 'memory') if (!cls.library.canonicalUri.isScheme('memory'))
return IterationStep.CONTINUE; return IterationStep.CONTINUE;
TypeMask mask = new TypeMask.nonNullSubclass(cls, closedWorld); TypeMask mask = new TypeMask.nonNullSubclass(cls, closedWorld);

View file

@ -157,7 +157,7 @@ Future<TestResult> runTests(
.process(['--csp', Flags.disableInlining, ...options], verbose: verbose); .process(['--csp', Flags.disableInlining, ...options], verbose: verbose);
TestResult result = new TestResult(config, filename, processor); TestResult result = new TestResult(config, filename, processor);
for (SourceMapInfo info in sourceMaps.elementSourceMapInfos.values) { 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); result.userInfoList.add(info);
Iterable<CodePoint> missingCodePoints = Iterable<CodePoint> missingCodePoints =
info.codePoints.where((c) => c.isMissing); info.codePoints.where((c) => c.isMissing);

View file

@ -638,7 +638,7 @@ Future<void> resolveScripts(Options options) async {
String sourceUriOrPath, String relativeSnapshotPath) async { String sourceUriOrPath, String relativeSnapshotPath) async {
Uri sourceUri = sdkRoot.resolve(sourceUriOrPath); Uri sourceUri = sdkRoot.resolve(sourceUriOrPath);
String result = String result =
sourceUri.scheme == 'file' ? sourceUri.toFilePath() : sourceUriOrPath; sourceUri.isScheme('file') ? sourceUri.toFilePath() : sourceUriOrPath;
if (_options.useSdk) { if (_options.useSdk) {
String snapshot = Uri.file(Platform.resolvedExecutable) String snapshot = Uri.file(Platform.resolvedExecutable)
.resolve(relativeSnapshotPath) .resolve(relativeSnapshotPath)

View file

@ -64,7 +64,7 @@ _showLayout(String file) async {
print(' contains:'); print(' contains:');
map.forEach((lib, elements) { map.forEach((lib, elements) {
var uri = lib.uri; 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.path.substring(dir.length + 1)
: '$uri'; : '$uri';

View file

@ -133,7 +133,7 @@ LibraryInfo _getLibraryOf(Info info) {
return current; return current;
} }
bool _isPackageUri(Uri uri) => uri.scheme == 'package'; bool _isPackageUri(Uri uri) => uri.isScheme('package');
String _getPackageName(Uri uri) { String _getPackageName(Uri uri) {
assert(_isPackageUri(uri)); assert(_isPackageUri(uri));

View file

@ -116,7 +116,7 @@ String packageName(Info info) {
info = info.parent; info = info.parent;
} }
if (info is LibraryInfo) { if (info is LibraryInfo) {
if (info.uri.scheme == 'package') { if (info.uri.isScheme('package')) {
return '${info.uri}'.split('/').first; return '${info.uri}'.split('/').first;
} }
} }

View file

@ -31,7 +31,7 @@ String deobfuscateStackTrace(String obfuscatedTrace) {
var provider = CachingFileProvider(); var provider = CachingFileProvider();
StackDeobfuscationResult result = deobfuscateStack(obfuscatedTrace, provider); StackDeobfuscationResult result = deobfuscateStack(obfuscatedTrace, provider);
Frame firstFrame = result.original.frames.first; Frame firstFrame = result.original.frames.first;
String translatedError = (firstFrame.uri.scheme == 'error' String translatedError = (firstFrame.uri.isScheme('error')
? null ? null
: translate(error, provider.mappingFor(firstFrame.uri))) ?? : translate(error, provider.mappingFor(firstFrame.uri))) ??
'<no error message found>'; '<no error message found>';

View file

@ -34,7 +34,7 @@ class CachingFileProvider implements FileProvider {
/// deobfuscation locally for debugging purposes. /// deobfuscation locally for debugging purposes.
class DownloadedFileProvider extends CachingFileProvider { class DownloadedFileProvider extends CachingFileProvider {
_localize(uri) { _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); String filename = uri.path.substring(uri.path.lastIndexOf('/') + 1);
return Uri.base.resolve(filename); return Uri.base.resolve(filename);
} }

View file

@ -46,13 +46,13 @@ abstract class DartDevelopmentService {
DevToolsConfiguration? devToolsConfiguration, DevToolsConfiguration? devToolsConfiguration,
bool logRequests = false, bool logRequests = false,
}) async { }) async {
if (remoteVmServiceUri.scheme != 'http') { if (!remoteVmServiceUri.isScheme('http')) {
throw ArgumentError( throw ArgumentError(
'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}', 'remoteVmServiceUri must have an HTTP scheme. Actual: ${remoteVmServiceUri.scheme}',
); );
} }
if (serviceUri != null) { if (serviceUri != null) {
if (serviceUri.scheme != 'http') { if (!serviceUri.isScheme('http')) {
throw ArgumentError( throw ArgumentError(
'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}', 'serviceUri must have an HTTP scheme. Actual: ${serviceUri.scheme}',
); );

View file

@ -460,11 +460,11 @@ class AmdModuleBuilder extends _ModuleBuilder {
} }
bool isSdkInternalRuntimeUri(Uri importUri) { bool isSdkInternalRuntimeUri(Uri importUri) {
return importUri.scheme == 'dart' && importUri.path == '_runtime'; return importUri.isScheme('dart') && importUri.path == '_runtime';
} }
String libraryUriToJsIdentifier(Uri importUri) { String libraryUriToJsIdentifier(Uri importUri) {
if (importUri.scheme == 'dart') { if (importUri.isScheme('dart')) {
return isSdkInternalRuntimeUri(importUri) ? 'dart' : importUri.path; return isSdkInternalRuntimeUri(importUri) ? 'dart' : importUri.path;
} }
return pathToJSIdentifier(p.withoutExtension(importUri.pathSegments.last)); return pathToJSIdentifier(p.withoutExtension(importUri.pathSegments.last));

View file

@ -347,7 +347,7 @@ Uri sourcePathToUri(String source, {bool windows}) {
Uri sourcePathToRelativeUri(String source, {bool windows}) { Uri sourcePathToRelativeUri(String source, {bool windows}) {
var uri = sourcePathToUri(source, windows: windows); var uri = sourcePathToUri(source, windows: windows);
if (uri.scheme == 'file') { if (uri.isScheme('file')) {
var uriPath = uri.path; var uriPath = uri.path;
var root = Uri.base.path; var root = Uri.base.path;
if (uriPath.startsWith(root)) { if (uriPath.startsWith(root)) {
@ -400,7 +400,7 @@ Map placeSourceMap(Map sourceMap, String sourceMapPath, String multiRootScheme,
return sourcePath; return sourcePath;
} }
if (uri.scheme == 'http') return sourcePath; if (uri.isScheme('http')) return sourcePath;
// Convert to a local file path if it's not. // Convert to a local file path if it's not.
sourcePath = sourcePathToUri(p.absolute(p.fromUri(uri))).path; sourcePath = sourcePathToUri(p.absolute(p.fromUri(uri))).path;

View file

@ -32,7 +32,7 @@ class AssetFileSystem implements FileSystem {
@override @override
FileSystemEntity entityForUri(Uri uri) { FileSystemEntity entityForUri(Uri uri) {
if (uri.scheme == 'file') { if (uri.isScheme('file')) {
return original.entityForUri(uri); return original.entityForUri(uri);
} }

View file

@ -177,7 +177,7 @@ Future<CompilerResult> _compile(List<String> args,
options.multiRootScheme, multiRootPaths, fe.StandardFileSystem.instance); options.multiRootScheme, multiRootPaths, fe.StandardFileSystem.instance);
Uri toCustomUri(Uri uri) { Uri toCustomUri(Uri uri) {
if (uri.scheme == '') { if (!uri.hasScheme) {
return Uri(scheme: options.multiRootScheme, path: '/' + uri.path); return Uri(scheme: options.multiRootScheme, path: '/' + uri.path);
} }
return uri; return uri;
@ -486,7 +486,7 @@ Future<CompilerResult> _compile(List<String> args,
compilerState.incrementalCompiler.updateNeededDillLibrariesWithHierarchy( compilerState.incrementalCompiler.updateNeededDillLibrariesWithHierarchy(
neededDillLibraries, result.classHierarchy); neededDillLibraries, result.classHierarchy);
for (var lib in neededDillLibraries) { for (var lib in neededDillLibraries) {
if (lib.importUri.scheme == 'dart') continue; if (lib.importUri.isScheme('dart')) continue;
var uri = compilerState.libraryToInputDill[lib.importUri]; var uri = compilerState.libraryToInputDill[lib.importUri];
if (uri == null) { if (uri == null) {
throw StateError('Library ${lib.importUri} was recorded as used, ' throw StateError('Library ${lib.importUri} was recorded as used, '
@ -552,7 +552,7 @@ Future<CompilerResult> compileSdkFromDill(List<String> args) async {
var component = loadComponentFromBinary(inputs.single); var component = loadComponentFromBinary(inputs.single);
var invalidLibraries = <Uri>[]; var invalidLibraries = <Uri>[];
for (var library in component.libraries) { for (var library in component.libraries) {
if (library.importUri.scheme != 'dart') { if (!library.importUri.isScheme('dart')) {
invalidLibraries.add(library.importUri); invalidLibraries.add(library.importUri);
} }
} }

View file

@ -496,10 +496,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
@override @override
String jsLibraryAlias(Library library) { String jsLibraryAlias(Library library) {
var uri = library.importUri.normalizePath(); var uri = library.importUri.normalizePath();
if (uri.scheme == 'dart') return null; if (uri.isScheme('dart')) return null;
Iterable<String> segments; Iterable<String> segments;
if (uri.scheme == 'package') { if (uri.isScheme('package')) {
// Strip the package name. // Strip the package name.
segments = uri.pathSegments.skip(1); segments = uri.pathSegments.skip(1);
} else { } else {
@ -521,7 +521,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
/// True when [library] is the sdk internal library 'dart:_internal'. /// True when [library] is the sdk internal library 'dart:_internal'.
bool _isDartInternal(Library library) { bool _isDartInternal(Library library) {
var importUri = library.importUri; var importUri = library.importUri;
return importUri.scheme == 'dart' && importUri.path == '_internal'; return importUri.isScheme('dart') && importUri.path == '_internal';
} }
@override @override
@ -531,7 +531,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
@override @override
String libraryToModule(Library library) { String libraryToModule(Library library) {
if (library.importUri.scheme == 'dart') { if (library.importUri.isScheme('dart')) {
// TODO(jmesserly): we need to split out HTML. // TODO(jmesserly): we need to split out HTML.
return js_ast.dartSdkModule; return js_ast.dartSdkModule;
} }
@ -1940,7 +1940,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
bool _isForwardingStub(Procedure member) { bool _isForwardingStub(Procedure member) {
if (member.isForwardingStub || member.isForwardingSemiStub) { 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 // TODO(jmesserly): external methods in the SDK seem to get incorrectly
// tagged as forwarding stubs even if they are patched. Perhaps there is // 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 // an ordering issue in CFE. So for now we pattern match to see if it
@ -2254,7 +2254,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
_hierarchy.getClassAsInstanceOf(c.superclass, _coreTypes.iterableClass); _hierarchy.getClassAsInstanceOf(c.superclass, _coreTypes.iterableClass);
if (parentIterable != null) return null; 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')) { c.procedures.any((m) => _jsExportName(m) == 'Symbol.iterator')) {
return null; return null;
} }
@ -2764,7 +2764,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
var fn = _emitFunction(p.function, p.name.text) var fn = _emitFunction(p.function, p.name.text)
..sourceInformation = _nodeEnd(p.fileEndOffset); ..sourceInformation = _nodeEnd(p.fileEndOffset);
if (_currentLibrary.importUri.scheme == 'dart' && if (_currentLibrary.importUri.isScheme('dart') &&
_isInlineJSFunction(p.function.body)) { _isInlineJSFunction(p.function.body)) {
fn = js_ast.simplifyPassThroughArrowFunCallBody(fn); fn = js_ast.simplifyPassThroughArrowFunCallBody(fn);
} }
@ -3737,7 +3737,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
bool _reifyGenericFunction(Member m) => bool _reifyGenericFunction(Member m) =>
m == null || m == null ||
m.enclosingLibrary.importUri.scheme != 'dart' || !m.enclosingLibrary.importUri.isScheme('dart') ||
!m.annotations !m.annotations
.any((a) => isBuiltinAnnotation(a, '_js_helper', 'NoReifyGeneric')); .any((a) => isBuiltinAnnotation(a, '_js_helper', 'NoReifyGeneric'));
@ -5692,7 +5692,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
bool _isWebLibrary(Uri importUri) => bool _isWebLibrary(Uri importUri) =>
importUri != null && importUri != null &&
importUri.scheme == 'dart' && importUri.isScheme('dart') &&
(importUri.path == 'html' || (importUri.path == 'html' ||
importUri.path == 'svg' || importUri.path == 'svg' ||
importUri.path == 'indexed_db' || importUri.path == 'indexed_db' ||
@ -5792,7 +5792,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
if (args.positional.isEmpty && if (args.positional.isEmpty &&
args.named.isEmpty && args.named.isEmpty &&
ctorClass.enclosingLibrary.importUri.scheme == 'dart') { ctorClass.enclosingLibrary.importUri.isScheme('dart')) {
// Skip the slow SDK factory constructors when possible. // Skip the slow SDK factory constructors when possible.
switch (ctorClass.name) { switch (ctorClass.name) {
case 'Map': case 'Map':
@ -6308,7 +6308,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
]); ]);
bool _reifyFunctionType(FunctionNode f) { bool _reifyFunctionType(FunctionNode f) {
if (_currentLibrary.importUri.scheme != 'dart') return true; if (!_currentLibrary.importUri.isScheme('dart')) return true;
var parent = f.parent; var parent = f.parent;
// SDK libraries can skip reification if they request it. // SDK libraries can skip reification if they request it.
@ -6337,7 +6337,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
/// under which functions are compiled and exported. /// under which functions are compiled and exported.
String _jsExportName(NamedNode n) { String _jsExportName(NamedNode n) {
var library = getLibrary(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); return _annotationName(n, isJSExportNameAnnotation);
} }
@ -6363,7 +6363,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
js_ast.Expression visitConstant(Constant node) { js_ast.Expression visitConstant(Constant node) {
if (node is StaticTearOffConstant) { if (node is StaticTearOffConstant) {
// JS() or external JS consts should not be lazily loaded. // 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) { if (_isInForeignJS) {
return _emitStaticTarget(node.target); return _emitStaticTarget(node.target);
} }

View file

@ -299,7 +299,7 @@ class ExpressionCompilerWorker {
var libraryUri = Uri.parse(request.libraryUri); var libraryUri = Uri.parse(request.libraryUri);
var moduleName = request.moduleName; var moduleName = request.moduleName;
if (libraryUri.scheme == 'dart') { if (libraryUri.isScheme('dart')) {
// compiling expressions inside the SDK currently fails because // compiling expressions inside the SDK currently fails because
// SDK kernel outlines do not contain information that is needed // SDK kernel outlines do not contain information that is needed
// to detect the scope for expression evaluation - such as local // to detect the scope for expression evaluation - such as local
@ -329,7 +329,7 @@ class ExpressionCompilerWorker {
var originalComponent = _moduleCache.componentForModuleName[moduleName]; var originalComponent = _moduleCache.componentForModuleName[moduleName];
var component = _sdkComponent; var component = _sdkComponent;
if (libraryUri.scheme != 'dart') { if (!libraryUri.isScheme('dart')) {
_processedOptions.ticker.logMs('Collecting libraries for $moduleName'); _processedOptions.ticker.logMs('Collecting libraries for $moduleName');
var libraries = var libraries =

View file

@ -92,7 +92,7 @@ bool isBuiltinAnnotation(
var c = getAnnotationClass(value); var c = getAnnotationClass(value);
if (c != null && c.name == className) { if (c != null && c.name == className) {
var uri = c.enclosingLibrary.importUri; var uri = c.enclosingLibrary.importUri;
return uri.scheme == 'dart' && uri.path == libraryName; return uri.isScheme('dart') && uri.path == libraryName;
} }
return false; return false;
} }
@ -223,7 +223,7 @@ bool isCovariantField(Field f) {
/// ///
/// `dart:html` has many of these. /// `dart:html` has many of these.
bool isUnsupportedFactoryConstructor(Procedure node) { 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; var body = node.function.body;
if (body is Block) { if (body is Block) {
var statements = body.statements; var statements = body.statements;
@ -365,4 +365,4 @@ bool _isNativeMarkerAnnotation(Expression annotation) {
} }
bool _isDartInternal(Uri uri) => bool _isDartInternal(Uri uri) =>
uri.scheme == 'dart' && uri.path == '_internal'; uri.isScheme('dart') && uri.path == '_internal';

View file

@ -170,5 +170,5 @@ bool _isNativeAnnotation(Expression annotation) {
var c = getAnnotationClass(annotation); var c = getAnnotationClass(annotation);
return c != null && return c != null &&
(c.name == 'Native' || c.name == 'JsPeerInterface') && (c.name == 'Native' || c.name == 'JsPeerInterface') &&
c.enclosingLibrary.importUri.scheme == 'dart'; c.enclosingLibrary.importUri.isScheme('dart');
} }

View file

@ -338,9 +338,9 @@ class NullableInference extends ExpressionVisitor<bool> {
bool _isInternalSdkAnnotation(Library library) { bool _isInternalSdkAnnotation(Library library) {
var uri = library.importUri; var uri = library.importUri;
return uri.scheme == 'dart' && uri.pathSegments[0] == '_js_helper' || return uri.isScheme('dart') && uri.pathSegments[0] == '_js_helper' ||
allowPackageMetaAnnotations && allowPackageMetaAnnotations &&
uri.scheme == 'package' && uri.isScheme('package') &&
uri.pathSegments[0] == 'meta'; uri.pathSegments[0] == 'meta';
} }
} }

View file

@ -120,11 +120,11 @@ class DevCompilerTarget extends Target {
/// test framework. /// test framework.
bool _allowedTestLibrary(Uri uri) { bool _allowedTestLibrary(Uri uri) {
// Multi-root scheme used by modular test framework. // 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); return allowedNativeTest(uri);
} }
bool _allowedDartLibrary(Uri uri) => uri.scheme == 'dart'; bool _allowedDartLibrary(Uri uri) => uri.isScheme('dart');
@override @override
bool enableNative(Uri uri) => bool enableNative(Uri uri) =>

View file

@ -42,7 +42,7 @@ class Module {
Module(this.importUri, this.fileUri) Module(this.importUri, this.fileUri)
: name = libraryUriToJsIdentifier(importUri), : name = libraryUriToJsIdentifier(importUri),
path = importUri.scheme == 'package' path = importUri.isScheme('package')
? 'packages/${importUri.path}' ? 'packages/${importUri.path}'
: importUri.path; : importUri.path;

View file

@ -568,7 +568,7 @@ class _TestRecursiveVisitor extends RecursiveVisitor {
void visitLibrary(Library node) { void visitLibrary(Library node) {
_staticTypeContext.enterLibrary(node); _staticTypeContext.enterLibrary(node);
if (librariesFromDill.contains(node) || if (librariesFromDill.contains(node) ||
node.importUri.scheme == 'package' && node.importUri.isScheme('package') &&
node.importUri.pathSegments[0] == 'meta') { node.importUri.pathSegments[0] == 'meta') {
return; return;
} }

View file

@ -93,9 +93,9 @@ bool isExperimentEnabledInLibrary(ExperimentalFlag flag, Uri canonicalUri,
if (!enabled!) { if (!enabled!) {
allowedExperimentalFlags ??= defaultAllowedExperimentalFlags; allowedExperimentalFlags ??= defaultAllowedExperimentalFlags;
Set<ExperimentalFlag>? allowedFlags; Set<ExperimentalFlag>? allowedFlags;
if (canonicalUri.scheme == 'dart') { if (canonicalUri.isScheme('dart')) {
allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path); allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path);
} else if (canonicalUri.scheme == 'package') { } else if (canonicalUri.isScheme('package')) {
int index = canonicalUri.path.indexOf('/'); int index = canonicalUri.path.indexOf('/');
String packageName; String packageName;
if (index >= 0) { if (index >= 0) {
@ -123,9 +123,9 @@ Version getExperimentEnabledVersionInLibrary(ExperimentalFlag flag,
allowedExperimentalFlags ??= defaultAllowedExperimentalFlags; allowedExperimentalFlags ??= defaultAllowedExperimentalFlags;
Set<ExperimentalFlag>? allowedFlags; Set<ExperimentalFlag>? allowedFlags;
if (canonicalUri.scheme == 'dart') { if (canonicalUri.isScheme('dart')) {
allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path); allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path);
} else if (canonicalUri.scheme == 'package') { } else if (canonicalUri.isScheme('package')) {
int index = canonicalUri.path.indexOf('/'); int index = canonicalUri.path.indexOf('/');
String packageName; String packageName;
if (index >= 0) { if (index >= 0) {
@ -187,9 +187,9 @@ bool isExperimentEnabledInLibraryByVersion(
Set<ExperimentalFlag>? allowedFlags; Set<ExperimentalFlag>? allowedFlags;
bool enabledByAllowed = false; bool enabledByAllowed = false;
if (canonicalUri.scheme == 'dart') { if (canonicalUri.isScheme('dart')) {
allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path); allowedFlags = allowedExperimentalFlags.forSdkLibrary(canonicalUri.path);
} else if (canonicalUri.scheme == 'package') { } else if (canonicalUri.isScheme('package')) {
int index = canonicalUri.path.indexOf('/'); int index = canonicalUri.path.indexOf('/');
String packageName; String packageName;
if (index >= 0) { if (index >= 0) {

View file

@ -57,7 +57,7 @@ Future<VersionAndPackageUri> languageVersionForUri(
UriTranslator uriTranslator = await context.options.getUriTranslator(); UriTranslator uriTranslator = await context.options.getUriTranslator();
Uri? fileUri; Uri? fileUri;
Package? package; Package? package;
if (uri.scheme == "package") { if (uri.isScheme("package")) {
fileUri = uriTranslator.translate(uri); fileUri = uriTranslator.translate(uri);
package = uriTranslator.getPackage(uri); package = uriTranslator.getPackage(uri);
} else { } else {
@ -65,8 +65,8 @@ Future<VersionAndPackageUri> languageVersionForUri(
package = uriTranslator.packages.packageOf(uri); package = uriTranslator.packages.packageOf(uri);
} }
Uri packageUri = uri; Uri packageUri = uri;
if (packageUri.scheme != 'dart' && if (!packageUri.isScheme('dart') &&
packageUri.scheme != 'package' && !packageUri.isScheme('package') &&
package != null && package != null &&
// ignore: unnecessary_null_comparison // ignore: unnecessary_null_comparison
package.name != null) { package.name != null) {

View file

@ -23,12 +23,12 @@ class StandardFileSystem implements FileSystem {
@override @override
FileSystemEntity entityForUri(Uri uri) { FileSystemEntity entityForUri(Uri uri) {
if (uri.scheme == 'file') { if (uri.isScheme('file')) {
return new _IoFileSystemEntity(uri); return new _IoFileSystemEntity(uri);
} else if (uri.scheme == '') { } else if (!uri.hasScheme) {
// TODO(askesc): Empty schemes should have been handled elsewhere. // TODO(askesc): Empty schemes should have been handled elsewhere.
return new _IoFileSystemEntity(Uri.base.resolveUri(uri)); return new _IoFileSystemEntity(Uri.base.resolveUri(uri));
} else if (uri.scheme == 'data') { } else if (uri.isScheme('data')) {
return new DataFileSystemEntity(Uri.base.resolveUri(uri)); return new DataFileSystemEntity(Uri.base.resolveUri(uri));
} else { } else {
throw new FileSystemException( throw new FileSystemException(
@ -125,7 +125,7 @@ class DataFileSystemEntity implements FileSystemEntity {
final Uri uri; final Uri uri;
DataFileSystemEntity(this.uri) DataFileSystemEntity(this.uri)
: assert(uri.scheme == 'data'), : assert(uri.isScheme('data')),
assert(uri.data != null); assert(uri.data != null);
@override @override

View file

@ -563,7 +563,7 @@ class ProcessedOptions {
} }
// When compiling the SDK the input files are normally `dart:` URIs. // 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; return _packages = PackageConfig.empty;
} }
@ -577,7 +577,7 @@ class ProcessedOptions {
Uri input = inputs.first; Uri input = inputs.first;
if (input.scheme == 'package') { if (input.isScheme('package')) {
report( report(
messageCantInferPackagesFromPackageUri.withLocation( messageCantInferPackagesFromPackageUri.withLocation(
input, -1, noLength), input, -1, noLength),

View file

@ -95,7 +95,7 @@ Uri computePlatformBinariesLocation({bool forceBuildDir: false}) {
/// Translates an SDK URI ("org-dartlang-sdk:///...") to a file URI. /// Translates an SDK URI ("org-dartlang-sdk:///...") to a file URI.
Uri translateSdk(Uri uri) { Uri translateSdk(Uri uri) {
if (CompilerContext.isActive) { if (CompilerContext.isActive) {
if (uri.scheme == "org-dartlang-sdk") { if (uri.isScheme("org-dartlang-sdk")) {
String path = uri.path; String path = uri.path;
if (path.startsWith("/sdk/")) { if (path.startsWith("/sdk/")) {
CompilerContext context = CompilerContext.current; CompilerContext context = CompilerContext.current;
@ -148,7 +148,7 @@ Uri translateSdk(Uri uri) {
} }
bool isExistingFile(Uri uri) { bool isExistingFile(Uri uri) {
if (uri.scheme == "file") { if (uri.isScheme("file")) {
return new File.fromUri(uri).existsSync(); return new File.fromUri(uri).existsSync();
} else { } else {
return false; return false;

View file

@ -326,7 +326,7 @@ abstract class ClassBuilderImpl extends DeclarationBuilderImpl
} }
if (name == "FutureOr") { if (name == "FutureOr") {
LibraryBuilder parentLibrary = parent as LibraryBuilder; LibraryBuilder parentLibrary = parent as LibraryBuilder;
if (parentLibrary.importUri.scheme == "dart" && if (parentLibrary.importUri.isScheme("dart") &&
parentLibrary.importUri.path == "async") { parentLibrary.importUri.path == "async") {
assert(arguments != null && arguments.length == 1); assert(arguments != null && arguments.length == 1);
return new FutureOrType(arguments!.single, nullability); return new FutureOrType(arguments!.single, nullability);

View file

@ -86,7 +86,7 @@ class CompilerContext {
} }
static void recordDependency(Uri uri) { 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'."); throw new ArgumentError("Expected a file or http URI, but got: '$uri'.");
} }
CompilerContext? context = Zone.current[compilerContextKey]; CompilerContext? context = Zone.current[compilerContextKey];

View file

@ -120,7 +120,7 @@ class DillLoader extends Loader {
assert(libraryBuilder != null, "No library found for $uri."); assert(libraryBuilder != null, "No library found for $uri.");
_builders[uri] = libraryBuilder!; _builders[uri] = libraryBuilder!;
assert(libraryBuilder.loader == this); assert(libraryBuilder.loader == this);
if (uri.scheme == "dart") { if (uri.isScheme("dart")) {
if (uri.path == "core") { if (uri.path == "core") {
_coreLibrary = libraryBuilder; _coreLibrary = libraryBuilder;
} }
@ -352,7 +352,7 @@ severity: $severity
void registerLibraryBuilder(DillLibraryBuilder libraryBuilder) { void registerLibraryBuilder(DillLibraryBuilder libraryBuilder) {
Uri importUri = libraryBuilder.importUri; Uri importUri = libraryBuilder.importUri;
libraryBuilder.loader = this; libraryBuilder.loader = this;
if (importUri.scheme == "dart" && importUri.path == "core") { if (importUri.isScheme("dart") && importUri.path == "core") {
_coreLibrary = libraryBuilder; _coreLibrary = libraryBuilder;
} }
_builders[importUri] = libraryBuilder; _builders[importUri] = libraryBuilder;

View file

@ -37,7 +37,7 @@ class HybridFileSystemEntity implements FileSystemEntity {
Future<FileSystemEntity> get delegate async { Future<FileSystemEntity> get delegate async {
if (_delegate != null) return _delegate!; if (_delegate != null) return _delegate!;
FileSystemEntity entity = _fs.memory.entityForUri(uri); FileSystemEntity entity = _fs.memory.entityForUri(uri);
if (((uri.scheme != 'file' && uri.scheme != 'data') && if (((!uri.isScheme('file') && !uri.isScheme('data')) &&
_fs.physical is StandardFileSystem) || _fs.physical is StandardFileSystem) ||
await entity.exists()) { await entity.exists()) {
_delegate = entity; _delegate = entity;

View file

@ -1272,7 +1272,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
_platformBuilders = <LibraryBuilder>[]; _platformBuilders = <LibraryBuilder>[];
for (DillLibraryBuilder builder for (DillLibraryBuilder builder
in dillLoadedData.loader.libraryBuilders) { in dillLoadedData.loader.libraryBuilders) {
if (builder.importUri.scheme == "dart") { if (builder.importUri.isScheme("dart")) {
_platformBuilders!.add(builder); _platformBuilders!.add(builder);
} else { } else {
_userBuilders![builder.importUri] = builder; _userBuilders![builder.importUri] = builder;
@ -1425,7 +1425,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
_platformBuilders = <LibraryBuilder>[]; _platformBuilders = <LibraryBuilder>[];
for (DillLibraryBuilder builder for (DillLibraryBuilder builder
in _dillLoadedData!.loader.libraryBuilders) { in _dillLoadedData!.loader.libraryBuilders) {
if (builder.importUri.scheme == "dart") { if (builder.importUri.isScheme("dart")) {
_platformBuilders!.add(builder); _platformBuilders!.add(builder);
} else { } else {
_userBuilders![builder.importUri] = builder; _userBuilders![builder.importUri] = builder;
@ -1492,7 +1492,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
partUriToLibraryImportUri[partUri] = library.importUri; partUriToLibraryImportUri[partUri] = library.importUri;
} }
} }
if (library.importUri.scheme == "dart") { if (library.importUri.isScheme("dart")) {
result.add(library); result.add(library);
inputLibrariesFiltered?.add(library); inputLibrariesFiltered?.add(library);
} else { } else {
@ -1501,7 +1501,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
} }
} }
for (LibraryBuilder libraryBuilder in reusedLibraries) { for (LibraryBuilder libraryBuilder in reusedLibraries) {
if (libraryBuilder.importUri.scheme == "dart" && if (libraryBuilder.importUri.isScheme("dart") &&
!libraryBuilder.isSynthetic) { !libraryBuilder.isSynthetic) {
continue; continue;
} }
@ -1550,7 +1550,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
List<Library> removedLibraries = <Library>[]; List<Library> removedLibraries = <Library>[];
bool removedDillBuilders = false; bool removedDillBuilders = false;
for (Uri uri in potentiallyReferencedLibraries.keys) { for (Uri uri in potentiallyReferencedLibraries.keys) {
if (uri.scheme == "package") continue; if (uri.isScheme("package")) continue;
LibraryBuilder? builder = LibraryBuilder? builder =
currentKernelTarget.loader.deregisterLibraryBuilder(uri); currentKernelTarget.loader.deregisterLibraryBuilder(uri);
if (builder != null) { if (builder != null) {
@ -1913,7 +1913,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
if (importUri != fileUri && invalidatedUris.contains(fileUri)) { if (importUri != fileUri && invalidatedUris.contains(fileUri)) {
return true; 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, // Get package name, check if the base URI has changed for the package,
// if it has, translate the URI again, // if it has, translate the URI again,
// otherwise the URI cannot have changed. // otherwise the URI cannot have changed.
@ -1935,7 +1935,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
} }
void addBuilderAndInvalidateUris(Uri uri, LibraryBuilder libraryBuilder) { void addBuilderAndInvalidateUris(Uri uri, LibraryBuilder libraryBuilder) {
if (uri.scheme == "dart" && !libraryBuilder.isSynthetic) { if (uri.isScheme("dart") && !libraryBuilder.isSynthetic) {
if (seenUris.add(libraryBuilder.importUri)) { if (seenUris.add(libraryBuilder.importUri)) {
reusedLibraries.add(libraryBuilder); reusedLibraries.add(libraryBuilder);
} }
@ -2355,7 +2355,7 @@ class _InitializationFromComponent extends _InitializationStrategy {
bool foundDartCore = false; bool foundDartCore = false;
for (int i = 0; i < component.libraries.length; i++) { for (int i = 0; i < component.libraries.length; i++) {
Library library = component.libraries[i]; Library library = component.libraries[i];
if (library.importUri.scheme == "dart" && if (library.importUri.isScheme("dart") &&
library.importUri.path == "core") { library.importUri.path == "core") {
foundDartCore = true; foundDartCore = true;
break; break;
@ -2501,7 +2501,7 @@ class _InitializationFromUri extends _InitializationFromSdkSummary {
// (e.g. the package still exists and hasn't been updated). // (e.g. the package still exists and hasn't been updated).
// Also verify NNBD settings. // Also verify NNBD settings.
for (Library lib in data.component!.libraries) { for (Library lib in data.component!.libraries) {
if (lib.importUri.scheme == "package" && if (lib.importUri.isScheme("package") &&
uriTranslator.translate(lib.importUri, false) != lib.fileUri) { uriTranslator.translate(lib.importUri, false) != lib.fileUri) {
// Package has been removed or updated. // Package has been removed or updated.
// This library should be thrown away. // This library should be thrown away.
@ -2649,7 +2649,7 @@ class _ComponentProblems {
extension on UriTranslator { extension on UriTranslator {
Uri? getPartFileUri(Uri parentFileUri, LibraryPart part) { Uri? getPartFileUri(Uri parentFileUri, LibraryPart part) {
Uri? fileUri = getPartUri(parentFileUri, 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 // Part was specified via package URI and the resolve above thus
// did not go as expected. Translate the package URI to get the // did not go as expected. Translate the package URI to get the
// actual file URI. // actual file URI.

View file

@ -43,7 +43,7 @@ class IncrementalSerializer {
Uri uri = lib.importUri; Uri uri = lib.importUri;
// Uris need to be unique. // Uris need to be unique.
if (!uris.add(lib.fileUri)) return false; if (!uris.add(lib.fileUri)) return false;
if (uri.scheme == "package") { if (uri.isScheme("package")) {
String thisPackageName = uri.pathSegments.first; String thisPackageName = uri.pathSegments.first;
if (packageName == null) { if (packageName == null) {
packageName = thisPackageName; packageName = thisPackageName;
@ -117,7 +117,7 @@ class IncrementalSerializer {
List<Library> nonPackageLibraries = <Library>[]; List<Library> nonPackageLibraries = <Library>[];
for (Library lib in component.libraries) { for (Library lib in component.libraries) {
Uri uri = lib.importUri; Uri uri = lib.importUri;
if (uri.scheme == "package") { if (uri.isScheme("package")) {
packageLibraries.add(lib); packageLibraries.add(lib);
} else { } else {
nonPackageLibraries.add(lib); nonPackageLibraries.add(lib);
@ -179,7 +179,7 @@ class IncrementalSerializer {
for (Library lib in component.libraries) { for (Library lib in component.libraries) {
for (LibraryDependency dependency in lib.dependencies) { for (LibraryDependency dependency in lib.dependencies) {
if (!got.contains(dependency.targetLibrary)) { if (!got.contains(dependency.targetLibrary)) {
if (dependency.targetLibrary.importUri.scheme == "dart") { if (dependency.targetLibrary.importUri.isScheme("dart")) {
continue; continue;
} }
return false; return false;
@ -241,7 +241,7 @@ class IncrementalSerializer {
for (Library lib in libraries) { for (Library lib in libraries) {
for (LibraryDependency dep in lib.dependencies) { for (LibraryDependency dep in lib.dependencies) {
Library dependencyLibrary = dep.importedLibraryReference.asLibrary; Library dependencyLibrary = dep.importedLibraryReference.asLibrary;
if (dependencyLibrary.importUri.scheme != "package") continue; if (!dependencyLibrary.importUri.isScheme("package")) continue;
Uri dependencyLibraryUri = Uri dependencyLibraryUri =
dep.importedLibraryReference.asLibrary.fileUri; dep.importedLibraryReference.asLibrary.fileUri;
SerializationGroup? depGroup = uriToGroup[dependencyLibraryUri]; SerializationGroup? depGroup = uriToGroup[dependencyLibraryUri];

View file

@ -355,7 +355,7 @@ class BodyBuilder extends ScopeListener<JumpTarget>
stringExpectedAfterNative = libraryBuilder stringExpectedAfterNative = libraryBuilder
.loader.target.backendTarget.nativeExtensionExpectsString, .loader.target.backendTarget.nativeExtensionExpectsString,
ignoreMainInGetMainClosure = ignoreMainInGetMainClosure =
libraryBuilder.importUri.scheme == 'dart' && libraryBuilder.importUri.isScheme('dart') &&
(libraryBuilder.importUri.path == "_builtin" || (libraryBuilder.importUri.path == "_builtin" ||
libraryBuilder.importUri.path == "ui"), libraryBuilder.importUri.path == "ui"),
needsImplicitSuperInitializer = needsImplicitSuperInitializer =

View file

@ -965,7 +965,7 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
Map<String, String> _computeSupportedLibraries() { Map<String, String> _computeSupportedLibraries() {
Map<String, String> map = {}; Map<String, String> map = {};
for (Library library in component.libraries) { for (Library library in component.libraries) {
if (library.importUri.scheme == 'dart') { if (library.importUri.isScheme('dart')) {
map[library.importUri.path] = map[library.importUri.path] =
DartLibrarySupport.getDartLibrarySupportValue( DartLibrarySupport.getDartLibrarySupportValue(
library.importUri.path, library.importUri.path,

View file

@ -1667,7 +1667,7 @@ class KernelTarget extends TargetImplementation {
} }
void readPatchFiles(SourceLibraryBuilder library) { void readPatchFiles(SourceLibraryBuilder library) {
assert(library.importUri.scheme == "dart"); assert(library.importUri.isScheme("dart"));
List<Uri>? patches = uriTranslator.getDartPatches(library.importUri.path); List<Uri>? patches = uriTranslator.getDartPatches(library.importUri.path);
if (patches != null) { if (patches != null) {
SourceLibraryBuilder? first; SourceLibraryBuilder? first;

View file

@ -66,7 +66,7 @@ class TypeLabeler implements DartTypeVisitor<void>, ConstantVisitor<void> {
static bool isObject(DartType type) { static bool isObject(DartType type) {
if (type is InterfaceType && type.classNode.name == 'Object') { if (type is InterfaceType && type.classNode.name == 'Object') {
Uri importUri = type.classNode.enclosingLibrary.importUri; Uri importUri = type.classNode.enclosingLibrary.importUri;
return importUri.scheme == 'dart' && importUri.path == 'core'; return importUri.isScheme('dart') && importUri.path == 'core';
} }
return false; return false;
} }
@ -504,7 +504,7 @@ class LabeledNode {
} }
String get originMessage { String get originMessage {
if (importUri.scheme == 'dart' && importUri.path == 'core') { if (importUri.isScheme('dart') && importUri.path == 'core') {
if (node is Class && denylistedCoreClasses.contains(name)) { if (node is Class && denylistedCoreClasses.contains(name)) {
// Denylisted core class. Only print if ambiguous. // Denylisted core class. Only print if ambiguous.
List<LabeledNode> entityForName = typeLabeler.nameMap[name]!; List<LabeledNode> entityForName = typeLabeler.nameMap[name]!;
@ -521,7 +521,7 @@ class LabeledNode {
return ""; return "";
} }
} }
Message message = (importUri == fileUri || importUri.scheme == 'dart') Message message = (importUri == fileUri || importUri.isScheme('dart'))
? templateTypeOrigin.withArguments(toString(), importUri) ? templateTypeOrigin.withArguments(toString(), importUri)
: templateTypeOriginWithFileUri.withArguments( : templateTypeOriginWithFileUri.withArguments(
toString(), importUri, fileUri); toString(), importUri, fileUri);

View file

@ -241,7 +241,7 @@ class FastaVerifyingVisitor extends VerifyingVisitor {
// 'dart:test' is used in the unit tests and isn't an actual part of the // 'dart:test' is used in the unit tests and isn't an actual part of the
// platform. // platform.
if (skipPlatform && if (skipPlatform &&
node.importUri.scheme == 'dart' && node.importUri.isScheme('dart') &&
node.importUri.path != 'test') { node.importUri.path != 'test') {
return; return;
} }
@ -304,7 +304,7 @@ class FastaVerifyingVisitor extends VerifyingVisitor {
bool isObjectClass(Class c) { bool isObjectClass(Class c) {
return c.name == "Object" && return c.name == "Object" &&
c.enclosingLibrary.importUri.scheme == "dart" && c.enclosingLibrary.importUri.isScheme("dart") &&
c.enclosingLibrary.importUri.path == "core"; c.enclosingLibrary.importUri.path == "core";
} }
@ -435,7 +435,7 @@ class FastaVerifyingVisitor extends VerifyingVisitor {
} }
void _checkConstructorTearOff(Node node, Member tearOffTarget) { 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 // Platform libraries are not compilation with test flags and might
// contain tear-offs not expected when testing lowerings. // contain tear-offs not expected when testing lowerings.
return; 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 // 'dart:test' is used in the unit tests and isn't an actual part of the
// platform. // platform.
if (skipPlatform && if (skipPlatform &&
node.importUri.scheme == 'dart' && node.importUri.isScheme('dart') &&
node.importUri.path != "test") { node.importUri.path != "test") {
return; return;
} }

View file

@ -714,7 +714,7 @@ class SourceClassBuilder extends ClassBuilderImpl
this.charOffset, this.charOffset,
noLength); noLength);
} else if (interface.cls.name == "FutureOr" && } else if (interface.cls.name == "FutureOr" &&
interface.cls.enclosingLibrary.importUri.scheme == "dart" && interface.cls.enclosingLibrary.importUri.isScheme("dart") &&
interface.cls.enclosingLibrary.importUri.path == "async") { interface.cls.enclosingLibrary.importUri.path == "async") {
addProblem(messageImplementsFutureOr, this.charOffset, noLength); addProblem(messageImplementsFutureOr, this.charOffset, noLength);
} else if (implemented.contains(interface)) { } else if (implemented.contains(interface)) {

View file

@ -289,12 +289,12 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
new Scope.top()) { new Scope.top()) {
assert( assert(
_packageUri == null || _packageUri == null ||
importUri.scheme != 'package' || !importUri.isScheme('package') ||
importUri.path.startsWith(_packageUri!.path), importUri.path.startsWith(_packageUri!.path),
"Foreign package uri '$_packageUri' set on library with import uri " "Foreign package uri '$_packageUri' set on library with import uri "
"'${importUri}'."); "'${importUri}'.");
assert( assert(
importUri.scheme != 'dart' || _packageUri == null, !importUri.isScheme('dart') || _packageUri == null,
"Package uri '$_packageUri' set on dart: library with import uri " "Package uri '$_packageUri' set on dart: library with import uri "
"'${importUri}'."); "'${importUri}'.");
} }
@ -638,7 +638,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
return previous; 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}) { Uri resolve(Uri baseUri, String? uri, int uriOffset, {isPart: false}) {
if (uri == null) { if (uri == null) {
@ -657,7 +657,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
return new Uri( return new Uri(
scheme: MALFORMED_URI_SCHEME, query: Uri.encodeQueryComponent(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 // Resolve using special rules for dart: URIs
return resolveRelativeUri(baseUri, parsedUri); return resolveRelativeUri(baseUri, parsedUri);
} else { } else {
@ -1668,7 +1668,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
if (className != "Function") { if (className != "Function") {
return; return;
} }
if (decType == "class" && importUri.scheme == "dart") { if (decType == "class" && importUri.isScheme("dart")) {
// Allow declaration of class Function in the sdk. // Allow declaration of class Function in the sdk.
return; return;
} }
@ -3158,9 +3158,9 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
preferred = declaration; preferred = declaration;
} else if (other is LoadLibraryBuilder) { } else if (other is LoadLibraryBuilder) {
preferred = other; preferred = other;
} else if (otherUri.scheme == "dart" && uri.scheme != "dart") { } else if (otherUri.isScheme("dart") && !uri.isScheme("dart")) {
preferred = declaration; preferred = declaration;
} else if (uri.scheme == "dart" && otherUri.scheme != "dart") { } else if (uri.isScheme("dart") && !otherUri.isScheme("dart")) {
preferred = other; preferred = other;
} }
} }
@ -3901,7 +3901,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
} }
void exportMemberFromPatch(String name, Builder member) { 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), addProblem(templatePatchInjectionFailed.withArguments(name, importUri),
member.charOffset, noLength, member.fileUri); member.charOffset, noLength, member.fileUri);
} }

View file

@ -265,7 +265,7 @@ class SourceLoader extends Loader {
void registerLibraryBuilder(LibraryBuilder libraryBuilder) { void registerLibraryBuilder(LibraryBuilder libraryBuilder) {
Uri uri = libraryBuilder.importUri; Uri uri = libraryBuilder.importUri;
if (uri.scheme == "dart" && uri.path == "core") { if (uri.isScheme("dart") && uri.path == "core") {
_coreLibrary = libraryBuilder; _coreLibrary = libraryBuilder;
} }
_builders[uri] = libraryBuilder; _builders[uri] = libraryBuilder;
@ -326,7 +326,7 @@ class SourceLoader extends Loader {
referencesFrom: referencesFrom, referencesFrom: referencesFrom,
referenceIsPartOwner: referenceIsPartOwner, referenceIsPartOwner: referenceIsPartOwner,
isUnsupported: origin?.library.isUnsupported ?? isUnsupported: origin?.library.isUnsupported ??
importUri.scheme == 'dart' && importUri.isScheme('dart') &&
!target.uriTranslator.isLibrarySupported(importUri.path)); !target.uriTranslator.isLibrarySupported(importUri.path));
} }
@ -359,9 +359,9 @@ class SourceLoader extends Loader {
Library? referencesFrom, Library? referencesFrom,
bool? referenceIsPartOwner) { bool? referenceIsPartOwner) {
if (fileUri != null && if (fileUri != null &&
(fileUri.scheme == "dart" || (fileUri.isScheme("dart") ||
fileUri.scheme == "package" || fileUri.isScheme("package") ||
fileUri.scheme == "dart-ext")) { fileUri.isScheme("dart-ext"))) {
fileUri = null; fileUri = null;
} }
package_config.Package? packageForLanguageVersion; package_config.Package? packageForLanguageVersion;
@ -373,7 +373,7 @@ class SourceLoader extends Loader {
new Uri( new Uri(
scheme: untranslatableUriScheme, scheme: untranslatableUriScheme,
path: Uri.encodeComponent("$uri")); path: Uri.encodeComponent("$uri"));
if (uri.scheme == "package") { if (uri.isScheme("package")) {
packageForLanguageVersion = target.uriTranslator.getPackage(uri); packageForLanguageVersion = target.uriTranslator.getPackage(uri);
} else { } else {
packageForLanguageVersion = packageForLanguageVersion =
@ -396,8 +396,8 @@ class SourceLoader extends Loader {
Message? packageLanguageVersionProblem; Message? packageLanguageVersionProblem;
if (packageForLanguageVersion != null) { if (packageForLanguageVersion != null) {
Uri importUri = origin?.importUri ?? uri; Uri importUri = origin?.importUri ?? uri;
if (importUri.scheme != 'dart' && if (!importUri.isScheme('dart') &&
importUri.scheme != 'package' && !importUri.isScheme('package') &&
// ignore: unnecessary_null_comparison // ignore: unnecessary_null_comparison
packageForLanguageVersion.name != null) { packageForLanguageVersion.name != null) {
packageUri = packageUri =
@ -455,7 +455,7 @@ class SourceLoader extends Loader {
if (target.backendTarget.mayDefineRestrictedType(libraryUri)) { if (target.backendTarget.mayDefineRestrictedType(libraryUri)) {
libraryBuilder.mayImplementRestrictedTypes = true; libraryBuilder.mayImplementRestrictedTypes = true;
} }
if (uri.scheme == "dart") { if (uri.isScheme("dart")) {
target.readPatchFiles(libraryBuilder); target.readPatchFiles(libraryBuilder);
} }
_unparsedLibraries.addLast(libraryBuilder); _unparsedLibraries.addLast(libraryBuilder);
@ -516,7 +516,7 @@ class SourceLoader extends Loader {
} }
void _checkForDartCore(Uri uri, LibraryBuilder libraryBuilder) { void _checkForDartCore(Uri uri, LibraryBuilder libraryBuilder) {
if (uri.scheme == "dart") { if (uri.isScheme("dart")) {
if (uri.path == "core") { if (uri.path == "core") {
_coreLibrary = libraryBuilder; _coreLibrary = libraryBuilder;
} else if (uri.path == "typed_data") { } else if (uri.path == "typed_data") {
@ -595,7 +595,7 @@ class SourceLoader extends Loader {
} }
bool _hasLibraryAccess({required Uri imported, required Uri? importer}) { 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) { if (importer == null) {
return false; return false;
} else { } else {
@ -810,7 +810,7 @@ severity: $severity
if (bytes == null) { if (bytes == null) {
// Error recovery. // Error recovery.
if (fileUri.scheme == untranslatableUriScheme) { if (fileUri.isScheme(untranslatableUriScheme)) {
Message message = Message message =
templateUntranslatableUri.withArguments(library.importUri); templateUntranslatableUri.withArguments(library.importUri);
library.addProblemAtAccessors(message); library.addProblemAtAccessors(message);
@ -820,7 +820,7 @@ severity: $severity
templateInternalProblemUriMissingScheme.withArguments(fileUri), templateInternalProblemUriMissingScheme.withArguments(fileUri),
-1, -1,
library.importUri); library.importUri);
} else if (fileUri.scheme == SourceLibraryBuilder.MALFORMED_URI_SCHEME) { } else if (fileUri.isScheme(SourceLibraryBuilder.MALFORMED_URI_SCHEME)) {
library.addProblemAtAccessors(messageExpectedUri); library.addProblemAtAccessors(messageExpectedUri);
bytes = synthesizeSourceForMissingFile(library.importUri, null); bytes = synthesizeSourceForMissingFile(library.importUri, null);
} }
@ -1027,7 +1027,7 @@ severity: $severity
continue; continue;
} }
} }
if (libraryBuilder.importUri.scheme == 'package') { if (libraryBuilder.importUri.isScheme('package')) {
(libraryByPackage[null] ??= []).add(libraryBuilder); (libraryByPackage[null] ??= []).add(libraryBuilder);
} else { } else {
if (emitNonPackageErrors) { if (emitNonPackageErrors) {
@ -1965,7 +1965,7 @@ severity: $severity
for (LibraryBuilder libraryBuilder in libraryBuilders) { for (LibraryBuilder libraryBuilder in libraryBuilders) {
if (!libraryBuilder.isPatch && if (!libraryBuilder.isPatch &&
(libraryBuilder.loader == this || (libraryBuilder.loader == this ||
libraryBuilder.importUri.scheme == "dart" || libraryBuilder.importUri.isScheme("dart") ||
libraryBuilder == this.first)) { libraryBuilder == this.first)) {
if (libraries.add(libraryBuilder.library)) { if (libraries.add(libraryBuilder.library)) {
workList.add(libraryBuilder.library); workList.add(libraryBuilder.library);

View file

@ -1064,7 +1064,7 @@ class TypeInferrerImpl implements TypeInferrer {
onType, onType,
onTypeInstantiateToBounds, onTypeInstantiateToBounds,
target, target,
isPlatform: extensionBuilder.library.importUri.scheme == 'dart'); isPlatform: extensionBuilder.library.importUri.isScheme('dart'));
if (noneMoreSpecific.isNotEmpty) { if (noneMoreSpecific.isNotEmpty) {
bool isMostSpecific = true; bool isMostSpecific = true;
for (ExtensionAccessCandidate other in noneMoreSpecific) { for (ExtensionAccessCandidate other in noneMoreSpecific) {

View file

@ -70,7 +70,7 @@ class _TypeSchemaEliminationVisitor extends ReplacementVisitor {
assert(topType == const DynamicType() || assert(topType == const DynamicType() ||
topType is InterfaceType && topType is InterfaceType &&
topType.nullability == Nullability.nullable && topType.nullability == Nullability.nullable &&
topType.classNode.enclosingLibrary.importUri.scheme == "dart" && topType.classNode.enclosingLibrary.importUri.isScheme("dart") &&
topType.classNode.enclosingLibrary.importUri.path == "core" && topType.classNode.enclosingLibrary.importUri.path == "core" &&
topType.classNode.name == "Object"); topType.classNode.name == "Object");
assert( assert(

View file

@ -22,7 +22,7 @@ class UriTranslator {
dartLibraries.libraryInfoFor(libraryName)?.patches; dartLibraries.libraryInfoFor(libraryName)?.patches;
bool isPlatformImplementation(Uri uri) { bool isPlatformImplementation(Uri uri) {
if (uri.scheme != "dart") return false; if (!uri.isScheme("dart")) return false;
String path = uri.path; String path = uri.path;
return dartLibraries.libraryInfoFor(path) == null || path.startsWith("_"); 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 // callback, so we can provide an error location when one is available. For
// example, if the error occurs in an `import`. // example, if the error occurs in an `import`.
Uri? translate(Uri uri, [bool reportMessage = true]) { Uri? translate(Uri uri, [bool reportMessage = true]) {
if (uri.scheme == "dart") return _translateDartUri(uri); if (uri.isScheme("dart")) return _translateDartUri(uri);
if (uri.scheme == "package") { if (uri.isScheme("package")) {
return _translatePackageUri(uri, reportMessage); return _translatePackageUri(uri, reportMessage);
} }
return null; return null;
@ -42,7 +42,7 @@ class UriTranslator {
Package? getPackage(Uri uri) { Package? getPackage(Uri uri) {
// ignore: unnecessary_null_comparison // ignore: unnecessary_null_comparison
if (packages == null) return null; if (packages == null) return null;
if (uri.scheme != "package") return null; if (!uri.isScheme("package")) return null;
int firstSlash = uri.path.indexOf('/'); int firstSlash = uri.path.indexOf('/');
if (firstSlash == -1) return null; if (firstSlash == -1) return null;
String packageName = uri.path.substring(0, firstSlash); String packageName = uri.path.substring(0, firstSlash);

View file

@ -116,7 +116,7 @@ class _Processor {
Future<TopLevel> preprocessUri(Uri importUri, {Uri? partOf}) async { Future<TopLevel> preprocessUri(Uri importUri, {Uri? partOf}) async {
if (verbosityLevel >= 20) log("$importUri =>"); if (verbosityLevel >= 20) log("$importUri =>");
Uri fileUri = importUri; Uri fileUri = importUri;
if (importUri.scheme == "package") { if (importUri.isScheme("package")) {
fileUri = uriTranslator.translate(importUri)!; fileUri = uriTranslator.translate(importUri)!;
} }
if (verbosityLevel >= 20) log("$fileUri"); if (verbosityLevel >= 20) log("$fileUri");
@ -202,14 +202,14 @@ class _Processor {
worklist.add(new _TopLevelAndAstNode(entrypointish, child)); worklist.add(new _TopLevelAndAstNode(entrypointish, child));
if (child is Part) { if (child is Part) {
if (child.uri.scheme != "dart") { if (!child.uri.isScheme("dart")) {
TopLevel partTopLevel = parsed[child.uri] ?? TopLevel partTopLevel = parsed[child.uri] ??
await preprocessUri(child.uri, partOf: entrypointish.uri); await preprocessUri(child.uri, partOf: entrypointish.uri);
await _premarkTopLevel(worklist, closed, partTopLevel); await _premarkTopLevel(worklist, closed, partTopLevel);
} }
} else if (child is Export) { } else if (child is Export) {
for (Uri importedUri in child.uris) { for (Uri importedUri in child.uris) {
if (importedUri.scheme != "dart") { if (!importedUri.isScheme("dart")) {
TopLevel exportTopLevel = TopLevel exportTopLevel =
parsed[importedUri] ?? await preprocessUri(importedUri); parsed[importedUri] ?? await preprocessUri(importedUri);
await _premarkTopLevel(worklist, closed, exportTopLevel); await _premarkTopLevel(worklist, closed, exportTopLevel);
@ -230,7 +230,7 @@ class _Processor {
if (child is Import) { if (child is Import) {
child.marked = Coloring.Marked; child.marked = Coloring.Marked;
for (Uri importedUri in child.uris) { for (Uri importedUri in child.uris) {
if (importedUri.scheme != "dart") { if (!importedUri.isScheme("dart")) {
TopLevel importedTopLevel = TopLevel importedTopLevel =
parsed[importedUri] ?? await preprocessUri(importedUri); parsed[importedUri] ?? await preprocessUri(importedUri);
imported.add(importedTopLevel); imported.add(importedTopLevel);
@ -238,7 +238,7 @@ class _Processor {
} }
} else if (child is PartOf) { } else if (child is PartOf) {
child.marked = Coloring.Marked; child.marked = Coloring.Marked;
if (child.partOfUri.scheme != "dart") { if (!child.partOfUri.isScheme("dart")) {
TopLevel part = parsed[child.partOfUri]!; TopLevel part = parsed[child.partOfUri]!;
List<TopLevel> importsFromPart = List<TopLevel> importsFromPart =
await _preprocessImportsAsNeeded(imports, part); await _preprocessImportsAsNeeded(imports, part);
@ -392,7 +392,7 @@ class _Processor {
if (child is Part) { if (child is Part) {
child.marked = Coloring.Marked; child.marked = Coloring.Marked;
// do stuff to part. // do stuff to part.
if (child.uri.scheme != "dart") { if (!child.uri.isScheme("dart")) {
other = parsed[child.uri] ?? other = parsed[child.uri] ??
await preprocessUri(child.uri, partOf: topLevel.uri); await preprocessUri(child.uri, partOf: topLevel.uri);
} }
@ -400,7 +400,7 @@ class _Processor {
child.marked = Coloring.Marked; child.marked = Coloring.Marked;
// do stuff to export. // do stuff to export.
for (Uri importedUri in child.uris) { for (Uri importedUri in child.uris) {
if (importedUri.scheme != "dart") { if (!importedUri.isScheme("dart")) {
other = parsed[importedUri] ?? await preprocessUri(importedUri); other = parsed[importedUri] ?? await preprocessUri(importedUri);
} }
} }
@ -468,7 +468,7 @@ class _Processor {
} }
if (child is Import) { if (child is Import) {
for (Uri importedUri in child.uris) { for (Uri importedUri in child.uris) {
if (importedUri.scheme != "dart") { if (!importedUri.isScheme("dart")) {
imported.add(importedUri); imported.add(importedUri);
} }
} }
@ -478,7 +478,7 @@ class _Processor {
if (sb.isNotEmpty) count++; if (sb.isNotEmpty) count++;
Uri uri = entry.key; Uri uri = entry.key;
Uri fileUri = uri; Uri fileUri = uri;
if (uri.scheme == "package") { if (uri.isScheme("package")) {
fileUri = uriTranslator.translate(uri)!; fileUri = uriTranslator.translate(uri)!;
} }
result[fileUri] = sb.toString(); 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 // uri imports a file we haven't read. Check if it exists and include it
// as an empty file if it does. // as an empty file if it does.
Uri fileUri = uri; Uri fileUri = uri;
if (uri.scheme == "package") { if (uri.isScheme("package")) {
fileUri = uriTranslator.translate(uri)!; fileUri = uriTranslator.translate(uri)!;
} }
if (await fileSystem.entityForUri(fileUri).exists()) { if (await fileSystem.entityForUri(fileUri).exists()) {

View file

@ -140,7 +140,7 @@ String _invalidLibrariesSpec = '''
'''; ''';
bool isDartCoreLibrary(Library lib) => isDartCore(lib.importUri); 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] /// Find a library in [component] whose Uri ends with the given [suffix]
Library findLibrary(Component component, String suffix) { Library findLibrary(Component component, String suffix) {

View file

@ -451,8 +451,8 @@ Future<TestResult<T>> runTestForConfig<T>(
bool excludeLibrary(Library library) { bool excludeLibrary(Library library) {
return forUserLibrariesOnly && return forUserLibrariesOnly &&
(library.importUri.scheme == 'dart' || (library.importUri.isScheme('dart') ||
library.importUri.scheme == 'package'); library.importUri.isScheme('package'));
} }
await dataComputer.inspectTestResultData(testResultData); await dataComputer.inspectTestResultData(testResultData);

View file

@ -55,7 +55,7 @@ Future<void> main(List<String> args) async {
.where((Member m) => .where((Member m) =>
!m.isAbstract && !m.isAbstract &&
m.name.text == "toString" && m.name.text == "toString" &&
m.enclosingLibrary.importUri.scheme != "dart") !m.enclosingLibrary.importUri.isScheme("dart"))
.toList(); .toList();
if (toStringList.length > 1) throw "What?"; if (toStringList.length > 1) throw "What?";
if (toStringList.length == 1) { if (toStringList.length == 1) {
@ -157,7 +157,7 @@ Future<void> main(List<String> args) async {
.where((Member m) => .where((Member m) =>
!m.isAbstract && !m.isAbstract &&
m.name.text == "toString" && m.name.text == "toString" &&
m.enclosingLibrary.importUri.scheme != "dart") !m.enclosingLibrary.importUri.isScheme("dart"))
.toList(); .toList();
Member toString = toStringList.single; Member toString = toStringList.single;
if (toString.fileUri != uri) continue; if (toString.fileUri != uri) continue;

View file

@ -88,7 +88,7 @@ Future<void> main(List<String> args) async {
component = incrementalCompilerResult.component; component = incrementalCompilerResult.component;
for (Library library in component.libraries) { 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. // This isn't perfect because of parts, but (for now) it'll do.
for (Uri uri in libUris) { for (Uri uri in libUris) {
if (library.fileUri.toString().startsWith(uri.toString())) { if (library.fileUri.toString().startsWith(uri.toString())) {

View file

@ -363,7 +363,7 @@ class RegisterCallTransformer extends RecursiveVisitor {
@override @override
void visitLibrary(Library node) { void visitLibrary(Library node) {
if (node.importUri.scheme == "package" && if (node.importUri.isScheme("package") &&
node.importUri.pathSegments.first == "front_end") { node.importUri.pathSegments.first == "front_end") {
super.visitLibrary(node); super.visitLibrary(node);
} }
@ -395,7 +395,7 @@ class RegisterTimeTransformer extends RecursiveVisitor {
@override @override
void visitLibrary(Library node) { void visitLibrary(Library node) {
if (node.importUri.scheme == "package" && if (node.importUri.isScheme("package") &&
node.importUri.pathSegments.first == "front_end") { node.importUri.pathSegments.first == "front_end") {
super.visitLibrary(node); super.visitLibrary(node);
} }

View file

@ -778,9 +778,9 @@ worlds:
void _rewriteImportsExportsToUriInternal( void _rewriteImportsExportsToUriInternal(
Token uriToken, Uri oldUri, List<_Replacement> replacements, Uri newUri) { Token uriToken, Uri oldUri, List<_Replacement> replacements, Uri newUri) {
Uri tokenUri = _getUri(uriToken, oldUri, resolvePackage: false); 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); Uri asPackageUri = _getImportUri(tokenUri);
if (asPackageUri.scheme == "package") { if (asPackageUri.isScheme("package")) {
// Just replace with this package uri. // Just replace with this package uri.
replacements.add(new _Replacement( replacements.add(new _Replacement(
uriToken.offset - 1, uriToken.offset - 1,
@ -803,7 +803,7 @@ worlds:
String uriString = uriToken.lexeme; String uriString = uriToken.lexeme;
uriString = uriString.substring(1, uriString.length - 1); uriString = uriString.substring(1, uriString.length - 1);
Uri uriTokenUri = uri.resolve(uriString); Uri uriTokenUri = uri.resolve(uriString);
if (resolvePackage && uriTokenUri.scheme == "package") { if (resolvePackage && uriTokenUri.isScheme("package")) {
Package package = _latestCrashingIncrementalCompiler! Package package = _latestCrashingIncrementalCompiler!
.getPackageForPackageName(uriTokenUri.pathSegments.first)!; .getPackageForPackageName(uriTokenUri.pathSegments.first)!;
uriTokenUri = package.packageUriRoot uriTokenUri = package.packageUriRoot

View file

@ -116,7 +116,7 @@ Future<void> test(
Expect.isFalse( Expect.isFalse(
hadDiagnostic, "Compilation had diagnostics (errors, warnings)!"); hadDiagnostic, "Compilation had diagnostics (errors, warnings)!");
for (Library library in result.component!.libraries) { for (Library library in result.component!.libraries) {
if (library.importUri.scheme != 'dart') { if (!library.importUri.isScheme('dart')) {
bool usesLegacy = bool usesLegacy =
await uriUsesLegacyLanguageVersion(library.fileUri, options); await uriUsesLegacyLanguageVersion(library.fileUri, options);
VersionAndPackageUri versionAndPackageUri = VersionAndPackageUri versionAndPackageUri =
@ -143,7 +143,7 @@ Future<void> test(
"Expected library ${library.importUri} with version " "Expected library ${library.importUri} with version "
"${library.languageVersion} to be opted in."); "${library.languageVersion} to be opted in.");
Expect.isTrue( Expect.isTrue(
versionAndPackageUri.packageUri.scheme != 'package' || !versionAndPackageUri.packageUri.isScheme('package') ||
!versionAndPackageUri.packageUri.path !versionAndPackageUri.packageUri.path
.startsWith('allowed_package') || .startsWith('allowed_package') ||
library.languageVersion < versionOptsInAllowed || library.languageVersion < versionOptsInAllowed ||

View file

@ -598,7 +598,7 @@ class FastaContext extends ChainContext with MatchContext {
} }
for (String argument in parsedOptions.arguments) { for (String argument in parsedOptions.arguments) {
Uri uri = description.uri.resolve(argument); Uri uri = description.uri.resolve(argument);
if (uri.scheme != 'package') { if (!uri.isScheme('package')) {
File f = new File.fromUri(uri); File f = new File.fromUri(uri);
if (!f.existsSync()) { if (!f.existsSync()) {
throw new UnsupportedError("No file found: $f ($argument)"); throw new UnsupportedError("No file found: $f ($argument)");
@ -1328,11 +1328,11 @@ class FuzzCompiles
Map<Uri, LibraryBuilder> builders = {}; Map<Uri, LibraryBuilder> builders = {};
for (LibraryBuilder builder for (LibraryBuilder builder
in incrementalCompiler.kernelTargetForTesting!.loader.libraryBuilders) { 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; builders[builder.fileUri] = builder;
for (LibraryPart part in builder.library.parts) { for (LibraryPart part in builder.library.parts) {
Uri thisPartUri = builder.importUri.resolve(part.partUri); Uri thisPartUri = builder.importUri.resolve(part.partUri);
if (thisPartUri.scheme == "package") { if (thisPartUri.isScheme("package")) {
thisPartUri = incrementalCompiler thisPartUri = incrementalCompiler
.kernelTargetForTesting!.uriTranslator .kernelTargetForTesting!.uriTranslator
.translate(thisPartUri)!; .translate(thisPartUri)!;
@ -1761,8 +1761,8 @@ Set<Uri> createUserLibrariesImportUriSet(
component.libraries.map((Library library) => library.importUri).toSet(); component.libraries.map((Library library) => library.importUri).toSet();
Set<Uri> userLibraries = component.libraries Set<Uri> userLibraries = component.libraries
.where((Library library) => .where((Library library) =>
library.importUri.scheme != 'dart' && !library.importUri.isScheme('dart') &&
library.importUri.scheme != 'package' && !library.importUri.isScheme('package') &&
!excludedLibraries.contains(library)) !excludedLibraries.contains(library))
.map((Library library) => library.importUri) .map((Library library) => library.importUri)
.toSet(); .toSet();
@ -2171,7 +2171,7 @@ class MatchHierarchy
ComponentResult result, FastaContext context) { ComponentResult result, FastaContext context) {
Component component = result.component; Component component = result.component;
Uri uri = Uri uri =
component.uriToSource.keys.firstWhere((uri) => uri.scheme == "file"); component.uriToSource.keys.firstWhere((uri) => uri.isScheme("file"));
KernelTarget target = result.sourceTarget; KernelTarget target = result.sourceTarget;
ClassHierarchyBuilder hierarchy = target.loader.hierarchyBuilder; ClassHierarchyBuilder hierarchy = target.loader.hierarchyBuilder;
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();

View file

@ -48,13 +48,13 @@ class TypeConstraintGathererTest {
"the core library and the test library."); "the core library and the test library.");
Library firstLibrary = env.component.libraries.first; Library firstLibrary = env.component.libraries.first;
Library secondLibrary = env.component.libraries.last; Library secondLibrary = env.component.libraries.last;
if (firstLibrary.importUri.scheme == "dart" && if (firstLibrary.importUri.isScheme("dart") &&
firstLibrary.importUri.path == "core") { firstLibrary.importUri.path == "core") {
_coreLibrary = firstLibrary; _coreLibrary = firstLibrary;
_testLibrary = secondLibrary; _testLibrary = secondLibrary;
} else { } else {
assert( assert(
secondLibrary.importUri.scheme == "dart" && secondLibrary.importUri.isScheme("dart") &&
secondLibrary.importUri.path == "core", secondLibrary.importUri.path == "core",
"One of the libraries is expected to be 'dart:core'."); "One of the libraries is expected to be 'dart:core'.");
_coreLibrary == secondLibrary; _coreLibrary == secondLibrary;

View file

@ -48,13 +48,13 @@ class TypeConstraintGathererTest {
"the core library and the test library."); "the core library and the test library.");
Library firstLibrary = env.component.libraries.first; Library firstLibrary = env.component.libraries.first;
Library secondLibrary = env.component.libraries.last; Library secondLibrary = env.component.libraries.last;
if (firstLibrary.importUri.scheme == "dart" && if (firstLibrary.importUri.isScheme("dart") &&
firstLibrary.importUri.path == "core") { firstLibrary.importUri.path == "core") {
_coreLibrary = firstLibrary; _coreLibrary = firstLibrary;
_testLibrary = secondLibrary; _testLibrary = secondLibrary;
} else { } else {
assert( assert(
secondLibrary.importUri.scheme == "dart" && secondLibrary.importUri.isScheme("dart") &&
secondLibrary.importUri.path == "core", secondLibrary.importUri.path == "core",
"One of the libraries is expected to be 'dart:core'."); "One of the libraries is expected to be 'dart:core'.");
_coreLibrary == secondLibrary; _coreLibrary == secondLibrary;

View file

@ -46,13 +46,13 @@ class TypeSchemaEnvironmentTest {
"the core library and the test library."); "the core library and the test library.");
Library firstLibrary = typeParserEnvironment.component.libraries.first; Library firstLibrary = typeParserEnvironment.component.libraries.first;
Library secondLibrary = typeParserEnvironment.component.libraries.last; Library secondLibrary = typeParserEnvironment.component.libraries.last;
if (firstLibrary.importUri.scheme == "dart" && if (firstLibrary.importUri.isScheme("dart") &&
firstLibrary.importUri.path == "core") { firstLibrary.importUri.path == "core") {
_coreLibrary = firstLibrary; _coreLibrary = firstLibrary;
_testLibrary = secondLibrary; _testLibrary = secondLibrary;
} else { } else {
assert( assert(
secondLibrary.importUri.scheme == "dart" && secondLibrary.importUri.isScheme("dart") &&
secondLibrary.importUri.path == "core", secondLibrary.importUri.path == "core",
"One of the libraries is expected to be 'dart:core'."); "One of the libraries is expected to be 'dart:core'.");
_coreLibrary == secondLibrary; _coreLibrary == secondLibrary;

View file

@ -46,13 +46,13 @@ class TypeSchemaEnvironmentTest {
"the core library and the test library."); "the core library and the test library.");
Library firstLibrary = typeParserEnvironment.component.libraries.first; Library firstLibrary = typeParserEnvironment.component.libraries.first;
Library secondLibrary = typeParserEnvironment.component.libraries.last; Library secondLibrary = typeParserEnvironment.component.libraries.last;
if (firstLibrary.importUri.scheme == "dart" && if (firstLibrary.importUri.isScheme("dart") &&
firstLibrary.importUri.path == "core") { firstLibrary.importUri.path == "core") {
_coreLibrary = firstLibrary; _coreLibrary = firstLibrary;
_testLibrary = secondLibrary; _testLibrary = secondLibrary;
} else { } else {
assert( assert(
secondLibrary.importUri.scheme == "dart" && secondLibrary.importUri.isScheme("dart") &&
secondLibrary.importUri.path == "core", secondLibrary.importUri.path == "core",
"One of the libraries is expected to be 'dart:core'."); "One of the libraries is expected to be 'dart:core'.");
_coreLibrary == secondLibrary; _coreLibrary == secondLibrary;

View file

@ -28,13 +28,13 @@ abstract class LegacyUpperBoundTest {
"the core library and the test library."); "the core library and the test library.");
Library firstLibrary = env.component.libraries.first; Library firstLibrary = env.component.libraries.first;
Library secondLibrary = env.component.libraries.last; Library secondLibrary = env.component.libraries.last;
if (firstLibrary.importUri.scheme == "dart" && if (firstLibrary.importUri.isScheme("dart") &&
firstLibrary.importUri.path == "core") { firstLibrary.importUri.path == "core") {
coreLibrary = firstLibrary; coreLibrary = firstLibrary;
testLibrary = secondLibrary; testLibrary = secondLibrary;
} else { } else {
assert( assert(
secondLibrary.importUri.scheme == "dart" && secondLibrary.importUri.isScheme("dart") &&
secondLibrary.importUri.path == "core", secondLibrary.importUri.path == "core",
"One of the libraries is expected to be 'dart:core'."); "One of the libraries is expected to be 'dart:core'.");
coreLibrary = secondLibrary; coreLibrary = secondLibrary;

View file

@ -330,7 +330,7 @@ Future<Null> writeProgram(Component component, Uri outputUri) async {
// TODO(sigmund): the incremental generator should always filter these // TODO(sigmund): the incremental generator should always filter these
// libraries instead. // libraries instead.
new BinaryPrinter(sink, new BinaryPrinter(sink,
libraryFilter: (library) => library.importUri.scheme != 'dart') libraryFilter: (library) => !library.importUri.isScheme('dart'))
.writeComponentFile(component); .writeComponentFile(component);
await sink.close(); await sink.close();
} }

View file

@ -220,7 +220,7 @@ class Dart2jsTester {
uris = c.uriToSource.values uris = c.uriToSource.values
.map((s) => s.importUri) .map((s) => s.importUri)
.whereType<Uri>() .whereType<Uri>()
.where((u) => u.scheme != "dart") .where((u) => !u.isScheme("dart"))
.toSet() .toSet()
.toList(); .toList();

View file

@ -120,7 +120,7 @@ Future<void> main(List<String> args) async {
List<Uri> uris = c.uriToSource.values List<Uri> uris = c.uriToSource.values
.map((s) => s.importUri) .map((s) => s.importUri)
.whereType<Uri>() .whereType<Uri>()
.where((u) => u.scheme != "dart") .where((u) => !u.isScheme("dart"))
.toSet() .toSet()
.toList(); .toList();

Some files were not shown because too many files have changed in this diff Show more