From b9ead37244b1bfc4d35f36440088f35949738e41 Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Tue, 3 Jan 2023 21:51:48 +0100 Subject: [PATCH] Simplify null check. (#117026) * Simplify null check. * Simplify null check. * Simplify null check. * Fix. --- packages/flutter_tools/lib/src/device.dart | 54 +++++++++---------- .../application_package_test.dart | 6 +-- .../test/general.shard/dap/mocks.dart | 6 +-- .../integration.shard/hot_reload_test.dart | 4 +- .../template_manifest_test.dart | 2 +- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 80161152bb6..67e6cab36cb 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -1004,45 +1004,45 @@ class DebuggingOptions { static DebuggingOptions fromJson(Map json, BuildInfo buildInfo) => DebuggingOptions._( buildInfo: buildInfo, - debuggingEnabled: (json['debuggingEnabled'] as bool?)!, - startPaused: (json['startPaused'] as bool?)!, - dartFlags: (json['dartFlags'] as String?)!, - dartEntrypointArgs: ((json['dartEntrypointArgs'] as List?)?.cast())!, - disableServiceAuthCodes: (json['disableServiceAuthCodes'] as bool?)!, - enableDds: (json['enableDds'] as bool?)!, - cacheStartupProfile: (json['cacheStartupProfile'] as bool?)!, - enableSoftwareRendering: (json['enableSoftwareRendering'] as bool?)!, - skiaDeterministicRendering: (json['skiaDeterministicRendering'] as bool?)!, - traceSkia: (json['traceSkia'] as bool?)!, + debuggingEnabled: json['debuggingEnabled']! as bool, + startPaused: json['startPaused']! as bool, + dartFlags: json['dartFlags']! as String, + dartEntrypointArgs: (json['dartEntrypointArgs']! as List).cast(), + disableServiceAuthCodes: json['disableServiceAuthCodes']! as bool, + enableDds: json['enableDds']! as bool, + cacheStartupProfile: json['cacheStartupProfile']! as bool, + enableSoftwareRendering: json['enableSoftwareRendering']! as bool, + skiaDeterministicRendering: json['skiaDeterministicRendering']! as bool, + traceSkia: json['traceSkia']! as bool, traceAllowlist: json['traceAllowlist'] as String?, traceSkiaAllowlist: json['traceSkiaAllowlist'] as String?, - traceSystrace: (json['traceSystrace'] as bool?)!, - endlessTraceBuffer: (json['endlessTraceBuffer'] as bool?)!, - dumpSkpOnShaderCompilation: (json['dumpSkpOnShaderCompilation'] as bool?)!, - cacheSkSL: (json['cacheSkSL'] as bool?)!, - purgePersistentCache: (json['purgePersistentCache'] as bool?)!, - useTestFonts: (json['useTestFonts'] as bool?)!, - verboseSystemLogs: (json['verboseSystemLogs'] as bool?)!, + traceSystrace: json['traceSystrace']! as bool, + endlessTraceBuffer: json['endlessTraceBuffer']! as bool, + dumpSkpOnShaderCompilation: json['dumpSkpOnShaderCompilation']! as bool, + cacheSkSL: json['cacheSkSL']! as bool, + purgePersistentCache: json['purgePersistentCache']! as bool, + useTestFonts: json['useTestFonts']! as bool, + verboseSystemLogs: json['verboseSystemLogs']! as bool, hostVmServicePort: json['hostVmServicePort'] as int? , deviceVmServicePort: json['deviceVmServicePort'] as int?, - disablePortPublication: (json['disablePortPublication'] as bool?)!, + disablePortPublication: json['disablePortPublication']! as bool, ddsPort: json['ddsPort'] as int?, devToolsServerAddress: json['devToolsServerAddress'] != null ? Uri.parse(json['devToolsServerAddress']! as String) : null, port: json['port'] as String?, hostname: json['hostname'] as String?, webEnableExposeUrl: json['webEnableExposeUrl'] as bool?, - webUseSseForDebugProxy: (json['webUseSseForDebugProxy'] as bool?)!, - webUseSseForDebugBackend: (json['webUseSseForDebugBackend'] as bool?)!, - webUseSseForInjectedClient: (json['webUseSseForInjectedClient'] as bool?)!, - webRunHeadless: (json['webRunHeadless'] as bool?)!, + webUseSseForDebugProxy: json['webUseSseForDebugProxy']! as bool, + webUseSseForDebugBackend: json['webUseSseForDebugBackend']! as bool, + webUseSseForInjectedClient: json['webUseSseForInjectedClient']! as bool, + webRunHeadless: json['webRunHeadless']! as bool, webBrowserDebugPort: json['webBrowserDebugPort'] as int?, - webBrowserFlags: ((json['webBrowserFlags'] as List?)?.cast())!, - webEnableExpressionEvaluation: (json['webEnableExpressionEvaluation'] as bool?)!, + webBrowserFlags: (json['webBrowserFlags']! as List).cast(), + webEnableExpressionEvaluation: json['webEnableExpressionEvaluation']! as bool, webLaunchUrl: json['webLaunchUrl'] as String?, vmserviceOutFile: json['vmserviceOutFile'] as String?, - fastStart: (json['fastStart'] as bool?)!, - nullAssertions: (json['nullAssertions'] as bool?)!, - nativeNullAssertions: (json['nativeNullAssertions'] as bool?)!, + fastStart: json['fastStart']! as bool, + nullAssertions: json['nullAssertions']! as bool, + nativeNullAssertions: json['nativeNullAssertions']! as bool, enableImpeller: (json['enableImpeller'] as bool?) ?? false, uninstallFirst: (json['uninstallFirst'] as bool?) ?? false, enableDartProfiling: (json['enableDartProfiling'] as bool?) ?? true, diff --git a/packages/flutter_tools/test/general.shard/application_package_test.dart b/packages/flutter_tools/test/general.shard/application_package_test.dart index 1fa60d37c68..ce2d400b7fa 100644 --- a/packages/flutter_tools/test/general.shard/application_package_test.dart +++ b/packages/flutter_tools/test/general.shard/application_package_test.dart @@ -292,7 +292,7 @@ void main() { globals.fs.directory('bundle.app').createSync(); globals.fs.file('bundle.app/Info.plist').createSync(); testPlistParser.setProperty('CFBundleIdentifier', 'fooBundleId'); - final PrebuiltIOSApp iosApp = (IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app')) as PrebuiltIOSApp?)!; + final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app'))! as PrebuiltIOSApp; expect(testLogger.errorText, isEmpty); expect(iosApp.uncompressedBundle.path, 'bundle.app'); expect(iosApp.id, 'fooBundleId'); @@ -343,7 +343,7 @@ void main() { .file(globals.fs.path.join(bundleAppDir.path, 'Info.plist')) .createSync(); }; - final PrebuiltIOSApp iosApp = (IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa')) as PrebuiltIOSApp?)!; + final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa'))! as PrebuiltIOSApp; expect(testLogger.errorText, isEmpty); expect(iosApp.uncompressedBundle.path, endsWith('bundle.app')); expect(iosApp.id, 'fooBundleId'); @@ -594,7 +594,7 @@ void main() { testUsingContext('Success with far file', () { globals.fs.file('bundle.far').createSync(); - final PrebuiltFuchsiaApp fuchsiaApp = (FuchsiaApp.fromPrebuiltApp(globals.fs.file('bundle.far')) as PrebuiltFuchsiaApp?)!; + final PrebuiltFuchsiaApp fuchsiaApp = FuchsiaApp.fromPrebuiltApp(globals.fs.file('bundle.far'))! as PrebuiltFuchsiaApp; expect(testLogger.errorText, isEmpty); expect(fuchsiaApp.id, 'bundle.far'); expect(fuchsiaApp.applicationPackage.path, globals.fs.file('bundle.far').path); diff --git a/packages/flutter_tools/test/general.shard/dap/mocks.dart b/packages/flutter_tools/test/general.shard/dap/mocks.dart index 07618e93039..fba7f22cf6e 100644 --- a/packages/flutter_tools/test/general.shard/dap/mocks.dart +++ b/packages/flutter_tools/test/general.shard/dap/mocks.dart @@ -117,8 +117,8 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter { // Pretend to be the client, delegating any reverse-requests to the relevant // handler that is provided by the test. if (message is Event && message.event == 'flutter.forwardedRequest') { - final Map body = (message.body as Map?)!; - final String method = (body['method'] as String?)!; + final Map body = message.body! as Map; + final String method = body['method']! as String; final Map? params = body['params'] as Map?; final Object? result = _handleReverseRequest(method, params); @@ -138,7 +138,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter { Object? _handleReverseRequest(String method, Map? params) { switch (method) { case 'app.exposeUrl': - final String url = (params!['url'] as String?)!; + final String url = params!['url']! as String; return exposeUrlHandler!(url); default: throw ArgumentError('Reverse-request $method is unknown'); diff --git a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart index 71e91354cb2..0d5f132f486 100644 --- a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart +++ b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart @@ -193,6 +193,6 @@ bool _isHotReloadCompletionEvent(Map? event) { return event != null && event['event'] == 'app.progress' && event['params'] != null && - (event['params'] as Map?)!['progressId'] == 'hot.reload' && - (event['params'] as Map?)!['finished'] == true; + (event['params']! as Map)['progressId'] == 'hot.reload' && + (event['params']! as Map)['finished'] == true; } diff --git a/packages/flutter_tools/test/integration.shard/template_manifest_test.dart b/packages/flutter_tools/test/integration.shard/template_manifest_test.dart index 6709b13742a..80741f70c32 100644 --- a/packages/flutter_tools/test/integration.shard/template_manifest_test.dart +++ b/packages/flutter_tools/test/integration.shard/template_manifest_test.dart @@ -14,7 +14,7 @@ void main() { fileSystem.file('templates/template_manifest.json').readAsStringSync(), ) as Map; final Set declaredFileList = Set.from( - (manifest['files'] as List?)!.cast().map(fileSystem.path.toUri)); + (manifest['files']! as List).cast().map(fileSystem.path.toUri)); final Set activeTemplateList = fileSystem.directory('templates') .listSync(recursive: true)