Finalize min version checks
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-09-22 14:53:42 +02:00
Ursprung 067acf5f62
Commit f161379b62

Datei anzeigen

@ -38,6 +38,7 @@ import javax.tools.Diagnostic;
import java.io.*;
import java.io.Writer;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -185,7 +186,9 @@ public class LinkageProcessor extends AbstractProcessor {
TypeElement fieldType = (TypeElement) ((DeclaredType) variableElement.asType()).asElement();
neededFields.put(fieldType.getQualifiedName().toString(), fieldType);
specialElements(typeElement, buildPlan, buildPlan::addStaticLine, () -> {
buildPlan.addStaticLine(getElement(typeElement, neededFields) + "." + variableElement.getSimpleName().toString() + " = " + getElement((TypeElement) ((DeclaredType) variableElement.asType()).asElement(), neededFields) + ";");
});
}
}
neededFields.forEach((s, typeElement) -> {
@ -194,9 +197,11 @@ public class LinkageProcessor extends AbstractProcessor {
MethodBuilder initializer = new MethodBuilder(typeElement.getSimpleName().toString(), typeElement.getSimpleName().toString());
initializer.setPrivate(true);
specialElements(typeElement, buildPlan, initializer::addLine, () -> {
initializer.addLine("if (" + typeElement.getSimpleName().toString() + " == null) {");
initializer.addLine(" " + typeElement.getSimpleName().toString() + " = new " + typeElement.getSimpleName().toString() + "();");
initializer.addLine("}");
});
initializer.addLine("return " + typeElement.getSimpleName().toString() + ";");
buildPlan.addMethod(initializer);
});
@ -207,7 +212,6 @@ public class LinkageProcessor extends AbstractProcessor {
continue;
}
TypeElement typeElement = (TypeElement) element;
MinVersion minVersion = element.getAnnotation(MinVersion.class);
System.out.println("Found element: " + typeElement.getQualifiedName().toString());
element.getAnnotationMirrors().stream()
@ -265,13 +269,9 @@ public class LinkageProcessor extends AbstractProcessor {
buildPlan.addMethod(methodBuilder);
return methodBuilder;
});
if (context == LinkageType.Context.SPIGOT && minVersion != null) {
method.addLine("if (de.steamwar.core.Core.getVersion() >= " + minVersion.value() + ") {");
}
specialElements(typeElement, buildPlan, method::addLine, () -> {
type.generateCode(buildPlan, method, getElement(typeElement, neededFields), typeElement);
if (context == LinkageType.Context.SPIGOT && minVersion != null) {
method.addLine("}");
}
});
});
}
@ -287,4 +287,18 @@ public class LinkageProcessor extends AbstractProcessor {
}
return "new " + typeElement.getQualifiedName().toString() + "()";
}
private void specialElements(TypeElement typeElement, BuildPlan buildPlan, Consumer<String> stringConsumer, Runnable inner) {
if (context == LinkageType.Context.SPIGOT) {
MinVersion minVersion = typeElement.getAnnotation(MinVersion.class);
if (minVersion != null) {
buildPlan.addImport("de.steamwar.core.Core");
stringConsumer.accept("if (Core.getVersion() >= " + minVersion.value() + ") {");
}
inner.run();
if (minVersion != null) stringConsumer.accept("}");
} else {
inner.run();
}
}
}