1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. Oracle designates this 7 * particular file as subject to the "Classpath" exception as provided 8 * by Oracle in the LICENSE file that accompanied this code. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 /* 26 * This file is available under and governed by the GNU General Public 27 * License version 2 only, as published by the Free Software Foundation. 28 * However, the following notice accompanied the original version of this 29 * file: 30 * 31 * ASM: a very small and fast Java bytecode manipulation framework 32 * Copyright (c) 2000-2011 INRIA, France Telecom 33 * All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 1. Redistributions of source code must retain the above copyright 39 * notice, this list of conditions and the following disclaimer. 40 * 2. Redistributions in binary form must reproduce the above copyright 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 3. Neither the name of the copyright holders nor the names of its 44 * contributors may be used to endorse or promote products derived from 45 * this software without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 51 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 52 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 53 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 54 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 55 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 56 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 57 * THE POSSIBILITY OF SUCH DAMAGE. 58 */ 59 package jdk.internal.org.objectweb.asm; 60 61 /** 62 * A visitor to visit a Java annotation. The methods of this class must be 63 * called in the following order: ( <tt>visit</tt> | <tt>visitEnum</tt> | 64 * <tt>visitAnnotation</tt> | <tt>visitArray</tt> )* <tt>visitEnd</tt>. 65 * 66 * @author Eric Bruneton 67 * @author Eugene Kuleshov 68 */ 69 public abstract class AnnotationVisitor { 70 71 /** 72 * The ASM API version implemented by this visitor. The value of this field 73 * must be one of {@link Opcodes#ASM4}. 74 */ 75 protected final int api; 76 77 /** 78 * The annotation visitor to which this visitor must delegate method calls. 79 * May be null. 80 */ 81 protected AnnotationVisitor av; 82 83 /** 84 * Constructs a new {@link AnnotationVisitor}. 85 * 86 * @param api the ASM API version implemented by this visitor. Must be one 87 * of {@link Opcodes#ASM4}. 88 */ 89 public AnnotationVisitor(final int api) { 90 this(api, null); 91 } 92 93 /** 94 * Constructs a new {@link AnnotationVisitor}. 95 * 96 * @param api the ASM API version implemented by this visitor. Must be one 97 * of {@link Opcodes#ASM4}. 98 * @param av the annotation visitor to which this visitor must delegate 99 * method calls. May be null. 100 */ 101 public AnnotationVisitor(final int api, final AnnotationVisitor av) { 102 /*if (api != Opcodes.ASM4) { 103 throw new IllegalArgumentException(); 104 }*/ 105 this.api = api; 106 this.av = av; 107 } 108 109 /** 110 * Visits a primitive value of the annotation. 111 * 112 * @param name the value name. 113 * @param value the actual value, whose type must be {@link Byte}, 114 * {@link Boolean}, {@link Character}, {@link Short}, {@link Integer} 115 * , {@link Long}, {@link Float}, {@link Double}, {@link String} or 116 * {@link Type} or OBJECT or ARRAY sort. This value can also be an 117 * array of byte, boolean, short, char, int, long, float or double 118 * values (this is equivalent to using {@link #visitArray visitArray} 119 * and visiting each array element in turn, but is more convenient). 120 */ 121 public void visit(String name, Object value) { 122 if (av != null) { 123 av.visit(name, value); 124 } 125 } 126 127 /** 128 * Visits an enumeration value of the annotation. 129 * 130 * @param name the value name. 131 * @param desc the class descriptor of the enumeration class. 132 * @param value the actual enumeration value. 133 */ 134 public void visitEnum(String name, String desc, String value) { 135 if (av != null) { 136 av.visitEnum(name, desc, value); 137 } 138 } 139 140 /** 141 * Visits a nested annotation value of the annotation. 142 * 143 * @param name the value name. 144 * @param desc the class descriptor of the nested annotation class. 145 * @return a visitor to visit the actual nested annotation value, or 146 * <tt>null</tt> if this visitor is not interested in visiting 147 * this nested annotation. <i>The nested annotation value must be 148 * fully visited before calling other methods on this annotation 149 * visitor</i>. 150 */ 151 public AnnotationVisitor visitAnnotation(String name, String desc) { 152 if (av != null) { 153 return av.visitAnnotation(name, desc); 154 } 155 return null; 156 } 157 158 /** 159 * Visits an array value of the annotation. Note that arrays of primitive 160 * types (such as byte, boolean, short, char, int, long, float or double) 161 * can be passed as value to {@link #visit visit}. This is what 162 * {@link ClassReader} does. 163 * 164 * @param name the value name. 165 * @return a visitor to visit the actual array value elements, or 166 * <tt>null</tt> if this visitor is not interested in visiting 167 * these values. The 'name' parameters passed to the methods of this 168 * visitor are ignored. <i>All the array values must be visited 169 * before calling other methods on this annotation visitor</i>. 170 */ 171 public AnnotationVisitor visitArray(String name) { 172 if (av != null) { 173 return av.visitArray(name); 174 } 175 return null; 176 } 177 178 /** 179 * Visits the end of the annotation. 180 */ 181 public void visitEnd() { 182 if (av != null) { 183 av.visitEnd(); 184 } 185 } 186 }