Implementing switch expressions in flutter_tools/ (#145632)

This pull request is step 12 in the journey to make this entire repository more readable.

(previous PRs: #139048, #139882, #141591, #142279, #142634, #142793, #143293, #143496, #143634, #143812, #144580)

We're getting close to the end! 😄
This commit is contained in:
Nate 2024-03-29 16:31:19 -06:00 committed by GitHub
parent 7f6685658c
commit a17d4b34f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 222 additions and 409 deletions

View file

@ -681,108 +681,66 @@ DarwinArch getIOSArchForName(String arch) {
}
DarwinArch getDarwinArchForName(String arch) {
switch (arch) {
case 'arm64':
return DarwinArch.arm64;
case 'x86_64':
return DarwinArch.x86_64;
}
throw Exception('Unsupported MacOS arch name "$arch"');
return switch (arch) {
'arm64' => DarwinArch.arm64,
'x86_64' => DarwinArch.x86_64,
_ => throw Exception('Unsupported MacOS arch name "$arch"'),
};
}
String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch? darwinArch}) {
switch (platform) {
case TargetPlatform.android_arm:
return 'android-arm';
case TargetPlatform.android_arm64:
return 'android-arm64';
case TargetPlatform.android_x64:
return 'android-x64';
case TargetPlatform.android_x86:
return 'android-x86';
case TargetPlatform.ios:
if (darwinArch != null) {
return 'ios-${darwinArch.name}';
}
return 'ios';
case TargetPlatform.darwin:
if (darwinArch != null) {
return 'darwin-${darwinArch.name}';
}
return 'darwin';
case TargetPlatform.linux_x64:
return 'linux-x64';
case TargetPlatform.linux_arm64:
return 'linux-arm64';
case TargetPlatform.windows_x64:
return 'windows-x64';
case TargetPlatform.windows_arm64:
return 'windows-arm64';
case TargetPlatform.fuchsia_arm64:
return 'fuchsia-arm64';
case TargetPlatform.fuchsia_x64:
return 'fuchsia-x64';
case TargetPlatform.tester:
return 'flutter-tester';
case TargetPlatform.web_javascript:
return 'web-javascript';
case TargetPlatform.android:
return 'android';
}
return switch (platform) {
TargetPlatform.ios when darwinArch != null => 'ios-${darwinArch.name}',
TargetPlatform.darwin when darwinArch != null => 'darwin-${darwinArch.name}',
TargetPlatform.ios => 'ios',
TargetPlatform.darwin => 'darwin',
TargetPlatform.android_arm => 'android-arm',
TargetPlatform.android_arm64 => 'android-arm64',
TargetPlatform.android_x64 => 'android-x64',
TargetPlatform.android_x86 => 'android-x86',
TargetPlatform.linux_x64 => 'linux-x64',
TargetPlatform.linux_arm64 => 'linux-arm64',
TargetPlatform.windows_x64 => 'windows-x64',
TargetPlatform.windows_arm64 => 'windows-arm64',
TargetPlatform.fuchsia_arm64 => 'fuchsia-arm64',
TargetPlatform.fuchsia_x64 => 'fuchsia-x64',
TargetPlatform.tester => 'flutter-tester',
TargetPlatform.web_javascript => 'web-javascript',
TargetPlatform.android => 'android',
};
}
TargetPlatform getTargetPlatformForName(String platform) {
switch (platform) {
case 'android':
return TargetPlatform.android;
case 'android-arm':
return TargetPlatform.android_arm;
case 'android-arm64':
return TargetPlatform.android_arm64;
case 'android-x64':
return TargetPlatform.android_x64;
case 'android-x86':
return TargetPlatform.android_x86;
case 'fuchsia-arm64':
return TargetPlatform.fuchsia_arm64;
case 'fuchsia-x64':
return TargetPlatform.fuchsia_x64;
case 'ios':
return TargetPlatform.ios;
case 'darwin':
return switch (platform) {
'android' => TargetPlatform.android,
'android-arm' => TargetPlatform.android_arm,
'android-arm64' => TargetPlatform.android_arm64,
'android-x64' => TargetPlatform.android_x64,
'android-x86' => TargetPlatform.android_x86,
'fuchsia-arm64' => TargetPlatform.fuchsia_arm64,
'fuchsia-x64' => TargetPlatform.fuchsia_x64,
'ios' => TargetPlatform.ios,
// For backward-compatibility and also for Tester, where it must match
// host platform name (HostPlatform.darwin_x64)
case 'darwin-x64':
case 'darwin-arm64':
return TargetPlatform.darwin;
case 'linux-x64':
return TargetPlatform.linux_x64;
case 'linux-arm64':
return TargetPlatform.linux_arm64;
case 'windows-x64':
return TargetPlatform.windows_x64;
case 'windows-arm64':
return TargetPlatform.windows_arm64;
case 'web-javascript':
return TargetPlatform.web_javascript;
case 'flutter-tester':
return TargetPlatform.tester;
}
throw Exception('Unsupported platform name "$platform"');
'darwin' || 'darwin-x64' || 'darwin-arm64' => TargetPlatform.darwin,
'linux-x64' => TargetPlatform.linux_x64,
'linux-arm64' => TargetPlatform.linux_arm64,
'windows-x64' => TargetPlatform.windows_x64,
'windows-arm64' => TargetPlatform.windows_arm64,
'web-javascript' => TargetPlatform.web_javascript,
'flutter-tester' => TargetPlatform.tester,
_ => throw Exception('Unsupported platform name "$platform"'),
};
}
AndroidArch getAndroidArchForName(String platform) {
switch (platform) {
case 'android-arm':
return AndroidArch.armeabi_v7a;
case 'android-arm64':
return AndroidArch.arm64_v8a;
case 'android-x64':
return AndroidArch.x86_64;
case 'android-x86':
return AndroidArch.x86;
}
throw Exception('Unsupported Android arch name "$platform"');
return switch (platform) {
'android-arm' => AndroidArch.armeabi_v7a,
'android-arm64' => AndroidArch.arm64_v8a,
'android-x64' => AndroidArch.x86_64,
'android-x86' => AndroidArch.x86,
_ => throw Exception('Unsupported Android arch name "$platform"'),
};
}
HostPlatform getCurrentHostPlatform() {

View file

@ -88,36 +88,26 @@ class SourceVisitor implements ResolvedFiles {
void visitPattern(String pattern, bool optional) {
// perform substitution of the environmental values and then
// of the local values.
final List<String> segments = <String>[];
final List<String> rawParts = pattern.split('/');
final bool hasWildcard = rawParts.last.contains('*');
String? wildcardFile;
if (hasWildcard) {
wildcardFile = rawParts.removeLast();
}
// If the pattern does not start with an env variable, then we have nothing
// to resolve it to, error out.
switch (rawParts.first) {
case Environment.kProjectDirectory:
segments.addAll(
environment.fileSystem.path.split(environment.projectDir.resolveSymbolicLinksSync()));
case Environment.kBuildDirectory:
segments.addAll(environment.fileSystem.path.split(
environment.buildDir.resolveSymbolicLinksSync()));
case Environment.kCacheDirectory:
segments.addAll(
environment.fileSystem.path.split(environment.cacheDir.resolveSymbolicLinksSync()));
case Environment.kFlutterRootDirectory:
final List<String> segments = <String>[
...environment.fileSystem.path.split(switch (rawParts.first) {
// flutter root will not contain a symbolic link.
segments.addAll(
environment.fileSystem.path.split(environment.flutterRootDir.absolute.path));
case Environment.kOutputDirectory:
segments.addAll(
environment.fileSystem.path.split(environment.outputDir.resolveSymbolicLinksSync()));
default:
throw InvalidPatternException(pattern);
}
rawParts.skip(1).forEach(segments.add);
Environment.kFlutterRootDirectory => environment.flutterRootDir.absolute.path,
Environment.kProjectDirectory => environment.projectDir.resolveSymbolicLinksSync(),
Environment.kBuildDirectory => environment.buildDir.resolveSymbolicLinksSync(),
Environment.kCacheDirectory => environment.cacheDir.resolveSymbolicLinksSync(),
Environment.kOutputDirectory => environment.outputDir.resolveSymbolicLinksSync(),
// If the pattern does not start with an env variable, then we have nothing
// to resolve it to, error out.
_ => throw InvalidPatternException(pattern),
}),
...rawParts.skip(1),
];
final String filePath = environment.fileSystem.path.joinAll(segments);
if (!hasWildcard) {
if (optional && !environment.fileSystem.isFileSync(filePath)) {

View file

@ -1229,21 +1229,14 @@ class PubspecHeader extends PubspecLine {
final List<String> parts = strippedLine.split(':');
final String sectionName = parts.first;
final String value = parts.last.trim();
switch (sectionName) {
case 'dependencies':
return PubspecHeader(line, Section.dependencies);
case 'dev_dependencies':
return PubspecHeader(line, Section.devDependencies);
case 'dependency_overrides':
return PubspecHeader(line, Section.dependencyOverrides);
case 'builders':
return PubspecHeader(line, Section.builders);
case 'name':
case 'version':
return PubspecHeader(line, Section.header, name: sectionName, value: value);
default:
return PubspecHeader(line, Section.other);
}
return switch (sectionName) {
'dependencies' => PubspecHeader(line, Section.dependencies),
'dev_dependencies' => PubspecHeader(line, Section.devDependencies),
'dependency_overrides' => PubspecHeader(line, Section.dependencyOverrides),
'builders' => PubspecHeader(line, Section.builders),
'name' || 'version' => PubspecHeader(line, Section.header, name: sectionName, value: value),
_ => PubspecHeader(line, Section.other),
};
}
/// Returns the input after removing trailing spaces and anything after the

View file

@ -98,19 +98,12 @@ class ValidateProject {
}
String getStringResult(ProjectValidatorResult result) {
final String icon;
switch (result.status) {
case StatusProjectValidator.error:
icon = '[✗]';
case StatusProjectValidator.info:
case StatusProjectValidator.success:
icon = '[✓]';
case StatusProjectValidator.warning:
icon = '[!]';
case StatusProjectValidator.crash:
icon = '[☠]';
}
final String icon = switch (result.status) {
StatusProjectValidator.warning => '[!]',
StatusProjectValidator.error => '[✗]',
StatusProjectValidator.crash => '[☠]',
StatusProjectValidator.info || StatusProjectValidator.success => '[✓]',
};
return '$icon $result';
}
}

View file

@ -31,17 +31,13 @@ class TargetModel {
/// Throws an exception if passed a value other than 'flutter',
/// 'flutter_runner', 'vm', or 'dartdevc'.
factory TargetModel(String rawValue) {
switch (rawValue) {
case 'flutter':
return flutter;
case 'flutter_runner':
return flutterRunner;
case 'vm':
return vm;
case 'dartdevc':
return dartdevc;
}
throw Exception('Unexpected target model $rawValue');
return switch (rawValue) {
'flutter' => flutter,
'flutter_runner' => flutterRunner,
'vm' => vm,
'dartdevc' => dartdevc,
_ => throw Exception('Unexpected target model $rawValue'),
};
}
const TargetModel._(this._value);

View file

@ -242,15 +242,11 @@ class AnalysisError implements Comparable<AnalysisError> {
String get _separator => _platform.isWindows ? '-' : '';
String get colorSeverity {
switch (writtenError.severityLevel) {
case AnalysisSeverity.error:
return _terminal.color(writtenError.severity, TerminalColor.red);
case AnalysisSeverity.warning:
return _terminal.color(writtenError.severity, TerminalColor.yellow);
case AnalysisSeverity.info:
case AnalysisSeverity.none:
return writtenError.severity;
}
return switch (writtenError.severityLevel) {
AnalysisSeverity.error => _terminal.color(writtenError.severity, TerminalColor.red),
AnalysisSeverity.warning => _terminal.color(writtenError.severity, TerminalColor.yellow),
AnalysisSeverity.info || AnalysisSeverity.none => writtenError.severity,
};
}
String get type => writtenError.type;

View file

@ -581,23 +581,19 @@ enum DeviceConnectionInterface {
/// Returns the `DeviceConnectionInterface` enum based on its string name.
DeviceConnectionInterface getDeviceConnectionInterfaceForName(String name) {
switch (name) {
case 'attached':
return DeviceConnectionInterface.attached;
case 'wireless':
return DeviceConnectionInterface.wireless;
}
throw Exception('Unsupported DeviceConnectionInterface name "$name"');
return switch (name) {
'attached' => DeviceConnectionInterface.attached,
'wireless' => DeviceConnectionInterface.wireless,
_ => throw Exception('Unsupported DeviceConnectionInterface name "$name"'),
};
}
/// Returns a `DeviceConnectionInterface`'s string name.
String getNameForDeviceConnectionInterface(DeviceConnectionInterface connectionInterface) {
switch (connectionInterface) {
case DeviceConnectionInterface.attached:
return 'attached';
case DeviceConnectionInterface.wireless:
return 'wireless';
}
return switch (connectionInterface) {
DeviceConnectionInterface.attached => 'attached',
DeviceConnectionInterface.wireless => 'wireless',
};
}
/// A device is a physical hardware that can run a Flutter application.

View file

@ -162,47 +162,31 @@ class ValidationResult {
final List<ValidationMessage> messages;
String get leadingBox {
switch (type) {
case ValidationType.crash:
return '[☠]';
case ValidationType.missing:
return '[✗]';
case ValidationType.success:
return '[✓]';
case ValidationType.notAvailable:
case ValidationType.partial:
return '[!]';
}
return switch (type) {
ValidationType.crash => '[☠]',
ValidationType.missing => '[✗]',
ValidationType.success => '[✓]',
ValidationType.notAvailable || ValidationType.partial => '[!]',
};
}
String get coloredLeadingBox {
switch (type) {
case ValidationType.crash:
return globals.terminal.color(leadingBox, TerminalColor.red);
case ValidationType.missing:
return globals.terminal.color(leadingBox, TerminalColor.red);
case ValidationType.success:
return globals.terminal.color(leadingBox, TerminalColor.green);
case ValidationType.notAvailable:
case ValidationType.partial:
return globals.terminal.color(leadingBox, TerminalColor.yellow);
}
return globals.terminal.color(leadingBox, switch (type) {
ValidationType.success => TerminalColor.green,
ValidationType.crash || ValidationType.missing => TerminalColor.red,
ValidationType.notAvailable || ValidationType.partial => TerminalColor.yellow,
});
}
/// The string representation of the type.
String get typeStr {
switch (type) {
case ValidationType.crash:
return 'crash';
case ValidationType.missing:
return 'missing';
case ValidationType.success:
return 'installed';
case ValidationType.notAvailable:
return 'notAvailable';
case ValidationType.partial:
return 'partial';
}
return switch (type) {
ValidationType.crash => 'crash',
ValidationType.missing => 'missing',
ValidationType.success => 'installed',
ValidationType.notAvailable => 'notAvailable',
ValidationType.partial => 'partial',
};
}
@override
@ -254,25 +238,19 @@ class ValidationMessage {
bool get isInformation => type == ValidationMessageType.information;
String get indicator {
switch (type) {
case ValidationMessageType.error:
return '';
case ValidationMessageType.hint:
return '!';
case ValidationMessageType.information:
return '';
}
return switch (type) {
ValidationMessageType.error => '',
ValidationMessageType.hint => '!',
ValidationMessageType.information => '',
};
}
String get coloredIndicator {
switch (type) {
case ValidationMessageType.error:
return globals.terminal.color(indicator, TerminalColor.red);
case ValidationMessageType.hint:
return globals.terminal.color(indicator, TerminalColor.yellow);
case ValidationMessageType.information:
return globals.terminal.color(indicator, TerminalColor.green);
}
return globals.terminal.color(indicator, switch (type) {
ValidationMessageType.error => TerminalColor.red,
ValidationMessageType.hint => TerminalColor.yellow,
ValidationMessageType.information => TerminalColor.green,
});
}
@override

View file

@ -270,15 +270,11 @@ class Feature {
/// Retrieve the correct setting for the provided `channel`.
FeatureChannelSetting getSettingForChannel(String channel) {
switch (channel) {
case 'stable':
return stable;
case 'beta':
return beta;
case 'master':
default:
return master;
}
return switch (channel) {
'stable' => stable,
'beta' => beta,
'master' || _ => master,
};
}
}

View file

@ -143,27 +143,18 @@ class PlistParser {
static final RegExp _nonBase64Pattern = RegExp('[^a-zA-Z0-9+/=]+');
Object? _parseXmlNode(XmlElement node) {
switch (node.name.local){
case 'string':
return node.innerText;
case 'real':
return double.parse(node.innerText);
case 'integer':
return int.parse(node.innerText);
case 'true':
return true;
case 'false':
return false;
case 'date':
return DateTime.parse(node.innerText);
case 'data':
return base64.decode(node.innerText.replaceAll(_nonBase64Pattern, ''));
case 'array':
return node.children.whereType<XmlElement>().map<Object?>(_parseXmlNode).whereType<Object>().toList();
case 'dict':
return _parseXmlDict(node);
}
return null;
return switch (node.name.local) {
'string' => node.innerText,
'real' => double.parse(node.innerText),
'integer' => int.parse(node.innerText),
'true' => true,
'false' => false,
'date' => DateTime.parse(node.innerText),
'data' => base64.decode(node.innerText.replaceAll(_nonBase64Pattern, '')),
'array' => node.children.whereType<XmlElement>().map<Object?>(_parseXmlNode).whereType<Object>().toList(),
'dict' => _parseXmlDict(node),
_ => null,
};
}
/// Parses the Plist file located at [plistFilePath] and returns the value

View file

@ -156,34 +156,24 @@ Future<void> _copyNativeAssetsAndroid(
/// Get the [Target] for [androidArch].
Target _getNativeTarget(AndroidArch androidArch) {
switch (androidArch) {
case AndroidArch.armeabi_v7a:
return Target.androidArm;
case AndroidArch.arm64_v8a:
return Target.androidArm64;
case AndroidArch.x86:
return Target.androidIA32;
case AndroidArch.x86_64:
return Target.androidX64;
}
return switch (androidArch) {
AndroidArch.armeabi_v7a => Target.androidArm,
AndroidArch.arm64_v8a => Target.androidArm64,
AndroidArch.x86 => Target.androidIA32,
AndroidArch.x86_64 => Target.androidX64,
};
}
/// Get the [AndroidArch] for [target].
AndroidArch _getAndroidArch(Target target) {
switch (target) {
case Target.androidArm:
return AndroidArch.armeabi_v7a;
case Target.androidArm64:
return AndroidArch.arm64_v8a;
case Target.androidIA32:
return AndroidArch.x86;
case Target.androidX64:
return AndroidArch.x86_64;
case Target.androidRiscv64:
throwToolExit('Android RISC-V not yet supported.');
default:
throwToolExit('Invalid target: $target.');
}
return switch (target) {
Target.androidArm => AndroidArch.armeabi_v7a,
Target.androidArm64 => AndroidArch.arm64_v8a,
Target.androidIA32 => AndroidArch.x86,
Target.androidX64 => AndroidArch.x86_64,
Target.androidRiscv64 => throwToolExit('Android RISC-V not yet supported.'),
_ => throwToolExit('Invalid target: $target.'),
};
}
Map<AssetImpl, KernelAsset> _assetTargetLocations(

View file

@ -124,24 +124,19 @@ Future<List<Uri>> buildNativeAssetsIOS({
}
IOSSdkImpl _getIOSSdkImpl(EnvironmentType environmentType) {
switch (environmentType) {
case EnvironmentType.physical:
return IOSSdkImpl.iPhoneOS;
case EnvironmentType.simulator:
return IOSSdkImpl.iPhoneSimulator;
}
return switch (environmentType) {
EnvironmentType.physical => IOSSdkImpl.iPhoneOS,
EnvironmentType.simulator => IOSSdkImpl.iPhoneSimulator,
};
}
/// Extract the [Target] from a [DarwinArch].
Target _getNativeTarget(DarwinArch darwinArch) {
switch (darwinArch) {
case DarwinArch.armv7:
return Target.iOSArm;
case DarwinArch.arm64:
return Target.iOSArm64;
case DarwinArch.x86_64:
return Target.iOSX64;
}
return switch (darwinArch) {
DarwinArch.armv7 => Target.iOSArm,
DarwinArch.arm64 => Target.iOSArm64,
DarwinArch.x86_64 => Target.iOSX64,
};
}
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(

View file

@ -156,14 +156,11 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
/// Extract the [Target] from a [DarwinArch].
Target _getNativeTarget(DarwinArch darwinArch) {
switch (darwinArch) {
case DarwinArch.arm64:
return Target.macOSArm64;
case DarwinArch.x86_64:
return Target.macOSX64;
case DarwinArch.armv7:
throw Exception('Unknown DarwinArch: $darwinArch.');
}
return switch (darwinArch) {
DarwinArch.arm64 => Target.macOSArm64,
DarwinArch.x86_64 => Target.macOSX64,
DarwinArch.armv7 => throw Exception('Unknown DarwinArch: $darwinArch.'),
};
}
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(

View file

@ -64,29 +64,12 @@ class LocaleInfo implements Comparable<LocaleInfo> {
/// across various countries. For example, we know Taiwan uses traditional (Hant)
/// script, so it is safe to apply (Hant) to Taiwanese languages.
if (deriveScriptCode && scriptCode == null) {
switch (languageCode) {
case 'zh': {
if (countryCode == null) {
scriptCode = 'Hans';
}
switch (countryCode) {
case 'CN':
case 'SG':
scriptCode = 'Hans';
case 'TW':
case 'HK':
case 'MO':
scriptCode = 'Hant';
}
break;
}
case 'sr': {
if (countryCode == null) {
scriptCode = 'Cyrl';
}
break;
}
}
scriptCode = switch ((languageCode, countryCode)) {
('zh', 'CN' || 'SG' || null) => 'Hans',
('zh', 'TW' || 'HK' || 'MO') => 'Hant',
('sr', null) => 'Cyrl',
_ => null,
};
// Increment length if we were able to assume a scriptCode.
if (scriptCode != null) {
length += 1;

View file

@ -1511,24 +1511,16 @@ String _describePausedIsolates(int pausedIsolatesFound, String serviceEventKind)
message.write('$pausedIsolatesFound isolates are ');
plural = true;
}
switch (serviceEventKind) {
case vm_service.EventKind.kPauseStart:
message.write('paused (probably due to --start-paused)');
case vm_service.EventKind.kPauseExit:
message.write('paused because ${ plural ? 'they have' : 'it has' } terminated');
case vm_service.EventKind.kPauseBreakpoint:
message.write('paused in the debugger on a breakpoint');
case vm_service.EventKind.kPauseInterrupted:
message.write('paused due in the debugger');
case vm_service.EventKind.kPauseException:
message.write('paused in the debugger after an exception was thrown');
case vm_service.EventKind.kPausePostRequest:
message.write('paused');
case '':
message.write('paused for various reasons');
default:
message.write('paused');
}
message.write(switch (serviceEventKind) {
vm_service.EventKind.kPauseStart => 'paused (probably due to --start-paused)',
vm_service.EventKind.kPauseExit => 'paused because ${ plural ? 'they have' : 'it has' } terminated',
vm_service.EventKind.kPauseBreakpoint => 'paused in the debugger on a breakpoint',
vm_service.EventKind.kPauseInterrupted => 'paused due in the debugger',
vm_service.EventKind.kPauseException => 'paused in the debugger after an exception was thrown',
vm_service.EventKind.kPausePostRequest => 'paused',
'' => 'paused for various reasons',
_ => 'paused',
});
return message.toString();
}

View file

@ -375,22 +375,15 @@ class FlutterTesterTestDevice extends TestDevice {
}
String _getExitCodeMessage(int exitCode) {
switch (exitCode) {
case 1:
return 'Shell subprocess cleanly reported an error. Check the logs above for an error message.';
case 0:
return 'Shell subprocess ended cleanly. Did main() call exit()?';
case -0x0f: // ProcessSignal.SIGTERM
return 'Shell subprocess crashed with SIGTERM ($exitCode).';
case -0x0b: // ProcessSignal.SIGSEGV
return 'Shell subprocess crashed with segmentation fault.';
case -0x06: // ProcessSignal.SIGABRT
return 'Shell subprocess crashed with SIGABRT ($exitCode).';
case -0x02: // ProcessSignal.SIGINT
return 'Shell subprocess terminated by ^C (SIGINT, $exitCode).';
default:
return 'Shell subprocess crashed with unexpected exit code $exitCode.';
}
return switch (exitCode) {
1 => 'Shell subprocess cleanly reported an error. Check the logs above for an error message.',
0 => 'Shell subprocess ended cleanly. Did main() call exit()?',
-0x0f => 'Shell subprocess crashed with SIGTERM ($exitCode).', // ProcessSignal.SIGTERM
-0x0b => 'Shell subprocess crashed with segmentation fault.', // ProcessSignal.SIGSEGV
-0x06 => 'Shell subprocess crashed with SIGABRT ($exitCode).', // ProcessSignal.SIGABRT
-0x02 => 'Shell subprocess terminated by ^C (SIGINT, $exitCode).', // ProcessSignal.SIGINT
_ => 'Shell subprocess crashed with unexpected exit code $exitCode.',
};
}
StreamChannel<String> _webSocketToStreamChannel(WebSocket webSocket) {

View file

@ -1163,14 +1163,11 @@ class VersionFreshnessValidator {
/// beta releases happen approximately every month.
@visibleForTesting
static Duration versionAgeConsideredUpToDate(String channel) {
switch (channel) {
case 'stable':
return const Duration(days: 365 ~/ 2); // Six months
case 'beta':
return const Duration(days: 7 * 8); // Eight weeks
default:
return const Duration(days: 7 * 3); // Three weeks
}
return switch (channel) {
'stable' => const Duration(days: 365 ~/ 2), // Six months
'beta' => const Duration(days: 7 * 8), // Eight weeks
_ => const Duration(days: 7 * 3), // Three weeks
};
}
/// Execute validations and print warning to [logger] if necessary.

View file

@ -179,13 +179,10 @@ class VisualStudio {
/// version.
String? get cmakeGenerator {
// From https://cmake.org/cmake/help/v3.22/manual/cmake-generators.7.html#visual-studio-generators
switch (_majorVersion) {
case 17:
return 'Visual Studio 17 2022';
case 16:
default:
return 'Visual Studio 16 2019';
}
return switch (_majorVersion) {
17 => 'Visual Studio 17 2022',
_ => 'Visual Studio 16 2019',
};
}
/// The path to cl.exe, or null if no Visual Studio installation has

View file

@ -122,25 +122,15 @@ class LogLine {
}
static String clarify(String line) {
return line.runes.map<String>((int rune) {
if (rune >= 0x20 && rune <= 0x7F) {
return String.fromCharCode(rune);
}
switch (rune) {
case 0x00:
return '<NUL>';
case 0x07:
return '<BEL>';
case 0x08:
return '<TAB>';
case 0x09:
return '<BS>';
case 0x0A:
return '<LF>';
case 0x0D:
return '<CR>';
}
return '<${rune.toRadixString(16).padLeft(rune <= 0xFF ? 2 : rune <= 0xFFFF ? 4 : 5, '0')}>';
return line.runes.map<String>((int rune) => switch (rune) {
>= 0x20 && <= 0x7F => String.fromCharCode(rune),
0x00 => '<NUL>',
0x07 => '<BEL>',
0x08 => '<TAB>',
0x09 => '<BS>',
0x0A => '<LF>',
0x0D => '<CR>',
_ => '<${rune.toRadixString(16).padLeft(rune <= 0xFF ? 2 : rune <= 0xFFFF ? 4 : 5, '0')}>',
}).join();
}
}

View file

@ -20,23 +20,15 @@ enum HttpMethod {
}
HttpMethod _fromMethodString(String value) {
final String name = value.toLowerCase();
switch (name) {
case 'get':
return HttpMethod.get;
case 'put':
return HttpMethod.put;
case 'delete':
return HttpMethod.delete;
case 'post':
return HttpMethod.post;
case 'patch':
return HttpMethod.patch;
case 'head':
return HttpMethod.head;
default:
throw StateError('Unrecognized HTTP method $value');
}
return switch (value.toLowerCase()) {
'get' => HttpMethod.get,
'put' => HttpMethod.put,
'delete' => HttpMethod.delete,
'post' => HttpMethod.post,
'patch' => HttpMethod.patch,
'head' => HttpMethod.head,
_ => throw StateError('Unrecognized HTTP method $value'),
};
}
String _toMethodString(HttpMethod method) {