Git Product home page Git Product logo

builderberg's People

Contributors

davidburkett avatar dogsworth avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

builderberg's Issues

Provide annotation to generate compareTo

Allow annotation of fields to include in comparison, as well as the ordering of the comparison and direction of comparison. Example:

@BuilderComparison(1, inverse)

would compare that field first by calling compareTo and then taking the inverse of the result.

Fix hashCode method generation to guard against NullPointerException

There is a currently a potential bug where the generated hashCode() method will throw a NullPointerException. Consider the following generated code:

public int hashCode() {
    int result = 17;
    result = 31 * result + firstName.hashCode();
    result = 31 * result + middleName.hashCode();
    result = 31 * result + lastName.hashCode();
    return result;
}

If middle name is null, this will throw a NullPointerException. Please use Objects.hashCode() as it will convert a null value to the hash code of zero.

Add ability to mark member as mutable

Sometimes when working with certain persistence libraries (like mongo) the object sets the field annotated with @id to the generated id. Your current implementation will not support that.

Generate more thorough javadoc

Copy javadoc from fields into getters, and add additional javadoc like "Will never be null" when using @BuilderConstraint(notNull = true). Also, add javadoc for what validation will take place in the constructor and in the builder validate method.

Fails hard when including validation on unsupported objects.

image
null
java.lang.IllegalArgumentException
at com.github.davidburkett.builderberg.generators.ValidationGenerator.generateNotEmptyStatement(ValidationGenerator.java:86)
at com.github.davidburkett.builderberg.generators.ValidationGenerator.generateValidationStatement(ValidationGenerator.java:44)
at com.github.davidburkett.builderberg.generators.ValidationGenerator.generateValidationForField(ValidationGenerator.java:29)
at com.github.davidburkett.builderberg.generators.BuilderClassGenerator.generateWithSetters(BuilderClassGenerator.java:73)
at com.github.davidburkett.builderberg.generators.BuilderClassGenerator.createBuilderClass(BuilderClassGenerator.java:37)
at com.github.davidburkett.builderberg.BuilderbergRunnable.run(BuilderbergRunnable.java:30)
at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:252)
at com.intellij.openapi.command.WriteCommandAction$Simple.run(WriteCommandAction.java:234)
at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:171)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1003)
at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:170)
at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:210)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:149)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:119)
at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:212)
at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:168)
at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:151)
at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:254)
at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:241)
at com.github.davidburkett.builderberg.BuilderbergAction.actionPerformed(BuilderbergAction.java:29)
at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:220)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:237)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:321)
at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:911)
at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:136)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:311)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:130)
at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111)
at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:120)
at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:122)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:130)
at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:521)
at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:48)
at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:541)
at java.awt.Component.processMouseEvent(Component.java:6541)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6306)
at java.awt.Container.processEvent(Container.java:2237)
at java.awt.Component.dispatchEventImpl(Component.java:4897)
at java.awt.Container.dispatchEventImpl(Container.java:2295)
at java.awt.Component.dispatchEvent(Component.java:4719)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
at java.awt.Container.dispatchEventImpl(Container.java:2281)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4719)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:737)
at java.awt.EventQueue$4.run(EventQueue.java:735)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:822)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:646)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Allow user to define exception type

Asserts have limitations, and don't work for all users. Provide a way to specify what type of exception should be thrown when constraints are violated.

Don't generate Getters if field is public final.

This is good stuff! I am wondering since I have public final fields on data objects that the getters not be generated. BuilderOptions could have an option there for turning on/off the behavior.

Test coverage

One thing that will hold this plugin back as far as large scale adoption is lack of test coverage. My assumption is that there are others out there testing plugins like this that modify code so you could follow one of those for an example.

Add ability to build from another built instance

"A" is a class that has had the builder generated
"a" is an instance of A

A newA = A.builder(a).withFieldOne("someNewValue").build();

"newA" has all of the same values as "a" but "fieldOne" has been updated

Support Polymorphism

I would love to have support for polymorphism in Builderberg.

Simple example:

public abstract class Vehicle {
    private final String make;
    // [...]
}

public class Car extends Vehicle {
    private final int seatingCapacity;
    // [...]
}

public class Truck extends Vehicle {
    private final int payloadCapacity;
    // [...]
}

As a suggestion, this is how resulting builders could look like:

public abstract class Vehicle {
    // [...]

    // protected instead of public?
    // non-final?
    protected static class Builder {
        // [ all fields of type Vehicle ]
    }
}

public class Car extends Vehicle {
    // [...]

    public static final class Builder extends Vehicle.Builder {
        // [ all fields of type Car ]

        // PLUS:
        // Overrides for all methods of Vehicle.Builder (in order to allow strongly-typed fluent usage) - delegating to Vehicle.Builder but casting return value to Car.Builder)
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.