summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/TranslationIndex.java')
-rw-r--r--src/main/java/cuchaz/enigma/analysis/TranslationIndex.java85
1 files changed, 41 insertions, 44 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java
index 0261a96..f020ae2 100644
--- a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java
+++ b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java
@@ -30,50 +30,47 @@ public class TranslationIndex implements Serializable {
30 30
31 private static final long serialVersionUID = 738687982126844179L; 31 private static final long serialVersionUID = 738687982126844179L;
32 32
33 private Map<ClassEntry, ClassEntry> m_superclasses; 33 private Map<ClassEntry, ClassEntry> superclasses;
34 private Multimap<ClassEntry, FieldEntry> m_fieldEntries; 34 private Multimap<ClassEntry, FieldEntry> fieldEntries;
35 private Multimap<ClassEntry, BehaviorEntry> m_behaviorEntries; 35 private Multimap<ClassEntry, BehaviorEntry> behaviorEntries;
36 private Multimap<ClassEntry, ClassEntry> m_interfaces; 36 private Multimap<ClassEntry, ClassEntry> interfaces;
37 37
38 public TranslationIndex() { 38 public TranslationIndex() {
39 m_superclasses = Maps.newHashMap(); 39 this.superclasses = Maps.newHashMap();
40 m_fieldEntries = HashMultimap.create(); 40 this.fieldEntries = HashMultimap.create();
41 m_behaviorEntries = HashMultimap.create(); 41 this.behaviorEntries = HashMultimap.create();
42 m_interfaces = HashMultimap.create(); 42 this.interfaces = HashMultimap.create();
43 } 43 }
44 44
45 public TranslationIndex(TranslationIndex other, Translator translator) { 45 public TranslationIndex(TranslationIndex other, Translator translator) {
46 46
47 // translate the superclasses 47 // translate the superclasses
48 m_superclasses = Maps.newHashMap(); 48 this.superclasses = Maps.newHashMap();
49 for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.m_superclasses.entrySet()) { 49 for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.superclasses.entrySet()) {
50 m_superclasses.put( 50 this.superclasses.put(translator.translateEntry(mapEntry.getKey()), translator.translateEntry(mapEntry.getValue()));
51 translator.translateEntry(mapEntry.getKey()),
52 translator.translateEntry(mapEntry.getValue())
53 );
54 } 51 }
55 52
56 // translate the interfaces 53 // translate the interfaces
57 m_interfaces = HashMultimap.create(); 54 this.interfaces = HashMultimap.create();
58 for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.m_interfaces.entries()) { 55 for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.interfaces.entries()) {
59 m_interfaces.put( 56 this.interfaces.put(
60 translator.translateEntry(mapEntry.getKey()), 57 translator.translateEntry(mapEntry.getKey()),
61 translator.translateEntry(mapEntry.getValue()) 58 translator.translateEntry(mapEntry.getValue())
62 ); 59 );
63 } 60 }
64 61
65 // translate the fields 62 // translate the fields
66 m_fieldEntries = HashMultimap.create(); 63 this.fieldEntries = HashMultimap.create();
67 for (Map.Entry<ClassEntry, FieldEntry> mapEntry : other.m_fieldEntries.entries()) { 64 for (Map.Entry<ClassEntry, FieldEntry> mapEntry : other.fieldEntries.entries()) {
68 m_fieldEntries.put( 65 this.fieldEntries.put(
69 translator.translateEntry(mapEntry.getKey()), 66 translator.translateEntry(mapEntry.getKey()),
70 translator.translateEntry(mapEntry.getValue()) 67 translator.translateEntry(mapEntry.getValue())
71 ); 68 );
72 } 69 }
73 70
74 m_behaviorEntries = HashMultimap.create(); 71 this.behaviorEntries = HashMultimap.create();
75 for (Map.Entry<ClassEntry, BehaviorEntry> mapEntry : other.m_behaviorEntries.entries()) { 72 for (Map.Entry<ClassEntry, BehaviorEntry> mapEntry : other.behaviorEntries.entries()) {
76 m_behaviorEntries.put( 73 this.behaviorEntries.put(
77 translator.translateEntry(mapEntry.getKey()), 74 translator.translateEntry(mapEntry.getKey()),
78 translator.translateEntry(mapEntry.getValue()) 75 translator.translateEntry(mapEntry.getValue())
79 ); 76 );
@@ -94,14 +91,14 @@ public class TranslationIndex implements Serializable {
94 // add the superclass 91 // add the superclass
95 ClassEntry superclassEntry = EntryFactory.getSuperclassEntry(c); 92 ClassEntry superclassEntry = EntryFactory.getSuperclassEntry(c);
96 if (superclassEntry != null) { 93 if (superclassEntry != null) {
97 m_superclasses.put(classEntry, superclassEntry); 94 this.superclasses.put(classEntry, superclassEntry);
98 } 95 }
99 96
100 // add the interfaces 97 // add the interfaces
101 for (String interfaceClassName : c.getClassFile().getInterfaces()) { 98 for (String interfaceClassName : c.getClassFile().getInterfaces()) {
102 ClassEntry interfaceClassEntry = new ClassEntry(Descriptor.toJvmName(interfaceClassName)); 99 ClassEntry interfaceClassEntry = new ClassEntry(Descriptor.toJvmName(interfaceClassName));
103 if (!isJre(interfaceClassEntry)) { 100 if (!isJre(interfaceClassEntry)) {
104 m_interfaces.put(classEntry, interfaceClassEntry); 101 this.interfaces.put(classEntry, interfaceClassEntry);
105 } 102 }
106 } 103 }
107 104
@@ -109,25 +106,25 @@ public class TranslationIndex implements Serializable {
109 // add fields 106 // add fields
110 for (CtField field : c.getDeclaredFields()) { 107 for (CtField field : c.getDeclaredFields()) {
111 FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); 108 FieldEntry fieldEntry = EntryFactory.getFieldEntry(field);
112 m_fieldEntries.put(fieldEntry.getClassEntry(), fieldEntry); 109 this.fieldEntries.put(fieldEntry.getClassEntry(), fieldEntry);
113 } 110 }
114 111
115 // add behaviors 112 // add behaviors
116 for (CtBehavior behavior : c.getDeclaredBehaviors()) { 113 for (CtBehavior behavior : c.getDeclaredBehaviors()) {
117 BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior); 114 BehaviorEntry behaviorEntry = EntryFactory.getBehaviorEntry(behavior);
118 m_behaviorEntries.put(behaviorEntry.getClassEntry(), behaviorEntry); 115 this.behaviorEntries.put(behaviorEntry.getClassEntry(), behaviorEntry);
119 } 116 }
120 } 117 }
121 } 118 }
122 119
123 public void renameClasses(Map<String, String> renames) { 120 public void renameClasses(Map<String, String> renames) {
124 EntryRenamer.renameClassesInMap(renames, m_superclasses); 121 EntryRenamer.renameClassesInMap(renames, this.superclasses);
125 EntryRenamer.renameClassesInMultimap(renames, m_fieldEntries); 122 EntryRenamer.renameClassesInMultimap(renames,this.fieldEntries);
126 EntryRenamer.renameClassesInMultimap(renames, m_behaviorEntries); 123 EntryRenamer.renameClassesInMultimap(renames, this.behaviorEntries);
127 } 124 }
128 125
129 public ClassEntry getSuperclass(ClassEntry classEntry) { 126 public ClassEntry getSuperclass(ClassEntry classEntry) {
130 return m_superclasses.get(classEntry); 127 return this.superclasses.get(classEntry);
131 } 128 }
132 129
133 public List<ClassEntry> getAncestry(ClassEntry classEntry) { 130 public List<ClassEntry> getAncestry(ClassEntry classEntry) {
@@ -145,7 +142,7 @@ public class TranslationIndex implements Serializable {
145 142
146 // linear search is fast enough for now 143 // linear search is fast enough for now
147 List<ClassEntry> subclasses = Lists.newArrayList(); 144 List<ClassEntry> subclasses = Lists.newArrayList();
148 for (Map.Entry<ClassEntry, ClassEntry> entry : m_superclasses.entrySet()) { 145 for (Map.Entry<ClassEntry, ClassEntry> entry : this.superclasses.entrySet()) {
149 ClassEntry subclass = entry.getKey(); 146 ClassEntry subclass = entry.getKey();
150 ClassEntry superclass = entry.getValue(); 147 ClassEntry superclass = entry.getValue();
151 if (classEntry.equals(superclass)) { 148 if (classEntry.equals(superclass)) {
@@ -170,15 +167,15 @@ public class TranslationIndex implements Serializable {
170 } 167 }
171 168
172 public Collection<Map.Entry<ClassEntry, ClassEntry>> getClassInterfaces() { 169 public Collection<Map.Entry<ClassEntry, ClassEntry>> getClassInterfaces() {
173 return m_interfaces.entries(); 170 return this.interfaces.entries();
174 } 171 }
175 172
176 public Collection<ClassEntry> getInterfaces(ClassEntry classEntry) { 173 public Collection<ClassEntry> getInterfaces(ClassEntry classEntry) {
177 return m_interfaces.get(classEntry); 174 return this.interfaces.get(classEntry);
178 } 175 }
179 176
180 public boolean isInterface(ClassEntry classEntry) { 177 public boolean isInterface(ClassEntry classEntry) {
181 return m_interfaces.containsValue(classEntry); 178 return this.interfaces.containsValue(classEntry);
182 } 179 }
183 180
184 public boolean entryExists(Entry entry) { 181 public boolean entryExists(Entry entry) {
@@ -193,11 +190,11 @@ public class TranslationIndex implements Serializable {
193 } 190 }
194 191
195 public boolean fieldExists(FieldEntry fieldEntry) { 192 public boolean fieldExists(FieldEntry fieldEntry) {
196 return m_fieldEntries.containsEntry(fieldEntry.getClassEntry(), fieldEntry); 193 return this.fieldEntries.containsEntry(fieldEntry.getClassEntry(), fieldEntry);
197 } 194 }
198 195
199 public boolean behaviorExists(BehaviorEntry behaviorEntry) { 196 public boolean behaviorExists(BehaviorEntry behaviorEntry) {
200 return m_behaviorEntries.containsEntry(behaviorEntry.getClassEntry(), behaviorEntry); 197 return this.behaviorEntries.containsEntry(behaviorEntry.getClassEntry(), behaviorEntry);
201 } 198 }
202 199
203 public ClassEntry resolveEntryClass(Entry entry) { 200 public ClassEntry resolveEntryClass(Entry entry) {
@@ -243,7 +240,7 @@ public class TranslationIndex implements Serializable {
243 240
244 // the interfaces for any class is a forest 241 // the interfaces for any class is a forest
245 // so let's look at all the trees 242 // so let's look at all the trees
246 for (ClassEntry interfaceEntry : m_interfaces.get(entry.getClassEntry())) { 243 for (ClassEntry interfaceEntry : this.interfaces.get(entry.getClassEntry())) {
247 ClassEntry resolvedClassEntry = resolveSuperclass(entry.cloneToNewClass(interfaceEntry)); 244 ClassEntry resolvedClassEntry = resolveSuperclass(entry.cloneToNewClass(interfaceEntry));
248 if (resolvedClassEntry != null) { 245 if (resolvedClassEntry != null) {
249 return resolvedClassEntry; 246 return resolvedClassEntry;
@@ -261,9 +258,9 @@ public class TranslationIndex implements Serializable {
261 throws IOException { 258 throws IOException {
262 GZIPOutputStream gzipout = new GZIPOutputStream(out); 259 GZIPOutputStream gzipout = new GZIPOutputStream(out);
263 ObjectOutputStream oout = new ObjectOutputStream(gzipout); 260 ObjectOutputStream oout = new ObjectOutputStream(gzipout);
264 oout.writeObject(m_superclasses); 261 oout.writeObject(this.superclasses);
265 oout.writeObject(m_fieldEntries); 262 oout.writeObject(this.fieldEntries);
266 oout.writeObject(m_behaviorEntries); 263 oout.writeObject(this.behaviorEntries);
267 gzipout.finish(); 264 gzipout.finish();
268 } 265 }
269 266
@@ -272,9 +269,9 @@ public class TranslationIndex implements Serializable {
272 throws IOException { 269 throws IOException {
273 try { 270 try {
274 ObjectInputStream oin = new ObjectInputStream(new GZIPInputStream(in)); 271 ObjectInputStream oin = new ObjectInputStream(new GZIPInputStream(in));
275 m_superclasses = (HashMap<ClassEntry, ClassEntry>) oin.readObject(); 272 this.superclasses = (HashMap<ClassEntry, ClassEntry>) oin.readObject();
276 m_fieldEntries = (HashMultimap<ClassEntry, FieldEntry>) oin.readObject(); 273 this.fieldEntries = (HashMultimap<ClassEntry, FieldEntry>) oin.readObject();
277 m_behaviorEntries = (HashMultimap<ClassEntry, BehaviorEntry>) oin.readObject(); 274 this.behaviorEntries = (HashMultimap<ClassEntry, BehaviorEntry>) oin.readObject();
278 } catch (ClassNotFoundException ex) { 275 } catch (ClassNotFoundException ex) {
279 throw new Error(ex); 276 throw new Error(ex);
280 } 277 }