1 19 package org.netbeans.jmi.javamodel.codegen.RenameTests; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 import junit.textui.TestRunner; 24 import org.netbeans.jmi.javamodel.Assignment; 25 import org.netbeans.jmi.javamodel.Constructor; 26 import org.netbeans.jmi.javamodel.ExpressionStatement; 27 import org.netbeans.jmi.javamodel.Feature; 28 import org.netbeans.jmi.javamodel.ForStatement; 29 import org.netbeans.jmi.javamodel.IfStatement; 30 import org.netbeans.jmi.javamodel.InfixExpression; 31 import org.netbeans.jmi.javamodel.JavaClass; 32 import org.netbeans.jmi.javamodel.JavaModelPackage; 33 import org.netbeans.jmi.javamodel.Literal; 34 import org.netbeans.jmi.javamodel.LocalVarDeclaration; 35 import org.netbeans.jmi.javamodel.LocalVariable; 36 import org.netbeans.jmi.javamodel.Method; 37 import org.netbeans.jmi.javamodel.MethodInvocation; 38 import org.netbeans.jmi.javamodel.NewClassExpression; 39 import org.netbeans.jmi.javamodel.StatementBlock; 40 import org.netbeans.jmi.javamodel.codegen.Utility; 41 import org.netbeans.jmi.javamodel.codegen.CodegenTestCase; 42 import org.netbeans.junit.NbTestSuite; 43 44 49 public class RenameTestMethod extends CodegenTestCase { 50 51 52 public RenameTestMethod(String name) { 53 super(name, "RenameTestMethod"); 54 } 55 56 public static NbTestSuite suite() { 57 NbTestSuite suite = new NbTestSuite(); 58 suite.addTest(new RenameTestMethod("testRename")); 59 return suite; 60 } 61 62 JavaClass clazz; 63 JavaModelPackage pkg; 64 Feature[] feature = new Feature[5]; 65 66 private static final String newName = "renamedMethod"; 67 68 protected void setUp() { 69 clazz = Utility.findClass("org.netbeans.test.codegen.RenameTestMethod"); 70 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 71 int i = 0; 73 for (Iterator fIt = clazz.getFeatures().iterator(); fIt.hasNext(); i++) { 74 feature[i] = (Feature) fIt.next(); 75 } 76 } 77 78 public void testRename() { 79 boolean fail = true; 80 Utility.beginTrans(true); 81 try { 82 feature[2].setName(newName); 83 84 Method callerMethod = (Method) feature[3]; 85 StatementBlock body = callerMethod.getBody(); 86 List st = body.getStatements(); 87 88 LocalVarDeclaration lvd = (LocalVarDeclaration) st.get(0); 90 LocalVariable lv = (LocalVariable) lvd.getVariables().get(0); 91 MethodInvocation mi = (MethodInvocation) lv.getInitialValue(); 92 mi.setName(newName); 93 94 Assignment ass = (Assignment) ((ExpressionStatement) st.get(1)).getExpression(); 96 InfixExpression infx = (InfixExpression) ass.getRightSide(); 97 mi = (MethodInvocation) infx.getLeftSide(); 98 mi.setName(newName); 99 mi = (MethodInvocation) infx.getRightSide(); 100 mi.setName(newName); 101 102 IfStatement ifstmt = (IfStatement) st.get(2); 106 StatementBlock block = (StatementBlock) ifstmt.getThenPart(); 107 mi = (MethodInvocation) ((ExpressionStatement) block.getStatements().get(0)).getExpression(); 108 mi.setName(newName); 109 mi = (MethodInvocation) mi.getParameters().get(0); 110 mi.setName(newName); 111 112 callerMethod = (Method) feature[4]; 113 body = callerMethod.getBody(); 114 115 mi = (MethodInvocation) ((ExpressionStatement) body.getStatements().get(0)).getExpression(); 117 mi.setName(newName); 118 119 fail = false; 120 121 } 122 finally { 123 Utility.endTrans(fail); 124 } 125 makeDiff("testRename"); 126 } 127 128 131 public static void main(String [] args) { 132 TestRunner.run(suite()); 133 } 134 135 } 136 | Popular Tags |