projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.92k stars 2.4k forks source link

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

Open victorwss opened 1 month ago

victorwss commented 1 month ago

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):