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.Label;
033: import org.objectweb.asm.MethodVisitor;
034:
035: /**
036: * A <code>MethodAdapter</code> for type mapping.
037: *
038: * @author Eugene Kuleshov
039: */
040: public class RemappingMethodAdapter extends LocalVariablesSorter {
041:
042: protected final Remapper remapper;
043:
044: public RemappingMethodAdapter(int access, String desc,
045: MethodVisitor mv, Remapper renamer) {
046: super (access, desc, mv);
047: this .remapper = renamer;
048: }
049:
050: public void visitFieldInsn(int opcode, String owner, String name,
051: String desc) {
052: super .visitFieldInsn(opcode, remapper.mapType(owner), remapper
053: .mapFieldName(owner, name, desc), remapper
054: .mapDesc(desc));
055: }
056:
057: public void visitMethodInsn(int opcode, String owner, String name,
058: String desc) {
059: super .visitMethodInsn(opcode, remapper.mapType(owner), remapper
060: .mapMethodName(owner, name, desc), remapper
061: .mapMethodDesc(desc));
062: }
063:
064: public void visitTypeInsn(int opcode, String type) {
065: super .visitTypeInsn(opcode, remapper.mapType(type));
066: }
067:
068: public void visitLdcInsn(Object cst) {
069: super .visitLdcInsn(remapper.mapValue(cst));
070: }
071:
072: public void visitMultiANewArrayInsn(String desc, int dims) {
073: super .visitMultiANewArrayInsn(remapper.mapDesc(desc), dims);
074: }
075:
076: public void visitTryCatchBlock(Label start, Label end,
077: Label handler, String type) {
078: super .visitTryCatchBlock(start, end, handler, //
079: type == null ? null : remapper.mapType(type));
080: }
081:
082: public void visitLocalVariable(String name, String desc,
083: String signature, Label start, Label end, int index) {
084: super .visitLocalVariable(name, remapper.mapDesc(desc), remapper
085: .mapSignature(signature, true), start, end, index);
086: }
087:
088: public AnnotationVisitor visitAnnotation(String desc,
089: boolean visible) {
090: AnnotationVisitor av = mv.visitAnnotation(desc, visible);
091: return av == null ? av : new RemappingAnnotationAdapter(av,
092: remapper);
093: }
094:
095: public AnnotationVisitor visitAnnotationDefault() {
096: AnnotationVisitor av = mv.visitAnnotationDefault();
097: return av == null ? av : new RemappingAnnotationAdapter(av,
098: remapper);
099: }
100:
101: public AnnotationVisitor visitParameterAnnotation(int parameter,
102: String desc, boolean visible) {
103: AnnotationVisitor av = mv.visitParameterAnnotation(parameter,
104: desc, visible);
105: return av == null ? av : new RemappingAnnotationAdapter(av,
106: remapper);
107: }
108:
109: public void visitFrame(int type, int nLocal, Object[] local,
110: int nStack, Object[] stack) {
111: super .visitFrame(type, nLocal, remapEntries(nLocal, local),
112: nStack, remapEntries(nStack, stack));
113: }
114:
115: private Object[] remapEntries(int n, Object[] entries) {
116: for (int i = 0; i < n; i++) {
117: if (entries[i] instanceof String) {
118: Object[] newEntries = new Object[n];
119: if (i > 0) {
120: System.arraycopy(entries, 0, newEntries, 0, i);
121: }
122: do {
123: Object t = entries[i];
124: newEntries[i++] = t instanceof String ? remapper
125: .mapType((String) t) : t;
126: } while (i < n);
127: return newEntries;
128: }
129: }
130: return entries;
131: }
132:
133: }
|