public void finishOutput() throws IOException {
   currentOutput.close();
   if (grammar != null) {
     PrintWriter smapWriter;
     smapWriter = tool.openOutputFile(grammar.getClassName() + ".smap");
     String grammarFile = grammar.getFilename();
     grammarFile = grammarFile.replace('\\', '/');
     int lastSlash = grammarFile.lastIndexOf('/');
     if (lastSlash != -1) {
       grammarFile = grammarFile.substring(lastSlash + 1);
     }
     smapOutput.dump(smapWriter, grammar.getClassName(), grammarFile);
     sourceMaps.put(currentFileName, smapOutput.getSourceMap());
   }
   currentOutput = null;
 }
  public PrintWriter setupOutput(Tool tool, Grammar grammar, String fileName) throws IOException {
    this.tool = tool;
    this.grammar = grammar;

    if (fileName == null) {
      fileName = grammar.getClassName();
    }

    smapOutput = new PrintWriterWithSMAP(tool.openOutputFile(fileName + ".java"));
    currentFileName = fileName + ".java";
    currentOutput = smapOutput;
    return currentOutput;
  }