1 package test.renaming; 2 3 import junit.framework.*; 4 5 import test.TestdataHandler; 6 7 13 public class RenamingTestBase extends TestCase { 14 public RenamingTestBase(String name) { 15 super(name); 16 } 17 18 private TestdataHandler tdh; 19 20 protected void setUp() throws java.io.IOException { 21 tdh = TestdataHandler.getInstance("testdata/testdata"); 22 } 23 24 protected void tearDown() { 25 tdh = null; 26 } 27 28 protected String getNewClassNameByOld(String oldClassName) { 29 return tdh.getNewClassNameByOld(oldClassName); 30 } 31 32 protected String getNewFieldNameByOld(String oldClassName, String oldFieldName) { 33 String newFieldName = tdh.getNewFieldNameByOld(oldClassName + "!" + oldFieldName); 34 int n = newFieldName.indexOf('!'); 35 return newFieldName.substring(n+1); 36 } 37 38 protected String getNewMethodNameByOld(String oldClassName, String oldMethodName, String oldMethodSig) { 39 String newMethodName = tdh.getNewMethodNameByOld(oldClassName + "#" + oldMethodName + oldMethodSig); 40 int n1 = newMethodName.indexOf('#'); 41 int n2 = newMethodName.indexOf('('); 42 return newMethodName.substring(n1+1, n2); 43 } 44 45 protected String getNewMethodSigByOld(String oldClassName, String oldMethodName, String oldMethodSig) { 46 String newMethodSig = tdh.getNewMethodNameByOld(oldClassName + "#" + oldMethodName + oldMethodSig); 47 int n = newMethodSig.indexOf('('); 48 return newMethodSig.substring(n); 49 } 50 51 protected String convNewMethodSigByOld(String oldMethodSig) { 52 StringBuffer sbuf = new StringBuffer (); 53 for (int i=0; i<oldMethodSig.length(); i++) { 54 char c = oldMethodSig.charAt(i); 55 if (c == 'L') { 56 i++; 57 StringBuffer sbufL = new StringBuffer (); 58 for (; i<oldMethodSig.length(); i++) { 59 char cc = oldMethodSig.charAt(i); 60 if (cc == ';') { 61 String oldClassName = sbufL.toString().replace('/', '.'); 62 String newClassName = getNewClassNameByOld(oldClassName); 63 if (newClassName == null) { 64 newClassName = oldClassName; 65 } 66 sbuf.append('L'); 67 sbuf.append(newClassName.replace('.', '/')); 68 sbuf.append(';'); 69 break; 70 } else { 71 sbufL.append(cc); 72 } 73 } 74 sbufL = null; 75 } else { 76 sbuf.append(c); 77 } 78 } 79 return sbuf.toString(); 80 } 81 82 protected void checkNameEquals(String oldName, String newName) { 83 this.assertEquals(oldName, newName); 84 } 85 86 protected void checkNameNotEquals(String oldName, String newName) { 87 this.assertTrue(!oldName.equals(newName)); 88 this.assertTrue(oldName.length() > newName.length()); 89 } 90 91 } 92 | Popular Tags |