Bugfixes
This commit is contained in:
parent
938b404ec7
commit
16b22d2e49
@ -213,11 +213,20 @@ public class DataModel {
|
||||
if (definition.isEmpty()) {
|
||||
throw new IllegalArgumentException(transformCoordinate + " refers to an unknown field: " + t.from);
|
||||
}
|
||||
var prevDef = tryInsertAtIndex(transformClass.data,
|
||||
t.to,
|
||||
definition.get().getValue(),
|
||||
definition.get().getKey()
|
||||
);
|
||||
String prevDef;
|
||||
if (t.index != null) {
|
||||
prevDef = tryInsertAtIndex(transformClass.data,
|
||||
t.to,
|
||||
definition.get().getValue(),
|
||||
t.index
|
||||
);
|
||||
} else {
|
||||
prevDef = tryInsertAtIndex(transformClass.data,
|
||||
t.to,
|
||||
definition.get().getValue(),
|
||||
definition.get().getKey()
|
||||
);
|
||||
}
|
||||
if (prevDef != null) {
|
||||
throw new IllegalArgumentException(
|
||||
transformCoordinate + " tries to overwrite the existing field \"" + t.to + "\" of value \""
|
||||
|
@ -29,6 +29,9 @@ public class MavenPlugin extends AbstractMojo {
|
||||
@Parameter( required = true, defaultValue = "false")
|
||||
private String useRecordBuilder;
|
||||
|
||||
@Parameter(defaultValue = "false")
|
||||
private String generateTestResources;
|
||||
|
||||
/**
|
||||
* @parameter default-value="${project}"
|
||||
* @required
|
||||
@ -41,7 +44,8 @@ public class MavenPlugin extends AbstractMojo {
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
try {
|
||||
SourcesGenerator sourcesGenerator = SourcesGenerator.load(configPath.toPath());
|
||||
Path genRecordsPath = project.getBasedir().getAbsoluteFile().toPath().resolve("target").resolve("generated-sources").resolve("database-classes");
|
||||
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 outPath = genRecordsPath.resolve("java");
|
||||
this.project.addCompileSourceRoot(outPath.toString());
|
||||
|
@ -1,12 +1,15 @@
|
||||
package it.cavallium.datagen.plugin;
|
||||
|
||||
import java.util.Objects;
|
||||
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() {
|
||||
@ -27,9 +30,8 @@ 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
|
||||
);
|
||||
return Objects.equals(transformClass, that.transformClass) && Objects.equals(from, that.from)
|
||||
&& Objects.equals(to, that.to) && Objects.equals(index, that.index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,6 +40,7 @@ public final class MoveDataConfiguration implements TransformationConfiguration
|
||||
hash += ConfigUtils.hashCode(transformClass);
|
||||
hash += ConfigUtils.hashCode(from);
|
||||
hash += ConfigUtils.hashCode(to);
|
||||
hash += ConfigUtils.hashCode(index);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@ -46,6 +49,7 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,11 @@ 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);
|
||||
}
|
||||
@ -96,23 +101,37 @@ public class GenSerializerArrayX extends ClassGenerator {
|
||||
method.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||
|
||||
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.addStatement("int sz = in.readInt()");
|
||||
var arrayTypeName = ArrayTypeName.of(typeArray.getBase().getJTypeName(basePackageName));
|
||||
method.addStatement("$T a = new $T[sz]", arrayTypeName, arrayTypeName.componentType);
|
||||
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);
|
||||
}
|
||||
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");
|
||||
method.addStatement("return new $T(a)", ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class),
|
||||
typeArray.getBase().getJTypeName(basePackageName)));
|
||||
if (USE_NATIVE_TYPED_ARRAYS) {
|
||||
method.addStatement("return new $T(a)", ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class), arrayComponentTypeName));
|
||||
} else {
|
||||
method.addStatement("return ($T) new $T(a)",
|
||||
ParameterizedTypeName.get(ClassName.get(ImmutableWrappedArrayList.class), arrayComponentTypeName),
|
||||
ClassName.get(ImmutableWrappedArrayList.class)
|
||||
);
|
||||
}
|
||||
|
||||
classBuilder.addMethod(method.build());
|
||||
}
|
||||
|
@ -101,6 +101,37 @@
|
||||
</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>
|
||||
|
@ -25,19 +25,4 @@ public class BufDataInput extends SafeDataInputStream {
|
||||
public void close() {
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(int readlimit) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
||||
/**
|
||||
* Compares this type-specific array list to another one.
|
||||
*
|
||||
* @apiNote This method exists only for sake of efficiency. The implementation inherited from the
|
||||
* 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.
|
||||
@ -655,7 +655,7 @@ public class ImmutableWrappedArrayList<K> extends AbstractObjectList<K> implemen
|
||||
/**
|
||||
* Compares this array list to another array list.
|
||||
*
|
||||
* @apiNote This method exists only for sake of efficiency. The implementation inherited from the
|
||||
* This method exists only for sake of efficiency. The implementation inherited from the
|
||||
* abstract implementation would already work.
|
||||
*
|
||||
* @param l an array list.
|
||||
|
@ -7,8 +7,9 @@ public class UpgradeUtil {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <A, B> List<B> upgradeArray(List<A> from, DataUpgrader<A, B> upgrader) {
|
||||
Object[] array;
|
||||
if (from instanceof ImmutableWrappedArrayList<A> immutableWrappedArrayList) {
|
||||
array = immutableWrappedArrayList.a;
|
||||
if (from.getClass() == ImmutableWrappedArrayList.class
|
||||
&& ((ImmutableWrappedArrayList<?>) from).a.getClass() == Object[].class) {
|
||||
array = ((ImmutableWrappedArrayList<?>) from).a;
|
||||
} else {
|
||||
array = from.toArray();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user