From dfc7f00a888e7a1d360f0438cf28fd5e7de0528d Mon Sep 17 00:00:00 2001 From: Hixie Date: Fri, 9 Oct 2015 09:23:06 -0700 Subject: [PATCH] Remove workarounds that avoided 'super' in mixins Dart supports this properly now. --- packages/flutter/lib/src/rendering/box.dart | 3 +- packages/flutter/lib/src/rendering/node.dart | 20 ++----- .../flutter/lib/src/rendering/object.dart | 59 +++++++++++-------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index 33a5b4ae23..57a79c5eab 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -631,7 +631,8 @@ abstract class RenderBox extends RenderObject { String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}size: ${size}\n'; } -/// A mixin that provides useful default behaviors for boxes with children managed by the [ContainerRenderObjectMixin] mixin +/// A mixin that provides useful default behaviors for boxes with children +/// managed by the [ContainerRenderObjectMixin] mixin. /// /// By convention, this class doesn't override any members of the superclass. /// Instead, it provides helpful functions that subclasses can call as diff --git a/packages/flutter/lib/src/rendering/node.dart b/packages/flutter/lib/src/rendering/node.dart index e4902add2b..fb989de505 100644 --- a/packages/flutter/lib/src/rendering/node.dart +++ b/packages/flutter/lib/src/rendering/node.dart @@ -68,32 +68,20 @@ class AbstractNode { /// Mark this node as attached. /// - /// Typically called only from overrides of [attachChildren] and to mark the - /// root of a tree attached. + /// Typically called only from the parent's attach(), and to mark the root of + /// a tree attached. void attach() { _attached = true; - attachChildren(); } - /// Override this function in subclasses with child to call attach() for each - /// child. Do not call directly. - attachChildren() { } - /// Mark this node as detached. /// - /// Typically called only from overrides for [detachChildren] and to mark the - /// root of a tree detached. + /// Typically called only from the parent's detach(), and to mark the root of + /// a tree detached. void detach() { _attached = false; - detachChildren(); } - /// Override this function in subclasses with child to call detach() for each - /// child. Do not call directly. - detachChildren() { } - - // TODO(ianh): remove attachChildren()/detachChildren() workaround once mixins can use super. - AbstractNode _parent; /// The parent of this node in the tree. AbstractNode get parent => _parent; diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index 4bedb368f7..451a35e594 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -25,15 +25,15 @@ typedef sky.Shader ShaderCallback(Rect bounds); /// input parameters to the parent's layout algorithm or their position relative /// to other children. class ParentData { - void detach() { - detachSiblings(); - } - void detachSiblings() { } // workaround for lack of inter-class mixins in Dart + /// Called when the RenderObject is removed from the tree. + void detach() { } - /// Override this function in subclasses to merge in data from other instance into this instance + /// Override this function in subclasses to merge in data from other instance + /// into this instance. void merge(ParentData other) { assert(other.runtimeType == this.runtimeType); } + String toString() => ''; } @@ -1158,11 +1158,13 @@ abstract class RenderObjectWithChildMixin implem if (_child != null) adoptChild(_child); } - void attachChildren() { + void attach() { + super.attach(); if (_child != null) _child.attach(); } - void detachChildren() { + void detach() { + super.detach(); if (_child != null) _child.detach(); } @@ -1178,14 +1180,15 @@ abstract class RenderObjectWithChildMixin implem } /// Parent data to support a doubly-linked list of children -abstract class ContainerParentDataMixin { +abstract class ContainerParentDataMixin implements ParentData { /// The previous sibling in the parent's child list ChildType previousSibling; /// The next sibling in the parent's child list ChildType nextSibling; /// Clear the sibling pointers. - void detachSiblings() { + void detach() { + super.detach(); if (previousSibling != null) { assert(previousSibling.parentData is ContainerParentDataMixin); assert(previousSibling != this); @@ -1362,6 +1365,27 @@ abstract class ContainerRenderObjectMixin