1 23 24 package org.enhydra.xml.xmlc.codegen; 25 26 27 30 public final class JavaCode { 31 34 private static final int INIT_BUFFER_SIZE = 1024; 35 36 40 private StringIndentWriter fVars; 41 42 45 private StringIndentWriter fCode = new StringIndentWriter(INIT_BUFFER_SIZE); 46 47 50 public JavaCode() { 51 } 52 53 56 public final void enter() { 57 fCode.enter(); 58 } 59 60 63 public final void leave() { 64 fCode.leave(); 65 } 66 67 70 public void addln() { 71 fCode.println(); 72 } 73 74 77 public void add(String code) { 78 fCode.print(code); 79 } 80 81 84 public void addln(String line) { 85 fCode.println(line); 86 } 87 88 91 public void addln(String [] lines) { 92 for (int idx = 0; idx < lines.length; idx++) { 93 fCode.println(lines[idx]); 94 } 95 } 96 97 101 public void addVars(String line) { 102 if (fVars == null) { 103 fVars = new StringIndentWriter(INIT_BUFFER_SIZE); 104 } 105 fVars.println(line); 106 } 107 108 111 public void addVars(String [] lines) { 112 for (int idx = 0; idx < lines.length; idx++) { 113 addVars(lines[idx]); 114 } 115 } 116 117 120 public boolean isEmpty() { 121 return ((fVars == null) && (fCode.getBuffer().length() == 0)); 122 } 123 124 127 public void print(IndentWriter out) { 128 if (fVars != null) { 129 out.print(fVars.toString()); 130 } 131 out.print(fCode.toString()); 132 } 133 } 134 | Popular Tags |