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

[BUG] @With does not care about @Accessors #3760

Open
victorwss opened this issue Oct 14, 2024 · 0 comments
Open

[BUG] @With does not care about @Accessors #3760

victorwss opened this issue Oct 14, 2024 · 0 comments

Comments

@victorwss
Copy link
Contributor

Describe the bug
Trying to use @Accessors(fluent = true) together with @With doeesn't work. @With does not generate fluent APIs and ignores @Accessors(fluent = true).

To Reproduce

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Value;
import lombok.With;
import lombok.experimental.Accessors;

public class Weird {

    // This is some class that isn't fluent, but works.
    @With
    @Value
    @AllArgsConstructor
    class NotFluent {
        final String sbrubbles;
    }

    public void someRandomMethod1() {
        // Compiles ok, but is not in the fluent style.
        var a = new NotFluent("foo").withSbrubbles("bar").getSbrubbles();
    }

    // Ok, now let's suppose that we refactor that into a fluent style.
    // So, if we add @Accessors(fluent = true), we're done, all the getters
    // and with-ers would be automatically renamed, right?
    // Let's try that:

    @With
    @Value
    @Accessors(fluent = true)
    @AllArgsConstructor
    class ShouldBeFluent {
        final String sbrubbles;
    }

    public void someRandomMethod2() {
        // Didn't work, this does not compiles!
        var a = new ShouldBeFluent("foo").sbrubbles("bar").sbrubbles();

        // Instead, the following compiles.
        // The @With didn't care about @Accessors(fluent = true)!
        var b = new ShouldBeFluent("foo").withSbrubbles("bar").sbrubbles();
    }

    // Ok, not a big deal... But, now let's suppose we have the following scenario:

    interface FluentInterface<F> {
        String sbrubbles();
        F sbrubbles(String newValue);
    }

    @With
    @Value
    @Accessors(fluent = true)
    @AllArgsConstructor
    class ShouldImplementsItNicely implements FluentInterface<ShouldImplementsItNicely> {
        final String sbrubbles;
    }

    // We get the following compile error:
    // Weird.ShouldImplementsItNicely is not abstract and does not override
    // abstract method sbrubbles(String) in FluentInterface
}

Expected behavior
Usage of @With and @Accessors(fluent = true) together should work.

Version info (please complete the following information):

  • Lombok version = 1.18.34
  • Platform = OpenJDK 21
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

1 participant