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