| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import java.io.*;
- import antlr.aidl.tools.AidlLoader;
- import org.antlr.v4.runtime.*;
- import org.antlr.v4.runtime.tree.*;
- import antlr.aidl.*;
- public class AidlToJson
- {
- public static void main(String[] args)
- {
- if (args.length < 2) {
- System.out.println("AidlToJson input_filename output_directory");
- return;
- }
- CharStream input = null;
- try {
- input = CharStreams.fromFileName(args[0]);
- } catch (IOException e) {
- e.printStackTrace();
- }
- AidlLexer lexer = new AidlLexer(input);
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- AidlParser parser = new AidlParser(tokens);
- ParseTree tree = parser.aidl();
- ParseTreeWalker walker = new ParseTreeWalker();
- AidlLoader loader = new AidlLoader();
- walker.walk(loader, tree);
- OutputStream os = null;
- try {
- os = new FileOutputStream(new File(args[1] + '\\' + loader.getName() + ".json"), false);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- try {
- os.write(loader.toJson().getBytes());
- } catch (IOException e) {
- e.printStackTrace();
- }
- try {
- os.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|