Fix missing upgrader code

This commit is contained in:
Andrea Cavalli 2023-11-09 01:58:17 +01:00
parent 7ceede1cc6
commit f836a26001

View File

@ -241,7 +241,6 @@ public class GenUpgraderBaseX extends ClassGenerator {
instanceField.fieldLocation().fieldName() instanceField.fieldLocation().fieldName()
); );
} }
classBuilder.addField(fieldBuilder.build()); classBuilder.addField(fieldBuilder.build());
initializerStaticFieldNames.put(identifier, initializerName); initializerStaticFieldNames.put(identifier, initializerName);
} }
@ -251,17 +250,24 @@ public class GenUpgraderBaseX extends ClassGenerator {
private String createUpgraderStaticField(AtomicInteger nextUpgraderStaticFieldId, private String createUpgraderStaticField(AtomicInteger nextUpgraderStaticFieldId,
HashMap<String, String> upgraderStaticFieldNames, HashMap<String, String> upgraderStaticFieldNames,
Builder classBuilder, Builder classBuilder,
String upgraderImplementationLocation, JInterfaceLocation upgraderLocation,
TypeName genericUpgraderClass) { TypeName genericUpgraderClass) {
var upgraderName = upgraderStaticFieldNames.get(upgraderImplementationLocation); var identifier = upgraderLocation.getIdentifier();
var upgraderName = upgraderStaticFieldNames.get(identifier);
if (upgraderName == null) { if (upgraderName == null) {
upgraderName = "U" + nextUpgraderStaticFieldId.getAndIncrement(); upgraderName = "U" + nextUpgraderStaticFieldId.getAndIncrement();
classBuilder.addField(FieldSpec var fieldBuilder = FieldSpec
.builder(genericUpgraderClass, upgraderName) .builder(genericUpgraderClass, upgraderName)
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL) .addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL);
.initializer("new $T()", upgraderClass) switch (upgraderLocation) {
.build()); case JInterfaceLocationClassName className -> fieldBuilder.initializer("new $T()", className.className());
upgraderStaticFieldNames.put(upgraderImplementationLocation, upgraderName); case JInterfaceLocationInstanceField instanceField -> fieldBuilder.initializer("$T.$N",
instanceField.fieldLocation().className(),
instanceField.fieldLocation().fieldName()
);
}
classBuilder.addField(fieldBuilder.build());
upgraderStaticFieldNames.put(identifier, upgraderName);
} }
return upgraderName; return upgraderName;
} }