diff --git a/pkg/analyzer/lib/dart/ast/ast.dart b/pkg/analyzer/lib/dart/ast/ast.dart index ed1a7853083..a2faf9dbf94 100644 --- a/pkg/analyzer/lib/dart/ast/ast.dart +++ b/pkg/analyzer/lib/dart/ast/ast.dart @@ -3768,6 +3768,10 @@ abstract class NodeList implements List { /// if the list is empty. Token? get endToken; + @Deprecated('NodeList cannot be resized') + @override + set length(int newLength); + /// Return the node that is the parent of each of the elements in the list. AstNode get owner; @@ -3778,6 +3782,26 @@ abstract class NodeList implements List { /// Use the given [visitor] to visit each of the nodes in this list. void accept(AstVisitor visitor); + + @Deprecated('NodeList cannot be resized') + @override + void add(E element); + + @Deprecated('NodeList cannot be resized') + @override + void addAll(Iterable iterable); + + @Deprecated('NodeList cannot be resized') + @override + void clear(); + + @Deprecated('NodeList cannot be resized') + @override + void insert(int index, E element); + + @Deprecated('NodeList cannot be resized') + @override + E removeAt(int index); } /// A formal parameter that is required (is not optional). diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart index 2d169b5a67b..faeb5121c37 100644 --- a/pkg/analyzer/lib/src/dart/ast/ast.dart +++ b/pkg/analyzer/lib/src/dart/ast/ast.dart @@ -2362,7 +2362,7 @@ class CompilationUnitImpl extends AstNodeImpl implements CompilationUnit { int get offset => 0; @override - ScriptTag? get scriptTag => _scriptTag; + ScriptTagImpl? get scriptTag => _scriptTag; set scriptTag(ScriptTag? scriptTag) { _scriptTag = _becomeParentOf(scriptTag as ScriptTagImpl?); @@ -8933,7 +8933,7 @@ class NodeListImpl with ListMixin implements NodeList { late final AstNodeImpl _owner; /// The elements contained in the list. - List _elements = []; + late final List _elements; /// Initialize a newly created list of nodes such that all of the nodes that /// are added to the list will have their parent set to the given [owner]. @@ -8962,6 +8962,7 @@ class NodeListImpl with ListMixin implements NodeList { @override int get length => _elements.length; + @Deprecated('NodeList cannot be resized') @override set length(int newLength) { throw UnsupportedError("Cannot resize NodeList."); @@ -8995,46 +8996,46 @@ class NodeListImpl with ListMixin implements NodeList { } } + @Deprecated('NodeList cannot be resized') @override void add(E element) { - insert(length, element); + throw UnsupportedError("Cannot resize NodeList."); } + @Deprecated('NodeList cannot be resized') @override void addAll(Iterable iterable) { - for (E node in iterable) { - _elements.add(node); - _owner._becomeParentOf(node as AstNodeImpl); - } + throw UnsupportedError("Cannot resize NodeList."); } + @Deprecated('NodeList cannot be resized') @override void clear() { - _elements = []; + throw UnsupportedError("Cannot resize NodeList."); } + @Deprecated('NodeList cannot be resized') @override void insert(int index, E element) { - _elements.insert(index, element); - _owner._becomeParentOf(element as AstNodeImpl); + throw UnsupportedError("Cannot resize NodeList."); } + @Deprecated('NodeList cannot be resized') @override E removeAt(int index) { - if (index < 0 || index >= _elements.length) { - throw RangeError("Index: $index, Size: ${_elements.length}"); - } - return _elements.removeAt(index); + throw UnsupportedError("Cannot resize NodeList."); } /// Set the [owner] of this container, and populate it with [elements]. void _initialize(AstNodeImpl owner, List? elements) { _owner = owner; - if (elements != null) { + if (elements == null || elements.isEmpty) { + _elements = const []; + } else { + _elements = elements.toList(growable: false); var length = elements.length; for (var i = 0; i < length; i++) { var node = elements[i]; - _elements.add(node); owner._becomeParentOf(node as AstNodeImpl); } } @@ -9100,11 +9101,6 @@ abstract class NormalFormalParameterImpl extends FormalParameterImpl @override NodeListImpl get metadata => _metadata; - set metadata(List metadata) { - _metadata.clear(); - _metadata.addAll(metadata); - } - @override Token? get name => _identifier?.token; diff --git a/pkg/analyzer/lib/src/fasta/ast_builder.dart b/pkg/analyzer/lib/src/fasta/ast_builder.dart index 70e8562d783..7e64934b8aa 100644 --- a/pkg/analyzer/lib/src/fasta/ast_builder.dart +++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart @@ -838,10 +838,17 @@ class AstBuilder extends StackListener { debugEvent("Cascade"); var expression = pop() as Expression; - var receiver = pop() as CascadeExpression; + var cascade = pop() as CascadeExpressionImpl; pop(); // Token. - receiver.cascadeSections.add(expression); - push(receiver); + push( + CascadeExpressionImpl( + target: cascade.target, + cascadeSections: [ + ...cascade.cascadeSections, + expression, + ], + ), + ); } @override @@ -2656,18 +2663,49 @@ class AstBuilder extends StackListener { var statements = popTypedList2(statementCount); List members; + List popLabels() { + final labels = []; + while (peek() is LabelImpl) { + labels.insert(0, pop() as LabelImpl); + --labelCount; + } + return labels; + } + + SwitchMemberImpl updateSwitchMember({ + required SwitchMember member, + List