Comments (9)
Thanks a lot. I tried it out already.
from freebuilder.
Is it necessary to not have the build method present? Otherwise you could just declare the legacy method in addition:
public Foo buildFoo() {
return build();
}
from freebuilder.
In my use case I want to overload the actual build() method to return a different type so I require the generated builder to not declare a build() method at all.
I have a mutable data object with getters/setters and a hand coded builder that I hope will eventually be migrated to an immutable Freebuilder implementation but as a stepping stone I want to at least be able to use FreeBuilder for the builder part.
from freebuilder.
Can you post a simplified example of what that API would look like?
There are two methods on builders with the same signature (no parameters, returns a Foo), build
and buildPartial
, and while I can't think of any others users might want to add, it would be API-breaking to stop emitting build
if one were added — but depending on the exact pattern you're making, it may still be possible to reliably detect it without breaking other use cases.
from freebuilder.
Could this work? It would not be a breaking change because currently, overloading the build() method return type leads to a compiler error.
@Freebuilder
interface Foo {
class Builder extends Foo_Builder {
public Bar build() { ... } // incompatible return type => don't emit a build()
public Foo buildFoo() { // compatible return type, emit buildFoo instead
return super.buildFoo();
|
}
}
from freebuilder.
I would prefer to find a non-obscured method name matching a specific pattern for selecting the build method — perhaps this:
- If the
build()
method is protected or package-protected on the subclass, follow suit - If the
build()
method is private or signature-incompatible, instead generate a package-protected_buildImpl()
method for the subclass to call - Optional for first implementation If that method is already present and incompatible, continue trying with
_buildImpl2()
etc. until a suitable candidate is found
This then cleanly extends to other methods in future, e.g. buildPartial()
becomes _buildPartialImpl()
That would make your code look like:
@FreeBuilder
interface Foo {
class Builder extends Foo_Builder {
public Bar build() { ... } // incompatible return type => FreeBuilder emits _buildImpl instead
public Foo buildFoo() {
return super._buildImpl();
}
}
}
I would be happy to accept a PR implementing this feature. If you are interested in doing this, let me know and I'll point you to the bits of the code you'd need to fit it into.
from freebuilder.
from freebuilder.
Gmail doesn't notify me of forum messages, so if you do pick it up, feel free reach out to me directly by email for a quicker response. Meanwhile, enjoy your holiday!
from freebuilder.
Hopefully FreeBuilder v2.7.0 will solve this issue for you. Please do raise another issue if it does not!
from freebuilder.
Related Issues (20)
- Unchecked warnings in code generated for GWT-serializable generic types
- Add support for singularizing plural method names HOT 2
- Evaluate optimizability of internal EnumSet HOT 1
- deserializing mongodb document HOT 1
- Specify property name in exception message on nested type build failure HOT 2
- Support remaining Guava collections HOT 4
- IgnoredByEquals doesn't work HOT 6
- IntelliJ, Auto-Discover Processors from Maven HOT 1
- Nested buildable types should use the enclosing type's defaults
- jackson serializer error HOT 2
- Support derived fields HOT 4
- Enhancement: Add nested builder functions HOT 2
- mergeFrom should support partials
- Support for @JsonAlias
- Not able to build on jdk 20
- Custom getters inside builder HOT 5
- JPMS HOT 10
- Java 21 throws warning with idiomatic Freebuilder usage HOT 5
- How can I install in vscode freebuilder ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freebuilder.