Skip to content

Commit

Permalink
Able to persist signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Nov 8, 2023
1 parent db4f8f2 commit 14c2282
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import scala.collection.immutable.Seq;

@Persistable(clazz = Polyglot.Java.class, id = 703)
@Persistable(clazz = DefinitionArgument.Specified.class, id = 704)
@Persistable(clazz = Name.Self.class, id = 705)
@Persistable(clazz = Literal.Number.class, id = 706)
public final class IrPersistance {
private IrPersistance() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,21 @@ private boolean generatePersistance(Element orig, Persistable anno) throws IOExc
w.append(" public ").append(className).append("() {\n");
w.append(" super(").append(typeElemName).append(".class, false, ").append(Integer.toString(anno.id())).append(");\n");
w.append(" }\n");
w.append(" @SuppressWarnings(\"unchecked\")\n");
w.append(" protected ").append(typeElemName).append(" readObject(Input in) throws IOException {\n");
w.append(" /* found: ").append(cons.getParameters().toString()).append("*/\n");
for (var v : cons.getParameters()) {
if (tu.isSameType(eu.getTypeElement("java.lang.String").asType(), v.asType())) {
w.append(" var ").append(v.getSimpleName()).append(" = in.readUTF();\n");
} else if (!v.asType().getKind().isPrimitive()) {
w.append(" var ").append(v.getSimpleName()).append(" = in.readInline(").append(typeElemName).append(".class);\n");
var type = tu.erasure(v.asType());
var elem = (TypeElement) tu.asElement(type);
var name = eu.getBinaryName(elem);
if (elem.getKind().isInterface()) {
w.append(" var ").append(v.getSimpleName()).append(" = (").append(name).append(") in.readObject();\n");
} else {
w.append(" var ").append(v.getSimpleName()).append(" = in.readInline(").append(name).append(".class);\n");
}
} else switch (v.asType().getKind()) {
case BOOLEAN ->
w.append(" var ").append(v.getSimpleName()).append(" = in.readBoolean();\n");
Expand All @@ -124,6 +132,7 @@ private boolean generatePersistance(Element orig, Persistable anno) throws IOExc
w.append("\n");
w.append(" );\n");
w.append(" }\n");
w.append(" @SuppressWarnings(\"unchecked\")\n");
w.append(" protected void writeObject(").append(typeElemName).append(" obj, Output out) throws IOException {\n");

w.append(" /* found: ").append(cons.getParameters().toString()).append("*/\n");
Expand All @@ -132,7 +141,14 @@ private boolean generatePersistance(Element orig, Persistable anno) throws IOExc
if (tu.isSameType(eu.getTypeElement("java.lang.String").asType(), v.asType())) {
w.append(" out.writeUTF(obj.").append(v.getSimpleName()).append("());\n");
} else if (!v.asType().getKind().isPrimitive()) {
w.append(" out.writeInline(obj.").append(v.getSimpleName()).append("());\n");
var type = tu.erasure(v.asType());
var elem = (TypeElement) tu.asElement(type);
var name = eu.getBinaryName(elem);
if (elem.getKind().isInterface()) {
w.append(" out.writeObject(obj.").append(v.getSimpleName()).append("());\n");
} else {
w.append(" out.writeInline(").append(name).append(".class, obj.").append(v.getSimpleName()).append("());\n");
}
} else switch (v.asType().getKind()) {
case BOOLEAN ->
w.append(" out.writeBoolean(obj.").append(v.getSimpleName()).append("());\n");
Expand Down

0 comments on commit 14c2282

Please sign in to comment.