https://github.com/liying2008/pojo-derivation
Combine multiple POJOs to generate a new POJO.
https://github.com/liying2008/pojo-derivation
annotation-processor annotations apt derivation java-library kapt kotlin library pojo pojo-derivation pojos
Last synced: 2 months ago
JSON representation
Combine multiple POJOs to generate a new POJO.
- Host: GitHub
- URL: https://github.com/liying2008/pojo-derivation
- Owner: liying2008
- License: mit
- Created: 2019-01-20T07:30:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T10:45:18.000Z (over 2 years ago)
- Last Synced: 2025-01-26T09:27:42.419Z (4 months ago)
- Topics: annotation-processor, annotations, apt, derivation, java-library, kapt, kotlin, library, pojo, pojo-derivation, pojos
- Language: Kotlin
- Homepage:
- Size: 338 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# pojo-derivation
[](https://mvnrepository.com/artifact/cc.duduhuo.util/pojo-derivation-annotations)
[](https://github.com/liying2008/pojo-derivation/blob/master/LICENSE)Combine multiple POJOs to generate a new POJO.
## 1 Setup
+ Kotlin Project
```gradle
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
```gradle
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:
```java
@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:
```java
// 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](LICENSE)