Skip to content

Commit 1195125

Browse files
authored
Consistent blank after => members in class-likes (#2146)
Closes #1143 The `class` emitter already used `writeln` following a `=>` method to include blank lines between members. Make this consistent for enums, extensions, and mixins. Extract a method and use it for each type. Sort changelog with user-facing changes at the top.
1 parent 1b52e89 commit 1195125

File tree

3 files changed

+20
-37
lines changed

3 files changed

+20
-37
lines changed

pkgs/code_builder/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
## 4.10.2-wip
22

3+
* Support `Expression.newInstanceNamed` with empty name
4+
* Consistently add blank lines between `=>` in class-like definitions.
5+
* Fixed bug: Fields declared with `static` and `external` now produce code with
6+
correct order
37
* Upgrade `dart_style` and `source_gen` to remove `package:macros` dependency.
48
* Require Dart `^3.6.0` due to the upgrades.
5-
* Support `Expression.newInstanceNamed` with empty name
6-
* Fixed bug: Fields declared with `static` and `external` now produce code with correct order
79

810
## 4.10.1
911

pkgs/code_builder/lib/src/emitter.dart

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,7 @@ class DartEmitter extends Object
162162
visitField(f, out);
163163
out.writeln();
164164
}
165-
for (var m in spec.methods) {
166-
visitMethod(m, out);
167-
if (_isLambdaMethod(m)) {
168-
out.writeln(';');
169-
}
170-
out.writeln();
171-
}
165+
_visitMethods(spec.methods, out);
172166
out.writeln(' }');
173167
return out;
174168
}
@@ -201,13 +195,7 @@ class DartEmitter extends Object
201195
visitField(f, out);
202196
out.writeln();
203197
}
204-
for (var m in spec.methods) {
205-
visitMethod(m, out);
206-
if (_isLambdaMethod(m)) {
207-
out.write(';');
208-
}
209-
out.writeln();
210-
}
198+
_visitMethods(spec.methods, out);
211199
out.write(' }');
212200
return out;
213201
}
@@ -326,13 +314,7 @@ class DartEmitter extends Object
326314
visitField(f, out);
327315
out.writeln();
328316
}
329-
for (var m in spec.methods) {
330-
visitMethod(m, out);
331-
if (_isLambdaMethod(m)) {
332-
out.write(';');
333-
}
334-
out.writeln();
335-
}
317+
_visitMethods(spec.methods, out);
336318
out.writeln(' }');
337319
return out;
338320
}
@@ -372,13 +354,7 @@ class DartEmitter extends Object
372354
visitField(f, out);
373355
out.writeln();
374356
}
375-
for (var m in spec.methods) {
376-
visitMethod(m, out);
377-
if (_isLambdaMethod(m)) {
378-
out.writeln(';');
379-
}
380-
out.writeln();
381-
}
357+
_visitMethods(spec.methods, out);
382358
out.writeln('}');
383359
return out;
384360
}
@@ -800,6 +776,16 @@ class DartEmitter extends Object
800776
}
801777
}
802778

779+
void _visitMethods(Iterable<Method> methods, StringSink out) {
780+
for (final m in methods) {
781+
visitMethod(m, out);
782+
if (_isLambdaMethod(m)) {
783+
out.writeln(';');
784+
}
785+
out.writeln();
786+
}
787+
}
788+
803789
@override
804790
StringSink visitReference(Reference spec, [StringSink? output]) =>
805791
(output ??= StringBuffer())..write(allocator.allocate(spec));
@@ -907,13 +893,7 @@ class DartEmitter extends Object
907893
visitField(f, out);
908894
out.writeln();
909895
}
910-
for (var m in spec.methods) {
911-
visitMethod(m, out);
912-
if (_isLambdaMethod(m)) {
913-
out.write(';');
914-
}
915-
out.writeln();
916-
}
896+
_visitMethods(spec.methods, out);
917897
out.writeln(' }');
918898
return out;
919899
}

pkgs/code_builder/test/specs/enum_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ void main() {
373373
c;
374374
375375
int get myInt => 123;
376+
376377
Iterable<String> myStrings() sync* {
377378
yield 'a';
378379
yield 'b';

0 commit comments

Comments
 (0)