bob

Builder generator for Java

License

License

Categories

Categories

JOnAS Container Application Servers
GroupId

GroupId

com.github.jonasgeiregat
ArtifactId

ArtifactId

bob
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

pom
Description

Description

bob
Builder generator for Java
Project URL

Project URL

https://github.com/jonasgeiregat/bob
Source Code Management

Source Code Management

https://github.com/jonasgeiregat/bob

Download bob

Filename Size
bob-0.1.0.pom 4 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jonasgeiregat/bob/ -->
<dependency>
    <groupId>com.github.jonasgeiregat</groupId>
    <artifactId>bob</artifactId>
    <version>0.1.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.jonasgeiregat/bob/
implementation 'com.github.jonasgeiregat:bob:0.1.0'
// https://jarcasting.com/artifacts/com.github.jonasgeiregat/bob/
implementation ("com.github.jonasgeiregat:bob:0.1.0")
'com.github.jonasgeiregat:bob:pom:0.1.0'
<dependency org="com.github.jonasgeiregat" name="bob" rev="0.1.0">
  <artifact name="bob" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.jonasgeiregat', module='bob', version='0.1.0')
)
libraryDependencies += "com.github.jonasgeiregat" % "bob" % "0.1.0"
[com.github.jonasgeiregat/bob "0.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.google.guava : guava jar 19.0-rc3
com.annimon : stream jar 1.1.6

test (2)

Group / Artifact Type Version
junit : junit jar 4.10
com.google.truth : truth jar 0.28

Project Modules

  • core
  • compiler

Bob

Builder generator for Java

Getting Started

Annotate the class you which to build with @Buildable

package foo.bar

@Buildable
public class Car {
    private Brand brand;
    private String color;
    private BigDecimal price;
    
    ...
}

A CarBuilder class will be generated for you in the same package as the source class with builder as suffix. For the car example this will be foo.bar.builder

The location of the builder can be changed:

@Buildable(package = "custom.package")
public class Car {
  ...

The generated builder can be used now:

Car redCar = new CarBuilder().color("red").build();

Bob will try to be smart about creating a builder for you.

  • If there are standard Java Bean setters available they will be used. (setField)
  • If you do not have any setters reflection will be used.
  • If the fields are accessible directly (public or protected fields) they will be set directly.

Fields can be excluded:

@Buildable(excludes = {"brand", "color"})
public class Car {
  ...

By default Bob will generated setter methods consisting out of new style setters (name(String name) instead of setName(String name) or the default builder pattern setter style withName(String name)) If you want to change the prefix of those setter methods you can:

@Buildable(prefix = "with")
public class Car {
  ...      

Bob is not afraid of generics

@Buildable
public class Cup<T, R extends String> {
    private T contents;
    private R topping;
    
// usage

Cup<BigDecimal, String> string = new CupBuilder<BigDecimal, String>().topping("String").contents(BigDecimal.ZERO).build();

Bob can handle final fields

@Buildable
public class Car {
    private final String color; 
    
    public Car(String color) {
        ....

Versions

Version
0.1.0