AidlToJson.java 1.3 KB

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