Take into consideration generic definitions
This commit is contained in:
parent
2f22e74eca
commit
d546801130
|
@ -77,7 +77,7 @@ public class Generator {
|
||||||
writer.write(" {\n");
|
writer.write(" {\n");
|
||||||
|
|
||||||
for (int i = 0; i < object.args.size(); ++i) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
writer.write("private ");
|
writer.write("private ");
|
||||||
|
@ -109,7 +109,7 @@ public class Generator {
|
||||||
private static void writeSerialize(final Writer writer, final TLObject object) throws IOException {
|
private static void writeSerialize(final Writer writer, final TLObject object) throws IOException {
|
||||||
writer.write("public void serialize(final BinaryWriter writer) {\n");
|
writer.write("public void serialize(final BinaryWriter writer) {\n");
|
||||||
for (final TLArg arg : object.args) {
|
for (final TLArg arg : object.args) {
|
||||||
if (arg.flags) {
|
if (!arg.genericDefinition && arg.flags) {
|
||||||
writer.write("int ");
|
writer.write("int ");
|
||||||
writer.write(arg.name);
|
writer.write(arg.name);
|
||||||
writer.write(" = 0;\n");
|
writer.write(" = 0;\n");
|
||||||
|
@ -117,7 +117,7 @@ public class Generator {
|
||||||
}
|
}
|
||||||
for (int i = 0; i < object.args.size(); ++i) {
|
for (int i = 0; i < object.args.size(); ++i) {
|
||||||
final TLArg arg = object.args.get(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("if (" + VARIABLE_SUFFIX + i);
|
||||||
writer.write(arg.javaSetCheck());
|
writer.write(arg.javaSetCheck());
|
||||||
writer.write(") { ");
|
writer.write(") { ");
|
||||||
|
@ -128,6 +128,9 @@ public class Generator {
|
||||||
}
|
}
|
||||||
for (int i = 0; i < object.args.size(); ++i) {
|
for (int i = 0; i < object.args.size(); ++i) {
|
||||||
final TLArg arg = object.args.get(i);
|
final TLArg arg = object.args.get(i);
|
||||||
|
if (arg.genericDefinition) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (arg.flag != null) {
|
if (arg.flag != null) {
|
||||||
writer.write("if (" + VARIABLE_SUFFIX + i);
|
writer.write("if (" + VARIABLE_SUFFIX + i);
|
||||||
writer.write(arg.javaSetCheck());
|
writer.write(arg.javaSetCheck());
|
||||||
|
@ -153,6 +156,9 @@ public class Generator {
|
||||||
writer.write("public void deserialize(final BinaryReader reader) {\n");
|
writer.write("public void deserialize(final BinaryReader reader) {\n");
|
||||||
for (int i = 0; i < object.args.size(); ++i) {
|
for (int i = 0; i < object.args.size(); ++i) {
|
||||||
final TLArg arg = object.args.get(i);
|
final TLArg arg = object.args.get(i);
|
||||||
|
if (arg.genericDefinition) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (arg.flags) {
|
if (arg.flags) {
|
||||||
writer.write("int ");
|
writer.write("int ");
|
||||||
writer.write(arg.name);
|
writer.write(arg.name);
|
||||||
|
|
|
@ -8,17 +8,27 @@ public class TLArg {
|
||||||
public final List<String> types;
|
public final List<String> types;
|
||||||
public final boolean flags;
|
public final boolean flags;
|
||||||
public final Flag flag;
|
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.name = name;
|
||||||
this.types = types;
|
this.types = types;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
|
this.genericDefinition = genericDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TLArg fromString(String string) {
|
public static TLArg fromString(String string) {
|
||||||
final String[] tmp = string.split(":");
|
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;
|
boolean flags = false;
|
||||||
if (tmp[1].equals("#")) {
|
if (tmp[1].equals("#")) {
|
||||||
tmp[1] = "";
|
tmp[1] = "";
|
||||||
|
@ -40,7 +50,7 @@ public class TLArg {
|
||||||
}
|
}
|
||||||
types.add(tmp[1]);
|
types.add(tmp[1]);
|
||||||
|
|
||||||
return new TLArg(tmp[0], types, flags, flag);
|
return new TLArg(tmp[0], types, flags, flag, genericDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String javaType() {
|
public String javaType() {
|
||||||
|
@ -48,6 +58,13 @@ public class TLArg {
|
||||||
|
|
||||||
boolean nested = false;
|
boolean nested = false;
|
||||||
for (final String type : types) {
|
for (final String type : types) {
|
||||||
|
if (type.startsWith("!")) {
|
||||||
|
if (nested) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
return "TLObject";
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "vector":
|
case "vector":
|
||||||
case "Vector":
|
case "Vector":
|
||||||
|
@ -117,6 +134,9 @@ public class TLArg {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
if (genericDefinition) {
|
||||||
|
builder.append('{');
|
||||||
|
}
|
||||||
builder.append(name);
|
builder.append(name);
|
||||||
builder.append(':');
|
builder.append(':');
|
||||||
if (flag != null) {
|
if (flag != null) {
|
||||||
|
@ -134,6 +154,9 @@ public class TLArg {
|
||||||
builder.append('>');
|
builder.append('>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (genericDefinition) {
|
||||||
|
builder.append('}');
|
||||||
|
}
|
||||||
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue