|
1 | 1 | package de.oceanlabs.mcp.mcinjector.adaptors; |
2 | 2 |
|
3 | | -import java.util.Collections; |
4 | | -import java.util.Comparator; |
5 | 3 | import java.util.HashMap; |
6 | 4 | import java.util.Map; |
7 | | -import java.util.logging.Logger; |
8 | 5 |
|
9 | 6 | import org.objectweb.asm.ClassVisitor; |
10 | | -import org.objectweb.asm.MethodVisitor; |
11 | | -import org.objectweb.asm.Opcodes; |
12 | 7 | import org.objectweb.asm.tree.LocalVariableNode; |
13 | 8 | import org.objectweb.asm.tree.MethodNode; |
14 | 9 |
|
15 | 10 | import de.oceanlabs.mcp.mcinjector.MCInjectorImpl; |
16 | 11 |
|
17 | | -public class LVTLvt extends ClassVisitor |
| 12 | +public class LVTLvt extends LVTRenamer |
18 | 13 | { |
19 | | - private static final Logger log = Logger.getLogger("MCInjector"); |
20 | | - //private MCInjectorImpl mci; |
21 | | - String className; |
| 14 | + private MethodNode lastMethod = null; |
| 15 | + private Map<Integer, Integer> vers = null; |
22 | 16 |
|
23 | 17 | public LVTLvt(ClassVisitor cn, MCInjectorImpl mci) |
24 | 18 | { |
25 | | - super(Opcodes.ASM5, cn); |
26 | | - //this.mci = mci; |
| 19 | + super(cn, mci); |
27 | 20 | } |
28 | 21 |
|
29 | 22 | @Override |
30 | | - public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) |
| 23 | + protected String getNewName(MethodNode mtd, LocalVariableNode lvn) |
31 | 24 | { |
32 | | - this.className = name; |
33 | | - super.visit(version, access, name, signature, superName, interfaces); |
34 | | - } |
35 | | - |
36 | | - @Override |
37 | | - public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) |
38 | | - { |
39 | | - return new MethodVisitor(api, cv.visitMethod(access, name, desc, signature, exceptions)) |
| 25 | + if (lastMethod != mtd) |
40 | 26 | { |
41 | | - @Override |
42 | | - public void visitEnd() |
43 | | - { |
44 | | - super.visitEnd(); |
45 | | - final MethodNode mn = MCInjectorImpl.getMethodNode(mv); |
46 | | - if (mn.localVariables != null && mn.localVariables.size() > 0) |
47 | | - { |
48 | | - Collections.sort(mn.localVariables, new Comparator<LocalVariableNode>() |
49 | | - { |
50 | | - @Override |
51 | | - public int compare(LocalVariableNode o1, LocalVariableNode o2) |
52 | | - { |
53 | | - if (o1.index < o2.index) return -1; |
54 | | - if (o1.index > o2.index) return 1; |
55 | | - int o1Start = mn.instructions.indexOf(o1.start); |
56 | | - int o2Start = mn.instructions.indexOf(o2.start); |
57 | | - if (o1Start < o2Start) return -1; |
58 | | - if (o2Start > o2Start) return 1; |
59 | | - return 0; |
60 | | - } |
| 27 | + vers = new HashMap<Integer, Integer>(); |
| 28 | + lastMethod = mtd; |
| 29 | + } |
61 | 30 |
|
62 | | - }); |
63 | | - |
64 | | - Map<Integer, Integer> vers = new HashMap<Integer, Integer>(); |
65 | | - for (LocalVariableNode lvn : mn.localVariables) |
66 | | - { |
67 | | - if (0x2603 != lvn.name.charAt(0)) // Snowmen, added in 1.8.2? rename them |
68 | | - continue; |
69 | | - int ver = 0; |
70 | | - if (vers.containsKey(lvn.index)) |
71 | | - { |
72 | | - ver = vers.get(lvn.index); |
73 | | - vers.put(lvn.index, ver + 1); |
74 | | - } |
75 | | - else |
76 | | - { |
77 | | - ver = 1; |
78 | | - vers.put(lvn.index, 2); |
79 | | - } |
80 | | - String name = "lvt_" + lvn.index + "_" + ver + "_"; |
81 | | - log.info(" Renaming LVT: " + lvn.index + " " + lvn.name + " " + lvn.desc + " -> " + name); |
82 | | - lvn.name = name; |
83 | | - } |
84 | | - } |
85 | | - } |
86 | | - }; |
| 31 | + int ver = 0; |
| 32 | + if (vers.containsKey(lvn.index)) |
| 33 | + { |
| 34 | + ver = vers.get(lvn.index); |
| 35 | + vers.put(lvn.index, ver + 1); |
| 36 | + } |
| 37 | + else |
| 38 | + { |
| 39 | + ver = 1; |
| 40 | + vers.put(lvn.index, 2); |
| 41 | + } |
| 42 | + return "lvt_" + lvn.index + "_" + ver + "_"; |
87 | 43 | } |
88 | 44 | } |
0 commit comments