AidlToJson.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import java.io.*;
  2. import src.main.java.xyz.ignatz.antlr.aidl.gen.AidlLexer;
  3. import src.main.java.xyz.ignatz.antlr.aidl.gen.AidlParser;
  4. import src.main.java.xyz.ignatz.antlr.aidl.tools.AidlLoader;
  5. import org.antlr.v4.runtime.*;
  6. import org.antlr.v4.runtime.tree.*;
  7. public class AidlToJson
  8. {
  9. public static void main(String[] args)
  10. {
  11. if (args.length < 2) {
  12. System.out.println("AidlToJson input_filename output_directory");
  13. return;
  14. }
  15. CharStream input = null;
  16. try {
  17. input = CharStreams.fromFileName(args[0]);
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21. AidlLexer lexer = new AidlLexer(input);
  22. CommonTokenStream tokens = new CommonTokenStream(lexer);
  23. AidlParser parser = new AidlParser(tokens);
  24. ParseTree tree = parser.aidl();
  25. ParseTreeWalker walker = new ParseTreeWalker();
  26. AidlLoader loader = new AidlLoader();
  27. walker.walk(loader, tree);
  28. OutputStream os = null;
  29. try {
  30. os = new FileOutputStream(new File(args[1] + '\\' + loader.getName() + ".json"), false);
  31. } catch (FileNotFoundException e) {
  32. e.printStackTrace();
  33. }
  34. try {
  35. os.write(loader.toJson().getBytes());
  36. } catch (IOException e) {
  37. e.printStackTrace();
  38. }
  39. try {
  40. os.close();
  41. } catch (IOException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. }