Skip to content

Commit ed57918

Browse files
authored
make generation easier to debug (#753)
1 parent 7b349ea commit ed57918

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/Append.java

+21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
*/
1010
final class Append {
1111

12+
private static final boolean debug = Boolean.getBoolean("append.debug");
13+
1214
private final Writer writer;
15+
private final StringBuilder stringBuilder = new StringBuilder();
1316
private int nameIndex;
1417
private boolean comma;
1518
private String extraIndent;
@@ -27,8 +30,14 @@ Append indent(String content) {
2730
try {
2831
if (extraIndent != null) {
2932
writer.append(extraIndent);
33+
if (debug) {
34+
stringBuilder.append(extraIndent);
35+
}
3036
}
3137
writer.append(content);
38+
if (debug) {
39+
stringBuilder.append(content);
40+
}
3241
return this;
3342
} catch (IOException e) {
3443
throw new UncheckedIOException(e);
@@ -38,6 +47,9 @@ Append indent(String content) {
3847
Append append(String content) {
3948
try {
4049
writer.append(content);
50+
if (debug) {
51+
stringBuilder.append(content);
52+
}
4153
return this;
4254
} catch (IOException e) {
4355
throw new UncheckedIOException(e);
@@ -56,6 +68,9 @@ void close() {
5668
Append eol() {
5769
try {
5870
writer.append("\n");
71+
if (debug) {
72+
stringBuilder.append("\n");
73+
}
5974
return this;
6075
} catch (IOException e) {
6176
throw new UncheckedIOException(e);
@@ -86,4 +101,10 @@ void commaAppend(String name) {
86101
}
87102
append(name);
88103
}
104+
105+
106+
@Override
107+
public String toString() {
108+
return stringBuilder.toString();
109+
}
89110
}

inject-generator/src/test/java/io/avaje/inject/generator/InjectProcessorTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ void deleteGeneratedFiles() {
4646
//@Disabled
4747
@Test
4848
void testGeneration() throws Exception {
49+
50+
System.setProperty("append.debug", "true");
51+
4952
final String source =
5053
Paths.get("src/test/java/io/avaje/inject/generator/models/valid")
5154
.toAbsolutePath()

0 commit comments

Comments
 (0)