1 package test; 2 3 import java.io.File ; 4 import java.io.FileNotFoundException ; 5 import java.io.FileInputStream ; 6 import java.io.BufferedInputStream ; 7 import java.io.InputStreamReader ; 8 import java.io.LineNumberReader ; 9 import java.io.IOException ; 10 import java.util.HashMap ; 11 12 15 public class TestdataHandler { 16 private static HashMap instMap = new HashMap (); 17 public static TestdataHandler getInstance(String path) throws FileNotFoundException , IOException { 18 File file = new File (path); 19 path = file.getAbsolutePath(); 20 TestdataHandler inst = (TestdataHandler)instMap.get(path); 21 if (inst == null) { 22 inst = new TestdataHandler(path); 23 instMap.put(path, inst); 24 } 26 return inst; 27 } 28 29 private File rnlogFile; 30 33 private HashMap renameClassMap = new HashMap (); 34 private HashMap renameMethodMap = new HashMap (); 35 private HashMap renameFieldMap = new HashMap (); 36 37 private TestdataHandler(String path) throws FileNotFoundException , IOException { 38 if (path == null) { 39 throw new IllegalArgumentException ("path must be NOT null."); 40 } 41 if (path.length() <= 0) { 42 throw new IllegalArgumentException ("path must be 'path.length() > 0'."); 43 } 44 this.rnlogFile = new File (path + "_rnlog.txt"); 45 48 setupRenameMap(); 49 } 50 51 private void setupRenameMap() throws FileNotFoundException , IOException { 52 FileInputStream fin = new FileInputStream (this.rnlogFile); 53 LineNumberReader lnrd = new LineNumberReader ( 54 new InputStreamReader ( 55 new BufferedInputStream (fin))); 56 for (;;) { 57 String line = lnrd.readLine(); 58 if (line == null) { 59 break; 60 } 61 if (line.length() <= 0) { 62 continue; 63 } 64 int n = line.indexOf("\t <- ", 0); 65 if (n > 0) { 66 String str1 = line.substring(0, n); 67 String str2 = line.substring(n+5); if (str1.indexOf('!') > 0) { 69 renameFieldMap.put(str2, str1); 71 } else if (str1.indexOf('#') > 0) { 72 renameMethodMap.put(str2, str1); 74 } else { 75 renameClassMap.put(str2, str1); 77 } 78 } 79 } 80 lnrd.close(); 81 } 82 83 public String getNewClassNameByOld(String oldClassName) { 84 return (String )renameClassMap.get(oldClassName); 85 } 86 87 public String getNewMethodNameByOld(String oldMethodName) { 88 return (String )renameMethodMap.get(oldMethodName); 89 } 90 91 public String getNewFieldNameByOld(String oldFieldName) { 92 return (String )renameFieldMap.get(oldFieldName); 93 } 94 } 95 | Popular Tags |