01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.bytecode;
06:
07: import com.tc.asm.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.FieldVisitor;
10: import com.tc.asm.Label;
11: import com.tc.asm.MethodAdapter;
12: import com.tc.asm.MethodVisitor;
13: import com.tc.asm.Opcodes;
14: import com.tc.object.config.ClassReplacementMapping;
15:
16: public class RenameClassesAdapter extends ClassAdapter implements
17: Opcodes {
18: private final ClassReplacementMapping mapping;
19:
20: public RenameClassesAdapter(ClassVisitor cv,
21: ClassReplacementMapping mapping) {
22: super (cv);
23:
24: this .mapping = mapping;
25: }
26:
27: public void visit(int version, int access, String name,
28: String signature, String super Name, String[] interfaces) {
29: cv.visit(version, ACC_PUBLIC, mapping
30: .getOriginalClassNameSlashes(name), signature,
31: super Name, interfaces);
32: }
33:
34: public FieldVisitor visitField(int access, String name,
35: String desc, String signature, Object value) {
36: return cv.visitField(access, name, mapping
37: .getOriginalAsmType(desc), mapping
38: .ensureOriginalAsmTypes(signature), value);
39: }
40:
41: public MethodVisitor visitMethod(int access, String name,
42: String desc, String signature, String[] exceptions) {
43: MethodVisitor mv = cv.visitMethod(access, name, mapping
44: .ensureOriginalAsmTypes(desc), mapping
45: .ensureOriginalAsmTypes(signature), exceptions);
46: if (mv != null && (access & ACC_ABSTRACT) == 0) {
47: mv = new MethodRenamer(mv);
48: }
49: return mv;
50: }
51:
52: class MethodRenamer extends MethodAdapter {
53: public MethodRenamer(final MethodVisitor mv) {
54: super (mv);
55: }
56:
57: public void visitTypeInsn(int i, String s) {
58: mv.visitTypeInsn(i, mapping.getOriginalClassNameSlashes(s));
59: }
60:
61: public void visitFieldInsn(int opcode, String owner,
62: String name, String desc) {
63: mv.visitFieldInsn(opcode, mapping
64: .getOriginalClassNameSlashes(owner), name, mapping
65: .ensureOriginalAsmTypes(desc));
66: }
67:
68: public void visitMethodInsn(int opcode, String owner,
69: String name, String desc) {
70: mv.visitMethodInsn(opcode, mapping
71: .getOriginalClassNameSlashes(owner), name, mapping
72: .ensureOriginalAsmTypes(desc));
73: }
74:
75: public void visitLocalVariable(String name, String desc,
76: String signature, Label start, Label end, int index) {
77: mv.visitLocalVariable(name, mapping
78: .getOriginalAsmType(desc), mapping
79: .ensureOriginalAsmTypes(signature), start, end,
80: index);
81: }
82: }
83: }
|