From d546801130a0a44cfcada9967cb5b603288b8179 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 23 Jul 2018 19:43:04 +0200 Subject: [PATCH] Take into consideration generic definitions --- .../overgram/generator/Generator.java | 12 ++++++--- .../lonamiwebs/overgram/parser/TLArg.java | 27 +++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/lonamiwebs/overgram/generator/Generator.java b/src/main/java/io/github/lonamiwebs/overgram/generator/Generator.java index 4e8d49a..0fead3d 100644 --- a/src/main/java/io/github/lonamiwebs/overgram/generator/Generator.java +++ b/src/main/java/io/github/lonamiwebs/overgram/generator/Generator.java @@ -77,7 +77,7 @@ public class Generator { writer.write(" {\n"); for (int i = 0; i < object.args.size(); ++i) { - if (object.args.get(i).flags) { + if (object.args.get(i).genericDefinition || object.args.get(i).flags) { continue; } writer.write("private "); @@ -109,7 +109,7 @@ public class Generator { private static void writeSerialize(final Writer writer, final TLObject object) throws IOException { writer.write("public void serialize(final BinaryWriter writer) {\n"); for (final TLArg arg : object.args) { - if (arg.flags) { + if (!arg.genericDefinition && arg.flags) { writer.write("int "); writer.write(arg.name); writer.write(" = 0;\n"); @@ -117,7 +117,7 @@ public class Generator { } for (int i = 0; i < object.args.size(); ++i) { final TLArg arg = object.args.get(i); - if (arg.flag != null) { + if (!arg.genericDefinition && arg.flag != null) { writer.write("if (" + VARIABLE_SUFFIX + i); writer.write(arg.javaSetCheck()); writer.write(") { "); @@ -128,6 +128,9 @@ public class Generator { } for (int i = 0; i < object.args.size(); ++i) { final TLArg arg = object.args.get(i); + if (arg.genericDefinition) { + continue; + } if (arg.flag != null) { writer.write("if (" + VARIABLE_SUFFIX + i); writer.write(arg.javaSetCheck()); @@ -153,6 +156,9 @@ public class Generator { writer.write("public void deserialize(final BinaryReader reader) {\n"); for (int i = 0; i < object.args.size(); ++i) { final TLArg arg = object.args.get(i); + if (arg.genericDefinition) { + continue; + } if (arg.flags) { writer.write("int "); writer.write(arg.name); diff --git a/src/main/java/io/github/lonamiwebs/overgram/parser/TLArg.java b/src/main/java/io/github/lonamiwebs/overgram/parser/TLArg.java index 32d5061..1c2c402 100644 --- a/src/main/java/io/github/lonamiwebs/overgram/parser/TLArg.java +++ b/src/main/java/io/github/lonamiwebs/overgram/parser/TLArg.java @@ -8,17 +8,27 @@ public class TLArg { public final List types; public final boolean flags; public final Flag flag; + public final boolean genericDefinition; - private TLArg(final String name, final List types, final boolean flags, final Flag flag) { + private TLArg(final String name, final List types, final boolean flags, final Flag flag, + final boolean genericDefinition) { this.name = name; this.types = types; this.flags = flags; this.flag = flag; + this.genericDefinition = genericDefinition; } public static TLArg fromString(String string) { final String[] tmp = string.split(":"); + boolean genericDefinition = false; + if (tmp[1].equals("Type}")) { + tmp[1] = tmp[1].substring(0, tmp[1].length() - 1); + tmp[0] = tmp[0].substring(1); + genericDefinition = true; + } + boolean flags = false; if (tmp[1].equals("#")) { tmp[1] = ""; @@ -40,7 +50,7 @@ public class TLArg { } types.add(tmp[1]); - return new TLArg(tmp[0], types, flags, flag); + return new TLArg(tmp[0], types, flags, flag, genericDefinition); } public String javaType() { @@ -48,6 +58,13 @@ public class TLArg { boolean nested = false; for (final String type : types) { + if (type.startsWith("!")) { + if (nested) { + throw new UnsupportedOperationException(); + } + return "TLObject"; + } + switch (type) { case "vector": case "Vector": @@ -117,6 +134,9 @@ public class TLArg { @Override public String toString() { final StringBuilder builder = new StringBuilder(); + if (genericDefinition) { + builder.append('{'); + } builder.append(name); builder.append(':'); if (flag != null) { @@ -134,6 +154,9 @@ public class TLArg { builder.append('>'); } } + if (genericDefinition) { + builder.append('}'); + } return builder.toString(); }