BuilderGen

A small Java Annotation Processor library which for automatically generating Builder classes from constructors or static methods.

License

License

Categories

Categories

SBE Data Data Structures
GroupId

GroupId

com.github.misberner.buildergen
ArtifactId

ArtifactId

buildergen
Last Version

Last Version

0.1
Release Date

Release Date

Type

Type

jar
Description

Description

BuilderGen
A small Java Annotation Processor library which for automatically generating Builder classes from constructors or static methods.
Project URL

Project URL

https://github.com/misberner/buildergen
Source Code Management

Source Code Management

https://github.com/misberner/buildergen/tree/master

Download buildergen

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
org.antlr : stringtemplate jar 4.0.2

Project Modules

There are no modules declared in this project.

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.

Versions

Version
0.1