1 5 package xdoclet.modules.mockobjects.util; 6 7 import java.util.ArrayList ; 8 import java.util.HashMap ; 9 import java.util.List ; 10 import java.util.Map ; 11 12 import xjavadoc.XClass; 13 14 21 public class CodeUtils 22 { 23 24 private final static Map wrappers = new HashMap (); 25 26 static { 27 wrappers.put("boolean", "Boolean"); 28 wrappers.put("char", "Character"); 29 wrappers.put("byte", "Byte"); 30 wrappers.put("short", "Short"); 31 wrappers.put("int", "Integer"); 32 wrappers.put("long", "Long"); 33 wrappers.put("float", "Float"); 34 wrappers.put("double", "Double"); 35 } 36 37 46 public static List getAllMethods(XClass startClass) 47 { 48 return new ArrayList (startClass.getMethods(true)); 49 } 50 51 public static String wrapValue(String name, String type) 52 { 53 if (wrappers.containsKey(type)) { 54 StringBuffer result = new StringBuffer (); 55 56 result.append("new "); 57 result.append(wrappers.get(type)); 58 result.append('('); 59 result.append(name); 60 result.append(')'); 61 return result.toString(); 62 } 63 else { 64 return name; 65 } 66 } 67 68 public static String unwrapValue(String name, String type) 69 { 70 StringBuffer result = new StringBuffer (); 71 72 if (wrappers.containsKey(type)) { 73 result.append("(("); 74 result.append(wrappers.get(type)); 75 result.append(')'); 76 result.append(name); 77 result.append(")."); 78 result.append(type); 79 result.append("Value()"); 80 } 81 else { 82 result.append('('); 83 result.append(type); 84 result.append(')'); 85 result.append(name); 86 } 87 return result.toString(); 88 } 89 90 public static String capitalize(String s) 91 { 92 return s.substring(0, 1).toUpperCase() + s.substring(1); 93 } 94 } 95 | Popular Tags |