Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

epkugelmass
Copy link

@Randgalt Randgalt added the enhancement New feature or request label Feb 28, 2024
@Randgalt Randgalt added this to the v42 milestone Feb 28, 2024
recordTypeVariables = toTypeVariableNames(record.getTypeParameters());
List<TypeVariableName> builderTypeParams = new ArrayList<>(recordTypeVariables);
List<TypeVariableName> builderTypeParamsWildcard = new ArrayList<>(recordTypeVariables);
var self = TypeVariableName.get("SELF");
Copy link
Owner

@Randgalt Randgalt Mar 24, 2024

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);
Copy link
Owner

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.

Copy link
Owner

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();
Copy link
Owner

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.

Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants