Skip to content

Latest commit

 

History

History
158 lines (117 loc) · 3.2 KB

README.md

File metadata and controls

158 lines (117 loc) · 3.2 KB

pojo-derivation

maven-central license

Combine multiple POJOs to generate a new POJO.

1 Setup

  • Kotlin Project
apply plugin: 'kotlin-kapt'

dependencies {
    compileOnly('cc.duduhuo.util:pojo-derivation-annotations:1.2.0')
    kapt('cc.duduhuo.util:pojo-derivation-compiler:1.2.0')
}
  • Pure Java Project
dependencies {
    compileOnly('cc.duduhuo.util:pojo-derivation-annotations:1.2.0')
    annotationProcessor('cc.duduhuo.util:pojo-derivation-compiler:1.2.0')
}

2 Use

You can use the Derivation annotation on any class:

@Derivation(
        name = "ABC",
        sourceTypes = {A.class, B.class, C.class},
        constructorTypes = {ConstructorType.NO_ARGS, ConstructorType.ALL_ARGS, ConstructorType.ALL_SOURCE_OBJS}
)
final class ABCCombine {}

Then you will get a new class as shown below:

// This file is automatically generated by pojo-derivation (https://github.com/liying2008/pojo-derivation).
// Do not modify this file -- YOUR CHANGES WILL BE ERASED!
// File generation time: Sat Feb 13 17:45:10 CST 2021
package cc.duduhuo.util.pojo.derivation.samplebase.readme;

import java.lang.String;
import org.jetbrains.annotations.NotNull;

/**
 * Generated according to {@link cc.duduhuo.util.pojo.derivation.samplebase.readme.ABCCombine}.
 */
public class ABC {
    private int a1;

    private String a2;

    private boolean b1;

    private double b2;

    private boolean c1;

    private char c2;

    @NotNull
    private String c3;

    public ABC() {
    }

    public ABC(int a1, String a2, boolean b1, double b2, boolean c1, char c2, String c3) {
        this.a1 = a1;
        this.a2 = a2;
        this.b1 = b1;
        this.b2 = b2;
        this.c1 = c1;
        this.c2 = c2;
        this.c3 = c3;
    }

    public ABC(A a, B b, C c) {
        this.setA1(a.getA1());
        this.setA2(a.getA2());
        this.setB1(b.isB1());
        this.setB2(b.getB2());
        this.setC1(c.getC1());
        this.setC2(c.getC2());
        this.setC3(c.getC3());
    }

    public int getA1() {
        return a1;
    }

    public void setA1(int a1) {
        this.a1 = a1;
    }

    public String getA2() {
        return a2;
    }

    public void setA2(String a2) {
        this.a2 = a2;
    }

    public boolean isB1() {
        return b1;
    }

    public void setB1(boolean b1) {
        this.b1 = b1;
    }

    public double getB2() {
        return b2;
    }

    public void setB2(double b2) {
        this.b2 = b2;
    }

    public boolean isC1() {
        return c1;
    }

    public void setC1(boolean c1) {
        this.c1 = c1;
    }

    public char getC2() {
        return c2;
    }

    public void setC2(char c2) {
        this.c2 = c2;
    }

    public String getC3() {
        return c3;
    }

    public void setC3(String c3) {
        this.c3 = c3;
    }
}

See sample module for more examples.

3 License

MIT