From 44c0db9c57084d82a30e763cdde5d8ee3dcb4f94 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 16 Jan 2020 17:03:33 -0800 Subject: [PATCH] implicit casts and add missing docs (flutter/engine#15698) --- engine/src/flutter/analysis_options.yaml | 3 +- .../flutter_frontend_server/lib/server.dart | 6 +- engine/src/flutter/lib/ui/compositing.dart | 4 +- engine/src/flutter/lib/ui/geometry.dart | 66 ++++--- engine/src/flutter/lib/ui/hooks.dart | 9 +- engine/src/flutter/lib/ui/lerp.dart | 2 +- engine/src/flutter/lib/ui/natives.dart | 2 +- engine/src/flutter/lib/ui/painting.dart | 162 ++++++++++-------- engine/src/flutter/lib/ui/plugins.dart | 4 +- engine/src/flutter/lib/ui/text.dart | 121 ++++++------- engine/src/flutter/lib/ui/window.dart | 14 +- .../flutter/lib/web_ui/lib/src/ui/canvas.dart | 79 ++++++--- .../testing/dart/channel_buffers_test.dart | 2 +- .../testing/dart/compositing_test.dart | 34 ++-- .../dart/isolate_name_server_test.dart | 4 +- .../testing/scenario_app/lib/main.dart | 12 +- .../testing/symbols/verify_exported.dart | 6 +- 17 files changed, 284 insertions(+), 246 deletions(-) diff --git a/engine/src/flutter/analysis_options.yaml b/engine/src/flutter/analysis_options.yaml index 00c9eb0ab2..64c4409491 100644 --- a/engine/src/flutter/analysis_options.yaml +++ b/engine/src/flutter/analysis_options.yaml @@ -14,6 +14,7 @@ analyzer: # positives. exclude: [ testing/dart/window_hooks_integration_test.dart ] strong-mode: + implicit-casts: false implicit-dynamic: false errors: # treat missing required parameters as a warning (not a hint) @@ -39,7 +40,7 @@ linter: - always_specify_types - annotate_overrides # - avoid_annotating_with_dynamic # conflicts with always_specify_types - - avoid_as + # - avoid_as # required for implicit-casts: false # - avoid_bool_literals_in_conditional_expressions # not yet tested # - avoid_catches_without_on_clauses # we do this commonly # - avoid_catching_errors # we do this commonly diff --git a/engine/src/flutter/flutter_frontend_server/lib/server.dart b/engine/src/flutter/flutter_frontend_server/lib/server.dart index ddbe125a6d..036925de6c 100644 --- a/engine/src/flutter/flutter_frontend_server/lib/server.dart +++ b/engine/src/flutter/flutter_frontend_server/lib/server.dart @@ -101,13 +101,13 @@ Future starter( return 1; } - if (options['train']) { + if (options['train'] as bool) { if (!options.rest.isNotEmpty) { throw Exception('Must specify input.dart'); } final String input = options.rest[0]; - final String sdkRoot = options['sdk-root']; + final String sdkRoot = options['sdk-root'] as String; final Directory temp = Directory.systemTemp.createTempSync('train_frontend_server'); try { @@ -143,7 +143,7 @@ Future starter( compiler ??= _FlutterFrontendCompiler(output, transformer: transformer, - unsafePackageSerialization: options['unsafe-package-serialization']); + unsafePackageSerialization: options['unsafe-package-serialization'] as bool); if (options.rest.isNotEmpty) { return await compiler.compile(options.rest[0], options) ? 0 : 254; diff --git a/engine/src/flutter/lib/ui/compositing.dart b/engine/src/flutter/lib/ui/compositing.dart index cf73966e06..01a3550ae9 100644 --- a/engine/src/flutter/lib/ui/compositing.dart +++ b/engine/src/flutter/lib/ui/compositing.dart @@ -582,7 +582,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 { void addRetained(EngineLayer retainedLayer) { assert(retainedLayer is _EngineLayerWrapper); assert(() { - final _EngineLayerWrapper layer = retainedLayer; + final _EngineLayerWrapper layer = retainedLayer as _EngineLayerWrapper; void recursivelyCheckChildrenUsedOnce(_EngineLayerWrapper parentLayer) { _debugCheckUsedOnce(parentLayer, 'retained layer'); @@ -600,7 +600,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 { return true; }()); - final _EngineLayerWrapper wrapper = retainedLayer; + final _EngineLayerWrapper wrapper = retainedLayer as _EngineLayerWrapper; _addRetained(wrapper._nativeLayer); } diff --git a/engine/src/flutter/lib/ui/geometry.dart b/engine/src/flutter/lib/ui/geometry.dart index 822beb25c0..11849d3a8c 100644 --- a/engine/src/flutter/lib/ui/geometry.dart +++ b/engine/src/flutter/lib/ui/geometry.dart @@ -81,11 +81,9 @@ abstract class OffsetBase { /// the right-hand-side operand respectively. Returns false otherwise. @override bool operator ==(dynamic other) { - if (other is! OffsetBase) - return false; - final OffsetBase typedOther = other; - return _dx == typedOther._dx && - _dy == typedOther._dy; + return other is OffsetBase + && other._dx == _dx + && other._dy == _dy; } @override @@ -327,11 +325,9 @@ class Offset extends OffsetBase { /// Compares two Offsets for equality. @override bool operator ==(dynamic other) { - if (other is! Offset) - return false; - final Offset typedOther = other; - return dx == typedOther.dx && - dy == typedOther.dy; + return other is Offset + && other.dx == dx + && other.dy == dy; } @override @@ -595,11 +591,9 @@ class Size extends OffsetBase { // We don't compare the runtimeType because of _DebugSize in the framework. @override bool operator ==(dynamic other) { - if (other is! Size) - return false; - final Size typedOther = other; - return _dx == typedOther._dx && - _dy == typedOther._dy; + return other is Size + && other._dx == _dx + && other._dy == _dy; } @override @@ -877,11 +871,11 @@ class Rect { return true; if (runtimeType != other.runtimeType) return false; - final Rect typedOther = other; - return left == typedOther.left && - top == typedOther.top && - right == typedOther.right && - bottom == typedOther.bottom; + return other is Rect + && other.left == left + && other.top == top + && other.right == right + && other.bottom == bottom; } @override @@ -999,8 +993,10 @@ class Radius { return true; if (runtimeType != other.runtimeType) return false; - final Radius typedOther = other; - return typedOther.x == x && typedOther.y == y; + + return other is Radius + && other.x == x + && other.y == y; } @override @@ -1594,19 +1590,19 @@ class RRect { return true; if (runtimeType != other.runtimeType) return false; - final RRect typedOther = other; - return left == typedOther.left && - top == typedOther.top && - right == typedOther.right && - bottom == typedOther.bottom && - tlRadiusX == typedOther.tlRadiusX && - tlRadiusY == typedOther.tlRadiusY && - trRadiusX == typedOther.trRadiusX && - trRadiusY == typedOther.trRadiusY && - blRadiusX == typedOther.blRadiusX && - blRadiusY == typedOther.blRadiusY && - brRadiusX == typedOther.brRadiusX && - brRadiusY == typedOther.brRadiusY; + return other is RRect + && other.left == left + && other.top == top + && other.right == right + && other.bottom == bottom + && other.tlRadiusX == tlRadiusX + && other.tlRadiusY == tlRadiusY + && other.trRadiusX == trRadiusX + && other.trRadiusY == trRadiusY + && other.blRadiusX == blRadiusX + && other.blRadiusY == blRadiusY + && other.brRadiusX == brRadiusX + && other.brRadiusY == brRadiusY; } @override diff --git a/engine/src/flutter/lib/ui/hooks.dart b/engine/src/flutter/lib/ui/hooks.dart index 83ff3a1059..7972efc9f3 100644 --- a/engine/src/flutter/lib/ui/hooks.dart +++ b/engine/src/flutter/lib/ui/hooks.dart @@ -98,13 +98,13 @@ void _updateLocales(List locales) { @pragma('vm:entry-point') // ignore: unused_element void _updateUserSettingsData(String jsonData) { - final Map data = json.decode(jsonData); + final Map data = json.decode(jsonData) as Map; if (data.isEmpty) { return; } - _updateTextScaleFactor(data['textScaleFactor'].toDouble()); - _updateAlwaysUse24HourFormat(data['alwaysUse24HourFormat']); - _updatePlatformBrightness(data['platformBrightness']); + _updateTextScaleFactor((data['textScaleFactor'] as num).toDouble()); + _updateAlwaysUse24HourFormat(data['alwaysUse24HourFormat'] as bool); + _updatePlatformBrightness(data['platformBrightness'] as String); } @pragma('vm:entry-point') @@ -149,6 +149,7 @@ void _updateAccessibilityFeatures(int values) { } @pragma('vm:entry-point') +// ignore: unused_element void _dispatchPlatformMessage(String name, ByteData data, int responseId) { if (name == ChannelBuffers.kControlChannelName) { try { diff --git a/engine/src/flutter/lib/ui/lerp.dart b/engine/src/flutter/lib/ui/lerp.dart index 0c69476779..cf296ca925 100644 --- a/engine/src/flutter/lib/ui/lerp.dart +++ b/engine/src/flutter/lib/ui/lerp.dart @@ -10,5 +10,5 @@ double lerpDouble(num a, num b, double t) { return null; a ??= 0.0; b ??= 0.0; - return a + (b - a) * t; + return a + (b - a) * t as double; } diff --git a/engine/src/flutter/lib/ui/natives.dart b/engine/src/flutter/lib/ui/natives.dart index 841c925993..513595c869 100644 --- a/engine/src/flutter/lib/ui/natives.dart +++ b/engine/src/flutter/lib/ui/natives.dart @@ -71,7 +71,7 @@ List saveCompilationTrace() { final dynamic result = _saveCompilationTrace(); if (result is Error) throw result; - return result; + return result as List; } dynamic _saveCompilationTrace() native 'SaveCompilationTrace'; diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 9c6d3f9df3..89957f80ed 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -53,7 +53,7 @@ bool _radiusIsValid(Radius radius) { } Color _scaleAlpha(Color a, double factor) { - return a.withAlpha((a.alpha * factor).round().clamp(0, 255)); + return a.withAlpha((a.alpha * factor).round().clamp(0, 255) as int); } /// An immutable 32 bit color value in ARGB format. @@ -217,7 +217,7 @@ class Color { static double _linearizeColorComponent(double component) { if (component <= 0.03928) return component / 12.92; - return math.pow((component + 0.055) / 1.055, 2.4); + return math.pow((component + 0.055) / 1.055, 2.4) as double; } /// Returns a brightness value between 0 for darkest and 1 for lightest. @@ -265,10 +265,10 @@ class Color { if (b == null) return _scaleAlpha(a, 1.0 - t); return Color.fromARGB( - lerpDouble(a.alpha, b.alpha, t).toInt().clamp(0, 255), - lerpDouble(a.red, b.red, t).toInt().clamp(0, 255), - lerpDouble(a.green, b.green, t).toInt().clamp(0, 255), - lerpDouble(a.blue, b.blue, t).toInt().clamp(0, 255), + lerpDouble(a.alpha, b.alpha, t).toInt().clamp(0, 255) as int, + lerpDouble(a.red, b.red, t).toInt().clamp(0, 255) as int, + lerpDouble(a.green, b.green, t).toInt().clamp(0, 255) as int, + lerpDouble(a.blue, b.blue, t).toInt().clamp(0, 255) as int, ); } @@ -321,8 +321,8 @@ class Color { return true; if (other.runtimeType != runtimeType) return false; - final Color typedOther = other; - return value == typedOther.value; + return other is Color + && other.value == value; } @override @@ -1338,7 +1338,7 @@ class Paint { Shader get shader { if (_objects == null) return null; - return _objects[_kShaderIndex]; + return _objects[_kShaderIndex] as Shader; } set shader(Shader value) { _objects ??= List(_kObjectCount); @@ -1355,7 +1355,7 @@ class Paint { if (_objects == null || _objects[_kColorFilterIndex] == null) { return null; } - return _objects[_kColorFilterIndex].creator; + return _objects[_kColorFilterIndex].creator as ColorFilter; } set colorFilter(ColorFilter value) { @@ -1399,7 +1399,7 @@ class Paint { ImageFilter get imageFilter { if (_objects == null || _objects[_kImageFilterIndex] == null) return null; - return _objects[_kImageFilterIndex].creator; + return _objects[_kImageFilterIndex].creator as ImageFilter; } set imageFilter(ImageFilter value) { @@ -2508,11 +2508,9 @@ class MaskFilter { @override bool operator ==(dynamic other) { - if (other is! MaskFilter) - return false; - final MaskFilter typedOther = other; - return _style == typedOther._style && - _sigma == typedOther._sigma; + return other is MaskFilter + && other._style == _style + && other._sigma == _sigma; } @override @@ -2639,19 +2637,11 @@ class ColorFilter { @override bool operator ==(dynamic other) { - if (other is! ColorFilter) { - return false; - } - final ColorFilter typedOther = other; - - if (_type != typedOther._type) { - return false; - } - if (!_listEquals(_matrix, typedOther._matrix)) { - return false; - } - - return _color == typedOther._color && _blendMode == typedOther._blendMode; + return other is ColorFilter + && other._type == _type + && _listEquals(other._matrix, _matrix) + && other._color == _color + && other._blendMode == _blendMode; } _ColorFilter _toNativeColorFilter() { @@ -2791,19 +2781,10 @@ class ImageFilter { @override bool operator ==(dynamic other) { - if (other is! ImageFilter) { - return false; - } - final ImageFilter typedOther = other; - - if (_type != typedOther._type) { - return false; - } - if (!_listEquals(_data, typedOther._data)) { - return false; - } - - return _filterQuality == typedOther._filterQuality; + return other is ImageFilter + && other._type == _type + && _listEquals(other._data, _data) + && other._filterQuality == _filterQuality; } _ImageFilter _toNativeImageFilter() => _nativeFilter ??= _makeNativeImageFilter(); @@ -3187,6 +3168,15 @@ enum VertexMode { /// A set of vertex data used by [Canvas.drawVertices]. class Vertices extends NativeFieldWrapperClass2 { + /// Creates a set of vertex data for use with [Canvas.drawVertices]. + /// + /// The [mode] and [positions] parameters must not be null. + /// + /// If the [textureCoordinates] or [colors] parameters are provided, they must + /// be the same length as [positions]. + /// + /// If the [indices] parameter is provided, all values in the list must be + /// valid index values for [positions]. Vertices( VertexMode mode, List positions, { @@ -3218,6 +3208,24 @@ class Vertices extends NativeFieldWrapperClass2 { throw ArgumentError('Invalid configuration for vertices.'); } + /// Creates a set of vertex data for use with [Canvas.drawVertices], directly + /// using the encoding methods of [new Vertices]. + /// + /// The [mode] parameter must not be null. + /// + /// The [positions] list is interpreted as a list of repeated pairs of x,y + /// coordinates. It must not be null. + /// + /// The [textureCoordinates] list is interpreted as a list of repeated pairs + /// of x,y coordinates, and must be the same length of [positions] if it + /// is not null. + /// + /// The [colors] list is interpreted as a list of RGBA encoded colors, similar + /// to [Color.value]. It must be half length of [positions] if it is not + /// null. + /// + /// If the [indices] list is provided, all values in the list must be + /// valid index values for [positions]. Vertices.raw( VertexMode mode, Float32List positions, { @@ -3891,6 +3899,14 @@ class Canvas extends NativeFieldWrapperClass2 { int pointMode, Float32List points) native 'Canvas_drawPoints'; + /// Draws the set of [Vertices] onto the canvas. + /// + /// All parameters must not be null. + /// + /// See also: + /// * [new Vertices], which creates a set of vertices to draw on the canvas. + /// * [Vertices.raw], which creates the vertices using typed data lists + /// rather than unencoded lists. void drawVertices(Vertices vertices, BlendMode blendMode, Paint paint) { assert(vertices != null); // vertices is checked on the engine side assert(paint != null); @@ -3902,11 +3918,18 @@ class Canvas extends NativeFieldWrapperClass2 { List paintObjects, ByteData paintData) native 'Canvas_drawVertices'; - // - // See also: - // - // * [drawRawAtlas], which takes its arguments as typed data lists rather - // than objects. + /// Draws part of an image - the [atlas] - onto the canvas. + /// + /// This method allows for optimization when you only want to draw part of an + /// image on the canvas, such as when using sprites or zooming. It is more + /// efficient than using clips or masks directly. + /// + /// All parameters mmust not be null. + /// + /// See also: + /// + /// * [drawRawAtlas], which takes its arguments as typed data lists rather + /// than objects. void drawAtlas(Image atlas, List transforms, List rects, @@ -3957,21 +3980,26 @@ class Canvas extends NativeFieldWrapperClass2 { ); } - // - // The `rstTransforms` argument is interpreted as a list of four-tuples, with - // each tuple being ([RSTransform.scos], [RSTransform.ssin], - // [RSTransform.tx], [RSTransform.ty]). - // - // The `rects` argument is interpreted as a list of four-tuples, with each - // tuple being ([Rect.left], [Rect.top], [Rect.right], [Rect.bottom]). - // - // The `colors` argument, which can be null, is interpreted as a list of - // 32-bit colors, with the same packing as [Color.value]. - // - // See also: - // - // * [drawAtlas], which takes its arguments as objects rather than typed - // data lists. + /// Draws part of an image - the [atlas] - onto the canvas. + /// + /// This method allows for optimization when you only want to draw part of an + /// image on the canvas, such as when using sprites or zooming. It is more + /// efficient than using clips or masks directly. + /// + /// The [rstTransforms] argument is interpreted as a list of four-tuples, with + /// each tuple being ([RSTransform.scos], [RSTransform.ssin], + /// [RSTransform.tx], [RSTransform.ty]). + /// + /// The [rects] argument is interpreted as a list of four-tuples, with each + /// tuple being ([Rect.left], [Rect.top], [Rect.right], [Rect.bottom]). + /// + /// The [colors] argument, which can be null, is interpreted as a list of + /// 32-bit colors, with the same packing as [Color.value]. + /// + /// See also: + /// + /// * [drawAtlas], which takes its arguments as objects rather than typed + /// data lists. void drawRawAtlas(Image atlas, Float32List rstTransforms, Float32List rects, @@ -4250,12 +4278,10 @@ class Shadow { bool operator ==(dynamic other) { if (identical(this, other)) return true; - if (other is! Shadow) - return false; - final Shadow typedOther = other; - return color == typedOther.color && - offset == typedOther.offset && - blurRadius == typedOther.blurRadius; + return other is Shadow + && other.color == color + && other.offset == offset + && other.blurRadius == blurRadius; } @override diff --git a/engine/src/flutter/lib/ui/plugins.dart b/engine/src/flutter/lib/ui/plugins.dart index 0897fcebd2..d0639151b1 100644 --- a/engine/src/flutter/lib/ui/plugins.dart +++ b/engine/src/flutter/lib/ui/plugins.dart @@ -25,8 +25,8 @@ class CallbackHandle { bool operator ==(dynamic other) { if (runtimeType != other.runtimeType) return false; - final CallbackHandle typedOther = other; - return _handle == typedOther._handle; + return other is CallbackHandle + && other._handle == _handle; } @override diff --git a/engine/src/flutter/lib/ui/text.dart b/engine/src/flutter/lib/ui/text.dart index a290412819..19b06a906e 100644 --- a/engine/src/flutter/lib/ui/text.dart +++ b/engine/src/flutter/lib/ui/text.dart @@ -83,7 +83,7 @@ class FontWeight { assert(t != null); if (a == null && b == null) return null; - return values[lerpDouble(a?.index ?? normal.index, b?.index ?? normal.index, t).round().clamp(0, 8)]; + return values[lerpDouble(a?.index ?? normal.index, b?.index ?? normal.index, t).round().clamp(0, 8) as int]; } @override @@ -300,9 +300,9 @@ class FontFeature { return true; if (other.runtimeType != runtimeType) return false; - final FontFeature typedOther = other; - return feature == typedOther.feature - && value == typedOther.value; + return other is FontFeature + && other.feature == feature + && other.value == value; } @override @@ -387,10 +387,8 @@ class TextDecoration { @override bool operator ==(dynamic other) { - if (other is! TextDecoration) - return false; - final TextDecoration typedOther = other; - return _mask == typedOther._mask; + return other is TextDecoration + && other._mask == _mask; } @override @@ -680,30 +678,20 @@ class TextStyle { bool operator ==(dynamic other) { if (identical(this, other)) return true; - if (other is! TextStyle) - return false; - final TextStyle typedOther = other; - if (_fontFamily != typedOther._fontFamily || - _fontSize != typedOther._fontSize || - _letterSpacing != typedOther._letterSpacing || - _wordSpacing != typedOther._wordSpacing || - _height != typedOther._height || - _decorationThickness != typedOther._decorationThickness || - _locale != typedOther._locale || - _background != typedOther._background || - _foreground != typedOther._foreground) - return false; - for (int index = 0; index < _encoded.length; index += 1) { - if (_encoded[index] != typedOther._encoded[index]) - return false; - } - if (!_listEquals(_shadows, typedOther._shadows)) - return false; - if (!_listEquals(_fontFamilyFallback, typedOther._fontFamilyFallback)) - return false; - if (!_listEquals(_fontFeatures, typedOther._fontFeatures)) - return false; - return true; + return other is TextStyle + && other._fontFamily == _fontFamily + && other._fontSize == _fontSize + && other._letterSpacing == _letterSpacing + && other._wordSpacing == _wordSpacing + && other._height == _height + && other._decorationThickness == _decorationThickness + && other._locale == _locale + && other._background == _background + && other._foreground == _foreground + && _listEquals(other._encoded, _encoded) + && _listEquals(other._shadows, _shadows) + && _listEquals(other._fontFamilyFallback, _fontFamilyFallback) + && _listEquals(other._fontFeatures, _fontFeatures); } @override @@ -920,19 +908,14 @@ class ParagraphStyle { return true; if (other.runtimeType != runtimeType) return false; - final ParagraphStyle typedOther = other; - if (_fontFamily != typedOther._fontFamily || - _fontSize != typedOther._fontSize || - _height != typedOther._height || - _strutStyle != typedOther._strutStyle || - _ellipsis != typedOther._ellipsis || - _locale != typedOther._locale) - return false; - for (int index = 0; index < _encoded.length; index += 1) { - if (_encoded[index] != typedOther._encoded[index]) - return false; - } - return true; + return other is ParagraphStyle + && other._fontFamily == _fontFamily + && other._fontSize == _fontSize + && other._height == _height + && other._strutStyle == _strutStyle + && other._ellipsis == _ellipsis + && other._locale == _locale + && _listEquals(other._encoded, _encoded); } @override @@ -1101,18 +1084,10 @@ class StrutStyle { return true; if (other.runtimeType != runtimeType) return false; - final StrutStyle typedOther = other; - if (_fontFamily != typedOther._fontFamily) - return false; - final Int8List encodedList = _encoded.buffer.asInt8List(); - final Int8List otherEncodedList = typedOther._encoded.buffer.asInt8List(); - for (int index = 0; index < _encoded.lengthInBytes; index += 1) { - if (encodedList[index] != otherEncodedList[index]) - return false; - } - if (!_listEquals(_fontFamilyFallback, typedOther._fontFamilyFallback)) - return false; - return true; + return other is StrutStyle + && other._fontFamily == _fontFamily + && _listEquals(other._fontFamilyFallback, _fontFamilyFallback) + && _listEquals(other._encoded.buffer.asInt8List(), _encoded.buffer.asInt8List()); } @override @@ -1228,6 +1203,7 @@ class TextBox { ); @pragma('vm:entry-point') + // ignore: unused_element TextBox._( this.left, this.top, @@ -1282,12 +1258,12 @@ class TextBox { return true; if (other.runtimeType != runtimeType) return false; - final TextBox typedOther = other; - return typedOther.left == left - && typedOther.top == top - && typedOther.right == right - && typedOther.bottom == bottom - && typedOther.direction == direction; + return other is TextBox + && other.left == left + && other.top == top + && other.right == right + && other.bottom == bottom + && other.direction == direction; } @override @@ -1392,9 +1368,9 @@ class TextPosition { bool operator ==(dynamic other) { if (other.runtimeType != runtimeType) return false; - final TextPosition typedOther = other; - return typedOther.offset == offset - && typedOther.affinity == affinity; + return other is TextPosition + && other.offset == offset + && other.affinity == affinity; } @override @@ -1476,11 +1452,9 @@ class TextRange { bool operator ==(dynamic other) { if (identical(this, other)) return true; - if (other is! TextRange) - return false; - final TextRange typedOther = other; - return typedOther.start == start - && typedOther.end == end; + return other is TextRange + && other.start == start + && other.end == end; } @override @@ -1530,8 +1504,8 @@ class ParagraphConstraints { bool operator ==(dynamic other) { if (other.runtimeType != runtimeType) return false; - final ParagraphConstraints typedOther = other; - return typedOther.width == width; + return other is ParagraphConstraints + && other.width == width; } @override @@ -1683,6 +1657,7 @@ class LineMetrics { }); @pragma('vm:entry-point') + // ignore: unused_element LineMetrics._( this.hardBreak, this.ascent, diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index f7d951e769..96b48e2aef 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -472,12 +472,10 @@ class Locale { bool operator ==(dynamic other) { if (identical(this, other)) return true; - if (other is! Locale) - return false; - final Locale typedOther = other; - return languageCode == typedOther.languageCode - && scriptCode == typedOther.scriptCode - && countryCode == typedOther.countryCode; + return other is Locale + && other.languageCode == languageCode + && other.scriptCode == scriptCode + && other.countryCode == countryCode; } @override @@ -1260,8 +1258,8 @@ class AccessibilityFeatures { bool operator ==(dynamic other) { if (other.runtimeType != runtimeType) return false; - final AccessibilityFeatures typedOther = other; - return _index == typedOther._index; + return other is AccessibilityFeatures + && other._index == _index; } @override diff --git a/engine/src/flutter/lib/web_ui/lib/src/ui/canvas.dart b/engine/src/flutter/lib/web_ui/lib/src/ui/canvas.dart index 9d0b8a8733..53e0f2eb77 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/ui/canvas.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/ui/canvas.dart @@ -81,6 +81,15 @@ class Vertices { engine.initWebGl(); } + /// Creates a set of vertex data for use with [Canvas.drawVertices]. + /// + /// The [mode] and [positions] parameters must not be null. + /// + /// If the [textureCoordinates] or [colors] parameters are provided, they must + /// be the same length as [positions]. + /// + /// If the [indices] parameter is provided, all values in the list must be + /// valid index values for [positions]. factory Vertices( VertexMode mode, List positions, { @@ -137,6 +146,24 @@ class Vertices { return list; } + /// Creates a set of vertex data for use with [Canvas.drawVertices], directly + /// using the encoding methods of [new Vertices]. + /// + /// The [mode] parameter must not be null. + /// + /// The [positions] list is interpreted as a list of repeated pairs of x,y + /// coordinates. It must not be null. + /// + /// The [textureCoordinates] list is interpreted as a list of repeated pairs + /// of x,y coordinates, and must be the same length of [positions] if it + /// is not null. + /// + /// The [colors] list is interpreted as a list of RGBA encoded colors, similar + /// to [Color.value]. It must be half length of [positions] if it is not + /// null. + /// + /// If the [indices] list is provided, all values in the list must be + /// valid index values for [positions]. factory Vertices.raw( VertexMode mode, Float32List positions, { @@ -953,11 +980,18 @@ class Canvas { _canvas.drawVertices(vertices, blendMode, paint); } - // - // See also: - // - // * [drawRawAtlas], which takes its arguments as typed data lists rather - // than objects. + /// Draws part of an image - the [atlas] - onto the canvas. + /// + /// This method allows for optimization when you only want to draw part of an + /// image on the canvas, such as when using sprites or zooming. It is more + /// efficient than using clips or masks directly. + /// + /// All parameters must not be null. + /// + /// See also: + /// + /// * [drawRawAtlas], which takes its arguments as typed data lists rather + /// than objects. void drawAtlas(Image atlas, List transforms, List rects, List colors, BlendMode blendMode, Rect cullRect, Paint paint) { assert(atlas != null); // atlas is checked on the engine side @@ -980,21 +1014,26 @@ class Canvas { throw UnimplementedError(); } - // - // The `rstTransforms` argument is interpreted as a list of four-tuples, with - // each tuple being ([RSTransform.scos], [RSTransform.ssin], - // [RSTransform.tx], [RSTransform.ty]). - // - // The `rects` argument is interpreted as a list of four-tuples, with each - // tuple being ([Rect.left], [Rect.top], [Rect.right], [Rect.bottom]). - // - // The `colors` argument, which can be null, is interpreted as a list of - // 32-bit colors, with the same packing as [Color.value]. - // - // See also: - // - // * [drawAtlas], which takes its arguments as objects rather than typed - // data lists. + /// Draws part of an image - the [atlas] - onto the canvas. + /// + /// This method allows for optimization when you only want to draw part of an + /// image on the canvas, such as when using sprites or zooming. It is more + /// efficient than using clips or masks directly. + /// + /// The [rstTransforms] argument is interpreted as a list of four-tuples, with + /// each tuple being ([RSTransform.scos], [RSTransform.ssin], + /// [RSTransform.tx], [RSTransform.ty]). + /// + /// The [rects] argument is interpreted as a list of four-tuples, with each + /// tuple being ([Rect.left], [Rect.top], [Rect.right], [Rect.bottom]). + /// + /// The [colors] argument, which can be null, is interpreted as a list of + /// 32-bit colors, with the same packing as [Color.value]. + /// + /// See also: + /// + /// * [drawAtlas], which takes its arguments as objects rather than typed + /// data lists. void drawRawAtlas(Image atlas, Float32List rstTransforms, Float32List rects, Int32List colors, BlendMode blendMode, Rect cullRect, Paint paint) { assert(atlas != null); // atlas is checked on the engine side diff --git a/engine/src/flutter/testing/dart/channel_buffers_test.dart b/engine/src/flutter/testing/dart/channel_buffers_test.dart index b64cf3c0c0..567b20cc6b 100644 --- a/engine/src/flutter/testing/dart/channel_buffers_test.dart +++ b/engine/src/flutter/testing/dart/channel_buffers_test.dart @@ -7,7 +7,7 @@ import 'package:test/test.dart'; void main() { ByteData _makeByteData(String str) { - final Uint8List list = utf8.encode(str); + final Uint8List list = utf8.encode(str) as Uint8List; final ByteBuffer buffer = list is Uint8List ? list.buffer : Uint8List.fromList(list).buffer; return ByteData.view(buffer); } diff --git a/engine/src/flutter/testing/dart/compositing_test.dart b/engine/src/flutter/testing/dart/compositing_test.dart index 42f47c10e5..fc729a2963 100644 --- a/engine/src/flutter/testing/dart/compositing_test.dart +++ b/engine/src/flutter/testing/dart/compositing_test.dart @@ -164,7 +164,7 @@ void main() { void testPushChildLayerOfRetainedLayer(_TestNoSharingFunction pushFunction) { final SceneBuilder builder1 = SceneBuilder(); final EngineLayer layer = pushFunction(builder1, null); - final EngineLayer childLayer = builder1.pushOpacity(123); + final OpacityEngineLayer childLayer = builder1.pushOpacity(123); builder1.pop(); builder1.pop(); builder1.build(); @@ -187,7 +187,7 @@ void main() { void testRetainParentLayerOfPushedChild(_TestNoSharingFunction pushFunction) { final SceneBuilder builder1 = SceneBuilder(); final EngineLayer layer = pushFunction(builder1, null); - final EngineLayer childLayer = builder1.pushOpacity(123); + final OpacityEngineLayer childLayer = builder1.pushOpacity(123); builder1.pop(); builder1.pop(); builder1.build(); @@ -292,25 +292,25 @@ void main() { test('SceneBuilder does not share a layer between addRetained and push*', () { testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushOffset(0, 0, oldLayer: oldLayer); + return builder.pushOffset(0, 0, oldLayer: oldLayer as OffsetEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushTransform(Float64List(16), oldLayer: oldLayer); + return builder.pushTransform(Float64List(16), oldLayer: oldLayer as TransformEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushClipRect(Rect.zero, oldLayer: oldLayer); + return builder.pushClipRect(Rect.zero, oldLayer: oldLayer as ClipRectEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushClipRRect(RRect.zero, oldLayer: oldLayer); + return builder.pushClipRRect(RRect.zero, oldLayer: oldLayer as ClipRRectEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushClipPath(Path(), oldLayer: oldLayer); + return builder.pushClipPath(Path(), oldLayer: oldLayer as ClipPathEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushOpacity(100, oldLayer: oldLayer); + return builder.pushOpacity(100, oldLayer: oldLayer as OpacityEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushBackdropFilter(ImageFilter.blur(), oldLayer: oldLayer); + return builder.pushBackdropFilter(ImageFilter.blur(), oldLayer: oldLayer as BackdropFilterEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { return builder.pushShaderMask( @@ -321,11 +321,11 @@ void main() { ), Rect.zero, BlendMode.color, - oldLayer: oldLayer, + oldLayer: oldLayer as ShaderMaskEngineLayer, ); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { - return builder.pushPhysicalShape(path: Path(), color: const Color.fromARGB(0, 0, 0, 0), oldLayer: oldLayer); + return builder.pushPhysicalShape(path: Path(), color: const Color.fromARGB(0, 0, 0, 0), oldLayer: oldLayer as PhysicalShapeEngineLayer); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { return builder.pushColorFilter( @@ -333,7 +333,7 @@ void main() { Color.fromARGB(0, 0, 0, 0), BlendMode.color, ), - oldLayer: oldLayer, + oldLayer: oldLayer as ColorFilterEngineLayer, ); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { @@ -344,25 +344,25 @@ void main() { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, ]), - oldLayer: oldLayer, + oldLayer: oldLayer as ColorFilterEngineLayer, ); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { return builder.pushColorFilter( const ColorFilter.linearToSrgbGamma(), - oldLayer: oldLayer, + oldLayer: oldLayer as ColorFilterEngineLayer, ); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { return builder.pushColorFilter( const ColorFilter.srgbToLinearGamma(), - oldLayer: oldLayer, + oldLayer: oldLayer as ColorFilterEngineLayer, ); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { return builder.pushImageFilter( ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), - oldLayer: oldLayer, + oldLayer: oldLayer as ImageFilterEngineLayer, ); }); testNoSharing((SceneBuilder builder, EngineLayer oldLayer) { @@ -373,7 +373,7 @@ void main() { 0, 0, 1, 0, 0, 0, 0, 1, ])), - oldLayer: oldLayer, + oldLayer: oldLayer as ImageFilterEngineLayer, ); }); }); diff --git a/engine/src/flutter/testing/dart/isolate_name_server_test.dart b/engine/src/flutter/testing/dart/isolate_name_server_test.dart index 5a02d9722d..abc9c4f9cf 100644 --- a/engine/src/flutter/testing/dart/isolate_name_server_test.dart +++ b/engine/src/flutter/testing/dart/isolate_name_server_test.dart @@ -89,8 +89,8 @@ void main() { // Test driver. final ReceivePort testReceivePort = ReceivePort(); testReceivePort.listen(expectAsync1((dynamic response) { - final int code = response[0]; - final String message = response[1]; + final int code = response[0] as int; + final String message = response[1] as String; switch (code) { case kStartCode: break; diff --git a/engine/src/flutter/testing/scenario_app/lib/main.dart b/engine/src/flutter/testing/scenario_app/lib/main.dart index f387bf4668..2f0a768870 100644 --- a/engine/src/flutter/testing/scenario_app/lib/main.dart +++ b/engine/src/flutter/testing/scenario_app/lib/main.dart @@ -76,13 +76,15 @@ Future _getTimelineData() async { final Uri vmServiceTimelineUri = info.serverUri.resolve('getVMTimeline'); final Map cpuTimelineJson = await _getJson(cpuProfileTimelineUri); final Map vmServiceTimelineJson = await _getJson(vmServiceTimelineUri); - final Map cpuResult = cpuTimelineJson['result'].cast(); - final Map vmServiceResult = - vmServiceTimelineJson['result'].cast(); + final Map cpuResult = cpuTimelineJson['result'] as Map; + final Map vmServiceResult = vmServiceTimelineJson['result'] as Map; return json.encode({ 'stackFrames': cpuResult['stackFrames'], - 'traceEvents': [...cpuResult['traceEvents'], ...vmServiceResult['traceEvents']], + 'traceEvents': [ + ...cpuResult['traceEvents'] as List, + ...vmServiceResult['traceEvents'] as List, + ], }); } @@ -94,7 +96,7 @@ Future> _getJson(Uri uri) async { return null; } final String data = await utf8.decodeStream(response); - return json.decode(data); + return json.decode(data) as Map; } void _onBeginFrame(Duration duration) { diff --git a/engine/src/flutter/testing/symbols/verify_exported.dart b/engine/src/flutter/testing/symbols/verify_exported.dart index c0c6e7624e..549ac44841 100644 --- a/engine/src/flutter/testing/symbols/verify_exported.dart +++ b/engine/src/flutter/testing/symbols/verify_exported.dart @@ -35,7 +35,7 @@ void main(List arguments) { throw UnimplementedError('Script only support running on Linux or MacOS.'); } final String nmPath = p.join(buildToolsPath, platform, 'clang', 'bin', 'llvm-nm'); - assert(new Directory(outPath).existsSync()); + assert(Directory(outPath).existsSync()); final Iterable releaseBuilds = Directory(outPath).listSync() .where((FileSystemEntity entity) => entity is Directory) @@ -58,7 +58,7 @@ int _checkIos(String outPath, String nmPath, Iterable builds) { int failures = 0; for (String build in builds) { final String libFlutter = p.join(outPath, build, 'Flutter.framework', 'Flutter'); - if (!new File(libFlutter).existsSync()) { + if (!File(libFlutter).existsSync()) { print('SKIPPING: $libFlutter does not exist.'); continue; } @@ -90,7 +90,7 @@ int _checkAndroid(String outPath, String nmPath, Iterable builds) { int failures = 0; for (String build in builds) { final String libFlutter = p.join(outPath, build, 'libflutter.so'); - if (!new File(libFlutter).existsSync()) { + if (!File(libFlutter).existsSync()) { print('SKIPPING: $libFlutter does not exist.'); continue; }