| 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) {
|
|
|