From e6535f6da1a2649b46a3ed1318def576ad4fb87a Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 26 Aug 2021 14:01:05 -0700 Subject: [PATCH] Changed tool cached properties to late finals (#88923) --- .../lib/src/android/android_sdk.dart | 3 +-- packages/flutter_tools/lib/src/cache.dart | 3 +-- .../flutter_tools/lib/src/cmake_project.dart | 6 ++--- packages/flutter_tools/lib/src/ios/mac.dart | 3 +-- .../lib/src/platform_plugins.dart | 4 +-- packages/flutter_tools/lib/src/project.dart | 27 +++++++------------ .../lib/src/test/font_config_manager.dart | 17 +++++------- .../lib/src/windows/visual_studio.dart | 14 ++++------ 8 files changed, 26 insertions(+), 51 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/android_sdk.dart b/packages/flutter_tools/lib/src/android/android_sdk.dart index ccfe68d274e..ba3d01f6384 100644 --- a/packages/flutter_tools/lib/src/android/android_sdk.dart +++ b/packages/flutter_tools/lib/src/android/android_sdk.dart @@ -169,8 +169,7 @@ class AndroidSdk { AndroidSdkVersion? get latestVersion => _latestVersion; - String? get adbPath => _adbPath ??= getPlatformToolsPath(globals.platform.isWindows ? 'adb.exe' : 'adb'); - String? _adbPath; + late final String? adbPath = getPlatformToolsPath(globals.platform.isWindows ? 'adb.exe' : 'adb'); String? get emulatorPath => getEmulatorPath(); diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index d2e0a631a89..ced7928d44e 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -163,8 +163,7 @@ class Cache { final Net _net; final FileSystemUtils _fsUtils; - ArtifactUpdater get _artifactUpdater => __artifactUpdater ??= _createUpdater(); - ArtifactUpdater? __artifactUpdater; + late final ArtifactUpdater _artifactUpdater = _createUpdater(); @protected void registerArtifact(ArtifactSet artifactSet) { diff --git a/packages/flutter_tools/lib/src/cmake_project.dart b/packages/flutter_tools/lib/src/cmake_project.dart index dbd3fff1f53..84ca7af08d1 100644 --- a/packages/flutter_tools/lib/src/cmake_project.dart +++ b/packages/flutter_tools/lib/src/cmake_project.dart @@ -97,13 +97,11 @@ class WindowsUwpProject extends WindowsProject { int? get projectVersion => int.tryParse(_editableDirectory.childFile('project_version').readAsStringSync()); /// Retrieve the GUID of the UWP package. - String? get packageGuid => _packageGuid ??= getCmakePackageGuid(runnerCmakeFile); - String? _packageGuid; + late final String? packageGuid = getCmakePackageGuid(runnerCmakeFile); File get appManifest => _editableDirectory.childDirectory('runner_uwp').childFile('appxmanifest.in'); - String? get packageVersion => _packageVersion ??= parseAppVersion(this); - String? _packageVersion; + late final String? packageVersion = parseAppVersion(this); } @visibleForTesting diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index b0cb6cc1a41..2ae98e67ae6 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -50,8 +50,7 @@ class IMobileDevice { final ProcessManager _processManager; final ProcessUtils _processUtils; - bool get isInstalled => _isInstalled ??= _processManager.canRun(_idevicescreenshotPath); - bool? _isInstalled; + late final bool isInstalled = _processManager.canRun(_idevicescreenshotPath); /// Starts `idevicesyslog` and returns the running process. Future startLogger(String deviceID) { diff --git a/packages/flutter_tools/lib/src/platform_plugins.dart b/packages/flutter_tools/lib/src/platform_plugins.dart index 799f43d5ec0..7e9277b614b 100644 --- a/packages/flutter_tools/lib/src/platform_plugins.dart +++ b/packages/flutter_tools/lib/src/platform_plugins.dart @@ -106,10 +106,8 @@ class AndroidPlugin extends PluginPlatform { }; } - Set? _cachedEmbeddingVersion; - /// Returns the version of the Android embedding. - Set get _supportedEmbeddings => _cachedEmbeddingVersion ??= _getSupportedEmbeddings(); + late final Set _supportedEmbeddings = _getSupportedEmbeddings(); Set _getSupportedEmbeddings() { assert(pluginPath != null); diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart index 1454d8f05fa..1239f600075 100644 --- a/packages/flutter_tools/lib/src/project.dart +++ b/packages/flutter_tools/lib/src/project.dart @@ -163,36 +163,28 @@ class FlutterProject { } /// The iOS sub project of this project. - IosProject? _ios; - IosProject get ios => _ios ??= IosProject.fromFlutter(this); + late final IosProject ios = IosProject.fromFlutter(this); /// The Android sub project of this project. - AndroidProject? _android; - AndroidProject get android => _android ??= AndroidProject._(this); + late final AndroidProject android = AndroidProject._(this); /// The web sub project of this project. - WebProject? _web; - WebProject get web => _web ??= WebProject._(this); + late final WebProject web = WebProject._(this); /// The MacOS sub project of this project. - MacOSProject? _macos; - MacOSProject get macos => _macos ??= MacOSProject.fromFlutter(this); + late final MacOSProject macos = MacOSProject.fromFlutter(this); /// The Linux sub project of this project. - LinuxProject? _linux; - LinuxProject get linux => _linux ??= LinuxProject.fromFlutter(this); + late final LinuxProject linux = LinuxProject.fromFlutter(this); /// The Windows sub project of this project. - WindowsProject? _windows; - WindowsProject get windows => _windows ??= WindowsProject.fromFlutter(this); + late final WindowsProject windows = WindowsProject.fromFlutter(this); /// The Windows UWP sub project of this project. - WindowsUwpProject? _windowUwp; - WindowsUwpProject get windowsUwp => _windowUwp ??= WindowsUwpProject.fromFlutter(this); + late final WindowsUwpProject windowsUwp = WindowsUwpProject.fromFlutter(this); /// The Fuchsia sub project of this project. - FuchsiaProject? _fuchsia; - FuchsiaProject get fuchsia => _fuchsia ??= FuchsiaProject._(this); + late final FuchsiaProject fuchsia = FuchsiaProject._(this); /// The `pubspec.yaml` file of this project. File get pubspecFile => directory.childFile('pubspec.yaml'); @@ -414,8 +406,7 @@ class AndroidProject extends FlutterProjectPlatform { bool get usesAndroidX => parent.usesAndroidX; /// Returns true if the current version of the Gradle plugin is supported. - bool get isSupportedVersion => _isSupportedVersion ??= _computeSupportedVersion(); - bool? _isSupportedVersion; + late final bool isSupportedVersion = _computeSupportedVersion(); bool _computeSupportedVersion() { final FileSystem fileSystem = hostAppGradleRoot.fileSystem; diff --git a/packages/flutter_tools/lib/src/test/font_config_manager.dart b/packages/flutter_tools/lib/src/test/font_config_manager.dart index 7a47849e4ff..77158d7e49f 100644 --- a/packages/flutter_tools/lib/src/test/font_config_manager.dart +++ b/packages/flutter_tools/lib/src/test/font_config_manager.dart @@ -10,15 +10,10 @@ import '../globals_null_migrated.dart' as globals; /// Manages a Font configuration that can be shared across multiple tests. class FontConfigManager { Directory? _fontsDirectory; - File? _cachedFontConfig; /// Returns a Font configuration that limits font fallback to the artifact /// cache directory. - File get fontConfigFile { - if (_cachedFontConfig != null) { - return _cachedFontConfig!; - } - + late final File fontConfigFile = (){ final StringBuffer sb = StringBuffer(); sb.writeln(''); sb.writeln(' ${globals.cache.getCacheArtifacts().path}'); @@ -30,11 +25,11 @@ class FontConfigManager { globals.printTrace('Using this directory for fonts configuration: ${_fontsDirectory!.path}'); } - _cachedFontConfig = globals.fs.file('${_fontsDirectory!.path}/fonts.conf'); - _cachedFontConfig!.createSync(); - _cachedFontConfig!.writeAsStringSync(sb.toString()); - return _cachedFontConfig!; - } + final File cachedFontConfig = globals.fs.file('${_fontsDirectory!.path}/fonts.conf'); + cachedFontConfig.createSync(); + cachedFontConfig.writeAsStringSync(sb.toString()); + return cachedFontConfig; + }(); Future dispose() async { if (_fontsDirectory != null) { diff --git a/packages/flutter_tools/lib/src/windows/visual_studio.dart b/packages/flutter_tools/lib/src/windows/visual_studio.dart index f06b474818d..5fcf11e4c91 100644 --- a/packages/flutter_tools/lib/src/windows/visual_studio.dart +++ b/packages/flutter_tools/lib/src/windows/visual_studio.dart @@ -348,11 +348,7 @@ class VisualStudio { /// /// If no installation is found, the cached VS details are set to an empty map /// to avoid repeating vswhere queries that have already not found an installation. - Map? _cachedUsableVisualStudioDetails; - Map get _usableVisualStudioDetails { - if (_cachedUsableVisualStudioDetails != null) { - return _cachedUsableVisualStudioDetails!; - } + late final Map _usableVisualStudioDetails = (){ final List minimumVersionArguments = [ _vswhereMinVersionArgument, _minimumSupportedVersion.toString(), @@ -370,16 +366,16 @@ class VisualStudio { } } + Map? usableVisualStudioDetails; if (visualStudioDetails != null) { if (installationHasIssues(visualStudioDetails)) { _cachedAnyVisualStudioDetails = visualStudioDetails; } else { - _cachedUsableVisualStudioDetails = visualStudioDetails; + usableVisualStudioDetails = visualStudioDetails; } } - _cachedUsableVisualStudioDetails ??= {}; - return _cachedUsableVisualStudioDetails!; - } + return usableVisualStudioDetails ?? {}; + }(); /// Returns the details dictionary of the latest version of Visual Studio, /// regardless of components and version, or {} if no such installation is