Update comparison utility to fix a bug and make it easier to subclass
Change-Id: I34447bb530215938da929320904c26fd7ef39771
Reviewed-on: https://dart-review.googlesource.com/71226
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/dart/ast/utilities.dart b/pkg/analyzer/lib/src/dart/ast/utilities.dart
index cd0aa53..d014ecd 100644
--- a/pkg/analyzer/lib/src/dart/ast/utilities.dart
+++ b/pkg/analyzer/lib/src/dart/ast/utilities.dart
@@ -1084,6 +1084,15 @@
}
/**
+ * Check whether the values of the [first] and [second] nodes are [equal].
+ * Subclasses can override to throw.
+ */
+ bool failIfNotEqual(
+ AstNode first, Object firstValue, AstNode second, Object secondValue) {
+ return firstValue == secondValue;
+ }
+
+ /**
* Check whether [second] is null. Subclasses can override to throw.
*/
bool failIfNotNull(Object first, Object second) {
@@ -1186,7 +1195,7 @@
@override
bool visitAssertInitializer(AssertInitializer node) {
- AssertStatement other = _other as AssertStatement;
+ AssertInitializer other = _other as AssertInitializer;
return isEqualTokens(node.assertKeyword, other.assertKeyword) &&
isEqualTokens(node.leftParenthesis, other.leftParenthesis) &&
isEqualNodes(node.condition, other.condition) &&
@@ -1248,7 +1257,7 @@
bool visitBooleanLiteral(BooleanLiteral node) {
BooleanLiteral other = _other as BooleanLiteral;
return isEqualTokens(node.literal, other.literal) &&
- node.value == other.value;
+ failIfNotEqual(node, node.value, other, other.value);
}
@override
@@ -1448,7 +1457,7 @@
bool visitDoubleLiteral(DoubleLiteral node) {
DoubleLiteral other = _other as DoubleLiteral;
return isEqualTokens(node.literal, other.literal) &&
- node.value == other.value;
+ failIfNotEqual(node, node.value, other, other.value);
}
@override
@@ -1723,7 +1732,7 @@
bool visitIntegerLiteral(IntegerLiteral node) {
IntegerLiteral other = _other as IntegerLiteral;
return isEqualTokens(node.literal, other.literal) &&
- (node.value == other.value);
+ failIfNotEqual(node, node.value, other, other.value);
}
@override
@@ -1738,7 +1747,7 @@
bool visitInterpolationString(InterpolationString node) {
InterpolationString other = _other as InterpolationString;
return isEqualTokens(node.contents, other.contents) &&
- node.value == other.value;
+ failIfNotEqual(node, node.value, other, other.value);
}
@override
@@ -2006,7 +2015,7 @@
bool visitSimpleStringLiteral(SimpleStringLiteral node) {
SimpleStringLiteral other = _other as SimpleStringLiteral;
return isEqualTokens(node.literal, other.literal) &&
- (node.value == other.value);
+ failIfNotEqual(node, node.value, other, other.value);
}
@override