analytically / innerbuilder

IntelliJ IDEA plugin which generates an inner builder class

Home Page:https://plugins.jetbrains.com/plugin/7354-innerbuilder/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow builders to implement a Builder interface

HansBrende opened this issue · comments

For my use case, all builders must implement the IBuilder<O> interface which looks like this:

package com.example;

public interface IBuilder<O> {
    O build();
}

It would be amazing if we could configure the settings so that the generated builder class looks like this:

public final class Thing {
    ...
    public static final class Builder implements com.example.IBuilder<Thing> {
        ...
        @Override
        public Thing build() {
            return new Thing(...);
        }
    }
}

Maybe by specifying a configuration setting like the following:
build method = com.example.IBuilder.build

Which would also allow us to do something like this:
build method = java.util.function.Supplier.get,
generating the following code:

public static final class Builder implements java.util.function.Supplier<Thing> {
    ...
    @Override
    public Thing get() {
        return new Thing(...);
    }
}

Obviously, the specified interface would have to be a single-abstract-method functional interface, with the method having zero arguments.

That being the case, it might be redundant to specify the build method, when you could instead just specify the build interface. So something like this:

build interface = com.example.IBuilder
or
build interface = java.util.function.Supplier
or
build interface = org.apache.commons.lang3.builder.Builder
would also be great.