Skip to content

An Annotation Processor for automatically generating builder classes in Java

License

Notifications You must be signed in to change notification settings

misberner/buildergen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BuilderGen

A free, open-source Java Annotation Processor for generating Builder classes.

In a Nutshell

From code like this:

public class Foo {
  // ...
  public Foo(int id, float ratio, String name, boolean enable) {
    // ...
  }
  // ...
}

... generate a builder that can be used like this:

new FooBuilder().withId(5).withName("foo").withRatio(0.5f).create();

... by adding a single line:

public class Foo {
  // ...
  @GenerateBuilder // magic!
  public Foo(int id, float ratio, String name, boolean enable) {
    // ...
  }
  // ...
}

Using it

Annotation Processing has become standard since Java 1.6. Adding BuilderGen to your build hence is very simple:

Maven

BuilderGen is deployed to the Maven Central Repository. Add the following to the dependencies section of your pom.xml:

<dependency>
  <groupId>com.github.misberner.buildergen</groupId>
  <artifactId>buildergen</artifactId>
  <!-- Make this dependency non-transitive -->
  <scope>provided</scope>
  <version>0.1</version>
</dependency>

If you are using maven-compiler-plugin of at least version 2.2, your builders will be automatically generated (into src/target/generated-sources/annotations) and compiled.

Non-Maven

  • Download the latest stable version.
  • Make sure the JAR file is in your classpath during compilation (e.g., using an appropriate classpathref specification for the javac target in Ant).
  • Enjoy!

Documentation

Features

  • Builder generation from constructors or static methods
  • Handles generic type parameters of both instance classes and constructor methods
  • Respects throws specification of constructor or static method
  • Highly configurable
  • Very lightweight: only depends on StringTemplate

License

BuilderGen is distributed under the terms of the Apache License, Version 2.0.

Maintainer

Created and developed by Malte Isberner.

About

An Annotation Processor for automatically generating builder classes in Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages