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

aa027af causes compile errors #129

Open
mads-b opened this issue Sep 28, 2022 · 8 comments
Open

aa027af causes compile errors #129

mads-b opened this issue Sep 28, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@mads-b
Copy link
Contributor

mads-b commented Sep 28, 2022

Hello, The aforementioned commit is preventing me from upgrading from v33 to v34. The issue:

I have a quite simple record which should create a builder:

public record CombinedFields(
    @JsonValue String combinedField,
    List<CombinedFieldsLine> lines) implements CombinedFieldsBuilder.Bean {}

But now, the generated builder contains a setter with an undefined method (shim?)

    /**
     * Re-create the internally allocated {@code List<CombinedFields.CombinedFieldsLine>} for {@code lines} by copying the argument
     */
    @Generated("io.soabase.recordbuilder.core.RecordBuilder")
    public CombinedFieldsBuilder setLines(
            Collection<? extends CombinedFields.CombinedFieldsLine> lines) {
        this.lines = __list(lines);
        return this;
    }

It's this __list method that does not exist. Is this a bug or something I need to change in my configuration?

@Randgalt
Copy link
Owner

Randgalt commented Sep 28, 2022

Can you please post the entire source for CombinedFields so we can have a complete test case? In particular, we need to know the RecordBuilder.Options being used.

@Randgalt Randgalt added bug Something isn't working question Further information is requested labels Sep 28, 2022
@mads-b
Copy link
Contributor Author

mads-b commented Sep 29, 2022

Hi, my Options follows. I made this custom annotation for it to avoid repetition

@RecordBuilder.Template(options = @RecordBuilder.Options(
    enableWither = false,
    enableGetters = false,
    addConcreteSettersForOptional = true,
    addSingleItemCollectionBuilders = true,
    booleanPrefix = "is",
    getterPrefix = "get",
    setterPrefix = "set",
    beanClassName = "Bean"))
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@Inherited
public @interface RecordStyle {

}

@Randgalt Randgalt removed the question Further information is requested label Sep 29, 2022
@Randgalt
Copy link
Owner

It seems this was only tested when useImmutableCollections=true was also used. What do you think about addSingleItemCollectionBuilders = true also implying useImmutableCollections=true?

@freelon
Copy link
Contributor

freelon commented Sep 29, 2022

Sidenote: the JavaDoc for the setter methods also mentions the creation of a copy of the collection instead of just setting it:
* Re-create the internally allocated {@code Set<T>} for {@code mySet} by copying the argument
That should be adjusted as well if useImmutableCollections = false.

@Randgalt
Copy link
Owner

Randgalt commented Oct 1, 2022

@tmichel any thoughts on this?

@Randgalt
Copy link
Owner

Randgalt commented Oct 7, 2022

@tmichel are you around? I'd appreciate your thoughts on this issue.

@tmichel
Copy link

tmichel commented Oct 8, 2022

I feel that one setting implying another is really not intuitive. If possible any combination of options should work. Although I believe the implementation complexity comes from the interaction of features.

I believe when the addSingleItemCollectionBuilders is true the builder should maintain its own collection instance. The setter method breaks encapsulation in this case so maybe remove the option to overwrite the collection and only allow adding and clearing items. Then even the performance characteristics are clearer.

Basically instead of builder.setLines(...) only allow builder.clearLines().addLines(iterable).

I know that this is a breaking change in the API so this might not be so straightforward to introduce. I could see that if addSingleItemCollectionBuilders causes this many issues then it could be deprecated and a different option be introduced so that single collection builders and simple setters generate two distinct builder APIs. I guess the option could be useSingleItemCollectionBuilders.

useImmutableCollections should only affect whether the final collection during the build is an immutable copy of the internal collection or not.

Randgalt added a commit that referenced this issue Oct 19, 2022
…alse

- Removed `SingleItemsMetaDataMode.STANDARD` as it wasn't used
- Removed `needs*MutableMaker` - always add them when corresponding `needs*Shim` is true
- Merged `addMutableMakers()` into `addShims()`
- Always use mutable makers when addSingleItemCollectionBuilders is true

Fixes #129
@Randgalt
Copy link
Owner

Hey folks - please review #130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants