summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/RelatedMethodChecker.java
diff options
context:
space:
mode:
authorGravatar Michael Smith2015-05-21 23:30:00 +0100
committerGravatar Michael Smith2015-05-21 23:30:00 +0100
commite3f452250e51b7271f3989c7dfd12e4422934942 (patch)
tree5aa482f9a6e21eb318a3e23e7d8274d77c73faf6 /src/cuchaz/enigma/analysis/RelatedMethodChecker.java
downloadenigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.gz
enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.xz
enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.zip
Support Gradle alongside SSJB
This makes builds faster, simpler and better automated but still keeps Cuchaz happy. :)
Diffstat (limited to 'src/cuchaz/enigma/analysis/RelatedMethodChecker.java')
-rw-r--r--src/cuchaz/enigma/analysis/RelatedMethodChecker.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/RelatedMethodChecker.java b/src/cuchaz/enigma/analysis/RelatedMethodChecker.java
new file mode 100644
index 0000000..e592a1c
--- /dev/null
+++ b/src/cuchaz/enigma/analysis/RelatedMethodChecker.java
@@ -0,0 +1,106 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.analysis;
12
13import java.util.Map;
14import java.util.Set;
15
16import com.google.common.collect.Maps;
17import com.google.common.collect.Sets;
18
19import cuchaz.enigma.mapping.BehaviorEntry;
20import cuchaz.enigma.mapping.ClassEntry;
21import cuchaz.enigma.mapping.EntryFactory;
22import cuchaz.enigma.mapping.MethodEntry;
23import cuchaz.enigma.mapping.MethodMapping;
24
25public class RelatedMethodChecker {
26
27 private JarIndex m_jarIndex;
28 private Map<Set<MethodEntry>,String> m_deobfNamesByGroup;
29 private Map<MethodEntry,String> m_deobfNamesByObfMethod;
30 private Map<MethodEntry,Set<MethodEntry>> m_groupsByObfMethod;
31 private Set<Set<MethodEntry>> m_inconsistentGroups;
32
33 public RelatedMethodChecker(JarIndex jarIndex) {
34 m_jarIndex = jarIndex;
35 m_deobfNamesByGroup = Maps.newHashMap();
36 m_deobfNamesByObfMethod = Maps.newHashMap();
37 m_groupsByObfMethod = Maps.newHashMap();
38 m_inconsistentGroups = Sets.newHashSet();
39 }
40
41 public void checkMethod(ClassEntry classEntry, MethodMapping methodMapping) {
42
43 // TEMP: disable the expensive check for now, maybe we can optimize it later, or just use it for debugging
44 if (true) return;
45
46 BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping);
47 if (!(obfBehaviorEntry instanceof MethodEntry)) {
48 // only methods have related implementations
49 return;
50 }
51 MethodEntry obfMethodEntry = (MethodEntry)obfBehaviorEntry;
52 String deobfName = methodMapping.getDeobfName();
53 m_deobfNamesByObfMethod.put(obfMethodEntry, deobfName);
54
55 // have we seen this method's group before?
56 Set<MethodEntry> group = m_groupsByObfMethod.get(obfMethodEntry);
57 if (group == null) {
58
59 // no, compute the group and save the name
60 group = m_jarIndex.getRelatedMethodImplementations(obfMethodEntry);
61 m_deobfNamesByGroup.put(group, deobfName);
62
63 assert(group.contains(obfMethodEntry));
64 for (MethodEntry relatedMethodEntry : group) {
65 m_groupsByObfMethod.put(relatedMethodEntry, group);
66 }
67 }
68
69 // check the name
70 if (!sameName(m_deobfNamesByGroup.get(group), deobfName)) {
71 m_inconsistentGroups.add(group);
72 }
73 }
74
75 private boolean sameName(String a, String b) {
76 if (a == null && b == null) {
77 return true;
78 } else if (a != null && b != null) {
79 return a.equals(b);
80 }
81 return false;
82 }
83
84 public boolean hasProblems() {
85 return m_inconsistentGroups.size() > 0;
86 }
87
88 public String getReport() {
89 StringBuilder buf = new StringBuilder();
90 buf.append(m_inconsistentGroups.size());
91 buf.append(" groups of methods related by inheritance and/or interfaces have different deobf names!\n");
92 for (Set<MethodEntry> group : m_inconsistentGroups) {
93 buf.append("\tGroup with ");
94 buf.append(group.size());
95 buf.append(" methods:\n");
96 for (MethodEntry methodEntry : group) {
97 buf.append("\t\t");
98 buf.append(methodEntry.toString());
99 buf.append(" => ");
100 buf.append(m_deobfNamesByObfMethod.get(methodEntry));
101 buf.append("\n");
102 }
103 }
104 return buf.toString();
105 }
106}