Update
This commit is contained in:
parent
bdf037da06
commit
f18ad32b87
@ -1,7 +1,11 @@
|
|||||||
package it.cavallium.data.generator.plugin;
|
package it.cavallium.data.generator.plugin;
|
||||||
|
|
||||||
|
import com.squareup.javapoet.ClassName;
|
||||||
|
|
||||||
public sealed interface ComputedTypeArray extends ComputedType permits ComputedTypeArrayFixed, ComputedTypeArrayNative,
|
public sealed interface ComputedTypeArray extends ComputedType permits ComputedTypeArrayFixed, ComputedTypeArrayNative,
|
||||||
ComputedTypeArrayVersioned {
|
ComputedTypeArrayVersioned {
|
||||||
|
|
||||||
ComputedType getBase();
|
ComputedType getBase();
|
||||||
|
|
||||||
|
ClassName getJSerializerName(String basePackageName);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package it.cavallium.data.generator.plugin;
|
package it.cavallium.data.generator.plugin;
|
||||||
|
|
||||||
|
import com.squareup.javapoet.ClassName;
|
||||||
|
|
||||||
public sealed interface ComputedTypeNullable extends ComputedType permits ComputedTypeNullableFixed,
|
public sealed interface ComputedTypeNullable extends ComputedType permits ComputedTypeNullableFixed,
|
||||||
ComputedTypeNullableNative, ComputedTypeNullableVersioned {
|
ComputedTypeNullableNative, ComputedTypeNullableVersioned {
|
||||||
|
|
||||||
ComputedType getBase();
|
ComputedType getBase();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
ClassName getJSerializerName(String basePackageName);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import com.squareup.javapoet.TypeSpec.Builder;
|
|||||||
import it.cavallium.data.generator.DataSerializer;
|
import it.cavallium.data.generator.DataSerializer;
|
||||||
import it.cavallium.data.generator.nativedata.ImmutableWrappedArrayList;
|
import it.cavallium.data.generator.nativedata.ImmutableWrappedArrayList;
|
||||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||||
|
import it.cavallium.data.generator.plugin.ComputedTypeArray;
|
||||||
|
import it.cavallium.data.generator.plugin.ComputedTypeArrayFixed;
|
||||||
import it.cavallium.data.generator.plugin.ComputedTypeArrayVersioned;
|
import it.cavallium.data.generator.plugin.ComputedTypeArrayVersioned;
|
||||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
@ -35,11 +37,12 @@ public class GenSerializerArrayX extends ClassGenerator {
|
|||||||
private Stream<GeneratedClass> generateVersionClasses(ComputedVersion version) {
|
private Stream<GeneratedClass> generateVersionClasses(ComputedVersion version) {
|
||||||
return dataModel
|
return dataModel
|
||||||
.getArrayTypesComputed(version)
|
.getArrayTypesComputed(version)
|
||||||
.filter(type -> type instanceof ComputedTypeArrayVersioned versioned && versioned.getVersion().equals(version))
|
.filter(type -> (type instanceof ComputedTypeArrayVersioned versioned
|
||||||
.map(type -> generateTypeVersioned(version, (ComputedTypeArrayVersioned) type));
|
&& versioned.getVersion().equals(version)) || type instanceof ComputedTypeArrayFixed)
|
||||||
|
.map(type -> generateTypeVersioned(version, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private GeneratedClass generateTypeVersioned(ComputedVersion version, ComputedTypeArrayVersioned typeArray) {
|
private GeneratedClass generateTypeVersioned(ComputedVersion version, ComputedTypeArray typeArray) {
|
||||||
ClassName serializerClassName = typeArray.getJSerializerName(basePackageName);
|
ClassName serializerClassName = typeArray.getJSerializerName(basePackageName);
|
||||||
var typeArrayClassName = typeArray.getJTypeName(basePackageName);
|
var typeArrayClassName = typeArray.getJTypeName(basePackageName);
|
||||||
|
|
||||||
@ -56,7 +59,7 @@ public class GenSerializerArrayX extends ClassGenerator {
|
|||||||
return new GeneratedClass(serializerClassName.packageName(), classBuilder);
|
return new GeneratedClass(serializerClassName.packageName(), classBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateSerialize(ComputedVersion version, ComputedTypeArrayVersioned typeArray, Builder classBuilder) {
|
private void generateSerialize(ComputedVersion version, ComputedTypeArray typeArray, Builder classBuilder) {
|
||||||
var method = MethodSpec.methodBuilder("serialize");
|
var method = MethodSpec.methodBuilder("serialize");
|
||||||
|
|
||||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||||
@ -89,7 +92,7 @@ public class GenSerializerArrayX extends ClassGenerator {
|
|||||||
classBuilder.addMethod(method.build());
|
classBuilder.addMethod(method.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDeserialize(ComputedVersion version, ComputedTypeArrayVersioned typeArray, Builder classBuilder) {
|
private void generateDeserialize(ComputedVersion version, ComputedTypeArray typeArray, Builder classBuilder) {
|
||||||
var method = MethodSpec.methodBuilder("deserialize");
|
var method = MethodSpec.methodBuilder("deserialize");
|
||||||
|
|
||||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||||
|
@ -8,6 +8,8 @@ import com.squareup.javapoet.TypeSpec;
|
|||||||
import com.squareup.javapoet.TypeSpec.Builder;
|
import com.squareup.javapoet.TypeSpec.Builder;
|
||||||
import it.cavallium.data.generator.DataSerializer;
|
import it.cavallium.data.generator.DataSerializer;
|
||||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||||
|
import it.cavallium.data.generator.plugin.ComputedTypeNullable;
|
||||||
|
import it.cavallium.data.generator.plugin.ComputedTypeNullableFixed;
|
||||||
import it.cavallium.data.generator.plugin.ComputedTypeNullableVersioned;
|
import it.cavallium.data.generator.plugin.ComputedTypeNullableVersioned;
|
||||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
@ -33,11 +35,13 @@ public class GenSerializerNullableX extends ClassGenerator {
|
|||||||
private Stream<GeneratedClass> generateVersionClasses(ComputedVersion version) {
|
private Stream<GeneratedClass> generateVersionClasses(ComputedVersion version) {
|
||||||
return dataModel
|
return dataModel
|
||||||
.getNullableTypesComputed(version)
|
.getNullableTypesComputed(version)
|
||||||
.filter(type -> type instanceof ComputedTypeNullableVersioned versioned && versioned.getVersion().equals(version))
|
.filter(type -> (
|
||||||
.map(type -> generateTypeVersioned(version, (ComputedTypeNullableVersioned) type));
|
(type instanceof ComputedTypeNullableVersioned versioned && versioned.getVersion().equals(version))
|
||||||
|
|| type instanceof ComputedTypeNullableFixed))
|
||||||
|
.map(type -> generateTypeVersioned(version, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private GeneratedClass generateTypeVersioned(ComputedVersion version, ComputedTypeNullableVersioned typeNullable) {
|
private GeneratedClass generateTypeVersioned(ComputedVersion version, ComputedTypeNullable typeNullable) {
|
||||||
ClassName serializerClassName = typeNullable.getJSerializerName(basePackageName);
|
ClassName serializerClassName = typeNullable.getJSerializerName(basePackageName);
|
||||||
var typeNullableClassName = typeNullable.getJTypeName(basePackageName);
|
var typeNullableClassName = typeNullable.getJTypeName(basePackageName);
|
||||||
|
|
||||||
@ -54,7 +58,7 @@ public class GenSerializerNullableX extends ClassGenerator {
|
|||||||
return new GeneratedClass(serializerClassName.packageName(), classBuilder);
|
return new GeneratedClass(serializerClassName.packageName(), classBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateSerialize(ComputedVersion version, ComputedTypeNullableVersioned typeNullable, Builder classBuilder) {
|
private void generateSerialize(ComputedVersion version, ComputedTypeNullable typeNullable, Builder classBuilder) {
|
||||||
var method = MethodSpec.methodBuilder("serialize");
|
var method = MethodSpec.methodBuilder("serialize");
|
||||||
|
|
||||||
var base = typeNullable.getBase();
|
var base = typeNullable.getBase();
|
||||||
@ -89,7 +93,7 @@ public class GenSerializerNullableX extends ClassGenerator {
|
|||||||
classBuilder.addMethod(method.build());
|
classBuilder.addMethod(method.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDeserialize(ComputedVersion version, ComputedTypeNullableVersioned typeNullable, Builder classBuilder) {
|
private void generateDeserialize(ComputedVersion version, ComputedTypeNullable typeNullable, Builder classBuilder) {
|
||||||
var method = MethodSpec.methodBuilder("deserialize");
|
var method = MethodSpec.methodBuilder("deserialize");
|
||||||
|
|
||||||
var base = typeNullable.getBase();
|
var base = typeNullable.getBase();
|
||||||
|
Loading…
Reference in New Issue
Block a user