Skip to content

Commit 5a14b5e

Browse files
authored
Move collection argument counts from ArgumentRule to PositionalRule. (#1123)
I didn't notice until after I sent out the last refactoring that NamedRule doesn't use these fields at all so there's no reason for them to be in the base class.
1 parent 2aaddd0 commit 5a14b5e

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

lib/src/rule/argument.dart

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ abstract class ArgumentRule extends Rule {
99
/// The chunks prior to each positional argument.
1010
final List<Chunk?> _arguments = [];
1111

12-
/// The number of leading collection arguments.
13-
///
14-
/// This and [_trailingCollections] cannot both be positive. If every
15-
/// argument is a collection, this will be [_arguments.length] and
16-
/// [_trailingCollections] will be 0.
17-
final int _leadingCollections;
18-
19-
/// The number of trailing collections.
20-
///
21-
/// This and [_leadingCollections] cannot both be positive.
22-
final int _trailingCollections;
23-
2412
/// If true, then inner rules that are written will force this rule to split.
2513
///
2614
/// Temporarily disabled while writing collection arguments so that they can
@@ -31,8 +19,6 @@ abstract class ArgumentRule extends Rule {
3119
@override
3220
bool get splitsOnInnerRules => _trackInnerRules;
3321

34-
ArgumentRule._(this._leadingCollections, this._trailingCollections);
35-
3622
/// Remembers [chunk] as containing the split that occurs right before an
3723
/// argument in the list.
3824
void beforeArgument(Chunk? chunk) {
@@ -70,6 +56,18 @@ abstract class ArgumentRule extends Rule {
7056
/// splits before all of the non-collection arguments, but does not split
7157
/// before the collections, so that they can split internally.
7258
class PositionalRule extends ArgumentRule {
59+
/// The number of leading collection arguments.
60+
///
61+
/// This and [_trailingCollections] cannot both be positive. If every
62+
/// argument is a collection, this will be [_arguments.length] and
63+
/// [_trailingCollections] will be 0.
64+
final int _leadingCollections;
65+
66+
/// The number of trailing collections.
67+
///
68+
/// This and [_leadingCollections] cannot both be positive.
69+
final int _trailingCollections;
70+
7371
/// Creates a new rule for a positional argument list.
7472
///
7573
/// [argumentCount] is the number of arguments that will be added to the rule
@@ -82,33 +80,32 @@ class PositionalRule extends ArgumentRule {
8280
{required int argumentCount,
8381
int leadingCollections = 0,
8482
int trailingCollections = 0})
85-
: super._(leadingCollections, trailingCollections) {
86-
if (collectionRule != null) {
87-
// Don't split inside collections if there are leading collections and
88-
// we split before the first argument.
89-
if (leadingCollections > 0) {
90-
addConstraint(1, collectionRule, Rule.unsplit);
91-
}
83+
: _leadingCollections = leadingCollections,
84+
_trailingCollections = trailingCollections {
85+
// Don't split inside collections if there are leading collections and
86+
// we split before the first argument.
87+
if (leadingCollections > 0) {
88+
addConstraint(1, collectionRule!, Rule.unsplit);
89+
}
9290

93-
// If we're only splitting before the non-collection arguments, the
94-
// intent is to split inside the collections, so force that here.
95-
if (leadingCollections > 0 || trailingCollections > 0) {
96-
addConstraint(argumentCount + 1, collectionRule, 1);
97-
}
91+
// If we're only splitting before the non-collection arguments, the
92+
// intent is to split inside the collections, so force that here.
93+
if (leadingCollections > 0 || trailingCollections > 0) {
94+
addConstraint(argumentCount + 1, collectionRule!, 1);
95+
}
9896

99-
// Split before a single argument. If it's in the middle of the collection
100-
// arguments, don't allow them to split.
101-
for (var argument = 0; argument < leadingCollections; argument++) {
102-
var value = argumentCount - argument + 1;
103-
addConstraint(value, collectionRule, Rule.unsplit);
104-
}
97+
// Split before a single argument. If it's in the middle of the collection
98+
// arguments, don't allow them to split.
99+
for (var argument = 0; argument < leadingCollections; argument++) {
100+
var value = argumentCount - argument + 1;
101+
addConstraint(value, collectionRule!, Rule.unsplit);
102+
}
105103

106-
for (var argument = argumentCount - trailingCollections;
107-
argument < argumentCount;
108-
argument++) {
109-
var value = argumentCount - argument + 1;
110-
addConstraint(value, collectionRule, Rule.unsplit);
111-
}
104+
for (var argument = argumentCount - trailingCollections;
105+
argument < argumentCount;
106+
argument++) {
107+
var value = argumentCount - argument + 1;
108+
addConstraint(value, collectionRule!, Rule.unsplit);
112109
}
113110
}
114111

@@ -201,8 +198,7 @@ class NamedRule extends ArgumentRule {
201198
/// arguments in the list. It must be provided if [leadingCollections] or
202199
/// [trailingCollections] is non-zero.
203200
NamedRule(
204-
Rule? collectionRule, int leadingCollections, int trailingCollections)
205-
: super._(leadingCollections, trailingCollections) {
201+
Rule? collectionRule, int leadingCollections, int trailingCollections) {
206202
if (leadingCollections > 0 || trailingCollections > 0) {
207203
// Split only before the first argument. Don't allow the collections to
208204
// split.

0 commit comments

Comments
 (0)