Skip to content

Adjust the indentation of the generated code for try/catch #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,17 @@ void builderAddBeanProvider(Append writer) {
return;
}
String indent = " ";

writer.indent(indent).append(" builder");
if (prototype) {
writer.append(".asPrototype()").eol();
writer.append(".asPrototype()");
} else if(secondary) {
writer.append(".asSecondary()").eol();
writer.append(".asSecondary()");
}

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

startTry(writer);
writer.indent(indent).append(" return ");
startTry(writer, " ");
writer.indent(indent).append(" return ");
writer.append("factory.%s(", methodName);
for (int i = 0; i < params.size(); i++) {
if (i > 0) {
Expand All @@ -215,7 +214,7 @@ void builderAddBeanProvider(Append writer) {
params.get(i).builderGetDependency(writer, "builder");
}
writer.append(");").eol();
endTry(writer);
endTry(writer, " ");
writer.indent(indent).append(" });").eol();
writer.indent(indent).append("}").eol();
}
Expand Down Expand Up @@ -306,18 +305,26 @@ boolean methodThrows() {
}

void startTry(Append writer) {
startTry(writer, "");
}

void startTry(Append writer, String indent) {
if (methodThrows()) {
writer.append(" try {").eol();
writer.setExtraIndent(" ");
writer.append(indent).append(" try {").eol();
writer.setExtraIndent(" " + indent);
}
}

void endTry(Append writer) {
endTry(writer, "");
}

void endTry(Append writer, String indent) {
if (methodThrows()) {
writer.setExtraIndent(null);
writer.append(" } catch (Throwable e) {").eol();
writer.append(" throw new RuntimeException(\"Error during wiring\", e);").eol();
writer.append(" }").eol();
writer.append(indent).append(" } catch (Throwable e) {").eol();
writer.append(indent).append(" throw new RuntimeException(\"Error during wiring\", e);").eol();
writer.append(indent).append(" }").eol();
}
}

Expand Down