|
Packit |
5e46da |
/***
|
|
Packit |
5e46da |
* ASM: a very small and fast Java bytecode manipulation framework
|
|
Packit |
5e46da |
* Copyright (c) 2000-2011 INRIA, France Telecom
|
|
Packit |
5e46da |
* All rights reserved.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
5e46da |
* modification, are permitted provided that the following conditions
|
|
Packit |
5e46da |
* are met:
|
|
Packit |
5e46da |
* 1. Redistributions of source code must retain the above copyright
|
|
Packit |
5e46da |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
5e46da |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
5e46da |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit |
5e46da |
* documentation and/or other materials provided with the distribution.
|
|
Packit |
5e46da |
* 3. Neither the name of the copyright holders nor the names of its
|
|
Packit |
5e46da |
* contributors may be used to endorse or promote products derived from
|
|
Packit |
5e46da |
* this software without specific prior written permission.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
5e46da |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
5e46da |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
5e46da |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
5e46da |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
5e46da |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
5e46da |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
5e46da |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
5e46da |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
5e46da |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
Packit |
5e46da |
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
package org.objectweb.asm.commons;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
import org.objectweb.asm.AnnotationVisitor;
|
|
Packit |
5e46da |
import org.objectweb.asm.ClassVisitor;
|
|
Packit |
5e46da |
import org.objectweb.asm.FieldVisitor;
|
|
Packit |
5e46da |
import org.objectweb.asm.MethodVisitor;
|
|
Packit |
5e46da |
import org.objectweb.asm.Opcodes;
|
|
Packit |
5e46da |
import org.objectweb.asm.TypePath;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
/**
|
|
Packit |
5e46da |
* A {@link ClassVisitor} for type remapping.
|
|
Packit |
5e46da |
*
|
|
Packit |
5e46da |
* @author Eugene Kuleshov
|
|
Packit |
5e46da |
*/
|
|
Packit |
5e46da |
public class RemappingClassAdapter extends ClassVisitor {
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected final Remapper remapper;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected String className;
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
public RemappingClassAdapter(final ClassVisitor cv, final Remapper remapper) {
|
|
Packit |
5e46da |
this(Opcodes.ASM5, cv, remapper);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected RemappingClassAdapter(final int api, final ClassVisitor cv,
|
|
Packit |
5e46da |
final Remapper remapper) {
|
|
Packit |
5e46da |
super(api, cv);
|
|
Packit |
5e46da |
this.remapper = remapper;
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
@Override
|
|
Packit |
5e46da |
public void visit(int version, int access, String name, String signature,
|
|
Packit |
5e46da |
String superName, String[] interfaces) {
|
|
Packit |
5e46da |
this.className = name;
|
|
Packit |
5e46da |
super.visit(version, access, remapper.mapType(name), remapper
|
|
Packit |
5e46da |
.mapSignature(signature, false), remapper.mapType(superName),
|
|
Packit |
5e46da |
interfaces == null ? null : remapper.mapTypes(interfaces));
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
@Override
|
|
Packit |
5e46da |
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
|
|
Packit |
5e46da |
AnnotationVisitor av = super.visitAnnotation(remapper.mapDesc(desc),
|
|
Packit |
5e46da |
visible);
|
|
Packit |
5e46da |
return av == null ? null : createRemappingAnnotationAdapter(av);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
@Override
|
|
Packit |
5e46da |
public AnnotationVisitor visitTypeAnnotation(int typeRef,
|
|
Packit |
5e46da |
TypePath typePath, String desc, boolean visible) {
|
|
Packit |
5e46da |
AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath,
|
|
Packit |
5e46da |
remapper.mapDesc(desc), visible);
|
|
Packit |
5e46da |
return av == null ? null : createRemappingAnnotationAdapter(av);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
@Override
|
|
Packit |
5e46da |
public FieldVisitor visitField(int access, String name, String desc,
|
|
Packit |
5e46da |
String signature, Object value) {
|
|
Packit |
5e46da |
FieldVisitor fv = super.visitField(access,
|
|
Packit |
5e46da |
remapper.mapFieldName(className, name, desc),
|
|
Packit |
5e46da |
remapper.mapDesc(desc), remapper.mapSignature(signature, true),
|
|
Packit |
5e46da |
remapper.mapValue(value));
|
|
Packit |
5e46da |
return fv == null ? null : createRemappingFieldAdapter(fv);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
@Override
|
|
Packit |
5e46da |
public MethodVisitor visitMethod(int access, String name, String desc,
|
|
Packit |
5e46da |
String signature, String[] exceptions) {
|
|
Packit |
5e46da |
String newDesc = remapper.mapMethodDesc(desc);
|
|
Packit |
5e46da |
MethodVisitor mv = super.visitMethod(access, remapper.mapMethodName(
|
|
Packit |
5e46da |
className, name, desc), newDesc, remapper.mapSignature(
|
|
Packit |
5e46da |
signature, false),
|
|
Packit |
5e46da |
exceptions == null ? null : remapper.mapTypes(exceptions));
|
|
Packit |
5e46da |
return mv == null ? null : createRemappingMethodAdapter(access,
|
|
Packit |
5e46da |
newDesc, mv);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
@Override
|
|
Packit |
5e46da |
public void visitInnerClass(String name, String outerName,
|
|
Packit |
5e46da |
String innerName, int access) {
|
|
Packit |
5e46da |
// TODO should innerName be changed?
|
|
Packit |
5e46da |
super.visitInnerClass(remapper.mapType(name), outerName == null ? null
|
|
Packit |
5e46da |
: remapper.mapType(outerName), innerName, access);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
@Override
|
|
Packit |
5e46da |
public void visitOuterClass(String owner, String name, String desc) {
|
|
Packit |
5e46da |
super.visitOuterClass(remapper.mapType(owner), name == null ? null
|
|
Packit |
5e46da |
: remapper.mapMethodName(owner, name, desc),
|
|
Packit |
5e46da |
desc == null ? null : remapper.mapMethodDesc(desc));
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected FieldVisitor createRemappingFieldAdapter(FieldVisitor fv) {
|
|
Packit |
5e46da |
return new RemappingFieldAdapter(fv, remapper);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected MethodVisitor createRemappingMethodAdapter(int access,
|
|
Packit |
5e46da |
String newDesc, MethodVisitor mv) {
|
|
Packit |
5e46da |
return new RemappingMethodAdapter(access, newDesc, mv, remapper);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
|
|
Packit |
5e46da |
protected AnnotationVisitor createRemappingAnnotationAdapter(
|
|
Packit |
5e46da |
AnnotationVisitor av) {
|
|
Packit |
5e46da |
return new RemappingAnnotationAdapter(av, remapper);
|
|
Packit |
5e46da |
}
|
|
Packit |
5e46da |
}
|