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