Compare commits
No commits in common. "master" and "v1.0.239" have entirely different histories.
@ -5,18 +5,18 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<name>Data generator</name>
|
||||
<artifactId>datagen-plugin</artifactId>
|
||||
<artifactId>data-generator-plugin</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<parent>
|
||||
<groupId>it.cavallium</groupId>
|
||||
<version>${revision}</version>
|
||||
<artifactId>datagen-parent</artifactId>
|
||||
<artifactId>data-generator</artifactId>
|
||||
</parent>
|
||||
<properties>
|
||||
<revision>1.0.0.0-SNAPSHOT</revision>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<fastutil.version>8.5.12</fastutil.version>
|
||||
<fastutil.version>8.5.11</fastutil.version>
|
||||
<maven.version>4.0.0-alpha-3</maven.version>
|
||||
</properties>
|
||||
<repositories>
|
||||
@ -59,7 +59,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.7.1</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
@ -82,9 +82,9 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
<release>17</release>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
@ -185,7 +185,7 @@
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>1.33</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.fabricmc</groupId>
|
||||
@ -195,7 +195,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>24.0.1</version>
|
||||
<version>23.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.unimi.dsi</groupId>
|
||||
@ -217,7 +217,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -233,7 +233,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.20.0</version>
|
||||
<version>2.19.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@ -243,7 +243,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j2-impl</artifactId>
|
||||
<version>2.20.0</version>
|
||||
<version>2.19.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
@ -269,7 +269,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.cavallium</groupId>
|
||||
<artifactId>datagen</artifactId>
|
||||
<artifactId>data-generator-runtime</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
|
||||
@ -29,7 +29,6 @@ public abstract class ClassGenerator {
|
||||
protected final boolean deepCheckBeforeCreatingNewEqualInstances;
|
||||
protected final boolean useRecordBuilders;
|
||||
protected final boolean generateOldSerializers;
|
||||
protected final boolean binaryStrings;
|
||||
|
||||
public ClassGenerator(ClassGeneratorParams params) {
|
||||
this.generatedFilesToDelete = params.generatedFilesToDelete;
|
||||
@ -39,7 +38,6 @@ public abstract class ClassGenerator {
|
||||
this.deepCheckBeforeCreatingNewEqualInstances = params.deepCheckBeforeCreatingNewEqualInstances;
|
||||
this.useRecordBuilders = params.useRecordBuilders;
|
||||
this.generateOldSerializers = params.generateOldSerializers;
|
||||
this.binaryStrings = params.binaryStrings;
|
||||
}
|
||||
|
||||
public void run() throws IOException {
|
||||
@ -91,6 +89,5 @@ public abstract class ClassGenerator {
|
||||
Path outPath,
|
||||
boolean deepCheckBeforeCreatingNewEqualInstances,
|
||||
boolean useRecordBuilders,
|
||||
boolean generateOldSerializers,
|
||||
boolean binaryStrings) {}
|
||||
boolean generateOldSerializers) {}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -12,7 +12,6 @@ public sealed interface ComputedType permits VersionedComputedType, ComputedType
|
||||
String getName();
|
||||
|
||||
TypeName getJTypeName(String basePackageName);
|
||||
TypeName getJTypeNameGeneric(String basePackageName);
|
||||
|
||||
TypeName getJSerializerName(String basePackageName);
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.nativedata.UpgradeUtil;
|
||||
import it.cavallium.data.generator.nativedata.UpgradeUtil;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
@ -71,11 +71,6 @@ public final class ComputedTypeArrayFixed implements ComputedTypeArray {
|
||||
computedTypeSupplier.get(baseType).getJTypeName(basePackageName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeName(basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return ClassName.get(currentVersion.getSerializersPackage(basePackageName), "Array" + baseType + "Serializer");
|
@ -1,9 +1,19 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.nativedata.*;
|
||||
import it.cavallium.data.generator.nativedata.ArrayInt52Serializer;
|
||||
import it.cavallium.data.generator.nativedata.ArrayStringSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArraybooleanSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArraybyteSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArraycharSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArraydoubleSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArrayfloatSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArrayintSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArraylongSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ArrayshortSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Serializers;
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanList;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteList;
|
||||
import it.unimi.dsi.fastutil.chars.CharList;
|
||||
@ -19,15 +29,13 @@ import java.util.stream.Stream;
|
||||
public final class ComputedTypeArrayNative implements ComputedTypeArray {
|
||||
|
||||
private final String baseType;
|
||||
private final boolean binaryStrings;
|
||||
|
||||
private ComputedTypeNative computedChild;
|
||||
private final ComputedTypeSupplier computedTypeSupplier;
|
||||
|
||||
public ComputedTypeArrayNative(String baseType, ComputedTypeSupplier computedTypeSupplier, boolean binaryStrings) {
|
||||
public ComputedTypeArrayNative(String baseType, ComputedTypeSupplier computedTypeSupplier) {
|
||||
this.baseType = baseType;
|
||||
this.computedTypeSupplier = computedTypeSupplier;
|
||||
this.binaryStrings = binaryStrings;
|
||||
}
|
||||
|
||||
public ComputedType getBase() {
|
||||
@ -88,11 +96,6 @@ public final class ComputedTypeArrayNative implements ComputedTypeArray {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeName(basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return switch (baseType) {
|
||||
@ -104,7 +107,7 @@ public final class ComputedTypeArrayNative implements ComputedTypeArray {
|
||||
case "long" -> ClassName.get(ArraylongSerializer.class);
|
||||
case "float" -> ClassName.get(ArrayfloatSerializer.class);
|
||||
case "double" -> ClassName.get(ArraydoubleSerializer.class);
|
||||
case "String" -> binaryStrings ? ClassName.get(ArrayBinaryStringSerializer.class) : ClassName.get(ArrayStringSerializer.class);
|
||||
case "String" -> ClassName.get(ArrayStringSerializer.class);
|
||||
case "Int52" -> ClassName.get(ArrayInt52Serializer.class);
|
||||
default -> throw new UnsupportedOperationException();
|
||||
};
|
||||
@ -112,14 +115,10 @@ public final class ComputedTypeArrayNative implements ComputedTypeArray {
|
||||
|
||||
@Override
|
||||
public FieldLocation getJSerializerInstance(String basePackageName) {
|
||||
if (baseType.equals("String") && binaryStrings) {
|
||||
return new FieldLocation(ClassName.get(Serializers.class), "ArrayBinaryStringSerializerInstance");
|
||||
} else {
|
||||
var className = ClassName.get(Serializers.class);
|
||||
var serializerFieldName = "Array" + baseType + "SerializerInstance";
|
||||
return new FieldLocation(className, serializerFieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJUpgraderName(String basePackageName) {
|
@ -1,11 +1,11 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.nativedata.UpgradeUtil;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.nativedata.UpgradeUtil;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -88,11 +88,6 @@ public final class ComputedTypeArrayVersioned implements VersionedComputedType,
|
||||
computedTypeSupplier.get(baseType).getJTypeName(basePackageName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeName(basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return ClassName.get(baseType.version().getSerializersPackage(basePackageName), "Array" + baseType.type() + "Serializer");
|
@ -1,9 +1,8 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
@ -102,11 +101,6 @@ public final class ComputedTypeBase implements VersionedComputedType {
|
||||
return ClassName.get(getVersion().getDataPackage(basePackageName), type.type());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeName(basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return ClassName.get(type.version().getSerializersPackage(basePackageName), type.type() + "Serializer");
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
@ -64,7 +64,7 @@ public final class ComputedTypeCustom implements ComputedType {
|
||||
return false;
|
||||
}
|
||||
|
||||
ComputedTypeCustom that = (ComputedTypeCustom) o;
|
||||
it.cavallium.data.generator.plugin.ComputedTypeCustom that = (it.cavallium.data.generator.plugin.ComputedTypeCustom) o;
|
||||
|
||||
if (!Objects.equals(type, that.type)) {
|
||||
return false;
|
||||
@ -93,11 +93,6 @@ public final class ComputedTypeCustom implements ComputedType {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeName(basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJSerializerName(String basePackageName) {
|
||||
return ClassName.bestGuess(serializer);
|
@ -1,9 +1,10 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.nativedata.*;
|
||||
|
||||
import it.cavallium.data.generator.nativedata.Int52Serializer;
|
||||
import it.cavallium.data.generator.nativedata.Serializers;
|
||||
import it.cavallium.data.generator.nativedata.StringSerializer;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@ -15,14 +16,12 @@ public final class ComputedTypeNative implements ComputedType {
|
||||
|
||||
private final String type;
|
||||
private final ComputedTypeSupplier computedTypeSupplier;
|
||||
private final boolean binaryStrings;
|
||||
private boolean primitive;
|
||||
|
||||
public ComputedTypeNative(String type, ComputedTypeSupplier computedTypeSupplier, boolean binaryStrings) {
|
||||
public ComputedTypeNative(String type, ComputedTypeSupplier computedTypeSupplier) {
|
||||
this.type = type;
|
||||
this.computedTypeSupplier = computedTypeSupplier;
|
||||
this.primitive = PRIMITIVE_TYPES.contains(type);
|
||||
this.binaryStrings = binaryStrings;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -32,7 +31,7 @@ public final class ComputedTypeNative implements ComputedType {
|
||||
@Override
|
||||
public TypeName getJTypeName(String basePackageName) {
|
||||
return switch (type) {
|
||||
case "String" -> binaryStrings ? ClassName.get(BinaryString.class) : ClassName.get(String.class);
|
||||
case "String" -> ClassName.get(String.class);
|
||||
case "boolean" -> TypeName.BOOLEAN;
|
||||
case "short" -> TypeName.SHORT;
|
||||
case "char" -> TypeName.CHAR;
|
||||
@ -41,20 +40,15 @@ public final class ComputedTypeNative implements ComputedType {
|
||||
case "float" -> TypeName.FLOAT;
|
||||
case "double" -> TypeName.DOUBLE;
|
||||
case "byte" -> TypeName.BYTE;
|
||||
case "Int52" -> ClassName.get(Int52.class);
|
||||
case "Int52" -> ClassName.get(it.cavallium.data.generator.nativedata.Int52.class);
|
||||
default -> throw new UnsupportedOperationException(type + " is not a known native type");
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeName(basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJSerializerName(String basePackageName) {
|
||||
return switch (type) {
|
||||
case "String" -> binaryStrings ? ClassName.get(BinaryStringSerializer.class) : ClassName.get(StringSerializer.class);
|
||||
case "String" -> ClassName.get(StringSerializer.class);
|
||||
case "boolean", "byte", "short", "char", "int", "long", "float", "double" ->
|
||||
throw new UnsupportedOperationException("Type " + type
|
||||
+ " is a native type, so it doesn't have a serializer");
|
||||
@ -65,12 +59,8 @@ public final class ComputedTypeNative implements ComputedType {
|
||||
|
||||
@Override
|
||||
public FieldLocation getJSerializerInstance(String basePackageName) {
|
||||
if (type.equals("String") && binaryStrings) {
|
||||
return new FieldLocation(ClassName.get(Serializers.class), "BinaryStringSerializerInstance");
|
||||
} else {
|
||||
return new FieldLocation(ClassName.get(Serializers.class), type + "SerializerInstance");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJUpgraderName(String basePackageName) {
|
||||
@ -91,7 +81,7 @@ public final class ComputedTypeNative implements ComputedType {
|
||||
return false;
|
||||
}
|
||||
|
||||
ComputedTypeNative that = (ComputedTypeNative) o;
|
||||
it.cavallium.data.generator.plugin.ComputedTypeNative that = (it.cavallium.data.generator.plugin.ComputedTypeNative) o;
|
||||
|
||||
return Objects.equals(type, that.type);
|
||||
}
|
||||
@ -111,10 +101,10 @@ public final class ComputedTypeNative implements ComputedType {
|
||||
return computedTypeSupplier.getDependents(getName());
|
||||
}
|
||||
|
||||
public static List<ComputedTypeNative> get(ComputedTypeSupplier computedTypeSupplier, boolean binaryStrings) {
|
||||
public static List<it.cavallium.data.generator.plugin.ComputedTypeNative> get(ComputedTypeSupplier computedTypeSupplier) {
|
||||
return Stream
|
||||
.of("String", "boolean", "short", "char", "int", "long", "float", "double", "byte", "Int52")
|
||||
.map(name -> new ComputedTypeNative(name, computedTypeSupplier, binaryStrings))
|
||||
.map(name -> new it.cavallium.data.generator.plugin.ComputedTypeNative(name, computedTypeSupplier))
|
||||
.toList();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
|
@ -1,11 +1,9 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.TypedNullable;
|
||||
import it.cavallium.datagen.nativedata.UpgradeUtil;
|
||||
import it.cavallium.data.generator.nativedata.UpgradeUtil;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -70,21 +68,11 @@ public final class ComputedTypeNullableFixed implements ComputedTypeNullable {
|
||||
return getJTypeNameOfVersion(currentVersion, basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeNameGenericOfVersion(currentVersion, basePackageName);
|
||||
}
|
||||
|
||||
private TypeName getJTypeNameOfVersion(ComputedVersion version, String basePackageName) {
|
||||
return ClassName.get(version.getDataNullablesPackage(basePackageName),
|
||||
"Nullable" + baseType);
|
||||
}
|
||||
|
||||
private TypeName getJTypeNameGenericOfVersion(ComputedVersion version, String basePackageName) {
|
||||
return ParameterizedTypeName.get(ClassName.get(TypedNullable.class),
|
||||
ClassName.get(version.getDataPackage(basePackageName), baseType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return ClassName.get(currentVersion.getSerializersPackage(basePackageName),
|
||||
@ -114,7 +102,7 @@ public final class ComputedTypeNullableFixed implements ComputedTypeNullable {
|
||||
var upgraderInstance = getBase().getJUpgraderInstance(basePackageName);
|
||||
builder.add("new $T($T.upgradeNullable(", next.getJTypeName(basePackageName), UpgradeUtil.class);
|
||||
builder.add(content);
|
||||
builder.add(".getNullable(), $T.$N)", upgraderInstance.className(), upgraderInstance.fieldName());
|
||||
builder.add(".value(), $T.$N)", upgraderInstance.className(), upgraderInstance.fieldName());
|
||||
builder.add(")");
|
||||
return builder.build();
|
||||
}
|
@ -1,9 +1,28 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.nativedata.*;
|
||||
|
||||
import it.cavallium.data.generator.nativedata.NullableInt52;
|
||||
import it.cavallium.data.generator.nativedata.NullableInt52Serializer;
|
||||
import it.cavallium.data.generator.nativedata.NullableString;
|
||||
import it.cavallium.data.generator.nativedata.NullableStringSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullableboolean;
|
||||
import it.cavallium.data.generator.nativedata.NullablebooleanSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullablebyte;
|
||||
import it.cavallium.data.generator.nativedata.NullablebyteSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullablechar;
|
||||
import it.cavallium.data.generator.nativedata.NullablecharSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullabledouble;
|
||||
import it.cavallium.data.generator.nativedata.NullabledoubleSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullablefloat;
|
||||
import it.cavallium.data.generator.nativedata.NullablefloatSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullableint;
|
||||
import it.cavallium.data.generator.nativedata.NullableintSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullablelong;
|
||||
import it.cavallium.data.generator.nativedata.NullablelongSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Nullableshort;
|
||||
import it.cavallium.data.generator.nativedata.NullableshortSerializer;
|
||||
import it.cavallium.data.generator.nativedata.Serializers;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -11,16 +30,14 @@ public final class ComputedTypeNullableNative implements ComputedTypeNullable {
|
||||
|
||||
private final String baseType;
|
||||
private final ComputedVersion latestVersion;
|
||||
private final boolean binaryStrings;
|
||||
|
||||
private ComputedTypeNative computedChild;
|
||||
private final ComputedTypeSupplier computedTypeSupplier;
|
||||
|
||||
public ComputedTypeNullableNative(String baseType, ComputedVersion latestVersion, ComputedTypeSupplier computedTypeSupplier, boolean binaryStrings) {
|
||||
public ComputedTypeNullableNative(String baseType, ComputedVersion latestVersion, ComputedTypeSupplier computedTypeSupplier) {
|
||||
this.baseType = baseType;
|
||||
this.latestVersion = latestVersion;
|
||||
this.computedTypeSupplier = computedTypeSupplier;
|
||||
this.binaryStrings = binaryStrings;
|
||||
}
|
||||
|
||||
public ComputedTypeNative getBase() {
|
||||
@ -76,17 +93,12 @@ public final class ComputedTypeNullableNative implements ComputedTypeNullable {
|
||||
case "long" -> ClassName.get(Nullablelong.class);
|
||||
case "float" -> ClassName.get(Nullablefloat.class);
|
||||
case "double" -> ClassName.get(Nullabledouble.class);
|
||||
case "String" -> binaryStrings ? ClassName.get(NullableBinaryString.class) : ClassName.get(NullableString.class);
|
||||
case "String" -> ClassName.get(NullableString.class);
|
||||
case "Int52" -> ClassName.get(NullableInt52.class);
|
||||
default -> ClassName.get(latestVersion.getDataNullablesPackage(basePackageName), "Nullable" + baseType);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeName(basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return switch (baseType) {
|
||||
@ -98,7 +110,7 @@ public final class ComputedTypeNullableNative implements ComputedTypeNullable {
|
||||
case "long" -> ClassName.get(NullablelongSerializer.class);
|
||||
case "float" -> ClassName.get(NullablefloatSerializer.class);
|
||||
case "double" -> ClassName.get(NullabledoubleSerializer.class);
|
||||
case "String" -> binaryStrings ? ClassName.get(NullableBinaryStringSerializer.class) : ClassName.get(NullableStringSerializer.class);
|
||||
case "String" -> ClassName.get(NullableStringSerializer.class);
|
||||
case "Int52" -> ClassName.get(NullableInt52Serializer.class);
|
||||
default -> throw new UnsupportedOperationException();
|
||||
};
|
||||
@ -106,9 +118,6 @@ public final class ComputedTypeNullableNative implements ComputedTypeNullable {
|
||||
|
||||
@Override
|
||||
public FieldLocation getJSerializerInstance(String basePackageName) {
|
||||
if (baseType.equals("String") && binaryStrings) {
|
||||
return new FieldLocation(ClassName.get(Serializers.class), "NullableBinaryStringSerializerInstance");
|
||||
} else {
|
||||
var className = switch (baseType) {
|
||||
case "boolean", "byte", "short", "char", "int", "long", "float", "double", "String", "Int52" ->
|
||||
ClassName.get(Serializers.class);
|
||||
@ -117,7 +126,6 @@ public final class ComputedTypeNullableNative implements ComputedTypeNullable {
|
||||
var serializerFieldName = "Nullable" + baseType + "SerializerInstance";
|
||||
return new FieldLocation(className, serializerFieldName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJUpgraderName(String basePackageName) {
|
@ -1,12 +1,10 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.TypedNullable;
|
||||
import it.cavallium.datagen.nativedata.UpgradeUtil;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.nativedata.UpgradeUtil;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
@ -83,21 +81,11 @@ public final class ComputedTypeNullableVersioned implements ComputedTypeNullable
|
||||
return getJTypeNameOfVersion(baseType.version(), basePackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return getJTypeNameGenericOfVersion(baseType.version(), basePackageName);
|
||||
}
|
||||
|
||||
private TypeName getJTypeNameOfVersion(ComputedVersion version, String basePackageName) {
|
||||
return ClassName.get(version.getDataNullablesPackage(basePackageName),
|
||||
"Nullable" + baseType.type());
|
||||
}
|
||||
|
||||
private TypeName getJTypeNameGenericOfVersion(ComputedVersion version, String basePackageName) {
|
||||
return ParameterizedTypeName.get(ClassName.get(TypedNullable.class),
|
||||
ClassName.get(version.getDataPackage(basePackageName), baseType.type()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return ClassName.get(baseType.version().getSerializersPackage(basePackageName),
|
||||
@ -127,7 +115,7 @@ public final class ComputedTypeNullableVersioned implements ComputedTypeNullable
|
||||
var upgraderInstance = getBase().getJUpgraderInstance(basePackageName);
|
||||
builder.add("new $T($T.upgradeNullable(", next.getJTypeName(basePackageName), UpgradeUtil.class);
|
||||
builder.add(content);
|
||||
builder.add(".getNullable(), $T.$N)", upgraderInstance.className(), upgraderInstance.fieldName());
|
||||
builder.add(".value(), $T.$N)", upgraderInstance.className(), upgraderInstance.fieldName());
|
||||
builder.add(")");
|
||||
return builder.build();
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -34,9 +33,9 @@ public final class ComputedTypeSuper implements VersionedComputedType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputedTypeSuper withChangeAtVersion(ComputedVersion version,
|
||||
public it.cavallium.data.generator.plugin.ComputedTypeSuper withChangeAtVersion(ComputedVersion version,
|
||||
VersionChangeChecker versionChangeChecker, LinkedHashMap<String, VersionedType> data) {
|
||||
return new ComputedTypeSuper(type.withVersion(version),
|
||||
return new it.cavallium.data.generator.plugin.ComputedTypeSuper(type.withVersion(version),
|
||||
subTypes.stream().map(subType -> subType.withVersionIfChanged(version, versionChangeChecker)).toList(),
|
||||
computedTypeSupplier
|
||||
);
|
||||
@ -63,7 +62,7 @@ public final class ComputedTypeSuper implements VersionedComputedType {
|
||||
return false;
|
||||
}
|
||||
|
||||
ComputedTypeSuper that = (ComputedTypeSuper) o;
|
||||
it.cavallium.data.generator.plugin.ComputedTypeSuper that = (it.cavallium.data.generator.plugin.ComputedTypeSuper) o;
|
||||
|
||||
if (!Objects.equals(type, that.type)) {
|
||||
return false;
|
||||
@ -98,11 +97,6 @@ public final class ComputedTypeSuper implements VersionedComputedType {
|
||||
return ClassName.get(getVersion().getDataPackage(basePackageName), type.type());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeName getJTypeNameGeneric(String basePackageName) {
|
||||
return ClassName.get(getVersion().getDataPackage(basePackageName), type.type());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassName getJSerializerName(String basePackageName) {
|
||||
return ClassName.get(type.version().getSerializersPackage(basePackageName), type.type() + "Serializer");
|
@ -1,7 +1,8 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
@ -1,9 +1,11 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import static it.cavallium.datagen.plugin.DataModel.joinPackage;
|
||||
import static it.cavallium.data.generator.plugin.DataModel.joinPackage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ComputedVersion implements Comparable<ComputedVersion> {
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.function.Function.identity;
|
||||
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
@ -63,8 +63,7 @@ public class DataModel {
|
||||
Map<String, ClassConfiguration> baseTypesData,
|
||||
Map<String, Set<String>> superTypesData,
|
||||
Map<String, CustomTypesConfiguration> customTypesData,
|
||||
Map<String, VersionConfiguration> rawVersions,
|
||||
boolean binaryStrings) {
|
||||
Map<String, VersionConfiguration> rawVersions) {
|
||||
|
||||
this.hash = hash;
|
||||
|
||||
@ -160,7 +159,7 @@ public class DataModel {
|
||||
.stream()
|
||||
.filter(x -> x.size() > 1)
|
||||
.forEach(x -> {
|
||||
var type = x.getFirst();
|
||||
var type = x.get(0);
|
||||
throw new IllegalArgumentException("Type " + type + " has been defined more than once (check base, super, and custom types)!");
|
||||
});
|
||||
|
||||
@ -210,19 +209,19 @@ public class DataModel {
|
||||
+ t.transformClass);
|
||||
}
|
||||
transformClass.addDifferentThanPrev(transformation);
|
||||
var definition = transformClass.remove(t.from);
|
||||
var definition = removeAndGetIndex(transformClass.data, t.from);
|
||||
if (definition.isEmpty()) {
|
||||
throw new IllegalArgumentException(transformCoordinate + " refers to an unknown field: " + t.from);
|
||||
}
|
||||
ParsedClass.FieldInfo prevDef = transformClass.insert(
|
||||
Objects.requireNonNullElse(t.index, definition.get().getKey()),
|
||||
var prevDef = tryInsertAtIndex(transformClass.data,
|
||||
t.to,
|
||||
new ParsedClass.InputFieldInfo(definition.get().getValue().typeName(), List.of())
|
||||
definition.get().getValue(),
|
||||
definition.get().getKey()
|
||||
);
|
||||
if (prevDef != null) {
|
||||
throw new IllegalArgumentException(
|
||||
transformCoordinate + " tries to overwrite the existing field \"" + t.to + "\" of value \""
|
||||
+ prevDef.typeName() + "\" with the field \"" + t.from + "\" of type \"" + definition.orElse(null) + "\"");
|
||||
+ prevDef + "\" with the field \"" + t.from + "\" of type \"" + definition.orElse(null) + "\"");
|
||||
}
|
||||
}
|
||||
case "new-data" -> {
|
||||
@ -236,12 +235,15 @@ public class DataModel {
|
||||
if (!allTypes.contains(extractTypeName(t.type))) {
|
||||
throw new IllegalArgumentException(transformCoordinate + " refers to an unknown type: " + t.type);
|
||||
}
|
||||
var type = fixType(t.type);
|
||||
var fieldInfo = new ParsedClass.InputFieldInfo(type, t.getContextParameters());
|
||||
ParsedClass.FieldInfo prevDef = transformClass.insert(t.index, t.to, fieldInfo);
|
||||
String prevDef;
|
||||
if (t.index != null) {
|
||||
prevDef = tryInsertAtIndex(transformClass.data, t.to, fixType(t.type), t.index);
|
||||
} else {
|
||||
prevDef = transformClass.data.putIfAbsent(t.to, fixType(t.type));
|
||||
}
|
||||
if (prevDef != null) {
|
||||
throw new IllegalArgumentException(transformCoordinate + " tries to overwrite the existing field \""
|
||||
+ t.to + "\" of value \"" + prevDef.typeName()
|
||||
+ t.to + "\" of value \"" + prevDef
|
||||
+ "\" with the new type \"" + t.type + "\"");
|
||||
}
|
||||
}
|
||||
@ -270,7 +272,7 @@ public class DataModel {
|
||||
if (!allTypes.contains(extractTypeName(t.type))) {
|
||||
throw new IllegalArgumentException(transformCoordinate + " refers to an unknown type: " + t.type);
|
||||
}
|
||||
var prevDefinition = transformClass.replace(t.from, new ParsedClass.InputFieldInfo(fixType(t.type), t.getContextParameters()));
|
||||
String prevDefinition = transformClass.data.replace(t.from, fixType(t.type));
|
||||
if (prevDefinition == null) {
|
||||
throw new IllegalArgumentException(transformCoordinate + " refers to an unknown field: " + t.from);
|
||||
}
|
||||
@ -329,7 +331,7 @@ public class DataModel {
|
||||
List<ComputedType> versionBaseTypes = computedClassConfig.get(versionIndexF).entrySet().stream()
|
||||
.map(e -> {
|
||||
var data = new LinkedHashMap<String, VersionedType>();
|
||||
e.getValue().getData().forEach((key, value) -> data.put(key, new VersionedType(value.typeName(), version)));
|
||||
e.getValue().getData().forEach((key, value) -> data.put(key, new VersionedType(value, version)));
|
||||
return new ComputedTypeBase(new VersionedType(e.getKey(), version),
|
||||
e.getValue().stringRepresenter, data, computedTypeSupplier);
|
||||
}).collect(Collectors.toList());
|
||||
@ -346,8 +348,8 @@ public class DataModel {
|
||||
var nullableRawTypes = computedClassConfig.values().stream()
|
||||
.flatMap(x -> x.values().stream())
|
||||
.flatMap(x -> x.getData().values().stream())
|
||||
.filter(x -> x.typeName().startsWith("-"))
|
||||
.map(nullableName -> nullableName.typeName().substring(1))
|
||||
.filter(x -> x.startsWith("-"))
|
||||
.map(nullableName -> nullableName.substring(1))
|
||||
.toList();
|
||||
// Compute nullable versioned types
|
||||
nullableRawTypes.stream()
|
||||
@ -364,7 +366,7 @@ public class DataModel {
|
||||
nullableRawTypes.stream()
|
||||
.filter(NATIVE_TYPES::contains)
|
||||
.map(baseType ->
|
||||
new ComputedTypeNullableNative(baseType, computedVersions.get(latestVersion), computedTypeSupplier, binaryStrings))
|
||||
new ComputedTypeNullableNative(baseType, computedVersions.get(latestVersion), computedTypeSupplier))
|
||||
.forEach(versionBaseTypes::add);
|
||||
}
|
||||
// Compute array types
|
||||
@ -372,8 +374,8 @@ public class DataModel {
|
||||
var arrayRawTypes = computedClassConfig.values().stream()
|
||||
.flatMap(x -> x.values().stream())
|
||||
.flatMap(x -> x.getData().values().stream())
|
||||
.filter(x -> x.typeName().startsWith("§"))
|
||||
.map(nullableName -> nullableName.typeName().substring(1))
|
||||
.filter(x -> x.startsWith("§"))
|
||||
.map(nullableName -> nullableName.substring(1))
|
||||
.toList();
|
||||
// Compute array versioned types
|
||||
arrayRawTypes.stream()
|
||||
@ -390,11 +392,11 @@ public class DataModel {
|
||||
arrayRawTypes.stream()
|
||||
.filter(NATIVE_TYPES::contains)
|
||||
.map(baseType ->
|
||||
new ComputedTypeArrayNative(baseType, computedTypeSupplier, binaryStrings))
|
||||
new ComputedTypeArrayNative(baseType, computedTypeSupplier))
|
||||
.forEach(versionBaseTypes::add);
|
||||
}
|
||||
// Compute native types
|
||||
versionBaseTypes.addAll(ComputedTypeNative.get(computedTypeSupplier, binaryStrings));
|
||||
versionBaseTypes.addAll(ComputedTypeNative.get(computedTypeSupplier));
|
||||
|
||||
var allLatestTypes = versionBaseTypes.stream().distinct().collect(Collectors.toMap(ComputedType::getName, identity()));
|
||||
|
||||
@ -439,7 +441,7 @@ public class DataModel {
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Entry::getKey, e -> {
|
||||
var fieldTypeName = e.getValue().typeName();
|
||||
var fieldTypeName = e.getValue();
|
||||
return new VersionedType(fieldTypeName, computedVersions.get(currentOrNewerTypeVersion.getInt(fieldTypeName)));
|
||||
}, (a, b) -> {
|
||||
throw new IllegalStateException();
|
||||
@ -580,6 +582,40 @@ public class DataModel {
|
||||
this.baseTypeDataChanges = baseTypeDataChanges;
|
||||
}
|
||||
|
||||
private String tryInsertAtIndex(LinkedHashMap<String, String> data, String key, String value, int index) {
|
||||
var before = new LinkedHashMap<String, String>();
|
||||
var after = new LinkedHashMap<String, String>();
|
||||
int i = 0;
|
||||
for (Entry<String, String> entry : data.entrySet()) {
|
||||
if (i < index) {
|
||||
before.put(entry.getKey(), entry.getValue());
|
||||
} else {
|
||||
after.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
data.clear();
|
||||
data.putAll(before);
|
||||
var prev = data.putIfAbsent(key, value);
|
||||
data.putAll(after);
|
||||
return prev;
|
||||
}
|
||||
|
||||
private Optional<Entry<Integer, String>> removeAndGetIndex(LinkedHashMap<String, String> data, String find) {
|
||||
int foundIndex = -1;
|
||||
{
|
||||
int i = 0;
|
||||
for (Entry<String, String> entry : data.entrySet()) {
|
||||
if (entry.getKey().equals(find)) {
|
||||
foundIndex = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (foundIndex == -1) return Optional.empty();
|
||||
return Optional.of(Map.entry(foundIndex, requireNonNull(data.remove(find))));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getNextVersion(Map<String, String> versionsSequence, String version) {
|
||||
return versionsSequence.get(version);
|
||||
@ -605,7 +641,7 @@ public class DataModel {
|
||||
if (list.size() != 1) {
|
||||
throw exceptionGenerator.apply(list);
|
||||
}
|
||||
return list.getFirst();
|
||||
return list.get(0);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -624,7 +660,7 @@ public class DataModel {
|
||||
if (list.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(list.getFirst());
|
||||
return Optional.of(list.get(0));
|
||||
}
|
||||
);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.TypeName;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -29,12 +29,6 @@ public class MavenPlugin extends AbstractMojo {
|
||||
@Parameter( required = true, defaultValue = "false")
|
||||
private String useRecordBuilder;
|
||||
|
||||
@Parameter(defaultValue = "false")
|
||||
private String generateTestResources;
|
||||
|
||||
@Parameter(defaultValue = "false")
|
||||
private String binaryStrings;
|
||||
|
||||
/**
|
||||
* @parameter default-value="${project}"
|
||||
* @required
|
||||
@ -47,13 +41,12 @@ public class MavenPlugin extends AbstractMojo {
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
try {
|
||||
SourcesGenerator sourcesGenerator = SourcesGenerator.load(configPath.toPath());
|
||||
project.hasLifecyclePhase("generate-test-sources");
|
||||
Path genRecordsPath = project.getBasedir().getAbsoluteFile().toPath().resolve("target").resolve(Boolean.parseBoolean(generateTestResources) ? "generated-test-sources" : "generated-sources").resolve("database-classes");
|
||||
Path genRecordsPath = project.getBasedir().getAbsoluteFile().toPath().resolve("target").resolve("generated-sources").resolve("database-classes");
|
||||
|
||||
Path outPath = genRecordsPath.resolve("java");
|
||||
this.project.addCompileSourceRoot(outPath.toString());
|
||||
sourcesGenerator.generateSources(basePackageName, outPath, Boolean.parseBoolean(useRecordBuilder), false, Boolean.parseBoolean(deepCheckBeforeCreatingNewEqualInstances),
|
||||
Boolean.parseBoolean(generateOldSerializers), Boolean.parseBoolean(binaryStrings));
|
||||
Boolean.parseBoolean(generateOldSerializers));
|
||||
} catch (IOException e) {
|
||||
throw new MojoExecutionException("Exception while generating classes", e);
|
||||
}
|
@ -1,18 +1,12 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class MoveDataConfiguration implements TransformationConfiguration {
|
||||
|
||||
public String transformClass;
|
||||
public String from;
|
||||
public String to;
|
||||
@Nullable
|
||||
public Integer index;
|
||||
|
||||
@Override
|
||||
public String getTransformClass() {
|
||||
@ -33,8 +27,9 @@ public final class MoveDataConfiguration implements TransformationConfiguration
|
||||
return false;
|
||||
}
|
||||
MoveDataConfiguration that = (MoveDataConfiguration) o;
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from)
|
||||
&& Objects.equals(to, that.to) && Objects.equals(index, that.index);
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from) && Objects.equals(to,
|
||||
that.to
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,7 +38,6 @@ public final class MoveDataConfiguration implements TransformationConfiguration
|
||||
hash += ConfigUtils.hashCode(transformClass);
|
||||
hash += ConfigUtils.hashCode(from);
|
||||
hash += ConfigUtils.hashCode(to);
|
||||
hash += ConfigUtils.hashCode(index);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@ -52,7 +46,6 @@ public final class MoveDataConfiguration implements TransformationConfiguration
|
||||
if (this.transformClass != null) c.transformClass = this.transformClass;
|
||||
if (this.from != null) c.from = this.from;
|
||||
if (this.to != null) c.to = this.to;
|
||||
if (this.index != null) c.index = this.index;
|
||||
return c;
|
||||
}
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class NewDataConfiguration implements TransformationConfiguration {
|
||||
@ -12,11 +9,8 @@ public class NewDataConfiguration implements TransformationConfiguration {
|
||||
public String to;
|
||||
public String type;
|
||||
public String initializer;
|
||||
public String initializerInstance;
|
||||
@Nullable
|
||||
public Integer index;
|
||||
@Nullable
|
||||
public List<String> contextParameters;
|
||||
|
||||
@Override
|
||||
public String getTransformClass() {
|
||||
@ -28,15 +22,6 @@ public class NewDataConfiguration implements TransformationConfiguration {
|
||||
return "new-data";
|
||||
}
|
||||
|
||||
public JInterfaceLocation getInitializerLocation() {
|
||||
return JInterfaceLocation.parse(initializer, initializerInstance);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getContextParameters() {
|
||||
return Objects.requireNonNullElse(contextParameters, List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
@ -48,9 +33,7 @@ public class NewDataConfiguration implements TransformationConfiguration {
|
||||
NewDataConfiguration that = (NewDataConfiguration) o;
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(to, that.to)
|
||||
&& Objects.equals(type, that.type) && Objects.equals(initializer, that.initializer)
|
||||
&& Objects.equals(initializerInstance, that.initializerInstance)
|
||||
&& Objects.equals(index, that.index)
|
||||
&& Objects.equals(contextParameters, that.contextParameters);
|
||||
&& Objects.equals(index, that.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,9 +43,7 @@ public class NewDataConfiguration implements TransformationConfiguration {
|
||||
hash += ConfigUtils.hashCode(to);
|
||||
hash += ConfigUtils.hashCode(type);
|
||||
hash += ConfigUtils.hashCode(initializer);
|
||||
hash += ConfigUtils.hashCode(initializerInstance);
|
||||
hash += ConfigUtils.hashCode(index);
|
||||
hash += ConfigUtils.hashCode(contextParameters);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@ -70,11 +51,9 @@ public class NewDataConfiguration implements TransformationConfiguration {
|
||||
var c = new NewDataConfiguration();
|
||||
if (this.transformClass != null) c.transformClass = this.transformClass;
|
||||
if (this.initializer != null) c.initializer = this.initializer;
|
||||
if (this.initializerInstance != null) c.initializerInstance = this.initializerInstance;
|
||||
if (this.to != null) c.to = this.to;
|
||||
if (this.type != null) c.type = this.type;
|
||||
if (this.index != null) c.index = this.index;
|
||||
if (this.contextParameters != null) c.contextParameters = this.contextParameters;
|
||||
return c;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import static it.cavallium.data.generator.plugin.DataModel.fixType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ParsedClass {
|
||||
|
||||
public String stringRepresenter;
|
||||
|
||||
public LinkedHashMap<String, String> data;
|
||||
public List<TransformationConfiguration> differentThanPrev;
|
||||
public boolean differentThanNext;
|
||||
|
||||
public ParsedClass(ClassConfiguration baseTypesData) {
|
||||
this.stringRepresenter = baseTypesData.stringRepresenter;
|
||||
if (baseTypesData.data != null) {
|
||||
this.data = baseTypesData.data.entrySet().stream()
|
||||
.map(e -> Map.entry(e.getKey(), fixType(e.getValue())))
|
||||
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (a, b) -> {
|
||||
throw new IllegalStateException();
|
||||
}, LinkedHashMap::new));
|
||||
}
|
||||
}
|
||||
|
||||
public ParsedClass() {
|
||||
|
||||
}
|
||||
|
||||
public String getStringRepresenter() {
|
||||
return stringRepresenter;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, String> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ParsedClass that = (ParsedClass) o;
|
||||
return Objects.equals(stringRepresenter, that.stringRepresenter) && Objects.equals(data, that.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += ConfigUtils.hashCode(stringRepresenter);
|
||||
hash += ConfigUtils.hashCode(data);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public ParsedClass copy() {
|
||||
var cc = new ParsedClass();
|
||||
if (this.stringRepresenter != null) cc.stringRepresenter = this.stringRepresenter;
|
||||
cc.data = new LinkedHashMap<>(data);
|
||||
cc.differentThanNext = differentThanNext;
|
||||
cc.differentThanPrev = differentThanPrev;
|
||||
return cc;
|
||||
}
|
||||
|
||||
public void addDifferentThanPrev(TransformationConfiguration transformation) {
|
||||
if (differentThanPrev == null) {
|
||||
differentThanPrev = new ArrayList<>();
|
||||
}
|
||||
differentThanPrev.add(transformation);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import static it.cavallium.datagen.plugin.DataModel.fixType;
|
||||
import static it.cavallium.data.generator.plugin.DataModel.fixType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
import java.util.List;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
|
||||
@ -12,30 +12,27 @@ import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import it.cavallium.datagen.nativedata.Int52;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator.ClassGeneratorParams;
|
||||
import it.cavallium.datagen.plugin.classgen.GenBaseType;
|
||||
import it.cavallium.datagen.plugin.classgen.GenCurrentVersion;
|
||||
import it.cavallium.datagen.plugin.classgen.GenDataBaseX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenDataSuperX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenIBaseType;
|
||||
import it.cavallium.datagen.plugin.classgen.GenINullableBaseType;
|
||||
import it.cavallium.datagen.plugin.classgen.GenINullableIType;
|
||||
import it.cavallium.datagen.plugin.classgen.GenINullableSuperType;
|
||||
import it.cavallium.datagen.plugin.classgen.GenIType;
|
||||
import it.cavallium.datagen.plugin.classgen.GenIVersion;
|
||||
import it.cavallium.datagen.plugin.classgen.GenNullableX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenSerializerArrayX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenSerializerBaseX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenSerializerNullableX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenSerializerSuperX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenSuperType;
|
||||
import it.cavallium.datagen.plugin.classgen.GenUpgraderBaseX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenUpgraderSuperX;
|
||||
import it.cavallium.datagen.plugin.classgen.GenVersion;
|
||||
import it.cavallium.datagen.plugin.classgen.GenVersions;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator.ClassGeneratorParams;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenBaseType;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenCurrentVersion;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenDataBaseX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenDataSuperX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenIBaseType;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenINullableBaseType;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenINullableIType;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenINullableSuperType;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenIType;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenIVersion;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenNullableX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenSerializerArrayX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenSerializerBaseX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenSerializerNullableX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenSerializerSuperX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenSuperType;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenUpgraderBaseX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenUpgraderSuperX;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenVersion;
|
||||
import it.cavallium.data.generator.plugin.classgen.GenVersions;
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanList;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteList;
|
||||
import it.unimi.dsi.fastutil.chars.CharList;
|
||||
@ -44,6 +41,8 @@ import it.unimi.dsi.fastutil.floats.FloatList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import it.unimi.dsi.fastutil.longs.LongList;
|
||||
import it.unimi.dsi.fastutil.shorts.ShortList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -69,13 +68,13 @@ public class SourcesGenerator {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SourcesGenerator.class);
|
||||
private static final boolean OVERRIDE_ALL_NULLABLE_METHODS = false;
|
||||
private static final String SERIAL_VERSION = "6";
|
||||
|
||||
private final SourcesGeneratorConfiguration configuration;
|
||||
private final DataModel dataModel;
|
||||
|
||||
private SourcesGenerator(InputStream yamlDataStream) {
|
||||
Yaml yaml = new Yaml();
|
||||
this.configuration = yaml.loadAs(yamlDataStream, SourcesGeneratorConfiguration.class);
|
||||
var configuration = yaml.loadAs(yamlDataStream, SourcesGeneratorConfiguration.class);
|
||||
this.dataModel = configuration.buildDataModel();
|
||||
}
|
||||
|
||||
public static SourcesGenerator load(InputStream yamlData) {
|
||||
@ -100,15 +99,8 @@ public class SourcesGenerator {
|
||||
* @param useRecordBuilders if true, the data will have @RecordBuilder annotation
|
||||
* @param force force overwrite
|
||||
* @param deepCheckBeforeCreatingNewEqualInstances if true, use equals, if false, use ==
|
||||
* @param binaryStrings use binary strings
|
||||
*/
|
||||
public void generateSources(String basePackageName,
|
||||
Path outPath,
|
||||
boolean useRecordBuilders,
|
||||
boolean force,
|
||||
boolean deepCheckBeforeCreatingNewEqualInstances,
|
||||
boolean generateOldSerializers,
|
||||
boolean binaryStrings) throws IOException {
|
||||
public void generateSources(String basePackageName, Path outPath, boolean useRecordBuilders, boolean force, boolean deepCheckBeforeCreatingNewEqualInstances, boolean generateOldSerializers) throws IOException {
|
||||
Path basePackageNamePath;
|
||||
{
|
||||
Path basePackageNamePathPartial = outPath;
|
||||
@ -118,26 +110,21 @@ public class SourcesGenerator {
|
||||
basePackageNamePath = basePackageNamePathPartial;
|
||||
}
|
||||
var hashPath = basePackageNamePath.resolve(".hash");
|
||||
var dataModel = configuration.buildDataModel(binaryStrings);
|
||||
var curHash = dataModel.computeHash();
|
||||
if (Files.isRegularFile(hashPath) && Files.isReadable(hashPath)) {
|
||||
var lines = Files.readAllLines(hashPath, StandardCharsets.UTF_8);
|
||||
if (lines.size() >= 7) {
|
||||
if (lines.size() >= 5) {
|
||||
var prevBasePackageName = lines.get(0);
|
||||
var prevRecordBuilders = lines.get(1);
|
||||
var prevHash = lines.get(2);
|
||||
var prevDeepCheckBeforeCreatingNewEqualInstances = lines.get(3);
|
||||
var prevGenerateOldSerializers = lines.get(4);
|
||||
var prevSerialVersion = lines.get(5);
|
||||
var prevBinaryStrings = lines.get(6);
|
||||
|
||||
if (!force
|
||||
&& prevBasePackageName.equals(basePackageName)
|
||||
&& (prevRecordBuilders.equalsIgnoreCase("true") == useRecordBuilders)
|
||||
&& (prevDeepCheckBeforeCreatingNewEqualInstances.equalsIgnoreCase("true") == deepCheckBeforeCreatingNewEqualInstances)
|
||||
&& (prevGenerateOldSerializers.equalsIgnoreCase("true") == generateOldSerializers)
|
||||
&& (prevBinaryStrings.equalsIgnoreCase("true") == binaryStrings)
|
||||
&& (prevSerialVersion.equals(SERIAL_VERSION))
|
||||
&& prevHash.equals(Integer.toString(curHash))) {
|
||||
logger.info("Skipped sources generation because it didn't change");
|
||||
return;
|
||||
@ -163,8 +150,7 @@ public class SourcesGenerator {
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
var genParams = new ClassGeneratorParams(generatedFilesToDelete, dataModel, basePackageName, outPath,
|
||||
deepCheckBeforeCreatingNewEqualInstances, useRecordBuilders, generateOldSerializers, binaryStrings);
|
||||
var genParams = new ClassGeneratorParams(generatedFilesToDelete, dataModel, basePackageName, outPath, deepCheckBeforeCreatingNewEqualInstances, useRecordBuilders, generateOldSerializers);
|
||||
|
||||
// Create the Versions class
|
||||
new GenVersions(genParams).run();
|
||||
@ -212,28 +198,14 @@ public class SourcesGenerator {
|
||||
new GenUpgraderSuperX(genParams).run();
|
||||
|
||||
// Update the hash at the end
|
||||
var newHashRaw = basePackageName + '\n'
|
||||
+ useRecordBuilders + '\n'
|
||||
+ deepCheckBeforeCreatingNewEqualInstances + '\n'
|
||||
+ generateOldSerializers + '\n'
|
||||
+ binaryStrings + '\n'
|
||||
+ SERIAL_VERSION + '\n'
|
||||
+ curHash + '\n';
|
||||
String oldHashRaw;
|
||||
if (Files.exists(hashPath)) {
|
||||
oldHashRaw = Files.readString(hashPath, StandardCharsets.UTF_8);
|
||||
} else {
|
||||
oldHashRaw = null;
|
||||
}
|
||||
if (!Objects.equals(newHashRaw, oldHashRaw)) {
|
||||
Files.writeString(hashPath,
|
||||
newHashRaw,
|
||||
basePackageName + '\n' + useRecordBuilders + '\n' + deepCheckBeforeCreatingNewEqualInstances + '\n' + curHash
|
||||
+ '\n',
|
||||
StandardCharsets.UTF_8,
|
||||
TRUNCATE_EXISTING,
|
||||
WRITE,
|
||||
CREATE
|
||||
);
|
||||
}
|
||||
generatedFilesToDelete.remove(outPath.relativize(hashPath));
|
||||
}
|
||||
|
||||
@ -277,8 +249,8 @@ public class SourcesGenerator {
|
||||
private static String getSpecialNativePackage(String specialNativeType) {
|
||||
//noinspection SwitchStatementWithTooFewBranches
|
||||
return switch (specialNativeType) {
|
||||
case "Int52" -> Int52.class.getPackageName();
|
||||
default -> Integer.class.getPackageName();
|
||||
case "Int52" -> "it.cavallium.data.generator.nativedata";
|
||||
default -> "java.lang";
|
||||
};
|
||||
}
|
||||
|
||||
@ -307,9 +279,10 @@ public class SourcesGenerator {
|
||||
serializeMethod.addModifiers(Modifier.PUBLIC);
|
||||
serializeMethod.addModifiers(Modifier.FINAL);
|
||||
serializeMethod.returns(TypeName.VOID);
|
||||
serializeMethod.addParameter(ParameterSpec.builder(SafeDataOutput.class, "dataOutput").build());
|
||||
serializeMethod.addParameter(ParameterSpec.builder(DataOutput.class, "dataOutput").build());
|
||||
serializeMethod
|
||||
.addParameter(ParameterSpec.builder(classType, "data").addAnnotation(NotNull.class).build());
|
||||
serializeMethod.addException(IOException.class);
|
||||
serializeMethod.addStatement("$T.requireNonNull(data)", Objects.class);
|
||||
return serializeMethod;
|
||||
}
|
||||
@ -321,7 +294,8 @@ public class SourcesGenerator {
|
||||
deserializeMethod.addModifiers(Modifier.PUBLIC);
|
||||
deserializeMethod.addModifiers(Modifier.FINAL);
|
||||
deserializeMethod.returns(classType);
|
||||
deserializeMethod.addParameter(ParameterSpec.builder(SafeDataInput.class, "dataInput").build());
|
||||
deserializeMethod.addParameter(ParameterSpec.builder(DataInput.class, "dataInput").build());
|
||||
deserializeMethod.addException(IOException.class);
|
||||
return deserializeMethod;
|
||||
}
|
||||
|
||||
@ -421,7 +395,7 @@ public class SourcesGenerator {
|
||||
return i;
|
||||
}
|
||||
|
||||
public static String capitalize(String field) {
|
||||
private String capitalize(String field) {
|
||||
return Character.toUpperCase(field.charAt(0)) + field.substring(1);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -37,15 +37,14 @@ public class SourcesGeneratorConfiguration {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public DataModel buildDataModel(boolean binaryStrings) {
|
||||
public DataModel buildDataModel() {
|
||||
return new DataModel(hashCode(),
|
||||
currentVersion,
|
||||
Objects.requireNonNullElse(interfacesData, Map.of()),
|
||||
Objects.requireNonNullElse(baseTypesData, Map.of()),
|
||||
Objects.requireNonNullElse(superTypesData, Map.of()),
|
||||
Objects.requireNonNullElse(customTypesData, Map.of()),
|
||||
Objects.requireNonNullElse(versions, Map.of()),
|
||||
binaryStrings
|
||||
Objects.requireNonNullElse(versions, Map.of())
|
||||
);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import static java.lang.Boolean.parseBoolean;
|
||||
|
||||
@ -19,8 +19,7 @@ public class Standalone {
|
||||
parseBoolean(args[3]),
|
||||
parseBoolean(args[4]),
|
||||
parseBoolean(args[5]),
|
||||
parseBoolean(args[6]),
|
||||
parseBoolean(args[7])
|
||||
parseBoolean(args[6])
|
||||
);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
public interface TransformationConfiguration {
|
||||
|
@ -1,9 +1,5 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
@ -12,9 +8,6 @@ public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
public String from;
|
||||
public String type;
|
||||
public String upgrader;
|
||||
public String upgraderInstance;
|
||||
@Nullable
|
||||
public List<String> contextParameters;
|
||||
|
||||
@Override
|
||||
public String getTransformClass() {
|
||||
@ -26,15 +19,6 @@ public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
return "upgrade-data";
|
||||
}
|
||||
|
||||
public JInterfaceLocation getUpgraderLocation() {
|
||||
return JInterfaceLocation.parse(upgrader, upgraderInstance);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getContextParameters() {
|
||||
return Objects.requireNonNullElse(contextParameters, List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
@ -45,9 +29,7 @@ public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
}
|
||||
UpgradeDataConfiguration that = (UpgradeDataConfiguration) o;
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from)
|
||||
&& Objects.equals(type, that.type) && Objects.equals(upgrader, that.upgrader)
|
||||
&& Objects.equals(upgraderInstance, that.upgraderInstance)
|
||||
&& Objects.equals(contextParameters, that.contextParameters);
|
||||
&& Objects.equals(type, that.type) && Objects.equals(upgrader, that.upgrader);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,8 +39,6 @@ public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
hash += ConfigUtils.hashCode(from);
|
||||
hash += ConfigUtils.hashCode(type);
|
||||
hash += ConfigUtils.hashCode(upgrader);
|
||||
hash += ConfigUtils.hashCode(upgraderInstance);
|
||||
hash += ConfigUtils.hashCode(contextParameters);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@ -68,8 +48,6 @@ public class UpgradeDataConfiguration implements TransformationConfiguration {
|
||||
if (this.from != null) c.from = this.from;
|
||||
if (this.type != null) c.type = this.type;
|
||||
if (this.upgrader != null) c.upgrader = this.upgrader;
|
||||
if (this.upgraderInstance != null) c.upgraderInstance = this.upgraderInstance;
|
||||
if (this.contextParameters != null) c.contextParameters = this.contextParameters;
|
||||
return c;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
package it.cavallium.data.generator.plugin;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
@ -11,10 +11,11 @@ import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import com.squareup.javapoet.TypeVariableName;
|
||||
import com.squareup.javapoet.WildcardTypeName;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedType;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Stream;
|
||||
@ -118,8 +119,8 @@ public class GenCurrentVersion extends ClassGenerator {
|
||||
.addModifiers(Modifier.PUBLIC).addModifiers(Modifier.STATIC).addModifiers(Modifier.FINAL).returns(TypeVariableName.get("U"))
|
||||
.addParameter(ParameterSpec.builder(TypeName.INT, "oldVersion").build()).addParameter(
|
||||
ParameterSpec.builder(ClassName.get(dataModel.getRootPackage(basePackageName), "BaseType"), "type").build())
|
||||
.addParameter(ParameterSpec.builder(SafeDataInput.class, "oldDataInput").build())
|
||||
.beginControlFlow("return upgradeDataToLatestVersion(oldVersion, switch (oldVersion)");
|
||||
.addParameter(ParameterSpec.builder(DataInput.class, "oldDataInput").build())
|
||||
.addException(IOException.class).beginControlFlow("return upgradeDataToLatestVersion(oldVersion, switch (oldVersion)");
|
||||
for (var versionConfiguration : dataModel.getVersionsSet()) {
|
||||
// Add a case in which the data version deserializes the serialized data and upgrades it
|
||||
var versions = ClassName.get(dataModel.getRootPackage(basePackageName), "Versions");
|
||||
@ -130,7 +131,7 @@ public class GenCurrentVersion extends ClassGenerator {
|
||||
);
|
||||
}
|
||||
var upgradeDataToLatestVersion1Method = upgradeDataToLatestVersion1MethodBuilder
|
||||
.addStatement("default -> throw new $T(\"Unknown version: \" + oldVersion)", UnsupportedOperationException.class)
|
||||
.addStatement("default -> throw new $T(\"Unknown version: \" + oldVersion)", IOException.class)
|
||||
.addCode(CodeBlock.of("$<});"))
|
||||
.build();
|
||||
currentVersionClass.addMethod(upgradeDataToLatestVersion1Method);
|
||||
@ -144,6 +145,7 @@ public class GenCurrentVersion extends ClassGenerator {
|
||||
.returns(TypeVariableName.get("U"))
|
||||
.addParameter(ParameterSpec.builder(TypeName.INT, "oldVersion").build())
|
||||
.addParameter(ParameterSpec.builder(TypeVariableName.get("T"), "oldData").build())
|
||||
.addException(IOException.class)
|
||||
.addStatement("$T data = oldData", Object.class);
|
||||
upgradeDataToLatestVersion2MethodBuilder.beginControlFlow("switch (oldVersion)");
|
||||
for (var versionConfiguration : dataModel.getVersionsSet()) {
|
||||
@ -166,7 +168,7 @@ public class GenCurrentVersion extends ClassGenerator {
|
||||
);
|
||||
}
|
||||
}
|
||||
upgradeDataToLatestVersion2MethodBuilder.addStatement("default: throw new $T(\"Unknown version: \" + oldVersion)", UnsupportedOperationException.class);
|
||||
upgradeDataToLatestVersion2MethodBuilder.addStatement("default: throw new $T(\"Unknown version: \" + oldVersion)", IOException.class);
|
||||
upgradeDataToLatestVersion2MethodBuilder.endControlFlow();
|
||||
currentVersionClass.addMethod(upgradeDataToLatestVersion2MethodBuilder.build());
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.soabase.recordbuilder.core.RecordBuilder;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeBase;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeBase;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
@ -68,7 +68,7 @@ public class GenDataBaseX extends ClassGenerator {
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
|
||||
base.getData().forEach((fieldName, fieldType) -> {
|
||||
var fieldTypeName = fieldType.getJTypeNameGeneric(basePackageName);
|
||||
var fieldTypeName = fieldType.getJTypeName(basePackageName);
|
||||
|
||||
var param = ParameterSpec
|
||||
.builder(fieldTypeName, fieldName)
|
@ -1,13 +1,12 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -37,17 +36,6 @@ public class GenDataSuperX extends ClassGenerator {
|
||||
|
||||
classBuilder.addModifiers(Modifier.PUBLIC);
|
||||
|
||||
if (version.isCurrent()) {
|
||||
classBuilder.addModifiers(Modifier.SEALED);
|
||||
Stream<TypeName> superTypesThatExtendThisSuperType = dataModel.getSuperTypesComputed(version)
|
||||
.filter(computedTypeSuper -> dataModel.getExtendsInterfaces(computedTypeSuper).anyMatch(typeSuper::equals))
|
||||
.map(computedTypeSuper -> computedTypeSuper.getJTypeName(basePackageName));
|
||||
Stream<TypeName> subTypes = typeSuper.subTypes().stream()
|
||||
.map(subType -> subType.getJTypeName(basePackageName));
|
||||
Stream<TypeName> permittedSubclasses = Stream.concat(superTypesThatExtendThisSuperType, subTypes).distinct();
|
||||
classBuilder.addPermittedSubclasses(permittedSubclasses.toList());
|
||||
}
|
||||
|
||||
dataModel.getTypeSameVersions(typeSuper).forEach(v -> {
|
||||
var iTypeClass = ClassName.get(v.getPackage(basePackageName), "IBaseType");
|
||||
classBuilder.addSuperinterface(iTypeClass);
|
||||
@ -61,7 +49,7 @@ public class GenDataSuperX extends ClassGenerator {
|
||||
Stream
|
||||
.concat(dataModel.getCommonInterfaceData(typeSuper), dataModel.getCommonInterfaceGetters(typeSuper))
|
||||
.forEach(superType -> {
|
||||
var returnType = superType.getValue().getJTypeNameGeneric(basePackageName);
|
||||
var returnType = superType.getValue().getJTypeName(basePackageName);
|
||||
var getter = MethodSpec
|
||||
.methodBuilder(superType.getKey())
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
|
||||
@ -73,7 +61,7 @@ public class GenDataSuperX extends ClassGenerator {
|
||||
});
|
||||
|
||||
dataModel.getCommonInterfaceData(typeSuper).forEach(superType -> {
|
||||
var returnType = superType.getValue().getJTypeNameGeneric(basePackageName);
|
||||
var returnType = superType.getValue().getJTypeName(basePackageName);
|
||||
|
||||
var setter = MethodSpec
|
||||
.methodBuilder("set" + StringUtils.capitalize(superType.getKey()))
|
@ -1,10 +1,10 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.nativedata.INullable;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.nativedata.INullable;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.io.Serializable;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
@ -7,8 +7,9 @@ import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeVariableName;
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
@ -34,6 +35,7 @@ public class GenIVersion extends ClassGenerator {
|
||||
TypeVariableName.get("B")
|
||||
))
|
||||
.returns(ParameterizedTypeName.get(ClassName.get(DataSerializer.class), TypeVariableName.get("T")))
|
||||
.addException(IOException.class)
|
||||
.addParameter(ParameterSpec
|
||||
.builder(ClassName.get(dataModel.getRootPackage(basePackageName), "BaseType"), "type")
|
||||
.build());
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.FieldSpec;
|
||||
@ -6,16 +6,16 @@ import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.TypedNullable;
|
||||
import it.cavallium.datagen.nativedata.INullable;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeBase;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeCustom;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeNullable;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeNullableFixed;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeNullableVersioned;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.TypedNullable;
|
||||
import it.cavallium.data.generator.nativedata.INullable;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeBase;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeCustom;
|
||||
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.ComputedTypeSuper;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
@ -88,9 +88,8 @@ public class GenNullableX extends ClassGenerator {
|
||||
classBuilder.addField(FieldSpec
|
||||
.builder(type, "NULL").addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL).initializer("new $T(null)", type).build());
|
||||
|
||||
classBuilder.addSuperinterfaces(List.of(iNullableITypeClass, iNullableClass, typedNullable));
|
||||
|
||||
if (version.isCurrent()) {
|
||||
classBuilder.addSuperinterfaces(List.of(iNullableITypeClass, iNullableClass, typedNullable));
|
||||
|
||||
classBuilder.addMethod(MethodSpec
|
||||
.methodBuilder("of")
|
@ -1,24 +1,23 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ArrayTypeName;
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import com.squareup.javapoet.WildcardTypeName;
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.datagen.NotSerializableException;
|
||||
import it.cavallium.datagen.nativedata.ImmutableWrappedArrayList;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeArray;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeArrayFixed;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeArrayVersioned;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.cavallium.data.generator.nativedata.ImmutableWrappedArrayList;
|
||||
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.ComputedVersion;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.NotSerializableException;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
@ -26,11 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GenSerializerArrayX extends ClassGenerator {
|
||||
|
||||
/**
|
||||
* Enabling this option can slow down deserialization updates
|
||||
*/
|
||||
private static final boolean USE_NATIVE_TYPED_ARRAYS = false;
|
||||
|
||||
public GenSerializerArrayX(ClassGeneratorParams params) {
|
||||
super(params);
|
||||
}
|
||||
@ -69,8 +63,9 @@ public class GenSerializerArrayX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("serialize");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec.builder(DataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec
|
||||
.builder(typeArray.getJTypeName(basePackageName), "data")
|
||||
.addAnnotation(NotNull.class)
|
||||
@ -82,9 +77,9 @@ public class GenSerializerArrayX extends ClassGenerator {
|
||||
method.addStatement("final int sz = data.size()");
|
||||
method.addStatement("out.writeInt(sz)");
|
||||
method.addCode("\n");
|
||||
method.beginControlFlow("for (var item : data)");
|
||||
method.beginControlFlow("for (int i = 0; i < sz; ++i)");
|
||||
var baseSerializerInstance = typeArray.getBase().getJSerializerInstance(basePackageName);
|
||||
method.addStatement("$T.$N.serialize(out, ($T) item)",
|
||||
method.addStatement("$T.$N.serialize(out, ($T) data.get(i))",
|
||||
baseSerializerInstance.className(),
|
||||
baseSerializerInstance.fieldName(),
|
||||
typeArray.getBase().getJTypeName(basePackageName)
|
||||
@ -101,40 +96,26 @@ public class GenSerializerArrayX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("deserialize");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
var typeArrayClassName = typeArray.getJTypeName(basePackageName);
|
||||
|
||||
var arrayComponentTypeName = typeArray.getBase().getJTypeName(basePackageName);
|
||||
var typedArrayTypeName = ArrayTypeName.of(arrayComponentTypeName);
|
||||
|
||||
method.returns(typeArrayClassName);
|
||||
method.addAnnotation(NotNull.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataInput.class, "in").build());
|
||||
method.addParameter(ParameterSpec.builder(DataInput.class, "in").build());
|
||||
|
||||
method.addStatement("int sz = in.readInt()");
|
||||
if (USE_NATIVE_TYPED_ARRAYS) {
|
||||
method.addStatement("$T a = new $T[sz]", typedArrayTypeName, arrayComponentTypeName);
|
||||
} else {
|
||||
method.addStatement("$T a = new $T[sz]", Object[].class, Object.class);
|
||||
}
|
||||
var arrayTypeName = ArrayTypeName.of(typeArray.getBase().getJTypeName(basePackageName));
|
||||
method.addStatement("$T a = new $T[sz]", arrayTypeName, arrayTypeName.componentType);
|
||||
method.addCode("\n");
|
||||
method.beginControlFlow("for (int i = 0; i < sz; ++i)");
|
||||
var baseSerializerInstance = typeArray.getBase().getJSerializerInstance(basePackageName);
|
||||
|
||||
method.addStatement("a[i] = $T.$N.deserialize(in)", baseSerializerInstance.className(), baseSerializerInstance.fieldName());
|
||||
method.endControlFlow();
|
||||
|
||||
method.addCode("\n");
|
||||
if (USE_NATIVE_TYPED_ARRAYS) {
|
||||
method.addStatement("return $T.of(a)", ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class), arrayComponentTypeName));
|
||||
} else {
|
||||
method.addStatement("return ($T) ($T) $T.of(a)",
|
||||
ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class), arrayComponentTypeName),
|
||||
ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class), WildcardTypeName.subtypeOf(TypeName.OBJECT)),
|
||||
ClassName.get(ImmutableWrappedArrayList.class)
|
||||
);
|
||||
}
|
||||
method.addStatement("return new $T(a)", ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class),
|
||||
typeArray.getBase().getJTypeName(basePackageName)));
|
||||
|
||||
classBuilder.addMethod(method.build());
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
@ -7,13 +7,14 @@ import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.datagen.NotSerializableException;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeBase;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeBase;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.NotSerializableException;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
@ -59,8 +60,9 @@ public class GenSerializerBaseX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("serialize");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec.builder(DataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec
|
||||
.builder(typeBase.getJTypeName(basePackageName), "data")
|
||||
.addAnnotation(NotNull.class)
|
||||
@ -93,12 +95,13 @@ public class GenSerializerBaseX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("deserialize");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
ClassName typeBaseClassName = typeBase.getJTypeName(basePackageName);
|
||||
method.returns(typeBaseClassName);
|
||||
method.addAnnotation(NotNull.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataInput.class, "in").build());
|
||||
method.addParameter(ParameterSpec.builder(DataInput.class, "in").build());
|
||||
|
||||
method.addCode("return new $T(\n$>", typeBaseClassName);
|
||||
typeBase.getData().entrySet().stream().flatMap(entry -> {
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
@ -6,15 +6,16 @@ import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.datagen.NotSerializableException;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeNullable;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeNullableFixed;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeNullableVersioned;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
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.ComputedVersion;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.NotSerializableException;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
@ -42,7 +43,7 @@ public class GenSerializerNullableX extends ClassGenerator {
|
||||
|
||||
private GeneratedClass generateTypeVersioned(ComputedVersion version, ComputedTypeNullable typeNullable) {
|
||||
ClassName serializerClassName = typeNullable.getJSerializerName(basePackageName);
|
||||
var typeNullableClassName = typeNullable.getJTypeNameGeneric(basePackageName);
|
||||
var typeNullableClassName = typeNullable.getJTypeName(basePackageName);
|
||||
|
||||
var classBuilder = TypeSpec.classBuilder(serializerClassName.simpleName());
|
||||
|
||||
@ -65,10 +66,11 @@ public class GenSerializerNullableX extends ClassGenerator {
|
||||
var baseSerializerInstance = base.getJSerializerInstance(basePackageName);
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec.builder(DataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec
|
||||
.builder(typeNullable.getJTypeNameGeneric(basePackageName), "data")
|
||||
.builder(typeNullable.getJTypeName(basePackageName), "data")
|
||||
.addAnnotation(NotNull.class)
|
||||
.build());
|
||||
|
||||
@ -99,12 +101,13 @@ public class GenSerializerNullableX extends ClassGenerator {
|
||||
var baseSerializerInstance = base.getJSerializerInstance(basePackageName);
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
var typeNullableClassName = typeNullable.getJTypeName(basePackageName);
|
||||
method.returns(typeNullableClassName);
|
||||
method.addAnnotation(NotNull.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataInput.class, "in").build());
|
||||
method.addParameter(ParameterSpec.builder(DataInput.class, "in").build());
|
||||
|
||||
method.addStatement("return in.readBoolean() ? new $T(($T) $T.$N.deserialize(in)) : $T.empty()",
|
||||
typeNullableClassName,
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.MethodSpec;
|
||||
@ -6,14 +6,15 @@ import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.datagen.NotSerializableException;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedType;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.NotSerializableException;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
@ -60,10 +61,11 @@ public class GenSerializerSuperX extends ClassGenerator {
|
||||
int max = typeSuper.subTypes().size();
|
||||
var method = MethodSpec.methodBuilder("checkIdValidity");
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
method.addParameter(ParameterSpec.builder(int.class, "id").build());
|
||||
|
||||
method.beginControlFlow("if (id < 0 || id >= $L)", max);
|
||||
method.addStatement("throw new $T(id)", IndexOutOfBoundsException.class);
|
||||
method.addStatement("throw new $T(new $T(id))", IOException.class, IndexOutOfBoundsException.class);
|
||||
method.endControlFlow();
|
||||
|
||||
classBuilder.addMethod(method.build());
|
||||
@ -73,8 +75,9 @@ public class GenSerializerSuperX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("serialize");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec.builder(DataOutput.class, "out").build());
|
||||
method.addParameter(ParameterSpec
|
||||
.builder(typeSuper.getJTypeName(basePackageName), "data")
|
||||
.addAnnotation(NotNull.class)
|
||||
@ -115,12 +118,13 @@ public class GenSerializerSuperX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("deserialize");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
ClassName typeSuperClassName = typeSuper.getJTypeName(basePackageName);
|
||||
method.returns(typeSuperClassName);
|
||||
method.addAnnotation(NotNull.class);
|
||||
|
||||
method.addParameter(ParameterSpec.builder(SafeDataInput.class, "in").build());
|
||||
method.addParameter(ParameterSpec.builder(DataInput.class, "in").build());
|
||||
|
||||
method.addStatement("int id = in.readUnsignedByte()");
|
||||
method.beginControlFlow("return switch (id)");
|
@ -1,7 +1,7 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
@ -1,4 +1,6 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import static it.cavallium.data.generator.plugin.DataModel.fixType;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
@ -9,12 +11,19 @@ import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import it.cavallium.datagen.*;
|
||||
import it.cavallium.datagen.plugin.*;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.datagen.plugin.JInterfaceLocation.JInterfaceLocationClassName;
|
||||
import it.cavallium.datagen.plugin.JInterfaceLocation.JInterfaceLocationInstanceField;
|
||||
|
||||
import it.cavallium.data.generator.DataInitializer;
|
||||
import it.cavallium.data.generator.DataUpgrader;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeBase;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.MoveDataConfiguration;
|
||||
import it.cavallium.data.generator.plugin.NewDataConfiguration;
|
||||
import it.cavallium.data.generator.plugin.RemoveDataConfiguration;
|
||||
import it.cavallium.data.generator.plugin.TransformationConfiguration;
|
||||
import it.cavallium.data.generator.plugin.UpgradeDataConfiguration;
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -26,7 +35,6 @@ import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GenUpgraderBaseX extends ClassGenerator {
|
||||
|
||||
@ -55,7 +63,7 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
|
||||
classBuilder.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
|
||||
classBuilder.superclass(ParameterizedTypeName.get(ClassName.get(DataUpgraderSimple.class),
|
||||
classBuilder.addSuperinterface(ParameterizedTypeName.get(ClassName.get(DataUpgrader.class),
|
||||
typeBaseClassName,
|
||||
nextTypeBase.getJTypeName(basePackageName)
|
||||
));
|
||||
@ -71,6 +79,7 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("upgrade");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
ClassName typeBaseClassName = typeBase.getJTypeName(basePackageName);
|
||||
ClassName nextTypeBaseClassName = nextTypeBase.getJTypeName(basePackageName);
|
||||
@ -83,7 +92,6 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
|
||||
AtomicInteger nextInitializerStaticFieldId = new AtomicInteger();
|
||||
HashMap<String, String> initializerStaticFieldNames = new HashMap<>();
|
||||
HashMap<String, ContextInfo> contextStaticFieldCodeBlocks = new HashMap<>();
|
||||
AtomicInteger nextUpgraderStaticFieldId = new AtomicInteger();
|
||||
HashMap<String, String> upgraderStaticFieldNames = new HashMap<>();
|
||||
List<TransformationConfiguration> transformations = dataModel.getChanges(nextTypeBase);
|
||||
@ -110,29 +118,20 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
var i = e.getKey();
|
||||
var newDataConfiguration = e.getValue();
|
||||
var computedTypes = dataModel.getComputedTypes(nextTypeBase.getVersion());
|
||||
var newFieldType = Objects.requireNonNull(computedTypes.get(DataModel.fixType(newDataConfiguration.type)));
|
||||
var initializerLocation = newDataConfiguration.getInitializerLocation();
|
||||
|
||||
var contextInfo = createContextStaticClass(typeBase, e.getValue().to,
|
||||
contextStaticFieldCodeBlocks,
|
||||
classBuilder,
|
||||
initializerLocation,
|
||||
newDataConfiguration.getContextParameters()
|
||||
);
|
||||
|
||||
var newFieldType = Objects.requireNonNull(computedTypes.get(fixType(newDataConfiguration.type)));
|
||||
var initializerClass = ClassName.bestGuess(newDataConfiguration.initializer);
|
||||
var genericInitializerClass = ParameterizedTypeName.get(ClassName.get(DataInitializer.class),
|
||||
contextInfo.typeName(),
|
||||
newFieldType.getJTypeName(basePackageName).box()
|
||||
);
|
||||
|
||||
var initializerName = createInitializerStaticField(nextInitializerStaticFieldId,
|
||||
initializerStaticFieldNames,
|
||||
classBuilder,
|
||||
initializerLocation,
|
||||
initializerClass,
|
||||
genericInitializerClass
|
||||
);
|
||||
|
||||
return new Field(newDataConfiguration.to, newFieldType, CodeBlock.of("$N.initialize($L)", initializerName, contextInfo.contextApply), i + 1);
|
||||
return new Field(newDataConfiguration.to, newFieldType, CodeBlock.of("$N.initialize()", initializerName), i + 1);
|
||||
})
|
||||
);
|
||||
resultFields = fields.<ResultField>mapMulti((field, consumer) -> {
|
||||
@ -149,7 +148,7 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
fieldName = moveDataConfiguration.to;
|
||||
} else if (transformation instanceof NewDataConfiguration newDataConfiguration) {
|
||||
if (newDataConfiguration.to.equals(fieldName)) {
|
||||
var type = dataModel.getComputedTypes(version).get(DataModel.fixType(newDataConfiguration.type));
|
||||
var type = dataModel.getComputedTypes(version).get(fixType(newDataConfiguration.type));
|
||||
throw new IllegalStateException(
|
||||
"New field " + typeBase.getName() + "." + fieldName + " of type \"" + type + "\" at version \"" + nextTypeBase.getVersion()
|
||||
+ "\" conflicts with another field of type \"" + fieldType + "\" with the same name at version \""
|
||||
@ -167,20 +166,11 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
if (!upgradeDataConfiguration.from.equals(fieldName)) {
|
||||
continue;
|
||||
}
|
||||
var upgraderImplementationLocation = upgradeDataConfiguration.getUpgraderLocation();
|
||||
var upgraderClass = ClassName.bestGuess(upgradeDataConfiguration.upgrader);
|
||||
var cb = CodeBlock.builder();
|
||||
var newFieldType = Objects
|
||||
.requireNonNull(dataModel.getComputedTypes(nextTypeBase.getVersion()).get(DataModel.fixType(upgradeDataConfiguration.type)));
|
||||
|
||||
var contextInfo = createContextStaticClass(typeBase, upgradeDataConfiguration.from,
|
||||
contextStaticFieldCodeBlocks,
|
||||
classBuilder,
|
||||
upgraderImplementationLocation,
|
||||
upgradeDataConfiguration.getContextParameters()
|
||||
);
|
||||
|
||||
.requireNonNull(dataModel.getComputedTypes(nextTypeBase.getVersion()).get(fixType(upgradeDataConfiguration.type)));
|
||||
var genericUpgraderClass = ParameterizedTypeName.get(ClassName.get(DataUpgrader.class),
|
||||
contextInfo.typeName(),
|
||||
fieldType.getJTypeName(basePackageName).box(),
|
||||
newFieldType.getJTypeName(basePackageName).box()
|
||||
);
|
||||
@ -188,14 +178,13 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
var upgraderName = createUpgraderStaticField(nextUpgraderStaticFieldId,
|
||||
upgraderStaticFieldNames,
|
||||
classBuilder,
|
||||
upgraderImplementationLocation,
|
||||
upgraderClass,
|
||||
genericUpgraderClass
|
||||
);
|
||||
|
||||
cb.add("($T) $N.upgrade($L, ($T) ",
|
||||
cb.add("($T) $N.upgrade(($T) ",
|
||||
newFieldType.getJTypeName(basePackageName),
|
||||
upgraderName,
|
||||
contextInfo.contextApply,
|
||||
fieldType.getJTypeName(basePackageName)
|
||||
);
|
||||
cb.add(codeBlock);
|
||||
@ -236,98 +225,37 @@ public class GenUpgraderBaseX extends ClassGenerator {
|
||||
private String createInitializerStaticField(AtomicInteger nextInitializerStaticFieldId,
|
||||
HashMap<String, String> initializerStaticFieldNames,
|
||||
Builder classBuilder,
|
||||
JInterfaceLocation initializerLocation,
|
||||
ClassName initializerClass,
|
||||
TypeName genericInitializerClass) {
|
||||
var identifier = initializerLocation.getIdentifier();
|
||||
var initializerName = initializerStaticFieldNames.get(identifier);
|
||||
var ref = initializerClass.reflectionName();
|
||||
var initializerName = initializerStaticFieldNames.get(ref);
|
||||
if (initializerName == null) {
|
||||
initializerName = "I" + nextInitializerStaticFieldId.getAndIncrement();
|
||||
var fieldBuilder = FieldSpec
|
||||
classBuilder.addField(FieldSpec
|
||||
.builder(genericInitializerClass, initializerName)
|
||||
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL);
|
||||
switch (initializerLocation) {
|
||||
case JInterfaceLocationClassName className -> fieldBuilder.initializer("new $T()", className.className());
|
||||
case JInterfaceLocationInstanceField instanceField -> fieldBuilder.initializer("$T.$N",
|
||||
instanceField.fieldLocation().className(),
|
||||
instanceField.fieldLocation().fieldName()
|
||||
);
|
||||
}
|
||||
classBuilder.addField(fieldBuilder.build());
|
||||
initializerStaticFieldNames.put(identifier, initializerName);
|
||||
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
|
||||
.initializer("new $T()", initializerClass)
|
||||
.build());
|
||||
initializerStaticFieldNames.put(ref, initializerName);
|
||||
}
|
||||
return initializerName;
|
||||
}
|
||||
|
||||
record ContextInfo(TypeName typeName, CodeBlock contextApply) {}
|
||||
|
||||
private ContextInfo createContextStaticClass(ComputedTypeBase typeBase,
|
||||
String fieldName,
|
||||
HashMap<String, ContextInfo> contextStaticFieldCodeBlocks,
|
||||
Builder classBuilder,
|
||||
JInterfaceLocation initializerLocation,
|
||||
@NotNull List<String> contextParameters) {
|
||||
var identifier = initializerLocation.getIdentifier();
|
||||
var contextStaticFieldCodeBlock = contextStaticFieldCodeBlocks.get(identifier);
|
||||
if (contextStaticFieldCodeBlock == null) {
|
||||
var codeBlockBuilder = CodeBlock.builder();
|
||||
TypeName typeName;
|
||||
|
||||
if (contextParameters.isEmpty()) {
|
||||
typeName = ClassName.get(DataContextNone.class);
|
||||
codeBlockBuilder.add("$T.INSTANCE", typeName);
|
||||
} else {
|
||||
var name = "Context" + SourcesGenerator.capitalize(fieldName);
|
||||
var contextTypeClassBuilder = TypeSpec.recordBuilder(name)
|
||||
.addSuperinterface(ClassName.get(DataContext.class))
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
typeName = typeBase.getJUpgraderName(basePackageName).nestedClass(name);
|
||||
|
||||
codeBlockBuilder.add("new $T(", typeName);
|
||||
boolean first = true;
|
||||
for (String contextParameter : contextParameters) {
|
||||
var fieldType = typeBase.getData().get(contextParameter);
|
||||
contextTypeClassBuilder.addRecordComponent(ParameterSpec.builder(fieldType.getJTypeNameGeneric(basePackageName), contextParameter).build());
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
codeBlockBuilder.add(", ");
|
||||
}
|
||||
codeBlockBuilder.add("data.$N()", contextParameter);
|
||||
}
|
||||
codeBlockBuilder.add(")");
|
||||
|
||||
var clazz = contextTypeClassBuilder.build();
|
||||
classBuilder.addType(clazz);
|
||||
}
|
||||
|
||||
contextStaticFieldCodeBlock = new ContextInfo(typeName, codeBlockBuilder.build());
|
||||
contextStaticFieldCodeBlocks.put(identifier, contextStaticFieldCodeBlock);
|
||||
}
|
||||
return contextStaticFieldCodeBlock;
|
||||
}
|
||||
|
||||
private String createUpgraderStaticField(AtomicInteger nextUpgraderStaticFieldId,
|
||||
HashMap<String, String> upgraderStaticFieldNames,
|
||||
Builder classBuilder,
|
||||
JInterfaceLocation upgraderLocation,
|
||||
ClassName upgraderClass,
|
||||
TypeName genericUpgraderClass) {
|
||||
var identifier = upgraderLocation.getIdentifier();
|
||||
var upgraderName = upgraderStaticFieldNames.get(identifier);
|
||||
var ref = upgraderClass.reflectionName();
|
||||
var upgraderName = upgraderStaticFieldNames.get(ref);
|
||||
if (upgraderName == null) {
|
||||
upgraderName = "U" + nextUpgraderStaticFieldId.getAndIncrement();
|
||||
var fieldBuilder = FieldSpec
|
||||
classBuilder.addField(FieldSpec
|
||||
.builder(genericUpgraderClass, upgraderName)
|
||||
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL);
|
||||
switch (upgraderLocation) {
|
||||
case JInterfaceLocationClassName className -> fieldBuilder.initializer("new $T()", className.className());
|
||||
case JInterfaceLocationInstanceField instanceField -> fieldBuilder.initializer("$T.$N",
|
||||
instanceField.fieldLocation().className(),
|
||||
instanceField.fieldLocation().fieldName()
|
||||
);
|
||||
}
|
||||
classBuilder.addField(fieldBuilder.build());
|
||||
upgraderStaticFieldNames.put(identifier, upgraderName);
|
||||
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
|
||||
.initializer("new $T()", upgraderClass)
|
||||
.build());
|
||||
upgraderStaticFieldNames.put(ref, upgraderName);
|
||||
}
|
||||
return upgraderName;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
@ -7,13 +7,13 @@ import com.squareup.javapoet.ParameterSpec;
|
||||
import com.squareup.javapoet.ParameterizedTypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import it.cavallium.datagen.DataUpgrader;
|
||||
import it.cavallium.datagen.DataUpgraderSimple;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedType;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.DataUpgrader;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -45,7 +45,7 @@ public class GenUpgraderSuperX extends ClassGenerator {
|
||||
|
||||
classBuilder.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
|
||||
classBuilder.superclass(ParameterizedTypeName.get(ClassName.get(DataUpgraderSimple.class),
|
||||
classBuilder.addSuperinterface(ParameterizedTypeName.get(ClassName.get(DataUpgrader.class),
|
||||
typeBaseClassName,
|
||||
nextTypeSuper.getJTypeName(basePackageName)
|
||||
));
|
||||
@ -61,6 +61,7 @@ public class GenUpgraderSuperX extends ClassGenerator {
|
||||
var method = MethodSpec.methodBuilder("upgrade");
|
||||
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
method.addException(IOException.class);
|
||||
|
||||
ClassName typeSuperClassName = typeSuper.getJTypeName(basePackageName);
|
||||
ClassName nextTypeSuperClassName = nextTypeSuper.getJTypeName(basePackageName);
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ClassName;
|
||||
import com.squareup.javapoet.CodeBlock;
|
||||
@ -9,17 +9,17 @@ import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import com.squareup.javapoet.TypeSpec.Builder;
|
||||
import com.squareup.javapoet.TypeVariableName;
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.datagen.DataUpgrader;
|
||||
import it.cavallium.datagen.DataUpgraderSimple;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeArrayFixed;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeBase;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeCustom;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeNullableFixed;
|
||||
import it.cavallium.datagen.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.cavallium.data.generator.DataUpgrader;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedType.VersionedComputedType;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeArrayFixed;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeBase;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeCustom;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeNullableFixed;
|
||||
import it.cavallium.data.generator.plugin.ComputedTypeSuper;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
||||
@ -105,6 +105,7 @@ public class GenVersion extends ClassGenerator {
|
||||
var methodBuilder = MethodSpec.methodBuilder("upgradeToNextVersion");
|
||||
|
||||
methodBuilder.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
|
||||
methodBuilder.addException(ClassName.get(IOException.class));
|
||||
|
||||
var nextIBaseType = ClassName.get(nextVersion.getPackage(basePackageName), "IBaseType");
|
||||
methodBuilder.returns(nextIBaseType);
|
||||
@ -165,7 +166,7 @@ public class GenVersion extends ClassGenerator {
|
||||
var serializerClassName = type.getJSerializerName(basePackageName);
|
||||
|
||||
var fieldBuilder = FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(DataSerializer.class),
|
||||
type.getJTypeNameGeneric(basePackageName)
|
||||
type.getJTypeName(basePackageName)
|
||||
), serializerFieldLocation.fieldName(), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
|
||||
fieldBuilder.initializer("new $T()", serializerClassName);
|
||||
classBuilder.addField(fieldBuilder.build());
|
||||
@ -189,7 +190,7 @@ public class GenVersion extends ClassGenerator {
|
||||
return;
|
||||
}
|
||||
|
||||
var genericClassName = ParameterizedTypeName.get(ClassName.get(DataUpgraderSimple.class),
|
||||
var genericClassName = ParameterizedTypeName.get(ClassName.get(DataUpgrader.class),
|
||||
type.getJTypeName(basePackageName), nextVersion.getJTypeName(basePackageName)
|
||||
);
|
||||
var upgraderClassName = type.getJUpgraderName(basePackageName);
|
||||
@ -210,6 +211,7 @@ public class GenVersion extends ClassGenerator {
|
||||
|
||||
methodBuilder.addModifiers(Modifier.PUBLIC);
|
||||
methodBuilder.addAnnotation(Override.class);
|
||||
methodBuilder.addException(ClassName.get(IOException.class));
|
||||
|
||||
var iBaseTypeClassName = ClassName.get(version.getPackage(basePackageName), "IBaseType");
|
||||
methodBuilder.addTypeVariable(TypeVariableName.get("T", iBaseTypeClassName));
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.plugin.classgen;
|
||||
package it.cavallium.data.generator.plugin.classgen;
|
||||
|
||||
import com.squareup.javapoet.ArrayTypeName;
|
||||
import com.squareup.javapoet.ClassName;
|
||||
@ -6,9 +6,11 @@ import com.squareup.javapoet.CodeBlock;
|
||||
import com.squareup.javapoet.FieldSpec;
|
||||
import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import it.cavallium.datagen.plugin.ClassGenerator;
|
||||
import it.cavallium.datagen.plugin.ComputedVersion;
|
||||
import it.cavallium.data.generator.plugin.ClassGenerator;
|
||||
import it.cavallium.data.generator.plugin.ComputedVersion;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import javax.lang.model.element.Modifier;
|
@ -5,13 +5,13 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<name>Data generator runtime</name>
|
||||
<artifactId>datagen</artifactId>
|
||||
<artifactId>data-generator-runtime</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>jar</packaging>
|
||||
<parent>
|
||||
<groupId>it.cavallium</groupId>
|
||||
<version>${revision}</version>
|
||||
<artifactId>datagen-parent</artifactId>
|
||||
<artifactId>data-generator</artifactId>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
@ -67,7 +67,7 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
<release>17</release>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
@ -101,37 +101,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadoc</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<doclint>all,-missing</doclint>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
@ -159,7 +128,7 @@
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore/>
|
||||
<ignore></ignore>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
@ -190,17 +159,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>33.0.0-jre</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@ -217,7 +175,7 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.9.2</version>
|
||||
<version>5.9.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
@ -225,95 +183,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>5.9.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>java9</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/java9/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>benchmark</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>1.36</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>1.36</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/benchmark/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<release>21</release>
|
||||
<encoding>UTF-8</encoding>
|
||||
<excludes>
|
||||
<exclude>src/main/java/module-info.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen;
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
public class CommonField {
|
||||
public final String fieldName;
|
@ -0,0 +1,9 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface DataInitializer<T> {
|
||||
|
||||
@NotNull T initialize() throws IOException;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface DataSerializer<T> {
|
||||
|
||||
void serialize(DataOutput dataOutput, @NotNull T data) throws IOException;
|
||||
|
||||
@NotNull T deserialize(DataInput dataInput) throws IOException;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface DataUpgrader<T, U> {
|
||||
|
||||
@NotNull U upgrade(@NotNull T data) throws IOException;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface NativeNullable<T> {
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
default boolean isPresent() {
|
||||
return !isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
T orElse(@NotNull T defaultValue);
|
||||
|
||||
@NotNull NativeNullable<? extends T> or(@NotNull NativeNullable<? extends T> fallback);
|
||||
|
||||
@Nullable
|
||||
T getNullable();
|
||||
|
||||
@Nullable
|
||||
T getNullable(@Nullable T defaultValue);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen;
|
||||
package it.cavallium.data.generator;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@ -9,26 +9,56 @@ import java.util.stream.Stream;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface NativeNullable<T> {
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
default boolean isPresent() {
|
||||
return !isEmpty();
|
||||
}
|
||||
public interface TypedNullable<T> extends NativeNullable<T> {
|
||||
|
||||
@NotNull
|
||||
T orElse(@NotNull T defaultValue);
|
||||
default T get() throws NullPointerException {
|
||||
var value = getNullable();
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull NativeNullable<? extends T> or(@NotNull NativeNullable<? extends T> fallback);
|
||||
@Override
|
||||
default @Nullable T getNullable(@Nullable T defaultValue) {
|
||||
var value = getNullable();
|
||||
return value == null ? defaultValue : value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
T getNullable();
|
||||
@Override
|
||||
default @NotNull T orElse(@NotNull T defaultValue) {
|
||||
var value = getNullable();
|
||||
if (value == null) {
|
||||
Objects.requireNonNull(defaultValue, "default value must not be null");
|
||||
return defaultValue;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
T getNullable(@Nullable T defaultValue);
|
||||
@Override
|
||||
default @NotNull NativeNullable<? extends T> or(@NotNull NativeNullable<? extends T> fallback) {
|
||||
var value = getNullable();
|
||||
if (value == null) {
|
||||
return fallback;
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
default <U, TN> @NotNull TN map(
|
||||
@Override
|
||||
default boolean isPresent() {
|
||||
return getNullable() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean isEmpty() {
|
||||
return getNullable() == null;
|
||||
}
|
||||
|
||||
default <U, TN extends TypedNullable<U>> @NotNull TN map(
|
||||
@NotNull Function<@NotNull T, @NotNull U> value,
|
||||
@NotNull Function<@Nullable U, @NotNull TN> nullableConstructor) {
|
||||
var nullable = getNullable();
|
||||
@ -41,19 +71,6 @@ public interface NativeNullable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
default <U, TN extends TypedNullable<U>> @NotNull TN mapNullable(
|
||||
@NotNull Function<@NotNull T, @NotNull TN> value,
|
||||
@NotNull Supplier<@NotNull TN> emptyNullableConstructor) {
|
||||
var nullable = getNullable();
|
||||
if (nullable != null) {
|
||||
var val = value.apply(nullable);
|
||||
Objects.requireNonNull(val, "Mapped value must not be null");
|
||||
return val;
|
||||
} else {
|
||||
return emptyNullableConstructor.get();
|
||||
}
|
||||
}
|
||||
|
||||
default <U> @NotNull Optional<U> map(@NotNull Function<@NotNull T, @NotNull U> value) {
|
||||
var nullable = getNullable();
|
||||
if (nullable != null) {
|
@ -0,0 +1,29 @@
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrayInt52Serializer implements DataSerializer< List<Int52>> {
|
||||
|
||||
@Override
|
||||
public void serialize(DataOutput dataOutput, List<Int52> data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (Int52 datum : data) {
|
||||
Int52Serializer.INSTANCE.serialize(dataOutput, datum);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Int52> deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new Int52[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = Int52Serializer.INSTANCE.deserialize(dataInput);
|
||||
}
|
||||
return List.of(data);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrayStringSerializer implements DataSerializer<List<String>> {
|
||||
|
||||
@Override
|
||||
public void serialize(DataOutput dataOutput, @NotNull List<String> data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeUTF(data.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new String[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readUTF();
|
||||
}
|
||||
return List.of(data);
|
||||
}
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArraybooleanSerializer implements DataSerializer<BooleanList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull BooleanList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull BooleanList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeBoolean(data.getBoolean(i));
|
||||
@ -18,7 +19,7 @@ public class ArraybooleanSerializer implements DataSerializer<BooleanList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public BooleanList deserialize(SafeDataInput dataInput) {
|
||||
public BooleanList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new boolean[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readBoolean();
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArraybyteSerializer implements DataSerializer<ByteList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull ByteList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull ByteList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeByte(data.getByte(i));
|
||||
@ -18,7 +19,7 @@ public class ArraybyteSerializer implements DataSerializer<ByteList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ByteList deserialize(SafeDataInput dataInput) {
|
||||
public ByteList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new byte[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readByte();
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.chars.CharList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArraycharSerializer implements DataSerializer<CharList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull CharList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull CharList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeChar(data.getChar(i));
|
||||
@ -18,7 +19,7 @@ public class ArraycharSerializer implements DataSerializer<CharList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CharList deserialize(SafeDataInput dataInput) {
|
||||
public CharList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new char[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readChar();
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.doubles.DoubleList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArraydoubleSerializer implements DataSerializer<DoubleList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull DoubleList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull DoubleList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeDouble(data.getDouble(i));
|
||||
@ -18,7 +19,7 @@ public class ArraydoubleSerializer implements DataSerializer<DoubleList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DoubleList deserialize(SafeDataInput dataInput) {
|
||||
public DoubleList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new double[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readDouble();
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.floats.FloatList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrayfloatSerializer implements DataSerializer<FloatList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull FloatList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull FloatList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeFloat(data.getFloat(i));
|
||||
@ -18,7 +19,7 @@ public class ArrayfloatSerializer implements DataSerializer<FloatList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FloatList deserialize(SafeDataInput dataInput) {
|
||||
public FloatList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new float[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readFloat();
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrayintSerializer implements DataSerializer<IntList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull IntList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull IntList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeInt(data.getInt(i));
|
||||
@ -18,7 +19,7 @@ public class ArrayintSerializer implements DataSerializer<IntList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public IntList deserialize(SafeDataInput dataInput) {
|
||||
public IntList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new int[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readInt();
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.longs.LongList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArraylongSerializer implements DataSerializer<LongList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull LongList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull LongList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeLong(data.getLong(i));
|
||||
@ -18,7 +19,7 @@ public class ArraylongSerializer implements DataSerializer<LongList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LongList deserialize(SafeDataInput dataInput) {
|
||||
public LongList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new long[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readLong();
|
@ -1,15 +1,16 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import it.unimi.dsi.fastutil.shorts.ShortList;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrayshortSerializer implements DataSerializer<ShortList> {
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull ShortList data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull ShortList data) throws IOException {
|
||||
dataOutput.writeInt(data.size());
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
dataOutput.writeShort(data.getShort(i));
|
||||
@ -18,7 +19,7 @@ public class ArrayshortSerializer implements DataSerializer<ShortList> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ShortList deserialize(SafeDataInput dataInput) {
|
||||
public ShortList deserialize(DataInput dataInput) throws IOException {
|
||||
var data = new short[dataInput.readInt()];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] = dataInput.readShort();
|
@ -1,4 +1,4 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
public interface INullable {
|
||||
Object getNullable();
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.AbstractObjectList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrays;
|
||||
@ -32,8 +32,6 @@ import java.util.function.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implements RandomAccess {
|
||||
|
||||
private static final ImmutableWrappedArrayList<?> EMPTY = new ImmutableWrappedArrayList<>(new Object[0]);
|
||||
/** The backing array. */
|
||||
protected final K[] a;
|
||||
/** The current actual size of the list (never greater than the backing-array length). */
|
||||
@ -44,7 +42,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
||||
*
|
||||
* @param a an array whose elements will be used to fill the array list.
|
||||
*/
|
||||
private ImmutableWrappedArrayList(final K[] a) {
|
||||
public ImmutableWrappedArrayList(final K[] a) {
|
||||
this.a = a;
|
||||
this.size = a.length;
|
||||
}
|
||||
@ -57,17 +55,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <K> ImmutableWrappedArrayList<K> of(final K... init) {
|
||||
return init.length == 0 ? of() : new ImmutableWrappedArrayList<>(init);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array list using an array of elements.
|
||||
*
|
||||
* @return a new array list backed by the given array.
|
||||
*/
|
||||
public static <K> ImmutableWrappedArrayList<K> of() {
|
||||
//noinspection unchecked
|
||||
return (ImmutableWrappedArrayList<K>) EMPTY;
|
||||
return new ImmutableWrappedArrayList<>(init);
|
||||
}
|
||||
|
||||
private UnsupportedOperationException ex() {
|
||||
@ -636,7 +624,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
||||
/**
|
||||
* Compares this type-specific array list to another one.
|
||||
*
|
||||
* This method exists only for sake of efficiency. The implementation inherited from the
|
||||
* @apiNote This method exists only for sake of efficiency. The implementation inherited from the
|
||||
* abstract implementation would already work.
|
||||
*
|
||||
* @param l a type-specific array list.
|
||||
@ -667,7 +655,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
||||
/**
|
||||
* Compares this array list to another array list.
|
||||
*
|
||||
* This method exists only for sake of efficiency. The implementation inherited from the
|
||||
* @apiNote This method exists only for sake of efficiency. The implementation inherited from the
|
||||
* abstract implementation would already work.
|
||||
*
|
||||
* @param l an array list.
|
@ -1,6 +1,7 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import java.lang.annotation.Native;
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Int52 extends Number implements Comparable<Int52> {
|
||||
@ -22,10 +23,6 @@ public class Int52 extends Number implements Comparable<Int52> {
|
||||
public static final Int52 ONE = new Int52(1L);
|
||||
public static final Int52 TWO = new Int52(2L);
|
||||
public static final Int52 TEN = new Int52(10L);
|
||||
public static final long MAX_VALUE_L = 0x0F_FF_FF_FF_FF_FF_FFL;
|
||||
public static final long MIN_VALUE_L = 0;
|
||||
public static final Int52 MAX_VALUE = fromLongSafe(MAX_VALUE_L);
|
||||
public static final Int52 MIN_VALUE = ZERO;
|
||||
|
||||
private final long value;
|
||||
|
||||
@ -33,18 +30,7 @@ public class Int52 extends Number implements Comparable<Int52> {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static void checkValidity(long value) {
|
||||
if (value < 0 || value > MAX_VALUE_L) {
|
||||
throw new IllegalArgumentException("Only positive values below or equal to " + MAX_VALUE_L + " are supported: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Int52 fromLong(long value) {
|
||||
checkValidity(value);
|
||||
return fromLongSafe(value);
|
||||
}
|
||||
|
||||
private static Int52 fromLongSafe(long value) {
|
||||
if (value == 0) {
|
||||
return ZERO;
|
||||
} else if (value == 1) {
|
||||
@ -53,33 +39,15 @@ public class Int52 extends Number implements Comparable<Int52> {
|
||||
return TWO;
|
||||
} else if (value == 10) {
|
||||
return TEN;
|
||||
} else if (value <= 0) {
|
||||
throw new IllegalArgumentException("Only positive values are supported");
|
||||
} else if (value > 0x0F_FF_FF_FF_FF_FF_FFL) {
|
||||
throw new IllegalArgumentException("Only values below or equal to " + 0xFFFFFFFFFFFFFL + " are supported");
|
||||
} else {
|
||||
return new Int52(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Int52 fromByteArray(byte[] bytes) {
|
||||
return fromLongSafe(fromByteArrayL(bytes));
|
||||
}
|
||||
|
||||
public static Int52 fromBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
|
||||
return fromLongSafe(fromBytesL(b1, b2, b3, b4, b5, b6, b7));
|
||||
}
|
||||
|
||||
public static long fromByteArrayL(byte[] bytes) {
|
||||
return fromBytesL(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6]);
|
||||
}
|
||||
|
||||
public static long fromBytesL(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
|
||||
return (b1 & 0xFFL) << 48
|
||||
| (b2 & 0xFFL) << 40
|
||||
| (b3 & 0xFFL) << 32
|
||||
| (b4 & 0xFFL) << 24
|
||||
| (b5 & 0xFFL) << 16
|
||||
| (b6 & 0xFFL) << 8
|
||||
| (b7 & 0xFFL);
|
||||
}
|
||||
|
||||
long getValue() {
|
||||
return value;
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Int52Serializer implements DataSerializer<Int52> {
|
||||
@ -10,17 +11,17 @@ public class Int52Serializer implements DataSerializer<Int52> {
|
||||
public static final Int52Serializer INSTANCE = new Int52Serializer();
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull Int52 data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull Int52 data) throws IOException {
|
||||
serializeValue(dataOutput, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Int52 deserialize(SafeDataInput dataInput) {
|
||||
public Int52 deserialize(DataInput dataInput) throws IOException {
|
||||
return deserializeValue(dataInput);
|
||||
}
|
||||
|
||||
public static void serializeValue(SafeDataOutput dataOutput, @NotNull Int52 data) {
|
||||
public static void serializeValue(DataOutput dataOutput, @NotNull Int52 data) throws IOException {
|
||||
long value = data.getValue();
|
||||
|
||||
for(int i = 0; i < 7; i++) {
|
||||
@ -28,9 +29,18 @@ public class Int52Serializer implements DataSerializer<Int52> {
|
||||
}
|
||||
}
|
||||
|
||||
public static Int52 deserializeValue(SafeDataInput dataInput) {
|
||||
long value = dataInput.readInt52();
|
||||
return Int52.fromLong(value);
|
||||
public static Int52 deserializeValue(DataInput dataInput) throws IOException {
|
||||
long value = 0;
|
||||
|
||||
return Int52.fromLong(
|
||||
((long) dataInput.readUnsignedByte() & 0b00001111) << 48
|
||||
| ((long) dataInput.readUnsignedByte()) << 40
|
||||
| ((long) dataInput.readUnsignedByte() << 32)
|
||||
| ((long) dataInput.readUnsignedByte() << 24)
|
||||
| ((long) dataInput.readUnsignedByte()) << 16
|
||||
| ((long) dataInput.readUnsignedByte()) << 8
|
||||
| ((long) dataInput.readUnsignedByte())
|
||||
);
|
||||
}
|
||||
|
||||
public static byte[] toByteArray(long value) {
|
@ -1,7 +1,7 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.NativeNullable;
|
||||
import it.cavallium.datagen.TypedNullable;
|
||||
import it.cavallium.data.generator.NativeNullable;
|
||||
import it.cavallium.data.generator.TypedNullable;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
@ -1,8 +1,9 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NullableInt52Serializer implements DataSerializer<NullableInt52> {
|
||||
@ -10,7 +11,7 @@ public class NullableInt52Serializer implements DataSerializer<NullableInt52> {
|
||||
public static final NullableInt52Serializer INSTANCE = new NullableInt52Serializer();
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull NullableInt52 data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull NullableInt52 data) throws IOException {
|
||||
// 0b10000000 = empty, 0b00000000 = with value
|
||||
if (data.isEmpty()) {
|
||||
dataOutput.writeByte(0b10000000);
|
||||
@ -21,7 +22,7 @@ public class NullableInt52Serializer implements DataSerializer<NullableInt52> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NullableInt52 deserialize(SafeDataInput dataInput) {
|
||||
public NullableInt52 deserialize(DataInput dataInput) throws IOException {
|
||||
// 0b10000000 = empty, 0b00000000 = with value
|
||||
byte firstByteAndIsPresent = dataInput.readByte();
|
||||
if ((firstByteAndIsPresent & 0b10000000) != 0) {
|
@ -1,7 +1,7 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.NativeNullable;
|
||||
import it.cavallium.datagen.TypedNullable;
|
||||
import it.cavallium.data.generator.NativeNullable;
|
||||
import it.cavallium.data.generator.TypedNullable;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
@ -1,35 +1,34 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class NullableStringSerializer implements DataSerializer<NullableString> {
|
||||
|
||||
public static final NullableStringSerializer INSTANCE = new NullableStringSerializer();
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull NullableString data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull NullableString data) throws IOException {
|
||||
if (data.isEmpty()) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
String dataContent = data.get();
|
||||
dataOutput.writeShortText(dataContent, StandardCharsets.UTF_8);
|
||||
dataOutput.writeUTF(dataContent);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NullableString deserialize(SafeDataInput dataInput) {
|
||||
public NullableString deserialize(DataInput dataInput) throws IOException {
|
||||
var isPresent = dataInput.readBoolean();
|
||||
if (!isPresent) {
|
||||
return NullableString.empty();
|
||||
} else {
|
||||
return NullableString.of(dataInput.readShortText(StandardCharsets.UTF_8));
|
||||
return NullableString.of(dataInput.readUTF());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.NativeNullable;
|
||||
import it.cavallium.data.generator.NativeNullable;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
@ -12,8 +12,6 @@ public class Nullableboolean implements Serializable, INullable, NativeNullable<
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Nullableboolean NULL = new Nullableboolean(null);
|
||||
private static final Nullableboolean TRUE = new Nullableboolean(true);
|
||||
private static final Nullableboolean FALSE = new Nullableboolean(false);
|
||||
|
||||
private final Boolean value;
|
||||
|
||||
@ -22,14 +20,14 @@ public class Nullableboolean implements Serializable, INullable, NativeNullable<
|
||||
}
|
||||
|
||||
public static Nullableboolean of(boolean value) {
|
||||
return value ? TRUE : FALSE;
|
||||
return new Nullableboolean(value);
|
||||
}
|
||||
|
||||
public static Nullableboolean ofNullable(@Nullable Boolean value) {
|
||||
if (value == null) {
|
||||
return NULL;
|
||||
} else {
|
||||
return value ? TRUE : FALSE;
|
||||
return new Nullableboolean(value);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NullablebooleanSerializer implements DataSerializer<Nullableboolean> {
|
||||
@ -10,7 +11,7 @@ public class NullablebooleanSerializer implements DataSerializer<Nullableboolean
|
||||
public static final NullablebooleanSerializer INSTANCE = new NullablebooleanSerializer();
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull Nullableboolean data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull Nullableboolean data) throws IOException {
|
||||
if (data.isEmpty()) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
@ -22,7 +23,7 @@ public class NullablebooleanSerializer implements DataSerializer<Nullableboolean
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Nullableboolean deserialize(SafeDataInput dataInput) {
|
||||
public Nullableboolean deserialize(DataInput dataInput) throws IOException {
|
||||
var isPresent = dataInput.readBoolean();
|
||||
if (!isPresent) {
|
||||
return Nullableboolean.empty();
|
@ -1,6 +1,6 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.NativeNullable;
|
||||
import it.cavallium.data.generator.NativeNullable;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
@ -12,13 +12,6 @@ public class Nullablebyte implements Serializable, INullable, NativeNullable<Byt
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Nullablebyte NULL = new Nullablebyte(null);
|
||||
private static final Nullablebyte[] BYTES = new Nullablebyte[1 << Byte.SIZE];
|
||||
|
||||
static {
|
||||
for (short i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
|
||||
BYTES[i - Byte.MIN_VALUE] = new Nullablebyte((byte) i);
|
||||
}
|
||||
}
|
||||
|
||||
private final Byte value;
|
||||
|
||||
@ -27,14 +20,14 @@ public class Nullablebyte implements Serializable, INullable, NativeNullable<Byt
|
||||
}
|
||||
|
||||
public static Nullablebyte of(byte value) {
|
||||
return BYTES[value - Byte.MIN_VALUE];
|
||||
return new Nullablebyte(value);
|
||||
}
|
||||
|
||||
public static Nullablebyte ofNullable(@Nullable Byte value) {
|
||||
if (value == null) {
|
||||
return NULL;
|
||||
} else {
|
||||
return BYTES[value - Byte.MIN_VALUE];
|
||||
return new Nullablebyte(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +35,7 @@ public class Nullablebyte implements Serializable, INullable, NativeNullable<Byt
|
||||
if (value == null) {
|
||||
return NULL;
|
||||
} else {
|
||||
return BYTES[value.byteValue() - Byte.MIN_VALUE];
|
||||
return new Nullablebyte(value.byteValue());
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NullablebyteSerializer implements DataSerializer<Nullablebyte> {
|
||||
@ -10,7 +11,7 @@ public class NullablebyteSerializer implements DataSerializer<Nullablebyte> {
|
||||
public static final NullablebyteSerializer INSTANCE = new NullablebyteSerializer();
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull Nullablebyte data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull Nullablebyte data) throws IOException {
|
||||
if (data.isEmpty()) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
@ -22,7 +23,7 @@ public class NullablebyteSerializer implements DataSerializer<Nullablebyte> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Nullablebyte deserialize(SafeDataInput dataInput) {
|
||||
public Nullablebyte deserialize(DataInput dataInput) throws IOException {
|
||||
var isPresent = dataInput.readBoolean();
|
||||
if (!isPresent) {
|
||||
return Nullablebyte.empty();
|
@ -1,6 +1,6 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.NativeNullable;
|
||||
import it.cavallium.data.generator.NativeNullable;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
@ -1,8 +1,9 @@
|
||||
package it.cavallium.datagen.nativedata;
|
||||
package it.cavallium.data.generator.nativedata;
|
||||
|
||||
import it.cavallium.datagen.DataSerializer;
|
||||
import it.cavallium.stream.SafeDataInput;
|
||||
import it.cavallium.stream.SafeDataOutput;
|
||||
import it.cavallium.data.generator.DataSerializer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NullablecharSerializer implements DataSerializer<Nullablechar> {
|
||||
@ -10,7 +11,7 @@ public class NullablecharSerializer implements DataSerializer<Nullablechar> {
|
||||
public static final NullablecharSerializer INSTANCE = new NullablecharSerializer();
|
||||
|
||||
@Override
|
||||
public void serialize(SafeDataOutput dataOutput, @NotNull Nullablechar data) {
|
||||
public void serialize(DataOutput dataOutput, @NotNull Nullablechar data) throws IOException {
|
||||
if (data.isEmpty()) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
@ -22,7 +23,7 @@ public class NullablecharSerializer implements DataSerializer<Nullablechar> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Nullablechar deserialize(SafeDataInput dataInput) {
|
||||
public Nullablechar deserialize(DataInput dataInput) throws IOException {
|
||||
var isPresent = dataInput.readBoolean();
|
||||
if (!isPresent) {
|
||||
return Nullablechar.empty();
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user