001: /***
002: * ASM: a very small and fast Java bytecode manipulation framework
003: * Copyright (c) 2000-2007 INRIA, France Telecom
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * 2. Redistributions in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in the
013: * documentation and/or other materials provided with the distribution.
014: * 3. Neither the name of the copyright holders nor the names of its
015: * contributors may be used to endorse or promote products derived from
016: * this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028: * THE POSSIBILITY OF SUCH DAMAGE.
029: */package org.objectweb.asm.commons;
030:
031: import org.objectweb.asm.AnnotationVisitor;
032: import org.objectweb.asm.ClassAdapter;
033: import org.objectweb.asm.ClassVisitor;
034: import org.objectweb.asm.FieldVisitor;
035: import org.objectweb.asm.MethodVisitor;
036:
037: /**
038: * A <code>ClassAdapter</code> for type remapping.
039: *
040: * @author Eugene Kuleshov
041: */
042: public class RemappingClassAdapter extends ClassAdapter {
043:
044: protected final Remapper remapper;
045:
046: protected String className;
047:
048: public RemappingClassAdapter(ClassVisitor cv, Remapper remapper) {
049: super (cv);
050: this .remapper = remapper;
051: }
052:
053: public void visit(int version, int access, String name,
054: String signature, String super Name, String[] interfaces) {
055: this .className = name;
056: super .visit(version, access, remapper.mapType(name), remapper
057: .mapSignature(signature, false), remapper
058: .mapType(super Name), interfaces == null ? null
059: : remapper.mapTypes(interfaces));
060: }
061:
062: public AnnotationVisitor visitAnnotation(String desc,
063: boolean visible) {
064: AnnotationVisitor av;
065: av = super .visitAnnotation(remapper.mapType(desc), visible);
066: return av == null ? null : createRemappingAnnotationAdapter(av);
067: }
068:
069: public FieldVisitor visitField(int access, String name,
070: String desc, String signature, Object value) {
071: FieldVisitor fv = super .visitField(access, remapper
072: .mapFieldName(className, name, desc), remapper
073: .mapDesc(desc), remapper.mapSignature(signature, true),
074: remapper.mapValue(value));
075: return fv == null ? null : createRemappingFieldAdapter(fv);
076: }
077:
078: public MethodVisitor visitMethod(int access, String name,
079: String desc, String signature, String[] exceptions) {
080: String newDesc = remapper.mapMethodDesc(desc);
081: MethodVisitor mv = super .visitMethod(access, remapper
082: .mapMethodName(className, name, desc), newDesc,
083: remapper.mapSignature(signature, false),
084: exceptions == null ? null : remapper
085: .mapTypes(exceptions));
086: return mv == null ? null : createRemappingMethodAdapter(access,
087: newDesc, mv);
088: }
089:
090: public void visitInnerClass(String name, String outerName,
091: String innerName, int access) {
092: super .visitInnerClass(remapper.mapType(name),
093: outerName == null ? null : remapper.mapType(outerName),
094: innerName, // TODO should it be changed?
095: access);
096: }
097:
098: public void visitOuterClass(String owner, String name, String desc) {
099: super .visitOuterClass(remapper.mapType(owner),
100: name == null ? null : remapper.mapMethodName(owner,
101: name, desc), desc == null ? null : remapper
102: .mapMethodDesc(desc));
103: }
104:
105: protected FieldVisitor createRemappingFieldAdapter(FieldVisitor fv) {
106: return new RemappingFieldAdapter(fv, remapper);
107: }
108:
109: protected MethodVisitor createRemappingMethodAdapter(int access,
110: String newDesc, MethodVisitor mv) {
111: return new RemappingMethodAdapter(access, newDesc, mv, remapper);
112: }
113:
114: protected AnnotationVisitor createRemappingAnnotationAdapter(
115: AnnotationVisitor av) {
116: return new RemappingAnnotationAdapter(av, remapper);
117: }
118: }
|