1 19 package org.netbeans.jmi.javamodel.codegen.indent; 20 21 import org.netbeans.jmi.javamodel.Assignment; 22 import org.netbeans.jmi.javamodel.Constructor; 23 import org.netbeans.jmi.javamodel.Expression; 24 import org.netbeans.jmi.javamodel.InitialValue; 25 import org.netbeans.jmi.javamodel.JavaClass; 26 import org.netbeans.jmi.javamodel.JavaModelPackage; 27 import org.netbeans.jmi.javamodel.LocalVarDeclaration; 28 import org.netbeans.jmi.javamodel.LocalVariable; 29 import org.netbeans.jmi.javamodel.OperatorEnum; 30 import org.netbeans.jmi.javamodel.TryStatement; 31 import org.netbeans.jmi.javamodel.VariableAccess; 32 import org.netbeans.jmi.javamodel.codegen.Utility; 33 import org.netbeans.junit.NbTestCase; 34 import org.netbeans.junit.NbTestSuite; 35 import org.openide.filesystems.FileStateInvalidException; 36 37 41 public class BlenderTest extends NbTestCase { 42 43 JavaClass clazz; 44 JavaModelPackage pkg; 45 46 47 public BlenderTest() { 48 super("BlenderTest"); 49 } 50 public static NbTestSuite suite() { 51 NbTestSuite suite = new NbTestSuite(BlenderTest.class); 52 return suite; 53 } 54 55 protected void setUp() { 56 clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.Blender"); 57 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 58 } 59 60 public void testMixStatements() throws java.io.IOException , FileStateInvalidException { 61 boolean fail = true; 62 Utility.beginTrans(true); 63 try { 64 Constructor constructor = (Constructor) clazz.getContents().get(0); 65 TryStatement tryStmt = (TryStatement) constructor.getBody().getStatements().get(1); 66 LocalVarDeclaration lvd = (LocalVarDeclaration) tryStmt.getBody().getStatements().remove(0); 67 LocalVariable lv = (LocalVariable) lvd.getVariables().get(0); 68 InitialValue iv = lv.getInitialValue(); 69 lv.setInitialValue(null); 70 VariableAccess va = (VariableAccess) pkg.getVariableAccess().createVariableAccess(lv.getName(), null, false); 71 Assignment a = pkg.getAssignment().createAssignment(va, OperatorEnum.ASSIGN, (Expression) iv); 72 constructor.getBody().getStatements().add(1, lvd); 73 tryStmt.getBody().getStatements().add(0, pkg.getExpressionStatement().createExpressionStatement(a)); 74 fail = false; 75 } 76 finally { 77 Utility.endTrans(fail); 78 } 79 assertFile("File is not correctly generated.", 80 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/Blender.java"), 81 getGoldenFile("testMixStatements_BlenderTest.pass"), 82 getWorkDir() 83 ); 84 } 85 } 86 | Popular Tags |