Commit 020b0688 authored by Adam Barth's avatar Adam Barth

Use protected and mustCallSuper in more places (#4291)

parent 9974de3b
...@@ -97,6 +97,7 @@ class AbstractNode { ...@@ -97,6 +97,7 @@ class AbstractNode {
AbstractNode get parent => _parent; AbstractNode get parent => _parent;
/// Subclasses should call this function when they acquire a new child. /// Subclasses should call this function when they acquire a new child.
@mustCallSuper
void adoptChild(AbstractNode child) { void adoptChild(AbstractNode child) {
assert(child != null); assert(child != null);
assert(child._parent == null); assert(child._parent == null);
...@@ -114,6 +115,7 @@ class AbstractNode { ...@@ -114,6 +115,7 @@ class AbstractNode {
} }
/// Subclasses should call this function when they lose a child. /// Subclasses should call this function when they lose a child.
@mustCallSuper
void dropChild(AbstractNode child) { void dropChild(AbstractNode child) {
assert(child != null); assert(child != null);
assert(child._parent == this); assert(child._parent == this);
......
...@@ -1169,19 +1169,24 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -1169,19 +1169,24 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
} }
} }
bool _needsLayout = true;
/// Whether this render object's layout information is dirty. /// Whether this render object's layout information is dirty.
bool get needsLayout => _needsLayout; bool get needsLayout => _needsLayout;
bool _needsLayout = true;
RenderObject _relayoutSubtreeRoot; RenderObject _relayoutSubtreeRoot;
bool _doingThisLayoutWithCallback = false; bool _doingThisLayoutWithCallback = false;
Constraints _constraints;
/// The layout constraints most recently supplied by the parent. /// The layout constraints most recently supplied by the parent.
@protected
Constraints get constraints => _constraints; Constraints get constraints => _constraints;
Constraints _constraints;
/// Verify that the object's constraints are being met. Override /// Verify that the object's constraints are being met. Override
/// this function in a subclass to verify that your state matches /// this function in a subclass to verify that your state matches
/// the constraints object. This function is only called in checked /// the constraints object. This function is only called in checked
/// mode and only when needsLayout is false. If the constraints are /// mode and only when needsLayout is false. If the constraints are
/// not met, it should assert or throw an exception. /// not met, it should assert or throw an exception.
@protected
void debugAssertDoesMeetConstraints(); void debugAssertDoesMeetConstraints();
/// When true, debugAssertDoesMeetConstraints() is currently /// When true, debugAssertDoesMeetConstraints() is currently
...@@ -1449,6 +1454,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -1449,6 +1454,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
/// Returning false is always correct, but returning true can be more /// Returning false is always correct, but returning true can be more
/// efficient when computing the size of this render object because we don't /// efficient when computing the size of this render object because we don't
/// need to recompute the size if the constraints don't change. /// need to recompute the size if the constraints don't change.
@protected
bool get sizedByParent => false; bool get sizedByParent => false;
/// Updates the render objects size using only the constraints. /// Updates the render objects size using only the constraints.
...@@ -1566,6 +1572,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -1566,6 +1572,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
/// ///
/// You must call markNeedsCompositingBitsUpdate() if the value of this /// You must call markNeedsCompositingBitsUpdate() if the value of this
/// getter changes. /// getter changes.
@protected
bool get alwaysNeedsCompositing => false; bool get alwaysNeedsCompositing => false;
OffsetLayer _layer; OffsetLayer _layer;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:ui' as ui show window; import 'dart:ui' as ui show window;
import 'package:meta/meta.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
import 'box.dart'; import 'box.dart';
...@@ -355,6 +356,7 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende ...@@ -355,6 +356,7 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende
/// This is a convenience function for subclasses to call from their /// This is a convenience function for subclasses to call from their
/// intrinsic-sizing functions if they don't have a good way to generate the /// intrinsic-sizing functions if they don't have a good way to generate the
/// numbers. /// numbers.
@protected
bool debugThrowIfNotCheckingIntrinsics() { bool debugThrowIfNotCheckingIntrinsics() {
assert(() { assert(() {
if (!RenderObject.debugCheckingIntrinsics) { if (!RenderObject.debugCheckingIntrinsics) {
...@@ -372,25 +374,25 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende ...@@ -372,25 +374,25 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende
@override @override
double getMinIntrinsicWidth(double height) { double getMinIntrinsicWidth(double height) {
assert(debugThrowIfNotCheckingIntrinsics); assert(debugThrowIfNotCheckingIntrinsics());
return 0.0; return 0.0;
} }
@override @override
double getMaxIntrinsicWidth(double height) { double getMaxIntrinsicWidth(double height) {
assert(debugThrowIfNotCheckingIntrinsics); assert(debugThrowIfNotCheckingIntrinsics());
return 0.0; return 0.0;
} }
@override @override
double getMinIntrinsicHeight(double width) { double getMinIntrinsicHeight(double width) {
assert(debugThrowIfNotCheckingIntrinsics); assert(debugThrowIfNotCheckingIntrinsics());
return 0.0; return 0.0;
} }
@override @override
double getMaxIntrinsicHeight(double width) { double getMaxIntrinsicHeight(double width) {
assert(debugThrowIfNotCheckingIntrinsics); assert(debugThrowIfNotCheckingIntrinsics());
return 0.0; return 0.0;
} }
......
...@@ -287,8 +287,17 @@ abstract class Widget { ...@@ -287,8 +287,17 @@ abstract class Widget {
return '$name(${data.join("; ")})'; return '$name(${data.join("; ")})';
} }
@protected
@mustCallSuper
void debugFillDescription(List<String> description) { } void debugFillDescription(List<String> description) { }
/// Lets [Element.debugFillDescription] call the @protected method
/// [debugFillDescription]. This pattern prevents other unwanted callers
/// outside this library.
void _debugFillDescription(List<String> description) {
debugFillDescription(description);
}
static bool canUpdate(Widget oldWidget, Widget newWidget) { static bool canUpdate(Widget oldWidget, Widget newWidget) {
return oldWidget.runtimeType == newWidget.runtimeType && return oldWidget.runtimeType == newWidget.runtimeType &&
oldWidget.key == newWidget.key; oldWidget.key == newWidget.key;
...@@ -315,6 +324,7 @@ abstract class StatelessWidget extends Widget { ...@@ -315,6 +324,7 @@ abstract class StatelessWidget extends Widget {
/// The given build context object contains information about the location in /// The given build context object contains information about the location in
/// the tree at which this widget is being built. For example, the context /// the tree at which this widget is being built. For example, the context
/// provides the set of inherited widgets for this location in the tree. /// provides the set of inherited widgets for this location in the tree.
@protected
Widget build(BuildContext context); Widget build(BuildContext context);
} }
...@@ -468,11 +478,13 @@ abstract class State<T extends StatefulWidget> { ...@@ -468,11 +478,13 @@ abstract class State<T extends StatefulWidget> {
/// The context argument is always the same as [State.context]. This argument /// The context argument is always the same as [State.context]. This argument
/// is provided redundantly here to match the [WidgetBuilder] function /// is provided redundantly here to match the [WidgetBuilder] function
/// signature used by [StatelessWidget.build] and other widgets. /// signature used by [StatelessWidget.build] and other widgets.
@protected
Widget build(BuildContext context); Widget build(BuildContext context);
/// Called when an Inherited widget in the ancestor chain has changed. Usually /// Called when an Inherited widget in the ancestor chain has changed. Usually
/// there is nothing to do here; whenever this is called, build() is also /// there is nothing to do here; whenever this is called, build() is also
/// called. /// called.
@mustCallSuper
void dependenciesChanged() { } void dependenciesChanged() { }
@override @override
...@@ -482,6 +494,8 @@ abstract class State<T extends StatefulWidget> { ...@@ -482,6 +494,8 @@ abstract class State<T extends StatefulWidget> {
return '$runtimeType(${data.join("; ")})'; return '$runtimeType(${data.join("; ")})';
} }
@protected
@mustCallSuper
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
description.add('$hashCode'); description.add('$hashCode');
assert(() { assert(() {
...@@ -961,6 +975,7 @@ abstract class Element implements BuildContext { ...@@ -961,6 +975,7 @@ abstract class Element implements BuildContext {
/// The updateChild() method returns the new child, if it had to create one, /// The updateChild() method returns the new child, if it had to create one,
/// or the child that was passed in, if it just had to update the child, or /// or the child that was passed in, if it just had to update the child, or
/// null, if it removed the child and did not replace it. /// null, if it removed the child and did not replace it.
@protected
Element updateChild(Element child, Widget newWidget, dynamic newSlot) { Element updateChild(Element child, Widget newWidget, dynamic newSlot) {
if (newWidget == null) { if (newWidget == null) {
if (child != null) if (child != null)
...@@ -1029,6 +1044,7 @@ abstract class Element implements BuildContext { ...@@ -1029,6 +1044,7 @@ abstract class Element implements BuildContext {
/// Called by MultiChildRenderObjectElement, and other RenderObjectElement /// Called by MultiChildRenderObjectElement, and other RenderObjectElement
/// subclasses that have multiple children, to update the slot of a particular /// subclasses that have multiple children, to update the slot of a particular
/// child when the child is moved in its child list. /// child when the child is moved in its child list.
@protected
void updateSlotForChild(Element child, dynamic newSlot) { void updateSlotForChild(Element child, dynamic newSlot) {
assert(_debugLifecycleState == _ElementLifecycle.active); assert(_debugLifecycleState == _ElementLifecycle.active);
assert(child != null); assert(child != null);
...@@ -1088,6 +1104,7 @@ abstract class Element implements BuildContext { ...@@ -1088,6 +1104,7 @@ abstract class Element implements BuildContext {
return element; return element;
} }
@protected
Element inflateWidget(Widget newWidget, dynamic newSlot) { Element inflateWidget(Widget newWidget, dynamic newSlot) {
assert(newWidget != null); assert(newWidget != null);
Key key = newWidget.key; Key key = newWidget.key;
...@@ -1120,6 +1137,7 @@ abstract class Element implements BuildContext { ...@@ -1120,6 +1137,7 @@ abstract class Element implements BuildContext {
}); });
} }
@protected
void deactivateChild(Element child) { void deactivateChild(Element child) {
assert(child != null); assert(child != null);
assert(child._parent == this); assert(child._parent == this);
...@@ -1184,6 +1202,7 @@ abstract class Element implements BuildContext { ...@@ -1184,6 +1202,7 @@ abstract class Element implements BuildContext {
} }
/// Called after children have been deactivated (see [deactivate]). /// Called after children have been deactivated (see [deactivate]).
@mustCallSuper
void debugDeactivated() { void debugDeactivated() {
assert(_debugLifecycleState == _ElementLifecycle.inactive); assert(_debugLifecycleState == _ElementLifecycle.inactive);
} }
...@@ -1271,7 +1290,8 @@ abstract class Element implements BuildContext { ...@@ -1271,7 +1290,8 @@ abstract class Element implements BuildContext {
ancestor = ancestor._parent; ancestor = ancestor._parent;
} }
void dependenciesChanged(); @mustCallSuper
void dependenciesChanged() { }
String debugGetCreatorChain(int limit) { String debugGetCreatorChain(int limit) {
List<String> chain = <String>[]; List<String> chain = <String>[];
...@@ -1297,6 +1317,8 @@ abstract class Element implements BuildContext { ...@@ -1297,6 +1317,8 @@ abstract class Element implements BuildContext {
return '$name(${data.join("; ")})'; return '$name(${data.join("; ")})';
} }
@protected
@mustCallSuper
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
if (depth == null) if (depth == null)
description.add('no depth'); description.add('no depth');
...@@ -1305,7 +1327,7 @@ abstract class Element implements BuildContext { ...@@ -1305,7 +1327,7 @@ abstract class Element implements BuildContext {
} else { } else {
if (widget.key != null) if (widget.key != null)
description.add('${widget.key}'); description.add('${widget.key}');
widget.debugFillDescription(description); widget._debugFillDescription(description);
} }
} }
...@@ -1348,6 +1370,7 @@ class ErrorWidget extends LeafRenderObjectWidget { ...@@ -1348,6 +1370,7 @@ class ErrorWidget extends LeafRenderObjectWidget {
@override @override
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('message: ' + _stringify(message)); description.add('message: ' + _stringify(message));
} }
} }
...@@ -1465,10 +1488,12 @@ abstract class BuildableElement extends Element { ...@@ -1465,10 +1488,12 @@ abstract class BuildableElement extends Element {
} }
/// Called by rebuild() after the appropriate checks have been made. /// Called by rebuild() after the appropriate checks have been made.
@protected
void performRebuild(); void performRebuild();
@override @override
void dependenciesChanged() { void dependenciesChanged() {
super.dependenciesChanged();
assert(_active); assert(_active);
markNeedsBuild(); markNeedsBuild();
} }
...@@ -1740,6 +1765,7 @@ abstract class _ProxyElement extends ComponentElement { ...@@ -1740,6 +1765,7 @@ abstract class _ProxyElement extends ComponentElement {
rebuild(); rebuild();
} }
@protected
void notifyClients(_ProxyWidget oldWidget); void notifyClients(_ProxyWidget oldWidget);
} }
...@@ -1835,6 +1861,7 @@ class InheritedElement extends _ProxyElement { ...@@ -1835,6 +1861,7 @@ class InheritedElement extends _ProxyElement {
/// returns true. Subclasses of [InheritedElement] might wish to call this /// returns true. Subclasses of [InheritedElement] might wish to call this
/// function at other times if their inherited information changes outside of /// function at other times if their inherited information changes outside of
/// the build phase. /// the build phase.
@protected
void dispatchDependenciesChanged() { void dispatchDependenciesChanged() {
for (Element dependent in _dependents) { for (Element dependent in _dependents) {
assert(() { assert(() {
...@@ -1886,7 +1913,7 @@ abstract class RenderObjectElement extends BuildableElement { ...@@ -1886,7 +1913,7 @@ abstract class RenderObjectElement extends BuildableElement {
void mount(Element parent, dynamic newSlot) { void mount(Element parent, dynamic newSlot) {
super.mount(parent, newSlot); super.mount(parent, newSlot);
_renderObject = widget.createRenderObject(this); _renderObject = widget.createRenderObject(this);
assert(() { debugUpdateRenderObjectOwner(); return true; }); assert(() { _debugUpdateRenderObjectOwner(); return true; });
assert(_slot == newSlot); assert(_slot == newSlot);
attachRenderObject(newSlot); attachRenderObject(newSlot);
_dirty = false; _dirty = false;
...@@ -1896,12 +1923,12 @@ abstract class RenderObjectElement extends BuildableElement { ...@@ -1896,12 +1923,12 @@ abstract class RenderObjectElement extends BuildableElement {
void update(RenderObjectWidget newWidget) { void update(RenderObjectWidget newWidget) {
super.update(newWidget); super.update(newWidget);
assert(widget == newWidget); assert(widget == newWidget);
assert(() { debugUpdateRenderObjectOwner(); return true; }); assert(() { _debugUpdateRenderObjectOwner(); return true; });
widget.updateRenderObject(this, renderObject); widget.updateRenderObject(this, renderObject);
_dirty = false; _dirty = false;
} }
void debugUpdateRenderObjectOwner() { void _debugUpdateRenderObjectOwner() {
_renderObject.debugCreator = debugGetCreatorChain(10); _renderObject.debugCreator = debugGetCreatorChain(10);
} }
...@@ -1915,6 +1942,7 @@ abstract class RenderObjectElement extends BuildableElement { ...@@ -1915,6 +1942,7 @@ abstract class RenderObjectElement extends BuildableElement {
/// Attempts to update the given old children list using the given new /// Attempts to update the given old children list using the given new
/// widgets, removing obsolete elements and introducing new ones as necessary, /// widgets, removing obsolete elements and introducing new ones as necessary,
/// and then returns the new child list. /// and then returns the new child list.
@protected
List<Element> updateChildren(List<Element> oldChildren, List<Widget> newWidgets, { Set<Element> detachedChildren }) { List<Element> updateChildren(List<Element> oldChildren, List<Widget> newWidgets, { Set<Element> detachedChildren }) {
assert(oldChildren != null); assert(oldChildren != null);
assert(newWidgets != null); assert(newWidgets != null);
...@@ -2115,8 +2143,13 @@ abstract class RenderObjectElement extends BuildableElement { ...@@ -2115,8 +2143,13 @@ abstract class RenderObjectElement extends BuildableElement {
_slot = null; _slot = null;
} }
@protected
void insertChildRenderObject(RenderObject child, dynamic slot); void insertChildRenderObject(RenderObject child, dynamic slot);
@protected
void moveChildRenderObject(RenderObject child, dynamic slot); void moveChildRenderObject(RenderObject child, dynamic slot);
@protected
void removeChildRenderObject(RenderObject child); void removeChildRenderObject(RenderObject child);
@override @override
......
...@@ -185,6 +185,7 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> { ...@@ -185,6 +185,7 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> {
@override @override
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('cached blocks identity: ${_cachedBlocks.hashCode}'); description.add('cached blocks identity: ${_cachedBlocks.hashCode}');
} }
} }
......
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