1 19 package org.netbeans.jmi.javamodel.codegen.indent; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import org.netbeans.jmi.javamodel.Annotation; 26 import org.netbeans.jmi.javamodel.JavaClass; 27 import org.netbeans.jmi.javamodel.JavaModelPackage; 28 import org.netbeans.jmi.javamodel.Method; 29 import org.netbeans.jmi.javamodel.MultipartId; 30 import org.netbeans.jmi.javamodel.codegen.Utility; 31 import org.netbeans.junit.NbTestCase; 32 import org.netbeans.junit.NbTestSuite; 33 import org.openide.filesystems.FileStateInvalidException; 34 35 39 public class AnnIndentTest2 extends NbTestCase { 40 41 JavaClass clazz; 42 JavaModelPackage pkg; 43 44 45 public AnnIndentTest2() { 46 super("AnnIndentTest2"); 47 } 48 49 public static NbTestSuite suite() { 50 NbTestSuite suite = new NbTestSuite(AnnIndentTest2.class); 51 return suite; 52 } 53 54 protected void setUp() { 55 clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.AnnIndentClass2"); 56 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 57 } 58 59 public void testAddAnns() throws java.io.IOException , FileStateInvalidException { 60 boolean fail = true; 61 Utility.beginTrans(true); 62 try { 63 MultipartId type1 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST); 64 MultipartId type2 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST); 65 Annotation ann1 = pkg.getAnnotation().createAnnotation(type1, Collections.EMPTY_LIST); 66 Annotation ann2 = pkg.getAnnotation().createAnnotation(type2, Collections.EMPTY_LIST); 67 clazz.getAnnotations().add(ann1); 68 clazz.getAnnotations().add(ann2); 69 Method m = pkg.getMethod().createMethod("newMethod", Collections.EMPTY_LIST, Modifier.PUBLIC, null, null, null, null, null, null, null, 70 pkg.getMultipartId().createMultipartId("void", null, null), 0); 71 clazz.getContents().add(m); 72 fail = false; 73 } finally { 74 Utility.endTrans(fail); 75 } 76 fail = true; 77 Utility.beginTrans(true); 78 try { 79 Method m = (Method) clazz.getContents().get(1); 80 MultipartId type3 = pkg.getMultipartId().createMultipartId("Deprecated()", null, Collections.EMPTY_LIST); 81 Annotation ann3 = pkg.getAnnotation().createAnnotation(type3, Collections.EMPTY_LIST); 82 List annList = m.getAnnotations(); 83 annList.add(ann3); 84 fail = false; 85 } finally { 86 Utility.endTrans(fail); 87 } 88 fail = true; 89 Utility.beginTrans(true); 90 try { 91 Method m = (Method) clazz.getContents().get(1); 92 MultipartId type4 = pkg.getMultipartId().createMultipartId("Deprecated2()", null, Collections.EMPTY_LIST); 93 Annotation ann4 = pkg.getAnnotation().createAnnotation(type4, Collections.EMPTY_LIST); 94 List annList = m.getAnnotations(); 95 annList.add(ann4); 96 fail = false; 97 } finally { 98 Utility.endTrans(fail); 99 } 100 assertFile("File is not correctly generated.", 101 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/AnnIndentClass2.java"), 102 getGoldenFile("testAddAnns_AnnIndentTest2.pass"), 103 getWorkDir() 104 ); 105 } 106 107 } 108 | Popular Tags |