1 19 package org.netbeans.jmi.javamodel.getters; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 import junit.textui.TestRunner; 24 import org.netbeans.jmi.javamodel.Annotation; 25 import org.netbeans.jmi.javamodel.Constructor; 26 import org.netbeans.jmi.javamodel.JavaClass; 27 import org.netbeans.jmi.javamodel.JavaModelPackage; 28 import org.netbeans.jmi.javamodel.LocalVarDeclaration; 29 import org.netbeans.jmi.javamodel.LocalVariable; 30 import org.netbeans.jmi.javamodel.codegen.Utility; 31 import org.netbeans.junit.NbTestCase; 32 import org.netbeans.junit.NbTestSuite; 33 34 38 public class AnnLocalVarTest extends NbTestCase { 39 40 JavaClass clazz; 41 JavaModelPackage pkg; 42 LocalVarDeclaration[] lvdecko = new LocalVarDeclaration[4]; 43 44 Annotation[] tmpAnnotation; 45 boolean isFinal; 46 47 48 public AnnLocalVarTest() { 49 super("AnnLocalVarTest"); 50 } 51 52 public static NbTestSuite suite() { 53 NbTestSuite suite = new NbTestSuite(AnnLocalVarTest.class); 54 return suite; 55 } 56 57 protected void setUp() { 58 clazz = (JavaClass) Utility.findClass("org.netbeans.test.getters.AnnotationLocVar"); 59 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 60 Constructor c = (Constructor) clazz.getContents().get(0); 61 int i = 0; 62 for (Iterator it = c.getBody().getStatements().iterator(); it.hasNext(); ) { 63 lvdecko[i++] = (LocalVarDeclaration) it.next(); 65 } 66 } 67 68 public void testStatement1() { 69 logData(0); 71 assertEquals(true, isFinal); 72 assertEquals(1, tmpAnnotation.length); 73 assertEquals("AnnotationType", tmpAnnotation[0].getTypeName().getName()); 74 } 75 76 public void testStatement2() { 77 logData(1); 79 assertEquals(false, isFinal); 80 assertEquals(2, tmpAnnotation.length); 81 assertEquals("SuppressWarnings", tmpAnnotation[0].getTypeName().getName()); 82 assertEquals("AnnotationType", tmpAnnotation[1].getTypeName().getName()); 83 } 84 85 public void testStatement3() { 86 logData(2); 88 assertEquals(true, isFinal); 89 assertEquals(0, tmpAnnotation.length); 90 } 91 92 public void testStatement4() { 93 logData(3); 95 assertEquals(true, isFinal); 96 assertEquals(2, tmpAnnotation.length); 97 assertEquals("AnnotationType", tmpAnnotation[0].getTypeName().getName()); 98 assertEquals("SuppressWarnings", tmpAnnotation[1].getTypeName().getName()); 99 } 100 101 private void logData(int statementIndex) { 102 Utility.beginTrans(false); 103 try { 104 LocalVarDeclaration l = lvdecko[statementIndex]; 105 isFinal = l.isFinal(); 106 getLog().println("Final? " + isFinal); 107 List anns = ((LocalVariable) l.getVariables().get(0)).getAnnotations(); 108 tmpAnnotation = new Annotation[anns.size()]; 109 int i = 0; 110 for (Iterator it = anns.iterator(); it.hasNext(); ) { 111 Annotation ann = (Annotation) it.next(); 112 tmpAnnotation[i++] = ann; 113 getLog().println("Ann: " + ann.getTypeName().getName()); 114 } 115 } 116 finally { 117 Utility.endTrans(); 118 } 119 } 120 121 124 public static void main(String [] args) { 125 TestRunner.run(suite()); 126 } 127 128 } 129 | Popular Tags |