-
Notifications
You must be signed in to change notification settings - Fork 57
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
Implement parameterized builder #169
base: master
Are you sure you want to change the base?
Conversation
recordTypeVariables = toTypeVariableNames(record.getTypeParameters()); | ||
List<TypeVariableName> builderTypeParams = new ArrayList<>(recordTypeVariables); | ||
List<TypeVariableName> builderTypeParamsWildcard = new ArrayList<>(recordTypeVariables); | ||
var self = TypeVariableName.get("SELF"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELF
should be defined in RecordBuilder.Options
metadata in case some client code already uses this name. The default would be better to be something very unique. Maybe RECORD_BUILDER_SELF
.
|
||
String builderName = getBuilderName(record, metaData, recordClassType, metaData.suffix()); | ||
recordTypeVariables = toTypeVariableNames(record.getTypeParameters()); | ||
List<TypeVariableName> builderTypeParams = new ArrayList<>(recordTypeVariables); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The construction of builderTypeParams
and builderTypeParamsWildcard
shouldn't result in a modifiable ArrayList
. Please move to separate method or ElementUtils
so that the constructed type is immutable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general comment. Every generated sub-class should have the same Parameterized Type list as the builder but this PR doesn't do that. It looks like builderTypeParamsWildcard
does that instead? Why not do what was done before: i.e. all the nested Stage/With classes should have the exact same Parameterized Type list as the builder.
class TestParameterizedBuilder { | ||
@Test | ||
void testNoSubclass() { | ||
ParameterizedBuilderBuilder<?> builder = ParameterizedBuilderBuilder.builder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels odd to have a static builder in a parameterized builder. It should likely not be added for parameterized and force use of the constructors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the no-subclass even useful? We could make the builder abstract
when parameterized.
#157 (comment)