2 * ASM: a very small and fast Java bytecode manipulation framework
3 * Copyright (c) 2000-2005 INRIA, France Telecom
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
30 package org.objectweb.asm.optimizer;
32 import org.objectweb.asm.AnnotationVisitor;
33 import org.objectweb.asm.Type;
36 * An {@link AnnotationVisitor} that collects the {@link Constant}s of the
37 * annotations it visits.
39 * @author Eric Bruneton
41 public class AnnotationConstantsCollector implements AnnotationVisitor {
43 private AnnotationVisitor av;
45 private ConstantPool cp;
47 public AnnotationConstantsCollector(
48 final AnnotationVisitor av,
49 final ConstantPool cp)
55 public void visit(final String name, final Object value) {
59 if (value instanceof Byte) {
60 cp.newInteger(((Byte) value).byteValue());
61 } else if (value instanceof Boolean) {
62 cp.newInteger(((Boolean) value).booleanValue() ? 1 : 0);
63 } else if (value instanceof Character) {
64 cp.newInteger(((Character) value).charValue());
65 } else if (value instanceof Short) {
66 cp.newInteger(((Short) value).shortValue());
67 } else if (value instanceof Type) {
68 cp.newUTF8(((Type) value).getDescriptor());
69 } else if (value instanceof byte[]) {
70 byte[] v = (byte[]) value;
71 for (int i = 0; i < v.length; i++) {
74 } else if (value instanceof boolean[]) {
75 boolean[] v = (boolean[]) value;
76 for (int i = 0; i < v.length; i++) {
77 cp.newInteger(v[i] ? 1 : 0);
79 } else if (value instanceof short[]) {
80 short[] v = (short[]) value;
81 for (int i = 0; i < v.length; i++) {
84 } else if (value instanceof char[]) {
85 char[] v = (char[]) value;
86 for (int i = 0; i < v.length; i++) {
89 } else if (value instanceof int[]) {
90 int[] v = (int[]) value;
91 for (int i = 0; i < v.length; i++) {
94 } else if (value instanceof long[]) {
95 long[] v = (long[]) value;
96 for (int i = 0; i < v.length; i++) {
99 } else if (value instanceof float[]) {
100 float[] v = (float[]) value;
101 for (int i = 0; i < v.length; i++) {
104 } else if (value instanceof double[]) {
105 double[] v = (double[]) value;
106 for (int i = 0; i < v.length; i++) {
112 av.visit(name, value);
115 public void visitEnum(
125 av.visitEnum(name, desc, value);
128 public AnnotationVisitor visitAnnotation(
136 return new AnnotationConstantsCollector(av.visitAnnotation(name, desc),
140 public AnnotationVisitor visitArray(final String name) {
144 return new AnnotationConstantsCollector(av.visitArray(name), cp);
147 public void visitEnd() {