1 23 24 package org.enhydra.xml.xmlc.codegen; 25 26 33 public class VarNames { 34 37 private String type; 38 39 42 private String prefix; 43 44 47 private int maxLevel = -1; 48 49 54 public VarNames(String varType, String varPrefix) { 55 type = varType; 56 prefix = varPrefix; 57 } 58 59 64 public String getVarName(int level) { 65 if (maxLevel < level) { 66 maxLevel = level; 67 } 68 return prefix + level; 69 } 70 71 75 public String getVarDefs() { 76 if (maxLevel < 0) { 77 return null; 78 } 79 StringBuffer def = new StringBuffer (type + " "); 80 for (int level = 0; level <= maxLevel; level++) { 81 if (level > 0) { 82 def.append(", "); 83 } 84 def.append(prefix+level); 85 } 86 def.append(";"); 87 return def.toString(); 88 } 89 90 93 public void insertVarDefs(JavaCode body) { 94 String defs = getVarDefs(); 95 if (defs != null) { 96 body.addVars(defs); 97 } 98 } 99 } 100 | Popular Tags |