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

Unified Diff: pkg/analyzer/lib/src/dart/sdk/patch.dart

Issue 2417053002: Extract appending nodes to the list into a helper method. (Closed)
Patch Set: Created 4 years, 2 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/sdk/patch.dart
diff --git a/pkg/analyzer/lib/src/dart/sdk/patch.dart b/pkg/analyzer/lib/src/dart/sdk/patch.dart
index e6475c3a028e7ae4d5f37be559c2967e5563eabe..02b497cf392cb33b32b80bc76bf7b56c4ded717c 100644
--- a/pkg/analyzer/lib/src/dart/sdk/patch.dart
+++ b/pkg/analyzer/lib/src/dart/sdk/patch.dart
@@ -197,14 +197,9 @@ class SdkPatcher {
patchMember.offset);
}
}
- // Append new top-level declarations.
- Token lastToken = baseClass.endToken.previous;
- for (ClassMember newMember in membersToAppend) {
- newMember.endToken.setNext(lastToken.next);
- lastToken.setNext(newMember.beginToken);
- baseClass.members.add(newMember);
- lastToken = newMember.endToken;
- }
+ // Append new class members.
+ _appendToNodeList(
+ baseClass.members, membersToAppend, baseClass.leftBracket);
}
void _patchDirectives(
@@ -279,13 +274,8 @@ class SdkPatcher {
}
}
// Append new top-level declarations.
- Token lastToken = baseUnit.endToken.previous;
- for (CompilationUnitMember newDeclaration in declarationsToAppend) {
- newDeclaration.endToken.setNext(lastToken.next);
- lastToken.setNext(newDeclaration.beginToken);
- baseUnit.declarations.add(newDeclaration);
- lastToken = newDeclaration.endToken;
- }
+ _appendToNodeList(baseUnit.declarations, declarationsToAppend,
+ baseUnit.endToken.previous);
}
/**
@@ -310,6 +300,21 @@ class SdkPatcher {
}
/**
+ * Append [newNodes] to the given [nodes] and attach new tokens to the end
+ * token of the last [nodes] items, or, if it is empty, to [defaultPrevToken].
+ */
+ static void _appendToNodeList(
+ NodeList<AstNode> nodes, List<AstNode> newNodes, Token defaultPrevToken) {
+ Token prevToken = nodes.endToken ?? defaultPrevToken;
+ for (AstNode newNode in newNodes) {
+ newNode.endToken.setNext(prevToken.next);
+ prevToken.setNext(newNode.beginToken);
+ nodes.add(newNode);
+ prevToken = newNode.endToken;
+ }
+ }
+
+ /**
* Return `true` if [metadata] has the `@patch` annotation.
*/
static bool _hasPatchAnnotation(List<Annotation> metadata) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698