Code Monkey home page Code Monkey logo

autopojo's Introduction

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;
    }
  }
}

autopojo's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.