summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert/MemberMatches.java
diff options
context:
space:
mode:
authorGravatar Thog2017-03-08 08:17:04 +0100
committerGravatar Thog2017-03-08 08:17:04 +0100
commit6e464ea251cab63c776ece0b2a356f1498ffa294 (patch)
tree5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/convert/MemberMatches.java
parentDrop unix case style and implement hashCode when equals is overrided (diff)
downloadenigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/MemberMatches.java')
-rw-r--r--src/main/java/cuchaz/enigma/convert/MemberMatches.java315
1 files changed, 156 insertions, 159 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/MemberMatches.java b/src/main/java/cuchaz/enigma/convert/MemberMatches.java
index 51cee85..bd74311 100644
--- a/src/main/java/cuchaz/enigma/convert/MemberMatches.java
+++ b/src/main/java/cuchaz/enigma/convert/MemberMatches.java
@@ -8,6 +8,7 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.convert; 12package cuchaz.enigma.convert;
12 13
13import com.google.common.collect.*; 14import com.google.common.collect.*;
@@ -18,165 +19,161 @@ import cuchaz.enigma.mapping.Entry;
18import java.util.Collection; 19import java.util.Collection;
19import java.util.Set; 20import java.util.Set;
20 21
21
22public class MemberMatches<T extends Entry> { 22public class MemberMatches<T extends Entry> {
23 23
24 private BiMap<T, T> matches; 24 private BiMap<T, T> matches;
25 private Multimap<ClassEntry, T> matchedSourceEntries; 25 private Multimap<ClassEntry, T> matchedSourceEntries;
26 private Multimap<ClassEntry, T> unmatchedSourceEntries; 26 private Multimap<ClassEntry, T> unmatchedSourceEntries;
27 private Multimap<ClassEntry, T> unmatchedDestEntries; 27 private Multimap<ClassEntry, T> unmatchedDestEntries;
28 private Multimap<ClassEntry, T> unmatchableSourceEntries; 28 private Multimap<ClassEntry, T> unmatchableSourceEntries;
29 29
30 public MemberMatches() { 30 public MemberMatches() {
31 matches = HashBiMap.create(); 31 matches = HashBiMap.create();
32 matchedSourceEntries = HashMultimap.create(); 32 matchedSourceEntries = HashMultimap.create();
33 unmatchedSourceEntries = HashMultimap.create(); 33 unmatchedSourceEntries = HashMultimap.create();
34 unmatchedDestEntries = HashMultimap.create(); 34 unmatchedDestEntries = HashMultimap.create();
35 unmatchableSourceEntries = HashMultimap.create(); 35 unmatchableSourceEntries = HashMultimap.create();
36 } 36 }
37 37
38 public void addMatch(T srcEntry, T destEntry) { 38 public void addMatch(T srcEntry, T destEntry) {
39 boolean wasAdded = matches.put(srcEntry, destEntry) == null; 39 boolean wasAdded = matches.put(srcEntry, destEntry) == null;
40 assert (wasAdded); 40 assert (wasAdded);
41 wasAdded = matchedSourceEntries.put(srcEntry.getClassEntry(), srcEntry); 41 wasAdded = matchedSourceEntries.put(srcEntry.getClassEntry(), srcEntry);
42 assert (wasAdded); 42 assert (wasAdded);
43 } 43 }
44 44
45 public void addUnmatchedSourceEntry(T sourceEntry) { 45 public void addUnmatchedSourceEntry(T sourceEntry) {
46 boolean wasAdded = unmatchedSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); 46 boolean wasAdded = unmatchedSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry);
47 assert (wasAdded); 47 assert (wasAdded);
48 } 48 }
49 49
50 public void addUnmatchedSourceEntries(Iterable<T> sourceEntries) { 50 public void addUnmatchedSourceEntries(Iterable<T> sourceEntries) {
51 for (T sourceEntry : sourceEntries) { 51 for (T sourceEntry : sourceEntries) {
52 addUnmatchedSourceEntry(sourceEntry); 52 addUnmatchedSourceEntry(sourceEntry);
53 } 53 }
54 } 54 }
55 55
56 public void addUnmatchedDestEntry(T destEntry) { 56 public void addUnmatchedDestEntry(T destEntry) {
57 if (destEntry.getName().equals("<clinit>") || destEntry.getName().equals("<init>")) 57 if (destEntry.getName().equals("<clinit>") || destEntry.getName().equals("<init>"))
58 return; 58 return;
59 boolean wasAdded = unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry); 59 boolean wasAdded = unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry);
60 assert (wasAdded); 60 assert (wasAdded);
61 } 61 }
62 62
63 public void addUnmatchedDestEntries(Iterable<T> destEntriesntries) { 63 public void addUnmatchedDestEntries(Iterable<T> destEntriesntries) {
64 for (T entry : destEntriesntries) { 64 for (T entry : destEntriesntries) {
65 addUnmatchedDestEntry(entry); 65 addUnmatchedDestEntry(entry);
66 } 66 }
67 } 67 }
68 68
69 public void addUnmatchableSourceEntry(T sourceEntry) { 69 public void addUnmatchableSourceEntry(T sourceEntry) {
70 boolean wasAdded = unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); 70 boolean wasAdded = unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry);
71 assert (wasAdded); 71 assert (wasAdded);
72 } 72 }
73 73
74 public Set<ClassEntry> getSourceClassesWithUnmatchedEntries() { 74 public Set<ClassEntry> getSourceClassesWithUnmatchedEntries() {
75 return unmatchedSourceEntries.keySet(); 75 return unmatchedSourceEntries.keySet();
76 } 76 }
77 77
78 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedEntries() { 78 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedEntries() {
79 Set<ClassEntry> out = Sets.newHashSet(); 79 Set<ClassEntry> out = Sets.newHashSet();
80 out.addAll(matchedSourceEntries.keySet()); 80 out.addAll(matchedSourceEntries.keySet());
81 out.removeAll(unmatchedSourceEntries.keySet()); 81 out.removeAll(unmatchedSourceEntries.keySet());
82 return out; 82 return out;
83 } 83 }
84 84
85 public Collection<T> getUnmatchedSourceEntries() { 85 public Collection<T> getUnmatchedSourceEntries() {
86 return unmatchedSourceEntries.values(); 86 return unmatchedSourceEntries.values();
87 } 87 }
88 88
89 public Collection<T> getUnmatchedSourceEntries(ClassEntry sourceClass) { 89 public Collection<T> getUnmatchedSourceEntries(ClassEntry sourceClass) {
90 return unmatchedSourceEntries.get(sourceClass); 90 return unmatchedSourceEntries.get(sourceClass);
91 } 91 }
92 92
93 public Collection<T> getUnmatchedDestEntries() { 93 public Collection<T> getUnmatchedDestEntries() {
94 return unmatchedDestEntries.values(); 94 return unmatchedDestEntries.values();
95 } 95 }
96 96
97 public Collection<T> getUnmatchedDestEntries(ClassEntry destClass) { 97 public Collection<T> getUnmatchedDestEntries(ClassEntry destClass) {
98 return unmatchedDestEntries.get(destClass); 98 return unmatchedDestEntries.get(destClass);
99 } 99 }
100 100
101 public Collection<T> getUnmatchableSourceEntries() { 101 public Collection<T> getUnmatchableSourceEntries() {
102 return unmatchableSourceEntries.values(); 102 return unmatchableSourceEntries.values();
103 } 103 }
104 104
105 public boolean hasSource(T sourceEntry) { 105 public boolean hasSource(T sourceEntry) {
106 return matches.containsKey(sourceEntry) || unmatchedSourceEntries.containsValue(sourceEntry); 106 return matches.containsKey(sourceEntry) || unmatchedSourceEntries.containsValue(sourceEntry);
107 } 107 }
108 108
109 public boolean hasDest(T destEntry) { 109 public boolean hasDest(T destEntry) {
110 return matches.containsValue(destEntry) || unmatchedDestEntries.containsValue(destEntry); 110 return matches.containsValue(destEntry) || unmatchedDestEntries.containsValue(destEntry);
111 } 111 }
112 112
113 public BiMap<T, T> matches() { 113 public BiMap<T, T> matches() {
114 return matches; 114 return matches;
115 } 115 }
116 116
117 public boolean isMatchedSourceEntry(T sourceEntry) { 117 public boolean isMatchedSourceEntry(T sourceEntry) {
118 return matches.containsKey(sourceEntry); 118 return matches.containsKey(sourceEntry);
119 } 119 }
120 120
121 public boolean isMatchedDestEntry(T destEntry) { 121 public boolean isMatchedDestEntry(T destEntry) {
122 return matches.containsValue(destEntry); 122 return matches.containsValue(destEntry);
123 } 123 }
124 124
125 public boolean isUnmatchableSourceEntry(T sourceEntry) { 125 public boolean isUnmatchableSourceEntry(T sourceEntry) {
126 return unmatchableSourceEntries.containsEntry(sourceEntry.getClassEntry(), sourceEntry); 126 return unmatchableSourceEntries.containsEntry(sourceEntry.getClassEntry(), sourceEntry);
127 } 127 }
128 public void makeMatch(T sourceEntry, T destEntry) { 128
129 makeMatch(sourceEntry, destEntry, null, null); 129 public void makeMatch(T sourceEntry, T destEntry) {
130 } 130 makeMatch(sourceEntry, destEntry, null, null);
131 131 }
132 public void makeMatch(T sourceEntry, T destEntry, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) { 132
133 if (sourceDeobfuscator != null && destDeobfuscator != null) 133 public void makeMatch(T sourceEntry, T destEntry, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) {
134 { 134 if (sourceDeobfuscator != null && destDeobfuscator != null) {
135 makeMatch(sourceEntry, destEntry); 135 makeMatch(sourceEntry, destEntry);
136 sourceEntry = (T) sourceEntry.cloneToNewClass(sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true)); 136 sourceEntry = (T) sourceEntry.cloneToNewClass(sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true));
137 destEntry = (T) destEntry.cloneToNewClass(destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true)); 137 destEntry = (T) destEntry.cloneToNewClass(destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true));
138 } 138 }
139 boolean wasRemoved = unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); 139 boolean wasRemoved = unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
140 assert (wasRemoved); 140 assert (wasRemoved);
141 wasRemoved = unmatchedDestEntries.remove(destEntry.getClassEntry(), destEntry); 141 wasRemoved = unmatchedDestEntries.remove(destEntry.getClassEntry(), destEntry);
142 assert (wasRemoved); 142 assert (wasRemoved);
143 addMatch(sourceEntry, destEntry); 143 addMatch(sourceEntry, destEntry);
144 } 144 }
145 145
146 public boolean isMatched(T sourceEntry, T destEntry) { 146 public boolean isMatched(T sourceEntry, T destEntry) {
147 T match = matches.get(sourceEntry); 147 T match = matches.get(sourceEntry);
148 return match != null && match.equals(destEntry); 148 return match != null && match.equals(destEntry);
149 } 149 }
150 150
151 public void unmakeMatch(T sourceEntry, T destEntry, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) 151 public void unmakeMatch(T sourceEntry, T destEntry, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) {
152 { 152 if (sourceDeobfuscator != null && destDeobfuscator != null) {
153 if (sourceDeobfuscator != null && destDeobfuscator != null) 153 unmakeMatch(sourceEntry, destEntry, null, null);
154 { 154 sourceEntry = (T) sourceEntry.cloneToNewClass(
155 unmakeMatch(sourceEntry, destEntry, null, null); 155 sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true));
156 sourceEntry = (T) sourceEntry.cloneToNewClass( 156 destEntry = (T) destEntry.cloneToNewClass(
157 sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true)); 157 destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true));
158 destEntry = (T) destEntry.cloneToNewClass( 158 }
159 destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true)); 159
160 } 160 boolean wasRemoved = matches.remove(sourceEntry) != null;
161 161 assert (wasRemoved);
162 boolean wasRemoved = matches.remove(sourceEntry) != null; 162 wasRemoved = matchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
163 assert (wasRemoved); 163 assert (wasRemoved);
164 wasRemoved = matchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); 164 addUnmatchedSourceEntry(sourceEntry);
165 assert (wasRemoved); 165 addUnmatchedDestEntry(destEntry);
166 addUnmatchedSourceEntry(sourceEntry); 166 }
167 addUnmatchedDestEntry(destEntry); 167
168 } 168 public void makeSourceUnmatchable(T sourceEntry, Deobfuscator sourceDeobfuscator) {
169 169 if (sourceDeobfuscator != null) {
170 public void makeSourceUnmatchable(T sourceEntry, Deobfuscator sourceDeobfuscator) { 170 makeSourceUnmatchable(sourceEntry, null);
171 if (sourceDeobfuscator != null) 171 sourceEntry = (T) sourceEntry.cloneToNewClass(
172 { 172 sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true));
173 makeSourceUnmatchable(sourceEntry, null); 173 }
174 sourceEntry = (T) sourceEntry.cloneToNewClass( 174 assert (!isMatchedSourceEntry(sourceEntry));
175 sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true)); 175 boolean wasRemoved = unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
176 } 176 assert (wasRemoved);
177 assert (!isMatchedSourceEntry(sourceEntry)); 177 addUnmatchableSourceEntry(sourceEntry);
178 boolean wasRemoved = unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); 178 }
179 assert (wasRemoved);
180 addUnmatchableSourceEntry(sourceEntry);
181 }
182} 179}