summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Thog2016-08-14 13:29:06 +0200
committerGravatar Thog2016-08-14 13:29:06 +0200
commit9353048dae8b747c4826a7e0102ca6d2aeb1853c (patch)
tree5c9deff83241a052c7c1ecbc802b639985010b13
parentAvoid using the override fix in others case than remapping (fix unit tests fa... (diff)
downloadenigma-9353048dae8b747c4826a7e0102ca6d2aeb1853c.tar.gz
enigma-9353048dae8b747c4826a7e0102ca6d2aeb1853c.tar.xz
enigma-9353048dae8b747c4826a7e0102ca6d2aeb1853c.zip
Reverse scan of superclasses to find the first definition of method signature avoiding remapping errors
-rw-r--r--src/main/java/cuchaz/enigma/analysis/TranslationIndex.java43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java
index 14bc6044..9f751083 100644
--- a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java
+++ b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java
@@ -207,27 +207,46 @@ public class TranslationIndex {
207 return null; 207 return null;
208 } 208 }
209 209
210 public ClassEntry resolveSuperclass(Entry entry) {
211 return resolveSuperclass(entry, false);
212 }
213
214 public ClassEntry resolveSuperclass(Entry entry, boolean checkSuperclassBeforeChild) { 210 public ClassEntry resolveSuperclass(Entry entry, boolean checkSuperclassBeforeChild) {
215 // this entry could refer to a method on a class where the method is not actually implemented 211
216 // travel up the inheritance tree to find the closest implementation 212 // Default case
213 if (!checkSuperclassBeforeChild)
214 return resolveSuperclass(entry);
217 215
218 // Save the original entry 216 // Save the original entry
219 Entry originalEntry = entry; 217 Entry originalEntry = entry;
220 218
221 // Scan superclass before main class to avoid missing override issues 219 // Get all possible superclasses and reverse the list
222 ClassEntry superclassEntry = null; 220 List<ClassEntry> superclasses = Lists.reverse(getAncestry(originalEntry.getClassEntry()));
223 while ((checkSuperclassBeforeChild && superclassEntry == null) || !entryExists(entry)) { 221 boolean existInEntry = false;
222
223 for (ClassEntry classEntry : superclasses)
224 {
225 entry = entry.cloneToNewClass(classEntry);
226 existInEntry = entryExists(entry);
227 if (existInEntry)
228 break;
229 }
230
231 // Doesn't exists in superclasses? check the child or return null
232 if (!existInEntry)
233 return !entryExists(originalEntry) ? null : originalEntry.getClassEntry();
234
235 return entry.getClassEntry();
236 }
237
238 public ClassEntry resolveSuperclass(Entry entry)
239 {
240 // this entry could refer to a method on a class where the method is not actually implemented
241 // travel up the inheritance tree to find the closest implementation
224 242
243 while (!entryExists(entry)) {
225 // is there a parent class? 244 // is there a parent class?
226 superclassEntry = getSuperclass(entry.getClassEntry()); 245 ClassEntry superclassEntry = getSuperclass(entry.getClassEntry());
227 if (superclassEntry == null) { 246 if (superclassEntry == null) {
228 // this is probably a method from a class in a library or it's in the default class 247 // this is probably a method from a class in a library
229 // we can't trace the implementation up any higher unless we index the library 248 // we can't trace the implementation up any higher unless we index the library
230 return checkSuperclassBeforeChild && entryExists(originalEntry) ? originalEntry.getClassEntry() : null; 249 return null;
231 } 250 }
232 251
233 // move up to the parent class 252 // move up to the parent class