From f836a260015013df92141f1d7b88aab403547d65 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 9 Nov 2023 01:58:17 +0100 Subject: [PATCH] Fix missing upgrader code --- .../plugin/classgen/GenUpgraderBaseX.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/datagen-plugin/src/main/java/it/cavallium/datagen/plugin/classgen/GenUpgraderBaseX.java b/datagen-plugin/src/main/java/it/cavallium/datagen/plugin/classgen/GenUpgraderBaseX.java index 88b64ec..d5dd7e7 100644 --- a/datagen-plugin/src/main/java/it/cavallium/datagen/plugin/classgen/GenUpgraderBaseX.java +++ b/datagen-plugin/src/main/java/it/cavallium/datagen/plugin/classgen/GenUpgraderBaseX.java @@ -241,7 +241,6 @@ public class GenUpgraderBaseX extends ClassGenerator { instanceField.fieldLocation().fieldName() ); } - classBuilder.addField(fieldBuilder.build()); initializerStaticFieldNames.put(identifier, initializerName); } @@ -251,17 +250,24 @@ public class GenUpgraderBaseX extends ClassGenerator { private String createUpgraderStaticField(AtomicInteger nextUpgraderStaticFieldId, HashMap upgraderStaticFieldNames, Builder classBuilder, - String upgraderImplementationLocation, + JInterfaceLocation upgraderLocation, TypeName genericUpgraderClass) { - var upgraderName = upgraderStaticFieldNames.get(upgraderImplementationLocation); + var identifier = upgraderLocation.getIdentifier(); + var upgraderName = upgraderStaticFieldNames.get(identifier); if (upgraderName == null) { upgraderName = "U" + nextUpgraderStaticFieldId.getAndIncrement(); - classBuilder.addField(FieldSpec + var fieldBuilder = FieldSpec .builder(genericUpgraderClass, upgraderName) - .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL) - .initializer("new $T()", upgraderClass) - .build()); - upgraderStaticFieldNames.put(upgraderImplementationLocation, 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); } return upgraderName; }