package dsl;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.eclipse.jdt.core.dom.*;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Visitor extends ASTVisitor {

    final CompilationUnit unit;
    final Options options;
    final PrintWriter output;
    final Gson gson;

    class JSONOutputWrapper {
        DBlock ast;
        List<Sequence> sequences;

        public JSONOutputWrapper(DBlock ast, List<Sequence> sequences) {
            this.ast = ast;
            this.sequences = sequences;
        }
    }

    public Visitor(CompilationUnit unit, Options options) throws FileNotFoundException {
        this.unit = unit;
        this.options = options;
        this.gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();

        if (options.cmdLine.hasOption("output-file"))
            this.output = new PrintWriter(options.cmdLine.getOptionValue("output-file"));
        else
            this.output = new PrintWriter(System.out);
    }

    @Override
    public boolean visit(MethodDeclaration method) {
        DBlock ast = new DBlock.Handle(method.getBody(), this).handle();
        if (ast != null) {
            List<Sequence> sequences = new ArrayList<>();
            sequences.add(new Sequence());
            ast.updateSequences(sequences);

            printJson(ast, sequences);
        }
        return false;
    }

    boolean first = true;
    private void printJson(DBlock ast, List<Sequence> sequences) {
        JSONOutputWrapper out = new JSONOutputWrapper(ast, sequences);
        output.write(first? "" : ",\n");
        output.write(gson.toJson(out));
        output.flush();
        first = false;
    }
}

@@ -410,16 +410,37 @@
 apper %7B%0A
+        String file;%0A
         
@@ -447,24 +447,24 @@
 DBlock ast;%0A
-
         List
@@ -519,16 +519,29 @@
 Wrapper(
+String file, 
 DBlock a
@@ -564,32 +564,62 @@
 e%3E sequences) %7B%0A
+            this.file = file;%0A
             this
@@ -1615,32 +1615,100 @@
 e%3E sequences) %7B%0A
+        String file = options.cmdLine.getOptionValue(%22input-file%22);%0A
         JSONOutp
@@ -1745,16 +1745,22 @@
 Wrapper(
+file, 
 ast, seq

Print name of the input file in output JSON