package codegen;

import java.io.PrintStream;

public class Output {
    private static final String INDENT = "  "; // two spaces

    private String indent = "";
    private PrintStream stream;

    public Output(PrintStream s) {
        stream = s;
    }

    public void increaseIndent() {
        indent += INDENT;
    }

    public void decreaseIndent() {
        indent = indent.substring(0, indent.length() - INDENT.length());
    }

    public void setOutputStream(PrintStream s) {
        stream = s;
    }

    public void write(String s) {
        stream.print(indent + s);
    }

    public void writeLine(String s) {
        stream.println(indent + s);
    }

    public void writeLine() {
        stream.println();
    }
}

@@ -187,16 +187,52 @@
  stream;
+%0A    private boolean newLine = true;
 %0A%0A    pu
@@ -601,27 +601,69 @@
 m.print(
-indent + s)
+(newLine ? indent : %22%22) + s);%0A        newLine = false
 ;%0A    %7D%0A
@@ -728,19 +728,60 @@
 tln(
-indent + s)
+(newLine ? indent : %22%22) + s);%0A        newLine = true
 ;%0A  

Fix indent bug in codegen.Output.