Commit 8bcf302e authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

use conditional assignment (#9252)

parent 3eb87830
......@@ -60,9 +60,7 @@ abstract class SyntaxHighlighter { // ignore: one_member_abstracts
class DartSyntaxHighlighter extends SyntaxHighlighter {
DartSyntaxHighlighter([this._style]) {
_spans = <_HighlightSpan>[];
if (_style == null)
_style = SyntaxHighlighterStyle.darkThemeStyle();
_style ??= SyntaxHighlighterStyle.darkThemeStyle();
}
SyntaxHighlighterStyle _style;
......
......@@ -78,8 +78,7 @@ Duration timeBase;
RenderTransform transformBox;
void rotate(Duration timeStamp) {
if (timeBase == null)
timeBase = timeStamp;
timeBase ??= timeStamp;
final double delta = (timeStamp - timeBase).inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND; // radians
transformBox.setIdentity();
......
......@@ -577,10 +577,8 @@ class BoxShadow {
static List<BoxShadow> lerpList(List<BoxShadow> a, List<BoxShadow> b, double t) {
if (a == null && b == null)
return null;
if (a == null)
a = <BoxShadow>[];
if (b == null)
b = <BoxShadow>[];
a ??= <BoxShadow>[];
b ??= <BoxShadow>[];
final List<BoxShadow> result = <BoxShadow>[];
final int commonLength = math.min(a.length, b.length);
for (int i = 0; i < commonLength; ++i)
......
......@@ -1482,8 +1482,7 @@ abstract class RenderBox extends RenderObject {
@mustCallSuper
double getDistanceToActualBaseline(TextBaseline baseline) {
assert(_debugDoingBaseline);
if (_cachedBaselines == null)
_cachedBaselines = <TextBaseline, double>{};
_cachedBaselines ??= <TextBaseline, double>{};
_cachedBaselines.putIfAbsent(baseline, () => computeDistanceToActualBaseline(baseline));
return _cachedBaselines[baseline];
}
......
......@@ -203,8 +203,7 @@ class ContainerLayer extends Layer {
if (_lastChild != null)
_lastChild._nextSibling = child;
_lastChild = child;
if (_firstChild == null)
_firstChild = child;
_firstChild ??= child;
}
void _remove(Layer child) {
......
......@@ -2697,8 +2697,7 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent
_firstChildParentData.previousSibling = child;
}
_firstChild = child;
if (_lastChild == null)
_lastChild = child;
_lastChild ??= child;
} else {
assert(_firstChild != null);
assert(_lastChild != null);
......
......@@ -199,8 +199,7 @@ class Ticker {
assert(scheduled);
_animationId = null;
if (_startTime == null)
_startTime = timeStamp;
_startTime ??= timeStamp;
_onTick(timeStamp - _startTime);
......
......@@ -132,8 +132,7 @@ class FocusScopeNode extends Object with TreeDiagnosticsMixin {
if (_firstChild != null)
_firstChild._previousSibling = child;
_firstChild = child;
if (_lastChild == null)
_lastChild = child;
_lastChild ??= child;
child._updateManager(_manager);
}
......
......@@ -24,8 +24,7 @@ class TestGestureFlutterBinding extends BindingBase with GestureBinding {
TestGestureFlutterBinding _binding = new TestGestureFlutterBinding();
void ensureTestGestureBinding() {
if (_binding == null)
_binding = new TestGestureFlutterBinding();
_binding ??= new TestGestureFlutterBinding();
assert(GestureBinding.instance != null);
}
......
......@@ -430,12 +430,7 @@ class AndroidDevice extends Device {
}
@override
DevicePortForwarder get portForwarder {
if (_portForwarder == null)
_portForwarder = new _AndroidDevicePortForwarder(this);
return _portForwarder;
}
DevicePortForwarder get portForwarder => _portForwarder ??= new _AndroidDevicePortForwarder(this);
static final RegExp _timeRegExp = new RegExp(r'^\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}', multiLine: true);
......
......@@ -116,8 +116,7 @@ class _PosixUtils extends OperatingSystemUtils {
.trim()} ${results[2].stdout.trim()}";
}
}
if (_name == null)
_name = super.name;
_name ??= super.name;
}
return _name;
}
......
......@@ -86,12 +86,7 @@ class Cache {
static String _dartSdkVersion;
static String get dartSdkVersion {
if (_dartSdkVersion == null) {
_dartSdkVersion = platform.version;
}
return _dartSdkVersion;
}
static String get dartSdkVersion => _dartSdkVersion ??= platform.version;
static String _engineRevision;
......
......@@ -724,8 +724,7 @@ class AppInstance {
}
dynamic _runInZone(AppDomain domain, dynamic method()) {
if (_logger == null)
_logger = new _AppRunLogger(domain, this, logToStdout: logToStdout);
_logger ??= new _AppRunLogger(domain, this, logToStdout: logToStdout);
final AppContext appContext = new AppContext();
appContext.setVariable(Logger, _logger);
......
......@@ -34,8 +34,7 @@ Future<Null> pubGet({
bool offline: false,
bool checkLastModified: true
}) async {
if (directory == null)
directory = fs.currentDirectory.path;
directory ??= fs.currentDirectory.path;
final File pubSpecYaml = fs.file(fs.path.join(directory, 'pubspec.yaml'));
final File dotPackages = fs.file(fs.path.join(directory, '.packages'));
......
......@@ -97,8 +97,7 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
void startPolling() {
if (_timer == null) {
if (_items == null)
_items = new ItemListNotifier<Device>();
_items ??= new ItemListNotifier<Device>();
_timer = new Timer.periodic(_pollingDuration, (Timer timer) {
_items.updateWithNewList(pollingGetDevices());
});
......@@ -112,20 +111,17 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
@override
List<Device> get devices {
if (_items == null)
_items = new ItemListNotifier<Device>.from(pollingGetDevices());
_items ??= new ItemListNotifier<Device>.from(pollingGetDevices());
return _items.items;
}
Stream<Device> get onAdded {
if (_items == null)
_items = new ItemListNotifier<Device>();
_items ??= new ItemListNotifier<Device>();
return _items.onAdded;
}
Stream<Device> get onRemoved {
if (_items == null)
_items = new ItemListNotifier<Device>();
_items ??= new ItemListNotifier<Device>();
return _items.onRemoved;
}
......
......@@ -357,12 +357,7 @@ class IOSDevice extends Device {
}
@override
DevicePortForwarder get portForwarder {
if (_portForwarder == null)
_portForwarder = new _IOSDevicePortForwarder(this);
return _portForwarder;
}
DevicePortForwarder get portForwarder => _portForwarder ??= new _IOSDevicePortForwarder(this);
@override
void clearLogs() {
......
......@@ -565,12 +565,7 @@ class IOSSimulator extends Device {
}
@override
DevicePortForwarder get portForwarder {
if (_portForwarder == null)
_portForwarder = new _IOSSimulatorDevicePortForwarder(this);
return _portForwarder;
}
DevicePortForwarder get portForwarder => _portForwarder ??= new _IOSSimulatorDevicePortForwarder(this);
@override
void clearLogs() {
......
......@@ -406,8 +406,7 @@ class OperationResult {
/// Given the value of the --target option, return the path of the Dart file
/// where the app's main function should be.
String findMainDartFile([String target]) {
if (target == null)
target = '';
target ??= '';
final String targetPath = fs.path.absolute(target);
if (fs.isDirectorySync(targetPath))
return fs.path.join(targetPath, 'lib', 'main.dart');
......
......@@ -286,8 +286,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
engineSourcePath = null;
}
if (engineSourcePath == null)
engineSourcePath = _tryEnginePath(fs.path.join(Cache.flutterRoot, '../engine/src'));
engineSourcePath ??= _tryEnginePath(fs.path.join(Cache.flutterRoot, '../engine/src'));
if (engineSourcePath == null) {
printError('Unable to detect local Flutter engine build directory.\n'
......@@ -327,8 +326,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
}
static void initFlutterRoot() {
if (Cache.flutterRoot == null)
Cache.flutterRoot = _defaultFlutterRoot;
Cache.flutterRoot ??= _defaultFlutterRoot;
}
/// Get all pub packages in the Flutter repo.
......
......@@ -266,11 +266,9 @@ abstract class ServiceObject {
serviceObject = new Isolate._empty(owner.vm);
break;
}
if (serviceObject == null) {
// If we don't have a model object for this service object type, as a
// fallback return a ServiceMap object.
serviceObject = new ServiceMap._empty(owner);
}
// If we don't have a model object for this service object type, as a
// fallback return a ServiceMap object.
serviceObject ??= new ServiceMap._empty(owner);
// We have now constructed an emtpy service object, call update to
// populate it.
serviceObject.update(map);
......
......@@ -43,19 +43,12 @@ class RecordingVMServiceChannel extends DelegatingStreamChannel<String> {
@override
Stream<String> get stream {
if (_streamRecorder == null) {
_streamRecorder = new _RecordingStream(super.stream, _messages);
}
_streamRecorder ??= new _RecordingStream(super.stream, _messages);
return _streamRecorder.stream;
}
@override
StreamSink<String> get sink {
if (_sinkRecorder == null) {
_sinkRecorder = new _RecordingSink(super.sink, _messages);
}
return _sinkRecorder;
}
StreamSink<String> get sink => _sinkRecorder ??= new _RecordingSink(super.sink, _messages);
}
/// Base class for request and response JSON-rpc messages.
......@@ -250,11 +243,7 @@ class ReplayVMServiceChannel extends StreamChannelMixin<String> {
}
@override
StreamSink<String> get sink {
if (_replaySink == null)
_replaySink = new _ReplaySink(this);
return _replaySink;
}
StreamSink<String> get sink => _replaySink ??= new _ReplaySink(this);
@override
Stream<String> get stream => _controller.stream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment