Skip to content

Commit 7688765

Browse files
committed
misc(_Builder): handle edge case where generator toString is multiline
- also moved "rendering" of the `Generator:` prefix to GeneratedOutput - Sets up changes in future commits
1 parent 9f916fb commit 7688765

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

source_gen/lib/src/builder.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:convert';
67

78
import 'package:analyzer/dart/element/element.dart';
89
import 'package:build/build.dart';
@@ -106,14 +107,15 @@ class _Builder extends Builder {
106107
contentBuffer.writeln('part of $name;');
107108
}
108109

109-
for (var output in generatedOutputs) {
110+
for (var item in generatedOutputs) {
110111
contentBuffer
111112
..writeln()
112113
..writeln(_headerLine)
113-
..writeln('// Generator: ${output.generator}')
114+
..writeAll(
115+
LineSplitter.split(item.toString()).map((line) => '// $line\n'))
114116
..writeln(_headerLine)
115117
..writeln()
116-
..write(output.output);
118+
..write(item.output);
117119
}
118120

119121
var genPartContent = contentBuffer.toString();

source_gen/lib/src/generated_output.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class GeneratedOutput {
2121

2222
GeneratedOutput.fromError(this.generator, this.error, this.stackTrace)
2323
: this.output = _outputFromError(error);
24+
25+
@override
26+
String toString() => 'Generator: $generator';
2427
}
2528

2629
String _outputFromError(Object error) {

0 commit comments

Comments
 (0)