1 2 package SOFA.SOFAnode.Made.CodeGen; 3 4 import java.io.File ; 5 import java.io.IOException ; 6 7 11 public class CGFileWriter extends java.io.FileWriter { 12 private int indent; 13 private boolean doIndent; 14 15 16 public CGFileWriter(String name) throws IOException { 17 super(name); 18 indent = 0; 19 doIndent = true; 20 } 21 22 public CGFileWriter(File file) throws IOException { 23 super(file); 24 indent = 0; 25 doIndent = true; 26 } 27 28 29 public static final String newLineSep = "\n"; 31 32 public static final int indentSize = 2; 33 34 35 36 public int curIndent() { 37 return indent; 38 } 39 40 41 public void incIndent() { 42 indent++; 43 } 44 45 46 public void decIndent() { 47 if (indent != 0) 48 indent--; 49 } 50 51 private void makeIndent() throws IOException { 52 if (doIndent) { 53 for (int i=0; i<indent * indentSize; i++) { 54 super.write(' '); 55 } 56 doIndent = false; 57 } 58 } 59 60 64 public void iwriteln() throws IOException { 65 makeIndent(); 66 super.write(newLineSep); 67 flush(); 68 doIndent = true; 69 } 70 71 76 public void iwriteln(String text) throws IOException { 77 makeIndent(); 78 super.write(text); 79 super.write(newLineSep); 80 flush(); 81 doIndent = true; 82 } 83 84 88 public void iwritespace(int number) throws IOException { 89 makeIndent(); 90 for (int i=0;i<number;i++) { 91 super.write(" "); 92 } 93 } 94 95 public void iwrite(char[] cbuf, int off, int len) throws IOException { 96 makeIndent(); 97 super.write(cbuf, off, len); 98 } 99 100 public void iwrite(int c) throws IOException { 101 makeIndent(); 102 super.write(c); 103 } 104 105 public void iwrite(String str, int off, int len) throws IOException { 106 makeIndent(); 107 super.write(str, off, len); 108 } 109 110 public void iwrite(char[] cbuf) throws IOException { 111 makeIndent(); 112 super.write(cbuf); 113 } 114 115 public void iwrite(String str) throws IOException { 116 makeIndent(); 117 super.write(str); 118 } 119 } 120 | Popular Tags |