Generate code to the lib module

This commit is contained in:
Lonami Exo 2018-07-23 21:26:02 +02:00
parent 9c0402e909
commit 957e29b4db
8 changed files with 27 additions and 14 deletions

View File

@ -1,5 +1,6 @@
plugins { plugins {
id 'java' id 'java'
id 'application'
} }
version '0.1' version '0.1'
@ -9,3 +10,14 @@ sourceCompatibility = 1.8
repositories { repositories {
mavenCentral() mavenCentral()
} }
task('gen_tl', dependsOn: jar, type: JavaExec) {
main = "io.github.lonamiwebs.overgram.Overgram"
classpath = sourceSets.main.runtimeClasspath
// TODO Learn gradle and do this properly
setArgs([
'../lib/src/main/java/io/github/lonamiwebs/overgram/tl/',
'src/main/resources/mtproto_api.tl',
'src/main/resources/telegram_api.tl'
])
}

View File

@ -6,21 +6,24 @@ import io.github.lonamiwebs.overgram.parser.TLReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class Overgram { public class Overgram {
public static void main(final String... args) { public static void main(final String... args) throws IOException {
final Map<String, List<TLObject>> objects = TLReader.readTlObjects(new File("telegram_api.tl")); final Map<String, List<TLObject>> objects = new HashMap<>();
try { for (int i = 1; i < args.length; ++i) {
TLReader.readTlObjects(objects, new File(args[i]));
}
final File parent = new File(args[0]);
Generator.generateJava( Generator.generateJava(
objects.get("types"), objects.get("types"),
objects.get("functions"), objects.get("functions"),
new File("Abstract.java"), new File(parent, "Abstract.java"),
new File("Types.java"), new File(parent, "Types.java"),
new File("Functions.java") new File(parent, "Functions.java")
); );
} catch (IOException ignored) {
}
} }
} }

View File

@ -12,8 +12,7 @@ import java.util.Map;
public class TLReader { public class TLReader {
public static final Map<String, List<TLObject>> readTlObjects(final File file) { public static void readTlObjects(final Map<String, List<TLObject>> result, final File file) {
final Map<String, List<TLObject>> result = new HashMap<>();
for (final Map.Entry<String, List<String>> entry : readTl(file).entrySet()) { for (final Map.Entry<String, List<String>> entry : readTl(file).entrySet()) {
final List<TLObject> objects = new ArrayList<>(); final List<TLObject> objects = new ArrayList<>();
for (final String string : entry.getValue()) { for (final String string : entry.getValue()) {
@ -21,7 +20,6 @@ public class TLReader {
} }
result.put(entry.getKey(), objects); result.put(entry.getKey(), objects);
} }
return result;
} }
private static Map<String, List<String>> readTl(final File file) { private static Map<String, List<String>> readTl(final File file) {