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. 028 029package io.ebean.enhance.asm.commons; 030 031import io.ebean.enhance.asm.AnnotationVisitor; 032import io.ebean.enhance.asm.FieldVisitor; 033import io.ebean.enhance.asm.Opcodes; 034import io.ebean.enhance.asm.TypePath; 035 036/** 037 * A {@link FieldVisitor} that remaps types with a {@link Remapper}. 038 * 039 * @author Eugene Kuleshov 040 */ 041public class FieldRemapper extends FieldVisitor { 042 043 /** The remapper used to remap the types in the visited field. */ 044 protected final Remapper remapper; 045 046 /** 047 * Constructs a new {@link FieldRemapper}. <i>Subclasses must not use this constructor</i>. 048 * Instead, they must use the {@link #FieldRemapper(int, FieldVisitor, Remapper)} version. 049 * 050 * @param fieldVisitor the field visitor this remapper must deleted to. 051 * @param remapper the remapper to use to remap the types in the visited field. 052 */ 053 public FieldRemapper(final FieldVisitor fieldVisitor, final Remapper remapper) { 054 this(Opcodes.ASM7, fieldVisitor, remapper); 055 } 056 057 /** 058 * Constructs a new {@link FieldRemapper}. 059 * 060 * @param api the ASM API version supported by this remapper. Must be one of {@link 061 * Opcodes#ASM4}, {@link Opcodes#ASM5} or {@link 062 * Opcodes#ASM6}. 063 * @param fieldVisitor the field visitor this remapper must deleted to. 064 * @param remapper the remapper to use to remap the types in the visited field. 065 */ 066 protected FieldRemapper(final int api, final FieldVisitor fieldVisitor, final Remapper remapper) { 067 super(api, fieldVisitor); 068 this.remapper = remapper; 069 } 070 071 @Override 072 public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) { 073 AnnotationVisitor annotationVisitor = 074 super.visitAnnotation(remapper.mapDesc(descriptor), visible); 075 return annotationVisitor == null 076 ? null 077 : new AnnotationRemapper(api, annotationVisitor, remapper); 078 } 079 080 @Override 081 public AnnotationVisitor visitTypeAnnotation( 082 final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) { 083 AnnotationVisitor annotationVisitor = 084 super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(descriptor), visible); 085 return annotationVisitor == null 086 ? null 087 : new AnnotationRemapper(api, annotationVisitor, remapper); 088 } 089}