feat(serialize-generator): pass refs through the chain
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2024-04-24 14:31:08 +02:00
parent d0a14329b6
commit 37ed2bf867
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 17 additions and 17 deletions

View File

@ -22,10 +22,7 @@ import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedOptions;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.*;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
import javax.tools.StandardLocation;
@ -140,7 +137,10 @@ public class SerializeGeneratorProcessor extends AbstractProcessor2 {
switch (name) {
case "targets" -> {
if (bld.targets != null) throw new IllegalArgumentException("Duplicate annotation parameter: targets");
bld.targets = ((List<?>) value.getValue()).stream().map(o -> (TypeMirror) o).toArray(TypeMirror[]::new);
bld.targets = ((List<?>) value.getValue()).stream()
.map(o -> (AnnotationValue) o)
.map(o -> (TypeMirror) o.getValue())
.toArray(TypeMirror[]::new);
}
case "nullSafe" -> {
if (bld.nullSafe != null) throw new IllegalArgumentException("Duplicate annotation parameter: nullSafe");

View File

@ -82,14 +82,14 @@ public class InstanceProcessor extends GProcessor {
if (param.getType().getKind().isPrimitive()) {
generateComments(param, code);
code.addStatement("writer.name($S)", getSerializedName(param));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet);
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, writeGet);
} else {
code.beginControlFlow("if (value.$N != null || writer.isSerializeNulls())", param.getCallableName());
generateComments(param, code);
code.addStatement("writer.name($S)", getSerializedName(param));
code.addStatement("if (value.$N == null) writer.nullValue()", param.getCallableName());
code.beginControlFlow("else");
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet);
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, writeGet);
code.endControlFlow();
code.endControlFlow();
}
@ -99,7 +99,7 @@ public class InstanceProcessor extends GProcessor {
if (param.getType().getKind().isPrimitive()) {
generateComments(param, code);
code.addStatement("writer.name($S)", getSerializedName(param));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("value.$N()", param.getCallableName()));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, () -> code.add("value.$N()", param.getCallableName()));
} else {
code.addStatement("$T $L$N = value.$N()", param.getType(), "$", param.getCallableName(), param.getCallableName());
code.beginControlFlow("if ($L$N != null || writer.isSerializeNulls())", "$", param.getCallableName());
@ -107,7 +107,7 @@ public class InstanceProcessor extends GProcessor {
code.addStatement("writer.name($S)", getSerializedName(param));
code.addStatement("if ($L$N == null) writer.nullValue()", "$", param.getCallableName());
code.beginControlFlow("else");
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$L$N", "$", param.getCallableName()));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, () -> code.add("$L$N", "$", param.getCallableName()));
code.endControlFlow();
code.endControlFlow();
}
@ -151,14 +151,14 @@ public class InstanceProcessor extends GProcessor {
code.beginControlFlow("case $S ->", getSerializedName(param));
if (param.getType().getKind().isPrimitive()) {
code.add("_$N = ", param.getName());
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message);
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, refs, message);
code.add(";\n");
} else {
code.beginControlFlow("if (reader.peek() == $T.NULL)", Cl.GSON_TOKEN)
.addStatement("reader.nextNull()")
.addStatement("_$N = null", param.getName());
code.unindent().add("} else _$N = ", param.getName());
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message);
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, refs, message);
code.add(";\n");
}
code.addStatement("has_$N = true", param.getName());

View File

@ -47,14 +47,14 @@ public class StaticProcessor extends GProcessor {
if (param.getType().getKind().isPrimitive()) {
generateComments(param, code);
code.addStatement("writer.name($S)", getSerializedName(param));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet);
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, writeGet);
} else {
code.beginControlFlow("if ($T.$N != null || writer.isSerializeNulls())", self.getTypeName(), param.getCallableName());
generateComments(param, code);
code.addStatement("writer.name($S)", getSerializedName(param));
code.addStatement("if ($T.$N == null) writer.nullValue()", self.getTypeName(), param.getCallableName());
code.beginControlFlow("else");
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet);
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, writeGet);
code.endControlFlow();
code.endControlFlow();
}
@ -64,7 +64,7 @@ public class StaticProcessor extends GProcessor {
if (param.getType().getKind().isPrimitive()) {
generateComments(param, code);
code.addStatement("writer.name($S)", getSerializedName(param));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$T.$N()", self.getTypeName(), param.getCallableName()));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, () -> code.add("$T.$N()", self.getTypeName(), param.getCallableName()));
} else {
code.addStatement("$T $L$N = $T.$N()", param.getType(), "$", param.getCallableName(), self.getTypeName(), param.getCallableName());
code.beginControlFlow("if ($L$N != null || writer.isSerializeNulls())", "$", param.getCallableName());
@ -72,7 +72,7 @@ public class StaticProcessor extends GProcessor {
code.addStatement("writer.name($S)", getSerializedName(param));
code.addStatement("if ($L$N == null) writer.nullValue()", "$", param.getCallableName());
code.beginControlFlow("else");
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$L$N", "$", param.getCallableName()));
Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, refs, message, () -> code.add("$L$N", "$", param.getCallableName()));
code.endControlFlow();
code.endControlFlow();
}
@ -131,7 +131,7 @@ public class StaticProcessor extends GProcessor {
if (param.getType().getKind().isPrimitive()) {
if (param instanceof Property.Field) code.add("$T.$N = ", self.getTypeName(), param.getName());
else code.add("_$N = ", param.getName());
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message);
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, refs, message);
code.add(";\n");
} else {
code.beginControlFlow("if (reader.peek() == $T.NULL)", Cl.GSON_TOKEN)
@ -143,7 +143,7 @@ public class StaticProcessor extends GProcessor {
code.addStatement("_$N = null", param.getName());
code.unindent().add("} else _$N = ", param.getName());
}
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message);
Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, refs, message);
code.add(";\n");
}
if (!(param instanceof Property.Field)) code.addStatement("has_$N = true", param.getName());