Migration: introduce NodeChange.toString() method.

This should make it easier to debug failures in FixBuilder unit tests.

Change-Id: I785e939648f10753ae9ac1e18530248c728a7157
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145564
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2020-04-30 21:52:32 +00:00 committed by commit-bot@chromium.org
parent ff53bd8d4a
commit 31c8b587b1

View file

@ -214,6 +214,11 @@ abstract class NodeChange<N extends AstNode> {
/// information.
bool get isInformative => false;
Iterable<String> get _toStringParts => const [];
@override
toString() => '$runtimeType(${_toStringParts.join(', ')})';
/// Applies this change to the given [node], producing an [EditPlan]. The
/// [aggregator] may be used to gather up any edits to the node's descendants
/// into their own [EditPlan]s.
@ -245,6 +250,10 @@ class NodeChangeForAnnotation extends NodeChange<Annotation> {
NodeChangeForAnnotation() : super._();
@override
Iterable<String> get _toStringParts =>
[if (changeToRequiredKeyword) 'changeToRequiredKeyword'];
@override
EditPlan _apply(Annotation node, FixAggregator aggregator) {
if (!changeToRequiredKeyword) {
@ -275,6 +284,10 @@ class NodeChangeForAsExpression extends NodeChangeForExpression<AsExpression> {
/// Indicates whether the cast should be removed.
bool removeAs = false;
@override
Iterable<String> get _toStringParts =>
[...super._toStringParts, if (removeAs) 'removeAs'];
@override
EditPlan _apply(AsExpression node, FixAggregator aggregator) {
if (removeAs) {
@ -295,6 +308,10 @@ class NodeChangeForCompilationUnit extends NodeChange<CompilationUnit> {
NodeChangeForCompilationUnit() : super._();
@override
Iterable<String> get _toStringParts =>
[if (removeLanguageVersionComment) 'removeLanguageVersionComment'];
@override
EditPlan _apply(CompilationUnit node, FixAggregator aggregator) {
List<EditPlan> innerPlans = [];
@ -324,6 +341,10 @@ mixin NodeChangeForConditional<N extends AstNode> on NodeChange<N> {
/// the [AtomicEditInfo] for the edit that removes the dead code.
FixReasonInfo conditionReason;
@override
Iterable<String> get _toStringParts =>
[...super._toStringParts, if (conditionValue != null) 'conditionValue'];
/// If dead code removal is warranted for [node], returns an [EditPlan] that
/// removes the dead code (and performs appropriate updates within any
/// descendant AST nodes that remain). Otherwise returns `null`.
@ -434,6 +455,10 @@ class NodeChangeForDefaultFormalParameter
NodeChangeForDefaultFormalParameter() : super._();
@override
Iterable<String> get _toStringParts =>
[if (addRequiredKeyword) 'addRequiredKeyword'];
@override
EditPlan _apply(DefaultFormalParameter node, FixAggregator aggregator) {
var innerPlan = aggregator.innerPlanForNode(node);
@ -471,6 +496,12 @@ class NodeChangeForExpression<N extends Expression> extends NodeChange<N> {
/// being introduced.
DartType get introducesAsType => _introducesAsType;
@override
Iterable<String> get _toStringParts => [
if (_addsNullCheck) 'addsNullCheck',
if (_introducesAsType != null) 'introducesAsType'
];
/// Causes a null check to be added to this expression, with the given [info].
void addNullCheck(AtomicEditInfo info, {HintComment hint}) {
assert(!_addsNullCheck);
@ -581,6 +612,10 @@ mixin NodeChangeForNullAware<N extends Expression> on NodeChange<N> {
/// Indicates whether null-awareness should be removed.
bool removeNullAwareness = false;
@override
Iterable<String> get _toStringParts =>
[...super._toStringParts, if (removeNullAwareness) 'removeNullAwareness'];
/// Returns an [EditPlan] that removes null awareness, if appropriate.
/// Otherwise returns `null`.
EditPlan _applyNullAware(N node, FixAggregator aggregator) {
@ -625,6 +660,10 @@ class NodeChangeForSimpleFormalParameter
NodeChangeForSimpleFormalParameter() : super._();
@override
Iterable<String> get _toStringParts =>
[if (addExplicitType != null) 'addExplicitType'];
@override
EditPlan _apply(SimpleFormalParameter node, FixAggregator aggregator) {
var innerPlan = aggregator.innerPlanForNode(node);
@ -663,6 +702,12 @@ class NodeChangeForTypeAnnotation extends NodeChange<TypeAnnotation> {
/// it.
HintComment get nullabilityHint => _nullabilityHint;
@override
Iterable<String> get _toStringParts => [
if (_makeNullable) 'makeNullable',
if (_nullabilityHint != null) 'nullabilityHint'
];
void recordNullability(DecoratedType decoratedType, bool makeNullable,
{HintComment nullabilityHint}) {
_decoratedType = decoratedType;
@ -728,6 +773,13 @@ class NodeChangeForVariableDeclarationList
NodeChangeForVariableDeclarationList() : super._();
@override
Iterable<String> get _toStringParts => [
if (addExplicitType != null) 'addExplicitType',
if (lateAdditionReason != null) 'lateAdditionReason',
if (lateHint != null) 'lateHint'
];
@override
EditPlan _apply(VariableDeclarationList node, FixAggregator aggregator) {
List<EditPlan> innerPlans = [];