From e96bc37a597299517286badd84e833a8e65c950e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Wed, 16 Sep 2015 17:13:49 -0700 Subject: [PATCH] cleanup for 'dartanalyzer --strong' Start: 13 errors, 80 warnings and 3 hints found End: 3 errors, 53 warnings and 2 hints found --- lib/src/display/bitmap_data.dart | 7 ++--- lib/src/display/display_object_children.dart | 4 +-- lib/src/display/stage.dart | 4 +-- lib/src/display_ex/canvas_shadow_wrapper.dart | 3 +- lib/src/events/event_dispatcher.dart | 4 +-- lib/src/events/event_stream.dart | 29 +++++++++++-------- lib/src/events/event_stream_subscription.dart | 2 +- lib/src/filters/displacement_map_filter.dart | 4 +-- lib/src/geom/point.dart | 2 +- .../implementation/audio_element_sound.dart | 10 ++++--- .../implementation/web_audio_api_sound.dart | 2 ++ lib/src/media/video.dart | 4 +-- lib/src/resources/resource_manager.dart | 17 +++++------ lib/src/resources/texture_atlas_loader.dart | 2 +- lib/src/text/text_field.dart | 2 +- lib/src/toolkit/movie_clip.dart | 5 ++-- lib/src/toolkit/timeline.dart | 9 +++--- 17 files changed, 58 insertions(+), 52 deletions(-) diff --git a/lib/src/display/bitmap_data.dart b/lib/src/display/bitmap_data.dart index 3c716a6a..c440655f 100644 --- a/lib/src/display/bitmap_data.dart +++ b/lib/src/display/bitmap_data.dart @@ -60,7 +60,7 @@ class BitmapData implements BitmapDrawable { /// Loads a BitmapData from the given url. - static Future load(String url, [BitmapDataLoadOptions bitmapDataLoadOptions]) { + static Future load(String url, [BitmapDataLoadOptions bitmapDataLoadOptions]) async { if (bitmapDataLoadOptions == null) { bitmapDataLoadOptions = BitmapData.defaultLoadOptions; @@ -83,9 +83,8 @@ class BitmapData implements BitmapDrawable { } var imageLoader = new ImageLoader(url, webpAvailable, corsEnabled); - return imageLoader.done.then((image) { - return new BitmapData.fromImageElement(image, pixelRatio); - }); + var image = await imageLoader.done; + return new BitmapData.fromImageElement(image, pixelRatio); } //---------------------------------------------------------------------------- diff --git a/lib/src/display/display_object_children.dart b/lib/src/display/display_object_children.dart index 226efe92..c2c69849 100644 --- a/lib/src/display/display_object_children.dart +++ b/lib/src/display/display_object_children.dart @@ -83,9 +83,7 @@ class DisplayObjectChildren implements Iterable { return _children.any(test); } - bool contains(DisplayObject element) { - return _children.contains(element); - } + bool contains(Object element) => _children.contains(element); DisplayObject elementAt(int index) { return _children[index]; diff --git a/lib/src/display/stage.dart b/lib/src/display/stage.dart index c8fdbf7e..67372ad8 100644 --- a/lib/src/display/stage.dart +++ b/lib/src/display/stage.dart @@ -540,8 +540,8 @@ class Stage extends DisplayObjectContainer { int button = event.button; InteractiveObject target = null; - Point stagePoint = _clientTransformation.transformPoint(event.client); - Point localPoint = new Point(0.0, 0.0); + var stagePoint = _clientTransformation.transformPoint(event.client); + var localPoint = new Point(0.0, 0.0); if (button < 0 || button > 2) return; if (event.type == "mousemove" && _mousePosition == stagePoint) return; diff --git a/lib/src/display_ex/canvas_shadow_wrapper.dart b/lib/src/display_ex/canvas_shadow_wrapper.dart index c7edf398..74267f56 100644 --- a/lib/src/display_ex/canvas_shadow_wrapper.dart +++ b/lib/src/display_ex/canvas_shadow_wrapper.dart @@ -73,8 +73,7 @@ class CanvasShadowWrapper extends DisplayObject { var renderContext = renderState.renderContext; if (renderContext is RenderContextCanvas) { - RenderContextCanvas renderContextCanvas = renderContext as RenderContextCanvas; - CanvasRenderingContext2D rawContext = renderContextCanvas.rawContext; + CanvasRenderingContext2D rawContext = renderContext.rawContext; Matrix shadowMatrix = renderState.globalMatrix; rawContext.save(); diff --git a/lib/src/events/event_dispatcher.dart b/lib/src/events/event_dispatcher.dart index 5f855d78..e8b83cd1 100644 --- a/lib/src/events/event_dispatcher.dart +++ b/lib/src/events/event_dispatcher.dart @@ -28,7 +28,7 @@ part of stagexl.events; class EventDispatcher { - Map _eventStreams; + Map> _eventStreams; //---------------------------------------------------------------------------- @@ -45,7 +45,7 @@ class EventDispatcher { var eventStreams = _eventStreams; if (eventStreams == null) { - eventStreams = new Map(); + eventStreams = new Map>(); _eventStreams = eventStreams; } diff --git a/lib/src/events/event_stream.dart b/lib/src/events/event_stream.dart index d307ffd1..e421ab6d 100644 --- a/lib/src/events/event_stream.dart +++ b/lib/src/events/event_stream.dart @@ -24,9 +24,9 @@ class EventStream extends Stream { bool get isBroadcast => true; @override - Stream asBroadcastStream({ - void onListen(StreamSubscription subscription), - void onCancel(StreamSubscription subscription)}) => this; + Stream asBroadcastStream( + {void onListen(StreamSubscription subscription), + void onCancel(StreamSubscription subscription)}) => this; bool get hasSubscriptions => _subscriptions.length > 0; bool get hasCapturingSubscriptions => _capturingSubscriptionCount > 0; @@ -53,9 +53,11 @@ class EventStream extends Stream { /// as the stream has no errors and is never done. @override - EventStreamSubscription listen(void onData(T event), { - void onError(error), void onDone(), - bool cancelOnError: false, int priority: 0 }) { + EventStreamSubscription listen(void onData(T event), + {Function onError, + void onDone(), + bool cancelOnError: false, + int priority: 0}) { return _subscribe(onData, false, priority); } @@ -98,15 +100,15 @@ class EventStream extends Stream { //---------------------------------------------------------------------------- EventStreamSubscription _subscribe( - EventListener eventListener, bool captures, int priority) { - - var subscription = new EventStreamSubscription._(this, - eventListener, captures, priority); + EventListener eventListener, bool captures, int priority) { + var subscription = new EventStreamSubscription._( + this, eventListener, captures, priority); // Insert the new subscription according to its priority. var oldSubscriptions = _subscriptions; - var newSubscriptions = new List(oldSubscriptions.length + 1); + var newSubscriptions = + new List(oldSubscriptions.length + 1); var index = newSubscriptions.length - 1; for(int o = 0, n = 0; o < oldSubscriptions.length; o++) { @@ -157,7 +159,8 @@ class EventStream extends Stream { var oldSubscriptions = _subscriptions; if (oldSubscriptions.length == 0) return; - var newSubscriptions = new List(oldSubscriptions.length - 1); + var newSubscriptions = + new List(oldSubscriptions.length - 1); for(int o = 0, n = 0; o < oldSubscriptions.length; o++) { var oldSubscription = oldSubscriptions[o]; @@ -179,6 +182,8 @@ class EventStream extends Stream { var subscriptions = _subscriptions; var isCapturing = eventPhase == EventPhase.CAPTURING_PHASE; + // dartanalyzer --strong known issues + // https://github.com/dart-lang/dev_compiler/issues/327 var inputEvent = event is InputEvent ? event : null; for(var i = 0; i < subscriptions.length; i++) { diff --git a/lib/src/events/event_stream_subscription.dart b/lib/src/events/event_stream_subscription.dart index 10af5654..6dd3ddc9 100644 --- a/lib/src/events/event_stream_subscription.dart +++ b/lib/src/events/event_stream_subscription.dart @@ -42,7 +42,7 @@ class EventStreamSubscription extends StreamSubscription { } @override - void onError(void handleError(error)) { + void onError(Function handleError) { // This stream has no errors. } diff --git a/lib/src/filters/displacement_map_filter.dart b/lib/src/filters/displacement_map_filter.dart index f7f6d85d..25e0556b 100644 --- a/lib/src/filters/displacement_map_filter.dart +++ b/lib/src/filters/displacement_map_filter.dart @@ -147,12 +147,12 @@ class DisplacementMapFilterProgram extends BitmapFilterProgram { disMatrix.copyFrom(renderTextureQuad.samplerMatrix); disMatrix.scale(displacementMapFilter.scaleX, displacementMapFilter.scaleY); - var uMapMatrix = new Float32List.fromList([ + var uMapMatrix = new Float32List.fromList([ mapMatrix.a, mapMatrix.c, mapMatrix.tx, mapMatrix.b, mapMatrix.d, mapMatrix.ty, 0.0, 0.0, 1.0]); - var uDisMatrix = new Float32List.fromList([ + var uDisMatrix = new Float32List.fromList([ disMatrix.a, disMatrix.c, 0.0, disMatrix.b, disMatrix.d, 0.0, 0.0, 0.0, 1.0]); diff --git a/lib/src/geom/point.dart b/lib/src/geom/point.dart index eacb6859..a1bb0989 100644 --- a/lib/src/geom/point.dart +++ b/lib/src/geom/point.dart @@ -106,7 +106,7 @@ class Point implements math.Point { /// Calculates the distance from this Point to another Point. - num distanceTo(math.Point point) { + double distanceTo(math.Point point) { return sqrt(squaredDistanceTo(point)); } diff --git a/lib/src/media/implementation/audio_element_sound.dart b/lib/src/media/implementation/audio_element_sound.dart index e295609d..f12f4603 100644 --- a/lib/src/media/implementation/audio_element_sound.dart +++ b/lib/src/media/implementation/audio_element_sound.dart @@ -32,6 +32,8 @@ class AudioElementSound extends Sound { return new AudioElementSound._(audioElement); } catch (e) { if (soundLoadOptions.ignoreErrors) { + // dartanalyzer --strong known issues + // https://github.com/dart-lang/dev_compiler/issues/316 return MockSound.load(url, soundLoadOptions); } else { throw new StateError("Failed to load audio."); @@ -41,7 +43,7 @@ class AudioElementSound extends Sound { static Future loadDataUrl(String dataUrl) async { - var audioUrls = [dataUrl]; + var audioUrls = [dataUrl]; var loadData = false; var corsEnabled = false; @@ -61,7 +63,7 @@ class AudioElementSound extends Sound { SoundChannel play([bool loop = false, SoundTransform soundTransform]) { var startTime = 0.0; var duration = _audioElement.duration; - if (duration.isInfinite) duration = 3600; + if (duration.isInfinite) duration = 3600.0; return new AudioElementSoundChannel( this, startTime, duration, loop, soundTransform); } @@ -84,7 +86,7 @@ class AudioElementSound extends Sound { } } - var audioElement = _audioElement.clone(true); + var audioElement = _audioElement.clone(true) as AudioElement; var audioCanPlay = audioElement.onCanPlay.first; if (audioElement.readyState == 0) await audioCanPlay; audioElement.onEnded.listen(_onAudioEnded); @@ -97,7 +99,7 @@ class AudioElementSound extends Sound { _soundChannels[audioElement] = null; } - void _onAudioEnded(event) { + void _onAudioEnded(html.Event event) { var audioElement = event.target; var soundChannel = _soundChannels[audioElement]; if (soundChannel != null) soundChannel._onAudioEnded(); diff --git a/lib/src/media/implementation/web_audio_api_sound.dart b/lib/src/media/implementation/web_audio_api_sound.dart index 20d04afd..e27a5512 100644 --- a/lib/src/media/implementation/web_audio_api_sound.dart +++ b/lib/src/media/implementation/web_audio_api_sound.dart @@ -29,6 +29,8 @@ class WebAudioApiSound extends Sound { } if (soundLoadOptions.ignoreErrors) { + // dartanalyzer --strong known issues + // https://github.com/dart-lang/dev_compiler/issues/316 return MockSound.load(url, soundLoadOptions); } else { throw new StateError("Failed to load audio."); diff --git a/lib/src/media/video.dart b/lib/src/media/video.dart index 90d4a270..f9934764 100644 --- a/lib/src/media/video.dart +++ b/lib/src/media/video.dart @@ -104,7 +104,7 @@ class Video { StreamSubscription onCanPlaySubscription = null; StreamSubscription onErrorSubscription = null; - void onCanPlay(e) { + void onCanPlay(html.Event e) { var video = new Video._(videoElement); video.volume = this.volume; video.muted = this.muted; @@ -113,7 +113,7 @@ class Video { completer.complete(video); } - void onError(e) { + void onError(html.Event e) { onCanPlaySubscription.cancel(); onErrorSubscription.cancel(); completer.completeError(e); diff --git a/lib/src/resources/resource_manager.dart b/lib/src/resources/resource_manager.dart index 4affeb9c..b26b82e2 100644 --- a/lib/src/resources/resource_manager.dart +++ b/lib/src/resources/resource_manager.dart @@ -51,18 +51,17 @@ class ResourceManager { //----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- - Future load() { + Future load() async { var futures = this.pendingResources.map((r) => r.complete); - return Future.wait(futures).then((value) { - var errors = this.failedResources.length; - if (errors > 0) { - throw new StateError("Failed to load $errors resource(s)."); - } else { - return this; - } - }); + await Future.wait(futures); + var errors = this.failedResources.length; + if (errors > 0) { + throw new StateError("Failed to load $errors resource(s)."); + } else { + return this; + } } //----------------------------------------------------------------------------------------------- diff --git a/lib/src/resources/texture_atlas_loader.dart b/lib/src/resources/texture_atlas_loader.dart index 12d3b1f9..b2a5917c 100644 --- a/lib/src/resources/texture_atlas_loader.dart +++ b/lib/src/resources/texture_atlas_loader.dart @@ -84,7 +84,7 @@ class _TextureAtlasLoaderTextureAtlas extends TextureAtlasLoader { Future getRenderTextureQuad(String filename) async { var name = this.namePrefix + getFilenameWithoutExtension(filename); var bitmapData = this.textureAtlas.getBitmapData(name); - return new Future.value(bitmapData.renderTextureQuad); + return bitmapData.renderTextureQuad; } } diff --git a/lib/src/text/text_field.dart b/lib/src/text/text_field.dart index 17ccb794..a84b35aa 100644 --- a/lib/src/text/text_field.dart +++ b/lib/src/text/text_field.dart @@ -295,7 +295,7 @@ class TextField extends InteractiveObject { var startIndex = 0; var checkLine = ''; var validLine = ''; - var lineWidth = 0; + var lineWidth = 0.0; var lineIndent = 0; var textFormat = _defaultTextFormat; diff --git a/lib/src/toolkit/movie_clip.dart b/lib/src/toolkit/movie_clip.dart index b4a7c707..41fcd810 100644 --- a/lib/src/toolkit/movie_clip.dart +++ b/lib/src/toolkit/movie_clip.dart @@ -27,7 +27,7 @@ part of stagexl.toolkit; * OTHER DEALINGS IN THE SOFTWARE. */ -/// **Note:** This class is not intended to be used directly. It is needed by +/// **Note:** This class is not intended to be used directly. It is needed by /// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL. class MovieClip extends Sprite { @@ -135,7 +135,8 @@ class MovieClip extends Sprite { * @param loop Initial value for the loop property. * @param labels A hash of labels to pass to the timeline instance associated with this MovieClip. **/ - MovieClip([String mode, int startPosition, bool loop, Map labels]) + MovieClip( + [String mode, int startPosition, bool loop, Map labels]) : super() { this.mode = mode != null ? mode : MovieClip.INDEPENDENT; diff --git a/lib/src/toolkit/timeline.dart b/lib/src/toolkit/timeline.dart index 5b4bf58f..2d50b3b0 100644 --- a/lib/src/toolkit/timeline.dart +++ b/lib/src/toolkit/timeline.dart @@ -29,7 +29,7 @@ part of stagexl.toolkit; typedef void ChangeHandler(dynamic sender); // Tween or Timeline -/// **Note:** This class is not intended to be used directly. It is needed by +/// **Note:** This class is not intended to be used directly. It is needed by /// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL. class TimelineAction { int t; @@ -42,7 +42,7 @@ class TimelineAction { } } -/// **Note:** This class is not intended to be used directly. It is needed by +/// **Note:** This class is not intended to be used directly. It is needed by /// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL. class TimelineStep { num d; @@ -60,7 +60,7 @@ class TimelineStep { } } -/// **Note:** This class is not intended to be used directly. It is needed by +/// **Note:** This class is not intended to be used directly. It is needed by /// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL. class Timeline { /** @@ -116,7 +116,8 @@ class Timeline { * * @constructor **/ - Timeline(List tweens, Map labels, Map props) { + Timeline(List tweens, Map labels, Map props) { + if (props != null) { loop = props.containsKey("loop") ? props["loop"] : false; ignoreGlobalPause = props.containsKey("ignoreGlobalPause") ? props["ignoreGlobalPause"] : false;