|
24 | 24 | import java.util.Map; |
25 | 25 | import java.util.Set; |
26 | 26 |
|
27 | | -import org.objectweb.asm.ClassReader; |
28 | 27 | import org.objectweb.asm.Opcodes; |
29 | 28 | import org.objectweb.asm.tree.AbstractInsnNode; |
30 | 29 | import org.objectweb.asm.tree.FieldInsnNode; |
|
39 | 38 | import org.objectweb.asm.tree.analysis.SourceValue; |
40 | 39 |
|
41 | 40 | public class FieldNameFinder { |
42 | | - public Map<MappingEntry, String> findNames(Iterable<byte[]> classes) throws Exception { |
43 | | - Map<String, List<MethodNode>> methods = new HashMap<>(); |
44 | | - Map<String, Set<String>> enumFields = new HashMap<>(); |
45 | | - |
46 | | - for (byte[] data : classes) { |
47 | | - ClassReader reader = new ClassReader(data); |
48 | | - NameFinderVisitor vClass = new NameFinderVisitor(Constants.ASM_VERSION, enumFields, methods); |
49 | | - reader.accept(vClass, ClassReader.SKIP_FRAMES); |
50 | | - } |
51 | | - |
52 | | - return findNames(enumFields, methods); |
53 | | - } |
54 | | - |
55 | 41 | public Map<MappingEntry, String> findNames(Map<String, Set<String>> allEnumFields, Map<String, List<MethodNode>> classes) { |
56 | 42 | Analyzer<SourceValue> analyzer = new Analyzer<>(new SourceInterpreter()); |
57 | 43 | Map<MappingEntry, String> fieldNames = new HashMap<>(); |
@@ -151,6 +137,11 @@ public Map<MappingEntry, String> findNames(Map<String, Set<String>> allEnumField |
151 | 137 | } |
152 | 138 |
|
153 | 139 | if (usedNames.contains(s)) { |
| 140 | + if (s.equals(((FieldInsnNode) instr2).name)) { |
| 141 | + // No need to map names that are already named what we want to name it. |
| 142 | + continue; |
| 143 | + } |
| 144 | + |
154 | 145 | fieldNames.put(new MappingEntry(((FieldInsnNode) instr2).owner, ((FieldInsnNode) instr2).name, ((FieldInsnNode) instr2).desc), s); |
155 | 146 | } |
156 | 147 | } |
|
0 commit comments