Skip to content

Commit 9e0917c

Browse files
authored
Merge pull request #535 from avaje/feature/indent-generated-code-only
Adjust the indentation of the generated code for try/catch
2 parents 2b7eaa8 + cea5fa7 commit 9e0917c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,17 @@ void builderAddBeanProvider(Append writer) {
195195
return;
196196
}
197197
String indent = " ";
198-
199198
writer.indent(indent).append(" builder");
200199
if (prototype) {
201-
writer.append(".asPrototype()").eol();
200+
writer.append(".asPrototype()");
202201
} else if(secondary) {
203-
writer.append(".asSecondary()").eol();
202+
writer.append(".asSecondary()");
204203
}
205204

206205
writer.indent(String.format(".%s(() -> {", lazy ? "registerLazy" : "registerProvider")).eol();
207206

208-
startTry(writer);
209-
writer.indent(indent).append(" return ");
207+
startTry(writer, " ");
208+
writer.indent(indent).append(" return ");
210209
writer.append("factory.%s(", methodName);
211210
for (int i = 0; i < params.size(); i++) {
212211
if (i > 0) {
@@ -215,7 +214,7 @@ void builderAddBeanProvider(Append writer) {
215214
params.get(i).builderGetDependency(writer, "builder");
216215
}
217216
writer.append(");").eol();
218-
endTry(writer);
217+
endTry(writer, " ");
219218
writer.indent(indent).append(" });").eol();
220219
writer.indent(indent).append("}").eol();
221220
}
@@ -306,18 +305,26 @@ boolean methodThrows() {
306305
}
307306

308307
void startTry(Append writer) {
308+
startTry(writer, "");
309+
}
310+
311+
void startTry(Append writer, String indent) {
309312
if (methodThrows()) {
310-
writer.append(" try {").eol();
311-
writer.setExtraIndent(" ");
313+
writer.append(indent).append(" try {").eol();
314+
writer.setExtraIndent(" " + indent);
312315
}
313316
}
314317

315318
void endTry(Append writer) {
319+
endTry(writer, "");
320+
}
321+
322+
void endTry(Append writer, String indent) {
316323
if (methodThrows()) {
317324
writer.setExtraIndent(null);
318-
writer.append(" } catch (Throwable e) {").eol();
319-
writer.append(" throw new RuntimeException(\"Error during wiring\", e);").eol();
320-
writer.append(" }").eol();
325+
writer.append(indent).append(" } catch (Throwable e) {").eol();
326+
writer.append(indent).append(" throw new RuntimeException(\"Error during wiring\", e);").eol();
327+
writer.append(indent).append(" }").eol();
321328
}
322329
}
323330

0 commit comments

Comments
 (0)