1 30 package org.objectweb.asm; 31 32 import org.objectweb.asm.commons.EmptyVisitor; 33 34 import junit.framework.TestSuite; 35 36 41 public class AnnotationsTest extends AbstractTest { 42 43 public static TestSuite suite() throws Exception { 44 return new AnnotationsTest().getSuite(); 45 } 46 47 public void test() throws Exception { 48 ClassReader cr = new ClassReader(is); 49 ClassWriter cw1 = new ClassWriter(0); 50 ClassWriter cw2 = new ClassWriter(0); 51 cr.accept(new RemoveAnnotationsAdapter1(cw1), 0); 52 cr.accept(new RemoveAnnotationsAdapter2(cw2), 0); 53 assertEquals(new ClassReader(cw2.toByteArray()), 54 new ClassReader(cw1.toByteArray())); 55 } 56 57 static class RemoveAnnotationsAdapter1 extends ClassAdapter { 58 59 public RemoveAnnotationsAdapter1(final ClassVisitor cv) { 60 super(cv); 61 } 62 63 public AnnotationVisitor visitAnnotation( 64 final String desc, 65 final boolean visible) 66 { 67 return new EmptyVisitor(); 68 } 69 70 public MethodVisitor visitMethod( 71 final int access, 72 final String name, 73 final String desc, 74 final String signature, 75 final String [] exceptions) 76 { 77 return new MethodAdapter(cv.visitMethod(access, 78 name, 79 desc, 80 signature, 81 exceptions)) 82 { 83 84 public AnnotationVisitor visitAnnotationDefault() { 85 return new EmptyVisitor(); 86 } 87 88 public AnnotationVisitor visitAnnotation( 89 String desc, 90 boolean visible) 91 { 92 return new EmptyVisitor(); 93 } 94 95 public AnnotationVisitor visitParameterAnnotation( 96 int parameter, 97 String desc, 98 boolean visible) 99 { 100 return new EmptyVisitor(); 101 } 102 }; 103 } 104 } 105 106 static class RemoveAnnotationsAdapter2 extends ClassAdapter { 107 108 public RemoveAnnotationsAdapter2(final ClassVisitor cv) { 109 super(cv); 110 } 111 112 public AnnotationVisitor visitAnnotation( 113 final String desc, 114 final boolean visible) 115 { 116 return null; 117 } 118 119 public MethodVisitor visitMethod( 120 final int access, 121 final String name, 122 final String desc, 123 final String signature, 124 final String [] exceptions) 125 { 126 return new MethodAdapter(cv.visitMethod(access, 127 name, 128 desc, 129 signature, 130 exceptions)) 131 { 132 133 public AnnotationVisitor visitAnnotationDefault() { 134 return null; 135 } 136 137 public AnnotationVisitor visitAnnotation( 138 String desc, 139 boolean visible) 140 { 141 return null; 142 } 143 144 public AnnotationVisitor visitParameterAnnotation( 145 int parameter, 146 String desc, 147 boolean visible) 148 { 149 return null; 150 } 151 }; 152 } 153 } 154 } 155 | Popular Tags |