diff options
| author | 2019-01-24 14:48:32 +0200 | |
|---|---|---|
| committer | 2019-01-24 13:48:32 +0100 | |
| commit | 00fcd0550fcdda621c2e4662f6ddd55ce673b931 (patch) | |
| tree | 6f9e4c24dbcc6d118fceec56adf7bf9d747a485c /src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java | |
| parent | mark as 0.13.0-SNAPSHOT for preliminary development (diff) | |
| download | enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.tar.gz enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.tar.xz enigma-fork-00fcd0550fcdda621c2e4662f6ddd55ce673b931.zip | |
[WIP] Mapping rework (#91)
* Move packages
* Mapping & entry refactor: first pass
* Fix deobf -> obf tree remapping
* Resolve various issues
* Give all entries the potential for parents and treat inner classes as children
* Deobf UI tree elements
* Tests pass
* Sort mapping output
* Fix delta tracking
* Index separation and first pass for #97
* Keep track of remapped jar index
* Fix child entries not being remapped
* Drop non-root entries
* Track dropped mappings
* Fix enigma mapping ordering
* EntryTreeNode interface
* Small tweaks
* Naive full index remap on rename
* Entries can resolve to more than one root entry
* Support alternative resolution strategies
* Bridge method resolution
* Tests pass
* Fix mappings being used where there are none
* Fix methods with different descriptors being considered unique. closes #89
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java b/src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java new file mode 100644 index 0000000..4ca7cd1 --- /dev/null +++ b/src/main/java/cuchaz/enigma/analysis/IndexTreeBuilder.java | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | package cuchaz.enigma.analysis; | ||
| 2 | |||
| 3 | import com.google.common.collect.Lists; | ||
| 4 | import cuchaz.enigma.analysis.index.EntryIndex; | ||
| 5 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 6 | import cuchaz.enigma.translation.Translator; | ||
| 7 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | ||
| 8 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 9 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 10 | |||
| 11 | import java.util.List; | ||
| 12 | |||
| 13 | public class IndexTreeBuilder { | ||
| 14 | private final JarIndex index; | ||
| 15 | |||
| 16 | public IndexTreeBuilder(JarIndex index) { | ||
| 17 | this.index = index; | ||
| 18 | } | ||
| 19 | |||
| 20 | public ClassInheritanceTreeNode buildClassInheritance(Translator translator, ClassEntry obfClassEntry) { | ||
| 21 | // get the root node | ||
| 22 | List<String> ancestry = Lists.newArrayList(); | ||
| 23 | ancestry.add(obfClassEntry.getFullName()); | ||
| 24 | for (ClassEntry classEntry : index.getInheritanceIndex().getAncestors(obfClassEntry)) { | ||
| 25 | ancestry.add(classEntry.getFullName()); | ||
| 26 | } | ||
| 27 | |||
| 28 | ClassInheritanceTreeNode rootNode = new ClassInheritanceTreeNode(translator, ancestry.get(ancestry.size() - 1)); | ||
| 29 | |||
| 30 | // expand all children recursively | ||
| 31 | rootNode.load(index.getInheritanceIndex(), true); | ||
| 32 | |||
| 33 | return rootNode; | ||
| 34 | } | ||
| 35 | |||
| 36 | public ClassImplementationsTreeNode buildClassImplementations(Translator translator, ClassEntry obfClassEntry) { | ||
| 37 | if (index.getInheritanceIndex().isParent(obfClassEntry)) { | ||
| 38 | ClassImplementationsTreeNode node = new ClassImplementationsTreeNode(translator, obfClassEntry); | ||
| 39 | node.load(index); | ||
| 40 | return node; | ||
| 41 | } | ||
| 42 | return null; | ||
| 43 | } | ||
| 44 | |||
| 45 | public MethodInheritanceTreeNode buildMethodInheritance(Translator translator, MethodEntry obfMethodEntry) { | ||
| 46 | MethodEntry resolvedEntry = index.getEntryResolver().resolveFirstEntry(obfMethodEntry, ResolutionStrategy.RESOLVE_ROOT); | ||
| 47 | |||
| 48 | // make a root node at the base | ||
| 49 | MethodInheritanceTreeNode rootNode = new MethodInheritanceTreeNode( | ||
| 50 | translator, resolvedEntry, | ||
| 51 | index.getEntryIndex().hasMethod(resolvedEntry) | ||
| 52 | ); | ||
| 53 | |||
| 54 | // expand the full tree | ||
| 55 | rootNode.load(index, true); | ||
| 56 | |||
| 57 | return rootNode; | ||
| 58 | } | ||
| 59 | |||
| 60 | public List<MethodImplementationsTreeNode> buildMethodImplementations(Translator translator, MethodEntry obfMethodEntry) { | ||
| 61 | EntryIndex entryIndex = index.getEntryIndex(); | ||
| 62 | |||
| 63 | List<MethodEntry> ancestorMethodEntries = Lists.newArrayList(); | ||
| 64 | |||
| 65 | if (entryIndex.hasMethod(obfMethodEntry)) { | ||
| 66 | ancestorMethodEntries.add(obfMethodEntry); | ||
| 67 | } | ||
| 68 | |||
| 69 | for (ClassEntry ancestorEntry : index.getInheritanceIndex().getAncestors(obfMethodEntry.getParent())) { | ||
| 70 | MethodEntry ancestorMethod = obfMethodEntry.withParent(ancestorEntry); | ||
| 71 | if (entryIndex.hasMethod(ancestorMethod)) { | ||
| 72 | ancestorMethodEntries.add(ancestorMethod); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | List<MethodImplementationsTreeNode> nodes = Lists.newArrayList(); | ||
| 77 | if (!ancestorMethodEntries.isEmpty()) { | ||
| 78 | for (MethodEntry interfaceMethodEntry : ancestorMethodEntries) { | ||
| 79 | MethodImplementationsTreeNode node = new MethodImplementationsTreeNode(translator, interfaceMethodEntry); | ||
| 80 | node.load(index); | ||
| 81 | nodes.add(node); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | return nodes; | ||
| 86 | } | ||
| 87 | } | ||