Take into consideration generic definitions

This commit is contained in:
Lonami Exo 2018-07-23 19:43:04 +02:00
parent 2f22e74eca
commit d546801130
2 changed files with 34 additions and 5 deletions

View File

@ -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);

View File

@ -8,17 +8,27 @@ public class TLArg {
public final List<String> types;
public final boolean flags;
public final Flag flag;
public final boolean genericDefinition;
private TLArg(final String name, final List<String> types, final boolean flags, final Flag flag) {
private TLArg(final String name, final List<String> 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();
}