Skip to content

Latest commit

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

BuilderGen

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

In a Nutshell

From code like this:

publicclassFoo {
// ...publicFoo(intid, floatratio, Stringname, booleanenable) {
// ...
}
// ...
}

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

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

... by adding a single line:

publicclassFoo {
// ...@GenerateBuilder// magic!publicFoo(intid, floatratio, Stringname, booleanenable) {
// ...
}
// ...
}

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

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages