Skip to content

Commit

Permalink
Enable private field promotion for flutter_tools (#134474)
Browse files Browse the repository at this point in the history
New feature in upcoming Dart 3.2. See dart-lang/language#2020. Feature is enabled by bumping the min SDK version to 3.2.

Part of flutter/flutter#134476.
  • Loading branch information
goderbauer authored Sep 12, 2023
1 parent 0573340 commit 240825a
Show file tree
Hide file tree
Showing 46 changed files with 98 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class AndroidDevices extends PollingDeviceDiscovery {

bool _doesNotHaveAdb() {
return _androidSdk == null ||
_androidSdk?.adbPath == null ||
!_processManager.canRun(_androidSdk!.adbPath);
_androidSdk.adbPath == null ||
!_processManager.canRun(_androidSdk.adbPath);
}

// 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AndroidEmulator extends Emulator {
@override
PlatformType get platformType => PlatformType.android;

String? _prop(String name) => _properties != null ? _properties![name] : null;
String? _prop(String name) => _properties != null ? _properties[name] : null;

@override
Future<void> launch({@visibleForTesting Duration? startupDuration, bool coldBoot = false}) async {
Expand Down
24 changes: 12 additions & 12 deletions packages/flutter_tools/lib/src/android/android_workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class AndroidWorkflow implements Workflow {

@override
bool get canListDevices => appliesToHostPlatform && _androidSdk != null
&& _androidSdk?.adbPath != null;
&& _androidSdk.adbPath != null;

@override
bool get canLaunchDevices => appliesToHostPlatform && _androidSdk != null
&& _androidSdk?.adbPath != null
&& (_androidSdk?.validateSdkWellFormed().isEmpty ?? false);
&& _androidSdk.adbPath != null
&& _androidSdk.validateSdkWellFormed().isEmpty;

@override
bool get canListEmulators => canListDevices && _androidSdk?.emulatorPath != null;
Expand Down Expand Up @@ -105,13 +105,13 @@ class AndroidValidator extends DoctorValidator {
return false;
}
messages.add(ValidationMessage(_userMessages.androidJdkLocation(_java!.binaryPath)));
if (!_java!.canRun()) {
messages.add(ValidationMessage.error(_userMessages.androidCantRunJavaBinary(_java!.binaryPath)));
if (!_java.canRun()) {
messages.add(ValidationMessage.error(_userMessages.androidCantRunJavaBinary(_java.binaryPath)));
return false;
}
Version? javaVersion;
try {
javaVersion = _java!.version;
javaVersion = _java.version;
} on Exception catch (error) {
_logger.printTrace(error.toString());
}
Expand Down Expand Up @@ -253,13 +253,13 @@ class AndroidLicenseValidator extends DoctorValidator {
final List<ValidationMessage> messages = <ValidationMessage>[];

// Match pre-existing early termination behavior
if (_androidSdk == null || _androidSdk?.latestVersion == null ||
_androidSdk!.validateSdkWellFormed().isNotEmpty ||
if (_androidSdk == null || _androidSdk.latestVersion == null ||
_androidSdk.validateSdkWellFormed().isNotEmpty ||
! await _checkJavaVersionNoOutput()) {
return ValidationResult(ValidationType.missing, messages);
}

final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk!.latestVersion!.buildToolsVersionName);
final String sdkVersionText = _userMessages.androidStatusInfo(_androidSdk.latestVersion!.buildToolsVersionName);

// Check for licenses.
switch (await licensesAccepted) {
Expand Down Expand Up @@ -371,7 +371,7 @@ class AndroidLicenseValidator extends DoctorValidator {

try {
final Process process = await _processManager.start(
<String>[_androidSdk!.sdkManagerPath!, '--licenses'],
<String>[_androidSdk.sdkManagerPath!, '--licenses'],
environment: _java?.environment,
);

Expand Down Expand Up @@ -404,15 +404,15 @@ class AndroidLicenseValidator extends DoctorValidator {
final int exitCode = await process.exitCode;
if (exitCode != 0) {
throwToolExit(_userMessages.androidCannotRunSdkManager(
_androidSdk?.sdkManagerPath ?? '',
_androidSdk.sdkManagerPath ?? '',
'exited code $exitCode',
_platform,
));
}
return true;
} on ProcessException catch (e) {
throwToolExit(_userMessages.androidCannotRunSdkManager(
_androidSdk?.sdkManagerPath ?? '',
_androidSdk.sdkManagerPath ?? '',
e.toString(),
_platform,
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class AndroidStudioJavaGradleConflictMigration extends ProjectMigrator {
return;
}

if (_androidStudio == null || _androidStudio!.version == null) {
if (_androidStudio == null || _androidStudio.version == null) {
logger.printTrace(androidStudioNotFound);
return;
} else if (_androidStudio!.version!.major < androidStudioFlamingo.major) {
} else if (_androidStudio.version!.major < androidStudioFlamingo.major) {
logger.printTrace(androidStudioVersionBelowFlamingo);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/base/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AppContext {
T? get<T>() {
dynamic value = _generateIfNecessary(T, _overrides);
if (value == null && _parent != null) {
value = _parent!.get<T>();
value = _parent.get<T>();
}
return _unboxNull(value ?? _generateIfNecessary(T, _fallbacks)) as T?;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class Cache {
/// Return the top-level directory in the cache; this is `bin/cache`.
Directory getRoot() {
if (_rootOverride != null) {
return _fileSystem.directory(_fileSystem.path.join(_rootOverride!.path, 'bin', 'cache'));
return _fileSystem.directory(_fileSystem.path.join(_rootOverride.path, 'bin', 'cache'));
} else {
return _fileSystem.directory(_fileSystem.path.join(flutterRoot!, 'bin', 'cache'));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/commands/attach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
logger: _logger,
),
notifyingLogger: (_logger is NotifyingLogger)
? _logger as NotifyingLogger
? _logger
: NotifyingLogger(verbose: _logger.isVerbose, parent: _logger),
logToStdout: true,
)
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/commands/update_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ Directory createTemporaryFlutterSdk(
// Fill in SDK dependency constraint.
output.write('''
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
''');

output.writeln('dependencies:');
Expand Down Expand Up @@ -1785,7 +1785,7 @@ description: Dart SDK extensions for dart:ui
homepage: http://flutter.io
# sky_engine requires sdk_ext support in the analyzer which was added in 1.11.x
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
''');

return directory;
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class DeviceDiscoverySupportFilter {
if (_flutterProject == null) {
return true;
}
return device.isSupportedForProject(_flutterProject!);
return device.isSupportedForProject(_flutterProject);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/ios/application_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class BuildableIOSApp extends IOSApp {
// not a top-level output directory.
// Specifying `build/ios/archive/Runner` will result in `build/ios/archive/Runner.xcarchive`.
String get archiveBundlePath => globals.fs.path.join(getIosBuildDirectory(), 'archive',
_hostAppBundleName == null ? 'Runner' : globals.fs.path.withoutExtension(_hostAppBundleName!));
_hostAppBundleName == null ? 'Runner' : globals.fs.path.withoutExtension(_hostAppBundleName));

// The output xcarchive bundle path `build/ios/archive/Runner.xcarchive`.
String get archiveBundleOutputPath =>
Expand All @@ -150,7 +150,7 @@ class BuildableIOSApp extends IOSApp {
String get builtInfoPlistPathAfterArchive => globals.fs.path.join(archiveBundleOutputPath,
'Products',
'Applications',
_hostAppBundleName == null ? 'Runner.app' : _hostAppBundleName!,
_hostAppBundleName ?? 'Runner.app',
'Info.plist');

String get projectAppIconDirName => _projectImageAssetDirName(_appIconAsset);
Expand Down
18 changes: 9 additions & 9 deletions packages/flutter_tools/lib/src/resident_devtools_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
return;
}
if (devToolsServerAddress != null) {
_devToolsLauncher!.devToolsUrl = devToolsServerAddress;
_devToolsLauncher.devToolsUrl = devToolsServerAddress;
} else {
await _devToolsLauncher!.serve();
await _devToolsLauncher.serve();
_served = true;
}
await _devToolsLauncher!.ready;
await _devToolsLauncher.ready;
// Do not attempt to print debugger list if the connection has failed or if we're shutting down.
if (_devToolsLauncher!.activeDevToolsServer == null || _shutdown) {
if (_devToolsLauncher.activeDevToolsServer == null || _shutdown) {
assert(!_readyToAnnounce);
return;
}

final Uri? devToolsUrl = _devToolsLauncher!.devToolsUrl;
final Uri? devToolsUrl = _devToolsLauncher.devToolsUrl;
if (devToolsUrl != null) {
for (final FlutterDevice? device in flutterDevices) {
if (device == null) {
Expand Down Expand Up @@ -130,7 +130,7 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
}

_readyToAnnounce = true;
assert(_devToolsLauncher!.activeDevToolsServer != null);
assert(_devToolsLauncher.activeDevToolsServer != null);
if (_residentRunner.reportedDebuggers) {
// Since the DevTools only just became available, we haven't had a chance to
// report their URLs yet. Do so now.
Expand All @@ -148,9 +148,9 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
if (!_residentRunner.supportsServiceProtocol || _devToolsLauncher == null) {
return false;
}
if (_devToolsLauncher!.devToolsUrl == null) {
if (_devToolsLauncher.devToolsUrl == null) {
_logger.startProgress('Waiting for Flutter DevTools to be served...');
unawaited(_devToolsLauncher!.ready.then((_) {
unawaited(_devToolsLauncher.ready.then((_) {
_launchDevToolsForDevices(flutterDevices);
}));
} else {
Expand Down Expand Up @@ -294,7 +294,7 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
}
_shutdown = true;
_readyToAnnounce = false;
await _devToolsLauncher!.close();
await _devToolsLauncher.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/resident_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ class TerminalHandler {
_addSignalHandler(io.ProcessSignal.sigusr2, _handleSignal);
if (_pidFile != null) {
_logger.printTrace('Writing pid to: $_pidFile');
_actualPidFile = _processInfo.writePidFile(_pidFile!);
_actualPidFile = _processInfo.writePidFile(_pidFile);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/windows/visual_studio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class VisualStudio {
if (_bestVisualStudioDetails == null) {
return false;
}
return _bestVisualStudioDetails!.isComplete ?? true;
return _bestVisualStudioDetails.isComplete ?? true;
}

/// True if Visual Studio is launchable.
Expand All @@ -91,7 +91,7 @@ class VisualStudio {
if (_bestVisualStudioDetails == null) {
return false;
}
return _bestVisualStudioDetails!.isLaunchable ?? true;
return _bestVisualStudioDetails.isLaunchable ?? true;
}

/// True if the Visual Studio installation is a pre-release version.
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Tools for building Flutter applications
homepage: https://flutter.dev

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'

dependencies:
# To update these, use "flutter update-packages --force-upgrade".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void main() {
pubspecFile.writeAsStringSync('''
name: foo_project
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
''');

final File dartFile = fileSystem.file(fileSystem.path.join(directory.path, 'lib', 'main.dart'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ format: true
pubspecFile.writeAsStringSync('''
name: test
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
dependencies:
flutter:
Expand Down Expand Up @@ -466,7 +466,7 @@ format: true
pubspecFile.writeAsStringSync('''
name: test
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ description: A framework for writing Flutter applications
homepage: http://flutter.dev
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
dependencies:
# To update these, use "flutter update-packages --force-upgrade".
Expand Down Expand Up @@ -60,7 +60,7 @@ homepage: http://flutter.dev
version: 1.0.0
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
flutter: ">=2.5.0-6.0.pre.30 <3.0.0"
dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: font
description: A test project that contains a font.

environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'

flutter:
uses-material-design: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: main
description: A test project that has a package with a font as a dependency.

environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'

dependencies:
font:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ class TestTarget extends Target {
@override
bool canSkip(Environment environment) {
if (_canSkip != null) {
return _canSkip!(environment);
return _canSkip(environment);
}
return super.canSkip(environment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ flutter:
pluginClass: none
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
flutter: ">=1.20.0"
''';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ flutter:
linux:
dartPluginClass: APlugin
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
flutter: ">=2.5.0"
''');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description: A framework for writing Flutter applications
homepage: http://flutter.dev
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
dependencies:
# To update these, use "flutter update-packages --force-upgrade".
Expand Down Expand Up @@ -51,7 +51,7 @@ description: A dummy pubspec with no dependencies
homepage: http://flutter.dev
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
''';

const String kInvalidGitPubspec = '''
Expand All @@ -60,7 +60,7 @@ description: A framework for writing Flutter applications
homepage: http://flutter.dev
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
dependencies:
# To update these, use "flutter update-packages --force-upgrade".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class _MyHomePageState extends State<MyHomePage> {
const String pubspecYamlSrc = r'''
name: flutter_project
environment:
sdk: '>=3.0.0-0 <4.0.0'
sdk: '>=3.2.0-0 <4.0.0'
dependencies:
flutter:
Expand Down
Loading

0 comments on commit 240825a

Please sign in to comment.