Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Unified Diff: pkg/analyzer/lib/src/dart/ast/utilities.dart

Issue 2085553002: Implement _SameResolutionValidator as AstComparator. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/incremental_resolution_validator.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/ast/utilities.dart
diff --git a/pkg/analyzer/lib/src/dart/ast/utilities.dart b/pkg/analyzer/lib/src/dart/ast/utilities.dart
index e3e379f02c00eeb57994605db6ada8deac9ad451..e2867a32d32e45c9998dbbd47d83679d10e6999f 100644
--- a/pkg/analyzer/lib/src/dart/ast/utilities.dart
+++ b/pkg/analyzer/lib/src/dart/ast/utilities.dart
@@ -994,6 +994,37 @@ class AstComparator implements AstVisitor<bool> {
AstNode _other;
/**
+ * Notify that [first] and second have different length.
+ * This implementation returns `false`. Subclasses can override and throw.
+ */
+ bool failDifferentLength(List first, List second) {
+ return false;
+ }
+
+ /**
+ * Check whether [second] is null. Subclasses can override to throw.
+ */
+ bool failIfNotNull(Object first, Object second) {
+ return second == null;
+ }
+
+ /**
+ * Notify that [first] is not `null` while [second] one is `null`.
+ * This implementation returns `false`. Subclasses can override and throw.
+ */
+ bool failIsNull(Object first, Object second) {
+ return false;
+ }
+
+ /**
+ * Notify that [first] and [second] have different types.
+ * This implementation returns `false`. Subclasses can override and throw.
+ */
+ bool failRuntimeType(Object first, Object second) {
+ return false;
+ }
+
+ /**
* Return `true` if the [first] node and the [second] node have the same
* structure.
*
@@ -1002,11 +1033,11 @@ class AstComparator implements AstVisitor<bool> {
*/
bool isEqualNodes(AstNode first, AstNode second) {
if (first == null) {
- return second == null;
+ return failIfNotNull(first, second);
} else if (second == null) {
- return false;
+ return failIsNull(first, second);
} else if (first.runtimeType != second.runtimeType) {
- return false;
+ return failRuntimeType(first, second);
}
_other = second;
return first.accept(this);
@@ -1021,17 +1052,24 @@ class AstComparator implements AstVisitor<bool> {
*/
bool isEqualTokens(Token first, Token second) {
if (first == null) {
- return second == null;
+ return failIfNotNull(first, second);
} else if (second == null) {
- return false;
+ return failIsNull(first, second);
} else if (identical(first, second)) {
return true;
}
- return first.offset == second.offset &&
- first.length == second.length &&
- first.lexeme == second.lexeme;
+ return isEqualTokensNotNull(first, second);
}
+ /**
+ * Return `true` if the [first] token and the [second] token have the same
+ * structure. Both [first] and [second] are not `null`.
+ */
+ bool isEqualTokensNotNull(Token first, Token second) =>
+ first.offset == second.offset &&
+ first.length == second.length &&
+ first.lexeme == second.lexeme;
+
@override
bool visitAdjacentStrings(AdjacentStrings node) {
AdjacentStrings other = _other as AdjacentStrings;
@@ -2016,13 +2054,13 @@ class AstComparator implements AstVisitor<bool> {
*/
bool _isEqualNodeLists(NodeList first, NodeList second) {
if (first == null) {
- return second == null;
+ return failIfNotNull(first, second);
} else if (second == null) {
- return false;
+ return failIsNull(first, second);
}
int size = first.length;
if (second.length != size) {
- return false;
+ return failDifferentLength(first, second);
}
for (int i = 0; i < size; i++) {
if (!isEqualNodes(first[i], second[i])) {
@@ -2039,7 +2077,7 @@ class AstComparator implements AstVisitor<bool> {
bool _isEqualTokenLists(List<Token> first, List<Token> second) {
int length = first.length;
if (second.length != length) {
- return false;
+ return failDifferentLength(first, second);
}
for (int i = 0; i < length; i++) {
if (!isEqualTokens(first[i], second[i])) {
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/incremental_resolution_validator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698