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
staged Builder for Factories #1112
Comments
+1 this would be great for my use case |
@elucash would you accept a contribution? |
Hi @elucash any chance on this? |
Hi @bmarwell I'll look into this (i.e. what can we do). Wanted to carve a day to work on Immutables, which seems like today :) |
Woohooo 🎉 |
I would definitely ask for help with documentation/guide. But as of now I'm quite puzzled how to change builder generation for factory (digging our code and trying to restore the picture) from top level to nested, we cannot put stage interfaces inside builder as it's prohibited for a type to extend/implement the type nested inside it (while the other way around is not a problem) |
Experimental implementation PR, need more testing, more changes than expected. The solution requires now to have @Value.Enclosing
@Value.Style(stagedBuilder = true)
public class StagedFactory {
@Builder.Factory
public static String superstring(int theory, String reality, @Nullable Void evidence) {
return theory + " != " + reality + ", " + evidence;
}
}
// generates the following methods/interfaces
ImmutableStagedFactory.SuperstringTheoryBuildStage a = ImmutableStagedFactory.superstringBuilder();
ImmutableStagedFactory.SuperstringRealityBuildStage b = a.theory(1);
ImmutableStagedFactory.SuperstringBuildFinal c = b.reality("x");
ImmutableStagedFactory.SuperstringBuildFinal d = c.evidence(null);
String superstring = d.build();
will get back to it in a couple of days, need a fresh look |
Hey! Thanks, will take a look at it in a few days (or maybe after vacation). Thank you so much for getting started! 👍🏻 |
Hey @elucash, I cannot compile your branch :(
|
Hm.. I'm doing |
Will try again! |
Experimental #1112 requiring Enclosing annotation
Is 5eb1de3 on any version in central I can try? |
Probably, |
Will try, sorry for the delay |
Hey @elucash! tested with 2.10.0. The annotated Constructor of "MyObject" will result in a compile error in the return line:
|
The Factory builder works flawlessly, thanks! :) |
Hi,
I'd love to see https://immutables.github.io/factory.html supporting a staged builder.
Caveat: in #761 you argued that external builders and staged builders combined make no sense. Please do look at the last comment. I think this can be implemented (for both Factory and Immutables).
The text was updated successfully, but these errors were encountered: