001// ASM: a very small and fast Java bytecode manipulation framework 002// Copyright (c) 2000-2011 INRIA, France Telecom 003// All rights reserved. 004// 005// Redistribution and use in source and binary forms, with or without 006// modification, are permitted provided that the following conditions 007// are met: 008// 1. Redistributions of source code must retain the above copyright 009// notice, this list of conditions and the following disclaimer. 010// 2. Redistributions in binary form must reproduce the above copyright 011// notice, this list of conditions and the following disclaimer in the 012// documentation and/or other materials provided with the distribution. 013// 3. Neither the name of the copyright holders nor the names of its 014// contributors may be used to endorse or promote products derived from 015// this software without specific prior written permission. 016// 017// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 018// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 019// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 020// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 021// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 022// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 023// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 024// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 025// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 026// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 027// THE POSSIBILITY OF SUCH DAMAGE. 028package io.ebean.enhance.asm; 029 030/** 031 * A visitor to visit a record component. The methods of this class must be called in the following 032 * order: ( {@code visitAnnotation} | {@code visitTypeAnnotation} | {@code visitAttribute} )* {@code 033 * visitEnd}. 034 * 035 * @author Remi Forax 036 * @author Eric Bruneton 037 */ 038public abstract class RecordComponentVisitor { 039 /** 040 * The ASM API version implemented by this visitor. The value of this field must be one of {@link 041 * Opcodes#ASM8} or {@link Opcodes#ASM9}. 042 */ 043 protected final int api; 044 045 /** 046 * The record visitor to which this visitor must delegate method calls. May be {@literal null}. 047 */ 048 protected RecordComponentVisitor delegate; 049 050 /** 051 * Constructs a new {@link RecordComponentVisitor}. 052 * 053 * @param api the ASM API version implemented by this visitor. Must be one of {@link Opcodes#ASM8} 054 * or {@link Opcodes#ASM9}. 055 */ 056 protected RecordComponentVisitor(final int api) { 057 this(api, null); 058 } 059 060 /** 061 * Constructs a new {@link RecordComponentVisitor}. 062 * 063 * @param api the ASM API version implemented by this visitor. Must be {@link Opcodes#ASM8}. 064 * @param recordComponentVisitor the record component visitor to which this visitor must delegate 065 * method calls. May be null. 066 */ 067 protected RecordComponentVisitor( 068 final int api, final RecordComponentVisitor recordComponentVisitor) { 069 if (api != Opcodes.ASM9 070 && api != Opcodes.ASM8 071 && api != Opcodes.ASM7 072 && api != Opcodes.ASM6 073 && api != Opcodes.ASM5 074 && api != Opcodes.ASM4 075 && api != Opcodes.ASM10_EXPERIMENTAL) { 076 throw new IllegalArgumentException("Unsupported api " + api); 077 } 078 if (api == Opcodes.ASM10_EXPERIMENTAL) { 079 Constants.checkAsmExperimental(this); 080 } 081 this.api = api; 082 this.delegate = recordComponentVisitor; 083 } 084 085 /** 086 * The record visitor to which this visitor must delegate method calls. May be {@literal null}. 087 * 088 * @return the record visitor to which this visitor must delegate method calls, or {@literal 089 * null}. 090 */ 091 public RecordComponentVisitor getDelegate() { 092 return delegate; 093 } 094 095 /** 096 * Visits an annotation of the record component. 097 * 098 * @param descriptor the class descriptor of the annotation class. 099 * @param visible {@literal true} if the annotation is visible at runtime. 100 * @return a visitor to visit the annotation values, or {@literal null} if this visitor is not 101 * interested in visiting this annotation. 102 */ 103 public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { 104 if (delegate != null) { 105 return delegate.visitAnnotation(descriptor, visible); 106 } 107 return null; 108 } 109 110 /** 111 * Visits an annotation on a type in the record component signature. 112 * 113 * @param typeRef a reference to the annotated type. The sort of this type reference must be 114 * {@link TypeReference#CLASS_TYPE_PARAMETER}, {@link 115 * TypeReference#CLASS_TYPE_PARAMETER_BOUND} or {@link TypeReference#CLASS_EXTENDS}. See 116 * {@link TypeReference}. 117 * @param typePath the path to the annotated type argument, wildcard bound, array element type, or 118 * static inner type within 'typeRef'. May be {@literal null} if the annotation targets 119 * 'typeRef' as a whole. 120 * @param descriptor the class descriptor of the annotation class. 121 * @param visible {@literal true} if the annotation is visible at runtime. 122 * @return a visitor to visit the annotation values, or {@literal null} if this visitor is not 123 * interested in visiting this annotation. 124 */ 125 public AnnotationVisitor visitTypeAnnotation( 126 final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { 127 if (delegate != null) { 128 return delegate.visitTypeAnnotation(typeRef, typePath, descriptor, visible); 129 } 130 return null; 131 } 132 133 /** 134 * Visits a non standard attribute of the record component. 135 * 136 * @param attribute an attribute. 137 */ 138 public void visitAttribute(final Attribute attribute) { 139 if (delegate != null) { 140 delegate.visitAttribute(attribute); 141 } 142 } 143 144 /** 145 * Visits the end of the record component. This method, which is the last one to be called, is 146 * used to inform the visitor that everything have been visited. 147 */ 148 public void visitEnd() { 149 if (delegate != null) { 150 delegate.visitEnd(); 151 } 152 } 153}