|
1 | 1 | /*** |
2 | 2 | * ASM: a very small and fast Java bytecode manipulation framework |
3 | | - * Copyright (c) 2000-2007 INRIA, France Telecom |
| 3 | + * Copyright (c) 2000-2011 INRIA, France Telecom |
4 | 4 | * All rights reserved. |
5 | 5 | * |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
|
30 | 30 | package jersey.repackaged.org.objectweb.asm; |
31 | 31 |
|
32 | 32 | /** |
33 | | - * A visitor to visit a Java annotation. The methods of this interface must be |
34 | | - * called in the following order: (<tt>visit<tt> | <tt>visitEnum<tt> | |
35 | | - * <tt>visitAnnotation<tt> | <tt>visitArray<tt>)* <tt>visitEnd<tt>. |
36 | | - * |
| 33 | + * A visitor to visit a Java annotation. The methods of this class must be |
| 34 | + * called in the following order: ( <tt>visit</tt> | <tt>visitEnum</tt> | |
| 35 | + * <tt>visitAnnotation</tt> | <tt>visitArray</tt> )* <tt>visitEnd</tt>. |
| 36 | + * |
37 | 37 | * @author Eric Bruneton |
38 | 38 | * @author Eugene Kuleshov |
39 | 39 | */ |
40 | | -public interface AnnotationVisitor { |
| 40 | +public abstract class AnnotationVisitor { |
| 41 | + |
| 42 | + /** |
| 43 | + * The ASM API version implemented by this visitor. The value of this field |
| 44 | + * must be one of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. |
| 45 | + */ |
| 46 | + protected final int api; |
| 47 | + |
| 48 | + /** |
| 49 | + * The annotation visitor to which this visitor must delegate method calls. |
| 50 | + * May be null. |
| 51 | + */ |
| 52 | + protected AnnotationVisitor av; |
| 53 | + |
| 54 | + /** |
| 55 | + * Constructs a new {@link AnnotationVisitor}. |
| 56 | + * |
| 57 | + * @param api |
| 58 | + * the ASM API version implemented by this visitor. Must be one |
| 59 | + * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. |
| 60 | + */ |
| 61 | + public AnnotationVisitor(final int api) { |
| 62 | + this(api, null); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Constructs a new {@link AnnotationVisitor}. |
| 67 | + * |
| 68 | + * @param api |
| 69 | + * the ASM API version implemented by this visitor. Must be one |
| 70 | + * of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}. |
| 71 | + * @param av |
| 72 | + * the annotation visitor to which this visitor must delegate |
| 73 | + * method calls. May be null. |
| 74 | + */ |
| 75 | + public AnnotationVisitor(final int api, final AnnotationVisitor av) { |
| 76 | + if (api != Opcodes.ASM4 && api != Opcodes.ASM5) { |
| 77 | + throw new IllegalArgumentException(); |
| 78 | + } |
| 79 | + this.api = api; |
| 80 | + this.av = av; |
| 81 | + } |
41 | 82 |
|
42 | 83 | /** |
43 | 84 | * Visits a primitive value of the annotation. |
44 | | - * |
45 | | - * @param name the value name. |
46 | | - * @param value the actual value, whose type must be {@link Byte}, |
47 | | - * {@link Boolean}, {@link Character}, {@link Short}, |
48 | | - * {@link Integer}, {@link Long}, {@link Float}, {@link Double}, |
49 | | - * {@link String} or {@link Type}. This value can also be an array |
50 | | - * of byte, boolean, short, char, int, long, float or double values |
51 | | - * (this is equivalent to using {@link #visitArray visitArray} and |
52 | | - * visiting each array element in turn, but is more convenient). |
| 85 | + * |
| 86 | + * @param name |
| 87 | + * the value name. |
| 88 | + * @param value |
| 89 | + * the actual value, whose type must be {@link Byte}, |
| 90 | + * {@link Boolean}, {@link Character}, {@link Short}, |
| 91 | + * {@link Integer} , {@link Long}, {@link Float}, {@link Double}, |
| 92 | + * {@link String} or {@link Type} or OBJECT or ARRAY sort. This |
| 93 | + * value can also be an array of byte, boolean, short, char, int, |
| 94 | + * long, float or double values (this is equivalent to using |
| 95 | + * {@link #visitArray visitArray} and visiting each array element |
| 96 | + * in turn, but is more convenient). |
53 | 97 | */ |
54 | | - void visit(String name, Object value); |
| 98 | + public void visit(String name, Object value) { |
| 99 | + if (av != null) { |
| 100 | + av.visit(name, value); |
| 101 | + } |
| 102 | + } |
55 | 103 |
|
56 | 104 | /** |
57 | 105 | * Visits an enumeration value of the annotation. |
58 | | - * |
59 | | - * @param name the value name. |
60 | | - * @param desc the class descriptor of the enumeration class. |
61 | | - * @param value the actual enumeration value. |
| 106 | + * |
| 107 | + * @param name |
| 108 | + * the value name. |
| 109 | + * @param desc |
| 110 | + * the class descriptor of the enumeration class. |
| 111 | + * @param value |
| 112 | + * the actual enumeration value. |
62 | 113 | */ |
63 | | - void visitEnum(String name, String desc, String value); |
| 114 | + public void visitEnum(String name, String desc, String value) { |
| 115 | + if (av != null) { |
| 116 | + av.visitEnum(name, desc, value); |
| 117 | + } |
| 118 | + } |
64 | 119 |
|
65 | 120 | /** |
66 | 121 | * Visits a nested annotation value of the annotation. |
67 | | - * |
68 | | - * @param name the value name. |
69 | | - * @param desc the class descriptor of the nested annotation class. |
| 122 | + * |
| 123 | + * @param name |
| 124 | + * the value name. |
| 125 | + * @param desc |
| 126 | + * the class descriptor of the nested annotation class. |
70 | 127 | * @return a visitor to visit the actual nested annotation value, or |
71 | | - * <tt>null</tt> if this visitor is not interested in visiting |
72 | | - * this nested annotation. <i>The nested annotation value must be |
73 | | - * fully visited before calling other methods on this annotation |
| 128 | + * <tt>null</tt> if this visitor is not interested in visiting this |
| 129 | + * nested annotation. <i>The nested annotation value must be fully |
| 130 | + * visited before calling other methods on this annotation |
74 | 131 | * visitor</i>. |
75 | 132 | */ |
76 | | - AnnotationVisitor visitAnnotation(String name, String desc); |
| 133 | + public AnnotationVisitor visitAnnotation(String name, String desc) { |
| 134 | + if (av != null) { |
| 135 | + return av.visitAnnotation(name, desc); |
| 136 | + } |
| 137 | + return null; |
| 138 | + } |
77 | 139 |
|
78 | 140 | /** |
79 | 141 | * Visits an array value of the annotation. Note that arrays of primitive |
80 | 142 | * types (such as byte, boolean, short, char, int, long, float or double) |
81 | 143 | * can be passed as value to {@link #visit visit}. This is what |
82 | 144 | * {@link ClassReader} does. |
83 | | - * |
84 | | - * @param name the value name. |
| 145 | + * |
| 146 | + * @param name |
| 147 | + * the value name. |
85 | 148 | * @return a visitor to visit the actual array value elements, or |
86 | | - * <tt>null</tt> if this visitor is not interested in visiting |
87 | | - * these values. The 'name' parameters passed to the methods of this |
| 149 | + * <tt>null</tt> if this visitor is not interested in visiting these |
| 150 | + * values. The 'name' parameters passed to the methods of this |
88 | 151 | * visitor are ignored. <i>All the array values must be visited |
89 | 152 | * before calling other methods on this annotation visitor</i>. |
90 | 153 | */ |
91 | | - AnnotationVisitor visitArray(String name); |
| 154 | + public AnnotationVisitor visitArray(String name) { |
| 155 | + if (av != null) { |
| 156 | + return av.visitArray(name); |
| 157 | + } |
| 158 | + return null; |
| 159 | + } |
92 | 160 |
|
93 | 161 | /** |
94 | 162 | * Visits the end of the annotation. |
95 | 163 | */ |
96 | | - void visitEnd(); |
| 164 | + public void visitEnd() { |
| 165 | + if (av != null) { |
| 166 | + av.visitEnd(); |
| 167 | + } |
| 168 | + } |
97 | 169 | } |
0 commit comments