/** * Load a class in and modify it with a new attribute - A SimpleAnnotation * annotation */ public void testModifyingClasses1() throws ClassNotFoundException { final JavaClass jc = getTestClass(PACKAGE_BASE_NAME+".data.SimpleAnnotatedClass"); final ClassGen cgen = new ClassGen(jc); final ConstantPoolGen cp = cgen.getConstantPool(); cgen.addAnnotationEntry(createFruitAnnotation(cp, "Pineapple")); assertTrue("Should now have two annotations but has " + cgen.getAnnotationEntries().length, cgen .getAnnotationEntries().length == 2); dumpClass(cgen, "SimpleAnnotatedClass.class"); assertTrue(wipe("SimpleAnnotatedClass.class")); }
final ConstantPoolGen cp = cg.getConstantPool(); final InstructionList il = new InstructionList(); cg.addAnnotationEntry(createSimpleVisibleAnnotation(cp)); cg.addAnnotationEntry(createSimpleInvisibleAnnotation(cp)); buildClassContents(cg, cp, il);
addAnnotationEntry(annotation);
/** * Load a class in and modify it with a new attribute - A ComplexAnnotation * annotation */ public void testModifyingClasses2() throws ClassNotFoundException { final JavaClass jc = getTestClass(PACKAGE_BASE_NAME+".data.SimpleAnnotatedClass"); final ClassGen cgen = new ClassGen(jc); final ConstantPoolGen cp = cgen.getConstantPool(); cgen.addAnnotationEntry(createCombinedAnnotation(cp)); assertTrue("Should now have two annotations but has " + cgen.getAnnotationEntries().length, cgen .getAnnotationEntries().length == 2); dumpClass(cgen, "SimpleAnnotatedClass.class"); final JavaClass jc2 = getClassFrom(".", "SimpleAnnotatedClass"); jc2.getAnnotationEntries(); assertTrue(wipe("SimpleAnnotatedClass.class")); // System.err.println(jc2.toString()); }