switch statement cleanup (#148382)
This PR is step 12 in the journey to solve issue #136139 and make the entire Flutter repo more readable. Most of it involves implementing switch expressions, and there's also a few other random things that I wanted to clean up a bit.
This commit is contained in:
@@ -1187,10 +1187,8 @@ Future<void> _runInteractive({
|
||||
case 'q':
|
||||
checker.cleanupTempDirectory();
|
||||
exit(0);
|
||||
case 'r':
|
||||
if (!busy) {
|
||||
rerun();
|
||||
}
|
||||
case 'r' when !busy:
|
||||
rerun();
|
||||
}
|
||||
});
|
||||
Watcher(file.absolute.path).events.listen((_) => rerun());
|
||||
|
||||
@@ -385,23 +385,12 @@ class StartContext extends Context {
|
||||
|
||||
/// Determine this release's version number from the [lastVersion] and the [incrementLetter].
|
||||
Version calculateNextVersion(Version lastVersion, ReleaseType releaseType) {
|
||||
late final Version nextVersion;
|
||||
switch (releaseType) {
|
||||
case ReleaseType.STABLE_INITIAL:
|
||||
nextVersion = Version(
|
||||
x: lastVersion.x,
|
||||
y: lastVersion.y,
|
||||
z: 0,
|
||||
type: VersionType.stable,
|
||||
);
|
||||
case ReleaseType.STABLE_HOTFIX:
|
||||
nextVersion = Version.increment(lastVersion, 'z');
|
||||
case ReleaseType.BETA_INITIAL:
|
||||
nextVersion = Version.fromCandidateBranch(candidateBranch);
|
||||
case ReleaseType.BETA_HOTFIX:
|
||||
nextVersion = Version.increment(lastVersion, 'n');
|
||||
}
|
||||
return nextVersion;
|
||||
return switch (releaseType) {
|
||||
ReleaseType.STABLE_INITIAL => Version(x: lastVersion.x, y: lastVersion.y, z: 0, type: VersionType.stable),
|
||||
ReleaseType.STABLE_HOTFIX => Version.increment(lastVersion, 'z'),
|
||||
ReleaseType.BETA_INITIAL => Version.fromCandidateBranch(candidateBranch),
|
||||
ReleaseType.BETA_HOTFIX || _ => Version.increment(lastVersion, 'n'),
|
||||
};
|
||||
}
|
||||
|
||||
/// Ensures the branch point [candidateBranch] and `master` has a version tag.
|
||||
|
||||
@@ -115,15 +115,11 @@ class ABTest {
|
||||
if (value == null) {
|
||||
value = ''.padRight(len);
|
||||
} else {
|
||||
switch (aligns[column]) {
|
||||
case FieldJustification.LEFT:
|
||||
value = value.padRight(len);
|
||||
case FieldJustification.RIGHT:
|
||||
value = value.padLeft(len);
|
||||
case FieldJustification.CENTER:
|
||||
value = value.padLeft((len + value.length) ~/2);
|
||||
value = value.padRight(len);
|
||||
}
|
||||
value = switch (aligns[column]) {
|
||||
FieldJustification.LEFT => value.padRight(len),
|
||||
FieldJustification.RIGHT => value.padLeft(len),
|
||||
FieldJustification.CENTER => value.padLeft((len + value.length) ~/ 2).padRight(len),
|
||||
};
|
||||
}
|
||||
if (column > 0) {
|
||||
value = value.padLeft(len+1);
|
||||
|
||||
@@ -252,14 +252,11 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
||||
}
|
||||
|
||||
Future<bool> _matchesCPURequirement(AndroidDevice device) async {
|
||||
switch (cpu) {
|
||||
case null:
|
||||
return true;
|
||||
case AndroidCPU.arm64:
|
||||
return device.isArm64();
|
||||
case AndroidCPU.arm:
|
||||
return device.isArm();
|
||||
}
|
||||
return switch (cpu) {
|
||||
null => Future<bool>.value(true),
|
||||
AndroidCPU.arm64 => device.isArm64(),
|
||||
AndroidCPU.arm => device.isArm(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Picks a random Android device out of connected devices and sets it as
|
||||
|
||||
@@ -37,19 +37,12 @@ class TestStepResult {
|
||||
});
|
||||
|
||||
factory TestStepResult.fromSnapshot(AsyncSnapshot<TestStepResult> snapshot) {
|
||||
switch (snapshot.connectionState) {
|
||||
case ConnectionState.none:
|
||||
return const TestStepResult('Not started', nothing, TestStatus.ok);
|
||||
case ConnectionState.waiting:
|
||||
return const TestStepResult('Executing', nothing, TestStatus.pending);
|
||||
case ConnectionState.done:
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
}
|
||||
return snapshot.error! as TestStepResult;
|
||||
case ConnectionState.active:
|
||||
throw 'Unsupported state ${snapshot.connectionState}';
|
||||
}
|
||||
return switch (snapshot.connectionState) {
|
||||
ConnectionState.none => const TestStepResult('Not started', nothing, TestStatus.ok),
|
||||
ConnectionState.waiting => const TestStepResult('Executing', nothing, TestStatus.pending),
|
||||
ConnectionState.done => snapshot.data ?? snapshot.error! as TestStepResult,
|
||||
ConnectionState.active => throw 'Unsupported state: ConnectionState.active',
|
||||
};
|
||||
}
|
||||
|
||||
final String name;
|
||||
|
||||
@@ -204,18 +204,12 @@ class _ListDemoState extends State<ListDemo> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String layoutText = _dense != null ? ' \u2013 Dense' : '';
|
||||
String? itemTypeText;
|
||||
switch (_itemType) {
|
||||
case _MaterialListType.oneLine:
|
||||
case _MaterialListType.oneLineWithAvatar:
|
||||
itemTypeText = 'Single-line';
|
||||
case _MaterialListType.twoLine:
|
||||
itemTypeText = 'Two-line';
|
||||
case _MaterialListType.threeLine:
|
||||
itemTypeText = 'Three-line';
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
final String? itemTypeText = switch (_itemType) {
|
||||
_MaterialListType.oneLine || _MaterialListType.oneLineWithAvatar => 'Single-line',
|
||||
_MaterialListType.twoLine => 'Two-line',
|
||||
_MaterialListType.threeLine => 'Three-line',
|
||||
null => null,
|
||||
};
|
||||
|
||||
Iterable<Widget> listTiles = items.map<Widget>((String item) => buildListTile(context, item));
|
||||
if (_showDividers != null) {
|
||||
|
||||
@@ -80,29 +80,12 @@ class _CustomRangeThumbShape extends RangeSliderThumbShape {
|
||||
);
|
||||
|
||||
final double size = _thumbSize * sizeTween.evaluate(enableAnimation);
|
||||
late Path thumbPath;
|
||||
switch (textDirection) {
|
||||
case TextDirection.rtl:
|
||||
switch (thumb) {
|
||||
case Thumb.start:
|
||||
thumbPath = _rightTriangle(size, center);
|
||||
case Thumb.end:
|
||||
thumbPath = _leftTriangle(size, center);
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
case TextDirection.ltr:
|
||||
switch (thumb) {
|
||||
case Thumb.start:
|
||||
thumbPath = _leftTriangle(size, center);
|
||||
case Thumb.end:
|
||||
thumbPath = _rightTriangle(size, center);
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
final Path thumbPath = switch ((textDirection!, thumb!)) {
|
||||
(TextDirection.rtl, Thumb.start) => _rightTriangle(size, center),
|
||||
(TextDirection.rtl, Thumb.end) => _leftTriangle(size, center),
|
||||
(TextDirection.ltr, Thumb.start) => _leftTriangle(size, center),
|
||||
(TextDirection.ltr, Thumb.end) => _rightTriangle(size, center),
|
||||
};
|
||||
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation)!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,15 +50,11 @@ enum GalleryDemoCategory {
|
||||
}
|
||||
|
||||
String? displayTitle(GalleryLocalizations localizations) {
|
||||
switch (this) {
|
||||
case GalleryDemoCategory.other:
|
||||
return localizations.homeCategoryReference;
|
||||
case GalleryDemoCategory.material:
|
||||
case GalleryDemoCategory.cupertino:
|
||||
return toString();
|
||||
case GalleryDemoCategory.study:
|
||||
}
|
||||
return null;
|
||||
return switch (this) {
|
||||
study => null,
|
||||
material || cupertino => toString(),
|
||||
other => localizations.homeCategoryReference,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,22 +96,15 @@ class GalleryOptions {
|
||||
/// In other words, if the theme is dark, returns light; if the theme is
|
||||
/// light, returns dark.
|
||||
SystemUiOverlayStyle resolvedSystemUiOverlayStyle() {
|
||||
Brightness brightness;
|
||||
switch (themeMode) {
|
||||
case ThemeMode.light:
|
||||
brightness = Brightness.light;
|
||||
case ThemeMode.dark:
|
||||
brightness = Brightness.dark;
|
||||
case ThemeMode.system:
|
||||
brightness =
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
}
|
||||
|
||||
final SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
|
||||
? SystemUiOverlayStyle.light
|
||||
: SystemUiOverlayStyle.dark;
|
||||
|
||||
return overlayStyle;
|
||||
final Brightness brightness = switch (themeMode) {
|
||||
ThemeMode.light => Brightness.light,
|
||||
ThemeMode.dark => Brightness.dark,
|
||||
ThemeMode.system => WidgetsBinding.instance.platformDispatcher.platformBrightness,
|
||||
};
|
||||
return switch (brightness) {
|
||||
Brightness.light => SystemUiOverlayStyle.dark,
|
||||
Brightness.dark => SystemUiOverlayStyle.light,
|
||||
};
|
||||
}
|
||||
|
||||
GalleryOptions copyWith({
|
||||
|
||||
@@ -105,18 +105,13 @@ class _CupertinoAlertDemoState extends State<CupertinoAlertDemo>
|
||||
|
||||
String _title(BuildContext context) {
|
||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||
switch (widget.type) {
|
||||
case AlertDemoType.alert:
|
||||
return localizations.demoCupertinoAlertTitle;
|
||||
case AlertDemoType.alertTitle:
|
||||
return localizations.demoCupertinoAlertWithTitleTitle;
|
||||
case AlertDemoType.alertButtons:
|
||||
return localizations.demoCupertinoAlertButtonsTitle;
|
||||
case AlertDemoType.alertButtonsOnly:
|
||||
return localizations.demoCupertinoAlertButtonsOnlyTitle;
|
||||
case AlertDemoType.actionSheet:
|
||||
return localizations.demoCupertinoActionSheetTitle;
|
||||
}
|
||||
return switch (widget.type) {
|
||||
AlertDemoType.alert => localizations.demoCupertinoAlertTitle,
|
||||
AlertDemoType.alertTitle => localizations.demoCupertinoAlertWithTitleTitle,
|
||||
AlertDemoType.alertButtons => localizations.demoCupertinoAlertButtonsTitle,
|
||||
AlertDemoType.alertButtonsOnly => localizations.demoCupertinoAlertButtonsOnlyTitle,
|
||||
AlertDemoType.actionSheet => localizations.demoCupertinoActionSheetTitle,
|
||||
};
|
||||
}
|
||||
|
||||
static Route<String> _alertDemoDialog(
|
||||
|
||||
@@ -17,21 +17,17 @@ class BottomSheetDemo extends StatelessWidget {
|
||||
|
||||
String _title(BuildContext context) {
|
||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||
switch (type) {
|
||||
case BottomSheetDemoType.persistent:
|
||||
return localizations.demoBottomSheetPersistentTitle;
|
||||
case BottomSheetDemoType.modal:
|
||||
return localizations.demoBottomSheetModalTitle;
|
||||
}
|
||||
return switch (type) {
|
||||
BottomSheetDemoType.persistent => localizations.demoBottomSheetPersistentTitle,
|
||||
BottomSheetDemoType.modal => localizations.demoBottomSheetModalTitle,
|
||||
};
|
||||
}
|
||||
|
||||
Widget _bottomSheetDemo(BuildContext context) {
|
||||
switch (type) {
|
||||
case BottomSheetDemoType.persistent:
|
||||
return _PersistentBottomSheetDemo();
|
||||
case BottomSheetDemoType.modal:
|
||||
return _ModalBottomSheetDemo();
|
||||
}
|
||||
return switch (type) {
|
||||
BottomSheetDemoType.persistent => _PersistentBottomSheetDemo(),
|
||||
BottomSheetDemoType.modal => _ModalBottomSheetDemo(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -13,18 +13,13 @@ class ButtonDemo extends StatelessWidget {
|
||||
|
||||
String _title(BuildContext context) {
|
||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||
switch (type) {
|
||||
case ButtonDemoType.text:
|
||||
return localizations.demoTextButtonTitle;
|
||||
case ButtonDemoType.elevated:
|
||||
return localizations.demoElevatedButtonTitle;
|
||||
case ButtonDemoType.outlined:
|
||||
return localizations.demoOutlinedButtonTitle;
|
||||
case ButtonDemoType.toggle:
|
||||
return localizations.demoToggleButtonTitle;
|
||||
case ButtonDemoType.floating:
|
||||
return localizations.demoFloatingButtonTitle;
|
||||
}
|
||||
return switch (type) {
|
||||
ButtonDemoType.text => localizations.demoTextButtonTitle,
|
||||
ButtonDemoType.elevated => localizations.demoElevatedButtonTitle,
|
||||
ButtonDemoType.outlined => localizations.demoOutlinedButtonTitle,
|
||||
ButtonDemoType.toggle => localizations.demoToggleButtonTitle,
|
||||
ButtonDemoType.floating => localizations.demoFloatingButtonTitle,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -16,16 +16,12 @@ class ChipDemo extends StatelessWidget {
|
||||
|
||||
String _title(BuildContext context) {
|
||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||
switch (type) {
|
||||
case ChipDemoType.action:
|
||||
return localizations.demoActionChipTitle;
|
||||
case ChipDemoType.choice:
|
||||
return localizations.demoChoiceChipTitle;
|
||||
case ChipDemoType.filter:
|
||||
return localizations.demoFilterChipTitle;
|
||||
case ChipDemoType.input:
|
||||
return localizations.demoInputChipTitle;
|
||||
}
|
||||
return switch (type) {
|
||||
ChipDemoType.action => localizations.demoActionChipTitle,
|
||||
ChipDemoType.choice => localizations.demoChoiceChipTitle,
|
||||
ChipDemoType.filter => localizations.demoFilterChipTitle,
|
||||
ChipDemoType.input => localizations.demoInputChipTitle,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -81,16 +81,12 @@ class _DialogDemoState extends State<DialogDemo> with RestorationMixin {
|
||||
|
||||
String _title(BuildContext context) {
|
||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||
switch (widget.type) {
|
||||
case DialogDemoType.alert:
|
||||
return localizations.demoAlertDialogTitle;
|
||||
case DialogDemoType.alertTitle:
|
||||
return localizations.demoAlertTitleDialogTitle;
|
||||
case DialogDemoType.simple:
|
||||
return localizations.demoSimpleDialogTitle;
|
||||
case DialogDemoType.fullscreen:
|
||||
return localizations.demoFullscreenDialogTitle;
|
||||
}
|
||||
return switch (widget.type) {
|
||||
DialogDemoType.alert => localizations.demoAlertDialogTitle,
|
||||
DialogDemoType.alertTitle => localizations.demoAlertTitleDialogTitle,
|
||||
DialogDemoType.simple => localizations.demoSimpleDialogTitle,
|
||||
DialogDemoType.fullscreen => localizations.demoFullscreenDialogTitle,
|
||||
};
|
||||
}
|
||||
|
||||
static Route<String> _alertDialogDemoRoute(
|
||||
|
||||
@@ -164,14 +164,11 @@ class _PickerDemoState extends State<PickerDemo> with RestorationMixin {
|
||||
|
||||
String get _title {
|
||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||
switch (widget.type) {
|
||||
case PickerDemoType.date:
|
||||
return localizations.demoDatePickerTitle;
|
||||
case PickerDemoType.time:
|
||||
return localizations.demoTimePickerTitle;
|
||||
case PickerDemoType.range:
|
||||
return localizations.demoDateRangePickerTitle;
|
||||
}
|
||||
return switch (widget.type) {
|
||||
PickerDemoType.date => localizations.demoDatePickerTitle,
|
||||
PickerDemoType.time => localizations.demoTimePickerTitle,
|
||||
PickerDemoType.range => localizations.demoDateRangePickerTitle,
|
||||
};
|
||||
}
|
||||
|
||||
String get _labelText {
|
||||
|
||||
@@ -13,14 +13,10 @@ class TabsDemo extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget tabs;
|
||||
switch (type) {
|
||||
case TabsDemoType.scrollable:
|
||||
tabs = _TabsScrollableDemo();
|
||||
case TabsDemoType.nonScrollable:
|
||||
tabs = _TabsNonScrollableDemo();
|
||||
}
|
||||
return tabs;
|
||||
return switch (type) {
|
||||
TabsDemoType.scrollable => _TabsScrollableDemo(),
|
||||
TabsDemoType.nonScrollable => _TabsNonScrollableDemo(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -433,16 +433,11 @@ class _GalleryDemoPageState extends State<GalleryDemoPage>
|
||||
page = AnimatedBuilder(
|
||||
animation: _codeBackgroundColorController,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
Brightness themeBrightness;
|
||||
|
||||
switch (GalleryOptions.of(context).themeMode) {
|
||||
case ThemeMode.system:
|
||||
themeBrightness = MediaQuery.of(context).platformBrightness;
|
||||
case ThemeMode.light:
|
||||
themeBrightness = Brightness.light;
|
||||
case ThemeMode.dark:
|
||||
themeBrightness = Brightness.dark;
|
||||
}
|
||||
final Brightness themeBrightness = switch (GalleryOptions.of(context).themeMode) {
|
||||
ThemeMode.system => MediaQuery.of(context).platformBrightness,
|
||||
ThemeMode.light => Brightness.light,
|
||||
ThemeMode.dark => Brightness.dark,
|
||||
};
|
||||
|
||||
Widget contents = Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
|
||||
@@ -89,17 +89,13 @@ class _ReplyAppState extends State<ReplyApp> with RestorationMixin {
|
||||
supportedLocales: GalleryLocalizations.supportedLocales,
|
||||
locale: GalleryOptions.of(context).locale,
|
||||
initialRoute: ReplyApp.homeRoute,
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
switch (settings.name) {
|
||||
case ReplyApp.homeRoute:
|
||||
return MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) => const AdaptiveNav(),
|
||||
settings: settings,
|
||||
);
|
||||
case ReplyApp.composeRoute:
|
||||
return ReplyApp.createComposeRoute(settings);
|
||||
}
|
||||
return null;
|
||||
onGenerateRoute: (RouteSettings settings) => switch (settings.name) {
|
||||
ReplyApp.homeRoute => MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) => const AdaptiveNav(),
|
||||
settings: settings,
|
||||
),
|
||||
ReplyApp.composeRoute => ReplyApp.createComposeRoute(settings),
|
||||
_ => null,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -34,40 +34,15 @@ class MailboxBody extends StatelessWidget {
|
||||
final String destinationString = destination
|
||||
.toString()
|
||||
.substring(destination.toString().indexOf('.') + 1);
|
||||
late List<Email> emails;
|
||||
|
||||
switch (destination) {
|
||||
case MailboxPageType.inbox:
|
||||
{
|
||||
emails = model.inboxEmails;
|
||||
break;
|
||||
}
|
||||
case MailboxPageType.sent:
|
||||
{
|
||||
emails = model.outboxEmails;
|
||||
break;
|
||||
}
|
||||
case MailboxPageType.starred:
|
||||
{
|
||||
emails = model.starredEmails;
|
||||
break;
|
||||
}
|
||||
case MailboxPageType.trash:
|
||||
{
|
||||
emails = model.trashEmails;
|
||||
break;
|
||||
}
|
||||
case MailboxPageType.spam:
|
||||
{
|
||||
emails = model.spamEmails;
|
||||
break;
|
||||
}
|
||||
case MailboxPageType.drafts:
|
||||
{
|
||||
emails = model.draftEmails;
|
||||
break;
|
||||
}
|
||||
}
|
||||
final List<Email> emails = switch (destination) {
|
||||
MailboxPageType.inbox => model.inboxEmails,
|
||||
MailboxPageType.sent => model.outboxEmails,
|
||||
MailboxPageType.starred => model.starredEmails,
|
||||
MailboxPageType.trash => model.trashEmails,
|
||||
MailboxPageType.spam => model.spamEmails,
|
||||
MailboxPageType.drafts => model.draftEmails,
|
||||
};
|
||||
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
|
||||
@@ -16,21 +16,12 @@ class TestStepResult {
|
||||
const TestStepResult(this.name, this.description, this.status);
|
||||
|
||||
factory TestStepResult.fromSnapshot(AsyncSnapshot<TestStepResult> snapshot) {
|
||||
switch (snapshot.connectionState) {
|
||||
case ConnectionState.none:
|
||||
return const TestStepResult('Not started', nothing, TestStatus.ok);
|
||||
case ConnectionState.waiting:
|
||||
return const TestStepResult('Executing', nothing, TestStatus.pending);
|
||||
case ConnectionState.done:
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
final Object? result = snapshot.error;
|
||||
return result! as TestStepResult;
|
||||
}
|
||||
case ConnectionState.active:
|
||||
throw 'Unsupported state ${snapshot.connectionState}';
|
||||
}
|
||||
return switch (snapshot.connectionState) {
|
||||
ConnectionState.none => const TestStepResult('Not started', nothing, TestStatus.ok),
|
||||
ConnectionState.waiting => const TestStepResult('Executing', nothing, TestStatus.pending),
|
||||
ConnectionState.done => snapshot.data ?? snapshot.error! as TestStepResult,
|
||||
ConnectionState.active => throw 'Unsupported state: ConnectionState.active',
|
||||
};
|
||||
}
|
||||
|
||||
final String name;
|
||||
|
||||
@@ -325,26 +325,18 @@ enum SourceElementType {
|
||||
unknownType,
|
||||
}
|
||||
|
||||
/// Converts the enun type [SourceElementType] to a human readable string.
|
||||
/// Converts the enum type [SourceElementType] to a human readable string.
|
||||
String sourceElementTypeAsString(SourceElementType type) {
|
||||
switch (type) {
|
||||
case SourceElementType.classType:
|
||||
return 'class';
|
||||
case SourceElementType.fieldType:
|
||||
return 'field';
|
||||
case SourceElementType.methodType:
|
||||
return 'method';
|
||||
case SourceElementType.constructorType:
|
||||
return 'constructor';
|
||||
case SourceElementType.typedefType:
|
||||
return 'typedef';
|
||||
case SourceElementType.topLevelVariableType:
|
||||
return 'variable';
|
||||
case SourceElementType.functionType:
|
||||
return 'function';
|
||||
case SourceElementType.unknownType:
|
||||
return 'unknown';
|
||||
}
|
||||
return switch (type) {
|
||||
SourceElementType.classType => 'class',
|
||||
SourceElementType.fieldType => 'field',
|
||||
SourceElementType.methodType => 'method',
|
||||
SourceElementType.constructorType => 'constructor',
|
||||
SourceElementType.typedefType => 'typedef',
|
||||
SourceElementType.topLevelVariableType => 'variable',
|
||||
SourceElementType.functionType => 'function',
|
||||
SourceElementType.unknownType => 'unknown',
|
||||
};
|
||||
}
|
||||
|
||||
/// A class that represents a Dart element in a source file.
|
||||
|
||||
@@ -62,29 +62,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;
|
||||
|
||||
Reference in New Issue
Block a user