replaceChild method
DartBlockValueTreeAlgebraicNode?
replaceChild(
- DartBlockValueTreeAlgebraicNode oldChild,
- DartBlockValueTreeAlgebraicNode? newChild
override
Only implemented by ArithmeticOperatorNode which features two child (left, right) properties. All other subclasses have empty implementations.
Implementation
@override
DartBlockValueTreeAlgebraicNode? replaceChild(
DartBlockValueTreeAlgebraicNode oldChild,
DartBlockValueTreeAlgebraicNode? newChild,
) {
if (leftChild == oldChild) {
leftChild = newChild;
leftChild?.parent = this;
} else if (rightChild == oldChild) {
rightChild = newChild;
rightChild?.parent = this;
}
if (leftChild == null) {
if (operator != DartBlockAlgebraicOperator.subtract &&
operator != DartBlockAlgebraicOperator.add) {
operator = null;
if (parent == null) {
rightChild?.parent = null;
return rightChild;
} else {
return parent?.replaceChild(this, rightChild);
}
}
}
if (rightChild == null && operator == null) {
if (parent == null) {
leftChild?.parent = null;
return leftChild;
} else {
return parent?.replaceChild(this, leftChild);
}
}
return this;
}