Skip to content

A Plain-Old-Java-Object annotation processing tool that generates code from a describing model interface

Notifications You must be signed in to change notification settings

gmazzo/autopojo

Repository files navigation

autopojo

A Plain-Old-Java-Object annotation processing tool that generates code from a describing model interface

How it works

This project is an annotation processor that takes any @POJO interface (classes are not allowed) describing its properties with simple no-args methods, and it generate concrete classes with private fields, and public getters and setters. Optionally it can also generate a builder.

Like Dagger's modules, those interfaces should not be used for anything else than code generation. You should relay in some ProGuard solution to strip them out from your final code.

Import

On your build.gradle add:

dependencies {
    annotationProcessor 'com.github.gmazzo.autopojo:autopojo-processor:0.1'

    implementation 'com.github.gmazzo.autopojo:autopojo-annotations:0.1'
}

Download

Usage

Given an interface like:

@POJO
public interface PersonPOJO {

    int id();

    String name();

}

AutoPOJO will generate:

import java.lang.String;
import javax.annotation.Generated;

@Generated("gs.autopojo.processor.POJOProcessor")
public class Person {
  private int id;

  private String name;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public static class Builder {
    private int id;

    private String name;

    public int id() {
      return id;
    }

    public Builder id(int id) {
      this.id = id;
      return this;
    }

    public String name() {
      return name;
    }

    public Builder name(String name) {
      this.name = name;
      return this;
    }

    protected void fillInstance(Person instance) {
      instance.id = id;
      instance.name = name;
    }

    public Person build() {
      Person instance = new Person();
      fillInstance(instance);
      return instance;
    }
  }
}

About

A Plain-Old-Java-Object annotation processing tool that generates code from a describing model interface

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages