KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > asm > AnnotationsTest


1 /***
2  * ASM tests
3  * Copyright (c) 2002-2005 France Telecom
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package org.objectweb.asm;
31
32 import org.objectweb.asm.commons.EmptyVisitor;
33
34 import junit.framework.TestSuite;
35
36 /**
37  * Annotations tests.
38  *
39  * @author Eric Bruneton
40  */

41 public class AnnotationsTest extends AbstractTest {
42
43     public static TestSuite suite() throws Exception JavaDoc {
44         return new AnnotationsTest().getSuite();
45     }
46
47     public void test() throws Exception JavaDoc {
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 JavaDoc desc,
65             final boolean visible)
66         {
67             return new EmptyVisitor();
68         }
69
70         public MethodVisitor visitMethod(
71             final int access,
72             final String JavaDoc name,
73             final String JavaDoc desc,
74             final String JavaDoc signature,
75             final String JavaDoc[] 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 JavaDoc desc,
90                     boolean visible)
91                 {
92                     return new EmptyVisitor();
93                 }
94
95                 public AnnotationVisitor visitParameterAnnotation(
96                     int parameter,
97                     String JavaDoc 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 JavaDoc desc,
114             final boolean visible)
115         {
116             return null;
117         }
118
119         public MethodVisitor visitMethod(
120             final int access,
121             final String JavaDoc name,
122             final String JavaDoc desc,
123             final String JavaDoc signature,
124             final String JavaDoc[] 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 JavaDoc desc,
139                     boolean visible)
140                 {
141                     return null;
142                 }
143
144                 public AnnotationVisitor visitParameterAnnotation(
145                     int parameter,
146                     String JavaDoc desc,
147                     boolean visible)
148                 {
149                     return null;
150                 }
151             };
152         }
153     }
154 }
155
Popular Tags