Skip to content

fix: compilation error with providers and throws #533

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 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
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 @@ -48,6 +48,12 @@ public Builder newBuilder() {
return new Builder();
}

@Prototype
@Bean
public BuilderThrows newBuilderThrows() throws Exception {
return new BuilderThrows();
}

@Bean
Generated newGenerated() {
return new Generated();
Expand All @@ -59,6 +65,12 @@ public MySecType generalSecondary() {
return new MySecType();
}

@Secondary
@Bean
public MySecTypeThrows generalSecondaryThrows() throws Exception {
return new MySecTypeThrows();
}

@Secondary
@Bean
public Optional<MySecOptType> optionalSecondary() {
Expand Down Expand Up @@ -100,12 +112,18 @@ MyAbstract myAbstract() {
public static class Builder {
}

public static class BuilderThrows {
}

public static class Generated {
}

public static class MySecType {
}

public static class MySecTypeThrows {
}

public static class MySecOptType {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ LazyBean lazyInt(@Nullable AtomicBoolean initialized) {
if (initialized != null) initialized.set(true);
return new LazyBean();
}

@Bean
@Named("factoryThrows")
LazyBean lazyIntThrows(@Nullable AtomicBoolean initialized) throws Exception {
return lazyInt(initialized);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ void builderAddBeanProvider(Append writer) {

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

startTry(writer);
writer.indent(indent).append(" return ");
writer.append("factory.%s(", methodName);
for (int i = 0; i < params.size(); i++) {
Expand All @@ -214,6 +215,7 @@ void builderAddBeanProvider(Append writer) {
params.get(i).builderGetDependency(writer, "builder");
}
writer.append(");").eol();
endTry(writer);
writer.indent(indent).append(" });").eol();
writer.indent(indent).append("}").eol();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ private void writeFactoryBeanMethod(MethodReader method) {
method.buildConditional(writer);
method.buildAddFor(writer);
method.builderGetFactory(writer, beanReader.hasConditions());
method.startTry(writer);
if (method.isLazy() || method.isProtoType() || method.isUseProviderForSecondary()) {
method.builderAddBeanProvider(writer);
method.endTry(writer);
} else {
method.startTry(writer);
method.builderBuildBean(writer);
method.builderBuildAddBean(writer);
method.endTry(writer);
Expand Down