@@ -802,7 +802,7 @@ class SourceVisitor extends ThrowingAstVisitor {
802
802
token (node.equals);
803
803
space ();
804
804
805
- visit (node.superclass2 );
805
+ visit (node.superclass );
806
806
807
807
builder.startRule (CombinatorRule ());
808
808
visit (node.withClause);
@@ -834,11 +834,12 @@ class SourceVisitor extends ThrowingAstVisitor {
834
834
835
835
var needsDouble = true ;
836
836
for (var declaration in node.declarations) {
837
- var hasClassBody = declaration is ClassDeclaration ||
837
+ var hasBody = declaration is ClassDeclaration ||
838
+ declaration is EnumDeclaration ||
838
839
declaration is ExtensionDeclaration ;
839
840
840
- // Add a blank line before declarations with class-like bodies.
841
- if (hasClassBody ) needsDouble = true ;
841
+ // Add a blank line before types with bodies.
842
+ if (hasBody ) needsDouble = true ;
842
843
843
844
if (needsDouble) {
844
845
twoNewlines ();
@@ -851,8 +852,8 @@ class SourceVisitor extends ThrowingAstVisitor {
851
852
visit (declaration);
852
853
853
854
needsDouble = false ;
854
- if (hasClassBody ) {
855
- // Add a blank line after declarations with class-like bodies.
855
+ if (hasBody ) {
856
+ // Add a blank line after types declarations with bodies.
856
857
needsDouble = true ;
857
858
} else if (declaration is FunctionDeclaration ) {
858
859
// Add a blank line after non-empty block functions.
@@ -1068,7 +1069,7 @@ class SourceVisitor extends ThrowingAstVisitor {
1068
1069
1069
1070
@override
1070
1071
void visitConstructorName (ConstructorName node) {
1071
- visit (node.type2 );
1072
+ visit (node.type );
1072
1073
token (node.period);
1073
1074
visit (node.name);
1074
1075
}
@@ -1165,25 +1166,80 @@ class SourceVisitor extends ThrowingAstVisitor {
1165
1166
void visitEnumConstantDeclaration (EnumConstantDeclaration node) {
1166
1167
visitMetadata (node.metadata);
1167
1168
visit (node.name);
1169
+
1170
+ var arguments = node.arguments;
1171
+ if (arguments != null ) {
1172
+ builder.nestExpression ();
1173
+ visit (arguments.typeArguments);
1174
+
1175
+ var constructor = arguments.constructorSelector;
1176
+ if (constructor != null ) {
1177
+ token (constructor.period);
1178
+ visit (constructor.name);
1179
+ }
1180
+
1181
+ visitArgumentList (arguments.argumentList, nestExpression: false );
1182
+ builder.unnest ();
1183
+ }
1168
1184
}
1169
1185
1170
1186
@override
1171
1187
void visitEnumDeclaration (EnumDeclaration node) {
1172
1188
visitMetadata (node.metadata);
1173
1189
1190
+ builder.nestExpression ();
1174
1191
token (node.enumKeyword);
1175
1192
space ();
1176
1193
visit (node.name);
1194
+ visit (node.typeParameters);
1195
+
1196
+ builder.startRule (CombinatorRule ());
1197
+ visit (node.withClause);
1198
+ visit (node.implementsClause);
1199
+ builder.endRule ();
1177
1200
space ();
1178
1201
1202
+ builder.unnest ();
1203
+
1179
1204
_beginBody (node.leftBracket, space: true );
1180
1205
visitCommaSeparatedNodes (node.constants, between: splitOrTwoNewlines);
1181
1206
1182
1207
// If there is a trailing comma, always force the constants to split.
1183
- if (hasCommaAfter (node.constants.last)) {
1208
+ Token ? trailingComma = _commaAfter (node.constants.last);
1209
+ if (trailingComma != null ) {
1184
1210
builder.forceRules ();
1185
1211
}
1186
1212
1213
+ // The ";" after the constants, which may occur after a trailing comma.
1214
+ Token afterConstants = node.constants.last.endToken.next! ;
1215
+ Token ? semicolon;
1216
+ if (afterConstants.type == TokenType .SEMICOLON ) {
1217
+ semicolon = node.constants.last.endToken.next! ;
1218
+ } else if (trailingComma != null &&
1219
+ trailingComma.next! .type == TokenType .SEMICOLON ) {
1220
+ semicolon = afterConstants.next! ;
1221
+ }
1222
+
1223
+ if (semicolon != null ) {
1224
+ // If there is both a trailing comma and a semicolon, move the semicolon
1225
+ // to the next line. This doesn't look great but it's less bad than being
1226
+ // next to the comma.
1227
+ // TODO(rnystrom): If the formatter starts making non-whitespace changes
1228
+ // like adding/removing trailing commas, then it should fix this too.
1229
+ if (trailingComma != null ) newline ();
1230
+
1231
+ token (semicolon);
1232
+
1233
+ // Always split the constants if they end in ";", even if there aren't
1234
+ // any members.
1235
+ builder.forceRules ();
1236
+
1237
+ // Put a blank line between the constants and members.
1238
+ if (node.members.isNotEmpty) twoNewlines ();
1239
+ }
1240
+
1241
+ _visitMembers (node.members);
1242
+
1187
1243
_endBody (node.rightBracket, space: true );
1188
1244
}
1189
1245
@@ -1373,7 +1429,7 @@ class SourceVisitor extends ThrowingAstVisitor {
1373
1429
soloSplit ();
1374
1430
token (node.extendsKeyword);
1375
1431
space ();
1376
- visit (node.superclass2 );
1432
+ visit (node.superclass );
1377
1433
}
1378
1434
1379
1435
@override
@@ -1999,7 +2055,7 @@ class SourceVisitor extends ThrowingAstVisitor {
1999
2055
2000
2056
@override
2001
2057
void visitImplementsClause (ImplementsClause node) {
2002
- _visitCombinator (node.implementsKeyword, node.interfaces2 );
2058
+ _visitCombinator (node.implementsKeyword, node.interfaces );
2003
2059
}
2004
2060
2005
2061
@override
@@ -2264,18 +2320,18 @@ class SourceVisitor extends ThrowingAstVisitor {
2264
2320
// If there is only a single superclass constraint, format it like an
2265
2321
// "extends" in a class.
2266
2322
var onClause = node.onClause;
2267
- if (onClause != null && onClause.superclassConstraints2 .length == 1 ) {
2323
+ if (onClause != null && onClause.superclassConstraints .length == 1 ) {
2268
2324
soloSplit ();
2269
2325
token (onClause.onKeyword);
2270
2326
space ();
2271
- visit (onClause.superclassConstraints2 .single);
2327
+ visit (onClause.superclassConstraints .single);
2272
2328
}
2273
2329
2274
2330
builder.startRule (CombinatorRule ());
2275
2331
2276
2332
// If there are multiple superclass constraints, format them like the
2277
2333
// "implements" clause.
2278
- if (onClause != null && onClause.superclassConstraints2 .length > 1 ) {
2334
+ if (onClause != null && onClause.superclassConstraints .length > 1 ) {
2279
2335
visit (onClause);
2280
2336
}
2281
2337
@@ -2326,7 +2382,7 @@ class SourceVisitor extends ThrowingAstVisitor {
2326
2382
2327
2383
@override
2328
2384
void visitOnClause (OnClause node) {
2329
- _visitCombinator (node.onKeyword, node.superclassConstraints2 );
2385
+ _visitCombinator (node.onKeyword, node.superclassConstraints );
2330
2386
}
2331
2387
2332
2388
@override
@@ -2730,7 +2786,7 @@ class SourceVisitor extends ThrowingAstVisitor {
2730
2786
2731
2787
@override
2732
2788
void visitWithClause (WithClause node) {
2733
- _visitCombinator (node.withKeyword, node.mixinTypes2 );
2789
+ _visitCombinator (node.withKeyword, node.mixinTypes );
2734
2790
}
2735
2791
2736
2792
@override
0 commit comments