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

[FEATURE] Value annotation should use already defined private constructor #2100

Closed
DevQuandt opened this issue Apr 18, 2019 · 4 comments
Closed

Comments

@DevQuandt
Copy link

Describe the feature
When I use the @value annotation with staticConstructor = "of" and a private Constructor is already defined, Lombok should use the private Constructor to generate a static of Constructor.

Lomboked version

@Value(staticConstructor = "of")
public final class SampleDocument {

    private final String value;

    private SampleDocument(final String value) {
        assertThat(value).isNotEmpty();
        this.value = value;
    }

}

Java version

public final class SampleDocument {

    private final String value;

    private SampleDocument(final String value) {
        assertThat(value).isNotEmpty();
        this.value = value;
    }

    public static SampleDocument of(final String value) {
        return new SampleDocument(value);
    }

[...]
}

Describe the target audience
Every programer who want's to do DDD and validate its value objects in the constructor to have only valid domain objects.

Additional context
Currently when a private constructor is already defined no static of constructor will be generated at all.

@rspilker
Copy link
Collaborator

I understand the request, and think it is a good idea to generate the static method if staticConstructor is provided, even if we don't generate the (private) all-args constructor.

@rspilker rspilker added low-priority help wanted We're looking for someone to do this work; we'll accept pull requests (if they have docs & tests) labels Apr 30, 2019
@rspilker
Copy link
Collaborator

If someone would create a pull request with implementations for ecj and javac and create test files in our test infrastructure, this gets higher priority.

@daliclass
Copy link
Contributor

Liked the idea and have have a pull request up for this here #2119

@rspilker rspilker removed help wanted We're looking for someone to do this work; we'll accept pull requests (if they have docs & tests) low-priority labels May 7, 2019
@rspilker
Copy link
Collaborator

rspilker commented May 7, 2019

It's fixed. We just need to add it to the changelog.

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

No branches or pull requests

4 participants