diff options
| author | 2016-07-02 20:13:13 +1000 | |
|---|---|---|
| committer | 2016-07-02 20:13:13 +1000 | |
| commit | 74edc74c2c7b3236f00bf92499bb884837673b7d (patch) | |
| tree | 155556b4d6e390574f16082583f2853e35e3c716 /src/main/java/cuchaz/enigma/convert | |
| parent | Renamed Fields (diff) | |
| download | enigma-fork-74edc74c2c7b3236f00bf92499bb884837673b7d.tar.gz enigma-fork-74edc74c2c7b3236f00bf92499bb884837673b7d.tar.xz enigma-fork-74edc74c2c7b3236f00bf92499bb884837673b7d.zip | |
Reformatting code
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert')
6 files changed, 29 insertions, 203 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java index 2317a3d..606c1df 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java | |||
| @@ -58,7 +58,7 @@ public class ClassIdentity { | |||
| 58 | 58 | ||
| 59 | // classes not in the none package can be passed through | 59 | // classes not in the none package can be passed through |
| 60 | ClassEntry classEntry = new ClassEntry(className); | 60 | ClassEntry classEntry = new ClassEntry(className); |
| 61 | if (!classEntry.getPackageName().equals(Constants.NonePackage)) { | 61 | if (!classEntry.getPackageName().equals(Constants.NONE_PACKAGE)) { |
| 62 | return className; | 62 | return className; |
| 63 | } | 63 | } |
| 64 | 64 | ||
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java index 3a25435..0b7e803 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatches.java | |||
| @@ -45,9 +45,7 @@ public class ClassMatches implements Iterable<ClassMatch> { | |||
| 45 | m_unmatchedSourceClasses = Sets.newHashSet(); | 45 | m_unmatchedSourceClasses = Sets.newHashSet(); |
| 46 | m_unmatchedDestClasses = Sets.newHashSet(); | 46 | m_unmatchedDestClasses = Sets.newHashSet(); |
| 47 | 47 | ||
| 48 | for (ClassMatch match : matches) { | 48 | matches.forEach(this::indexMatch); |
| 49 | indexMatch(match); | ||
| 50 | } | ||
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | public void add(ClassMatch match) { | 51 | public void add(ClassMatch match) { |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatching.java b/src/main/java/cuchaz/enigma/convert/ClassMatching.java index 9350ea7..194b6c4 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatching.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatching.java | |||
| @@ -55,23 +55,14 @@ public class ClassMatching { | |||
| 55 | public Collection<ClassMatch> matches() { | 55 | public Collection<ClassMatch> matches() { |
| 56 | List<ClassMatch> matches = Lists.newArrayList(); | 56 | List<ClassMatch> matches = Lists.newArrayList(); |
| 57 | for (Entry<ClassEntry, ClassEntry> entry : m_knownMatches.entrySet()) { | 57 | for (Entry<ClassEntry, ClassEntry> entry : m_knownMatches.entrySet()) { |
| 58 | matches.add(new ClassMatch( | 58 | matches.add(new ClassMatch(entry.getKey(), entry.getValue())); |
| 59 | entry.getKey(), | ||
| 60 | entry.getValue() | ||
| 61 | )); | ||
| 62 | } | 59 | } |
| 63 | for (ClassIdentity identity : m_sourceClasses.identities()) { | 60 | for (ClassIdentity identity : m_sourceClasses.identities()) { |
| 64 | matches.add(new ClassMatch( | 61 | matches.add(new ClassMatch(m_sourceClasses.getClasses(identity), m_destClasses.getClasses(identity))); |
| 65 | m_sourceClasses.getClasses(identity), | ||
| 66 | m_destClasses.getClasses(identity) | ||
| 67 | )); | ||
| 68 | } | 62 | } |
| 69 | for (ClassIdentity identity : m_destClasses.identities()) { | 63 | for (ClassIdentity identity : m_destClasses.identities()) { |
| 70 | if (!m_sourceClasses.containsIdentity(identity)) { | 64 | if (!m_sourceClasses.containsIdentity(identity)) { |
| 71 | matches.add(new ClassMatch( | 65 | matches.add(new ClassMatch(new ArrayList<>(), m_destClasses.getClasses(identity))); |
| 72 | new ArrayList<>(), | ||
| 73 | m_destClasses.getClasses(identity) | ||
| 74 | )); | ||
| 75 | } | 66 | } |
| 76 | } | 67 | } |
| 77 | return matches; | 68 | return matches; |
diff --git a/src/main/java/cuchaz/enigma/convert/FieldMatches.java b/src/main/java/cuchaz/enigma/convert/FieldMatches.java deleted file mode 100644 index 0899cd2..0000000 --- a/src/main/java/cuchaz/enigma/convert/FieldMatches.java +++ /dev/null | |||
| @@ -1,151 +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 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import com.google.common.collect.*; | ||
| 14 | |||
| 15 | import java.util.Collection; | ||
| 16 | import java.util.Set; | ||
| 17 | |||
| 18 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 19 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 20 | |||
| 21 | |||
| 22 | public class FieldMatches { | ||
| 23 | |||
| 24 | private BiMap<FieldEntry, FieldEntry> m_matches; | ||
| 25 | private Multimap<ClassEntry, FieldEntry> m_matchedSourceFields; | ||
| 26 | private Multimap<ClassEntry, FieldEntry> m_unmatchedSourceFields; | ||
| 27 | private Multimap<ClassEntry, FieldEntry> m_unmatchedDestFields; | ||
| 28 | private Multimap<ClassEntry, FieldEntry> m_unmatchableSourceFields; | ||
| 29 | |||
| 30 | public FieldMatches() { | ||
| 31 | m_matches = HashBiMap.create(); | ||
| 32 | m_matchedSourceFields = HashMultimap.create(); | ||
| 33 | m_unmatchedSourceFields = HashMultimap.create(); | ||
| 34 | m_unmatchedDestFields = HashMultimap.create(); | ||
| 35 | m_unmatchableSourceFields = HashMultimap.create(); | ||
| 36 | } | ||
| 37 | |||
| 38 | public void addMatch(FieldEntry srcField, FieldEntry destField) { | ||
| 39 | boolean wasAdded = m_matches.put(srcField, destField) == null; | ||
| 40 | assert (wasAdded); | ||
| 41 | wasAdded = m_matchedSourceFields.put(srcField.getClassEntry(), srcField); | ||
| 42 | assert (wasAdded); | ||
| 43 | } | ||
| 44 | |||
| 45 | public void addUnmatchedSourceField(FieldEntry fieldEntry) { | ||
| 46 | boolean wasAdded = m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); | ||
| 47 | assert (wasAdded); | ||
| 48 | } | ||
| 49 | |||
| 50 | public void addUnmatchedSourceFields(Iterable<FieldEntry> fieldEntries) { | ||
| 51 | for (FieldEntry fieldEntry : fieldEntries) { | ||
| 52 | addUnmatchedSourceField(fieldEntry); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | public void addUnmatchedDestField(FieldEntry fieldEntry) { | ||
| 57 | boolean wasAdded = m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); | ||
| 58 | assert (wasAdded); | ||
| 59 | } | ||
| 60 | |||
| 61 | public void addUnmatchedDestFields(Iterable<FieldEntry> fieldEntries) { | ||
| 62 | for (FieldEntry fieldEntry : fieldEntries) { | ||
| 63 | addUnmatchedDestField(fieldEntry); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | public void addUnmatchableSourceField(FieldEntry sourceField) { | ||
| 68 | boolean wasAdded = m_unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField); | ||
| 69 | assert (wasAdded); | ||
| 70 | } | ||
| 71 | |||
| 72 | public Set<ClassEntry> getSourceClassesWithUnmatchedFields() { | ||
| 73 | return m_unmatchedSourceFields.keySet(); | ||
| 74 | } | ||
| 75 | |||
| 76 | public Collection<ClassEntry> getSourceClassesWithoutUnmatchedFields() { | ||
| 77 | Set<ClassEntry> out = Sets.newHashSet(); | ||
| 78 | out.addAll(m_matchedSourceFields.keySet()); | ||
| 79 | out.removeAll(m_unmatchedSourceFields.keySet()); | ||
| 80 | return out; | ||
| 81 | } | ||
| 82 | |||
| 83 | public Collection<FieldEntry> getUnmatchedSourceFields() { | ||
| 84 | return m_unmatchedSourceFields.values(); | ||
| 85 | } | ||
| 86 | |||
| 87 | public Collection<FieldEntry> getUnmatchedSourceFields(ClassEntry sourceClass) { | ||
| 88 | return m_unmatchedSourceFields.get(sourceClass); | ||
| 89 | } | ||
| 90 | |||
| 91 | public Collection<FieldEntry> getUnmatchedDestFields() { | ||
| 92 | return m_unmatchedDestFields.values(); | ||
| 93 | } | ||
| 94 | |||
| 95 | public Collection<FieldEntry> getUnmatchedDestFields(ClassEntry destClass) { | ||
| 96 | return m_unmatchedDestFields.get(destClass); | ||
| 97 | } | ||
| 98 | |||
| 99 | public Collection<FieldEntry> getUnmatchableSourceFields() { | ||
| 100 | return m_unmatchableSourceFields.values(); | ||
| 101 | } | ||
| 102 | |||
| 103 | public boolean hasSource(FieldEntry fieldEntry) { | ||
| 104 | return m_matches.containsKey(fieldEntry) || m_unmatchedSourceFields.containsValue(fieldEntry); | ||
| 105 | } | ||
| 106 | |||
| 107 | public boolean hasDest(FieldEntry fieldEntry) { | ||
| 108 | return m_matches.containsValue(fieldEntry) || m_unmatchedDestFields.containsValue(fieldEntry); | ||
| 109 | } | ||
| 110 | |||
| 111 | public BiMap<FieldEntry, FieldEntry> matches() { | ||
| 112 | return m_matches; | ||
| 113 | } | ||
| 114 | |||
| 115 | public boolean isMatchedSourceField(FieldEntry sourceField) { | ||
| 116 | return m_matches.containsKey(sourceField); | ||
| 117 | } | ||
| 118 | |||
| 119 | public boolean isMatchedDestField(FieldEntry destField) { | ||
| 120 | return m_matches.containsValue(destField); | ||
| 121 | } | ||
| 122 | |||
| 123 | public void makeMatch(FieldEntry sourceField, FieldEntry destField) { | ||
| 124 | boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 125 | assert (wasRemoved); | ||
| 126 | wasRemoved = m_unmatchedDestFields.remove(destField.getClassEntry(), destField); | ||
| 127 | assert (wasRemoved); | ||
| 128 | addMatch(sourceField, destField); | ||
| 129 | } | ||
| 130 | |||
| 131 | public boolean isMatched(FieldEntry sourceField, FieldEntry destField) { | ||
| 132 | FieldEntry match = m_matches.get(sourceField); | ||
| 133 | return match != null && match.equals(destField); | ||
| 134 | } | ||
| 135 | |||
| 136 | public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) { | ||
| 137 | boolean wasRemoved = m_matches.remove(sourceField) != null; | ||
| 138 | assert (wasRemoved); | ||
| 139 | wasRemoved = m_matchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 140 | assert (wasRemoved); | ||
| 141 | addUnmatchedSourceField(sourceField); | ||
| 142 | addUnmatchedDestField(destField); | ||
| 143 | } | ||
| 144 | |||
| 145 | public void makeSourceUnmatchable(FieldEntry sourceField) { | ||
| 146 | assert (!isMatchedSourceField(sourceField)); | ||
| 147 | boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); | ||
| 148 | assert (wasRemoved); | ||
| 149 | addUnmatchableSourceField(sourceField); | ||
| 150 | } | ||
| 151 | } | ||
diff --git a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java index 394b8c8..d1daadb 100644 --- a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java +++ b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java | |||
| @@ -151,7 +151,9 @@ public class MappingsConverter { | |||
| 151 | } | 151 | } |
| 152 | } | 152 | } |
| 153 | } | 153 | } |
| 154 | destMapping.addInnerClassMapping(migrateClassMapping(obfDestClassEntry, sourceMapping, matches, true)); | 154 | if (destMapping != null) { |
| 155 | destMapping.addInnerClassMapping(migrateClassMapping(obfDestClassEntry, sourceMapping, matches, true)); | ||
| 156 | } | ||
| 155 | } | 157 | } |
| 156 | } | 158 | } |
| 157 | } | 159 | } |
| @@ -160,15 +162,12 @@ public class MappingsConverter { | |||
| 160 | 162 | ||
| 161 | private static ClassMapping migrateClassMapping(ClassEntry newObfClass, ClassMapping oldClassMapping, final ClassMatches matches, boolean useSimpleName) { | 163 | private static ClassMapping migrateClassMapping(ClassEntry newObfClass, ClassMapping oldClassMapping, final ClassMatches matches, boolean useSimpleName) { |
| 162 | 164 | ||
| 163 | ClassNameReplacer replacer = new ClassNameReplacer() { | 165 | ClassNameReplacer replacer = className -> { |
| 164 | @Override | 166 | ClassEntry newClassEntry = matches.getUniqueMatches().get(new ClassEntry(className)); |
| 165 | public String replace(String className) { | 167 | if (newClassEntry != null) { |
| 166 | ClassEntry newClassEntry = matches.getUniqueMatches().get(new ClassEntry(className)); | 168 | return newClassEntry.getName(); |
| 167 | if (newClassEntry != null) { | ||
| 168 | return newClassEntry.getName(); | ||
| 169 | } | ||
| 170 | return null; | ||
| 171 | } | 169 | } |
| 170 | return null; | ||
| 172 | }; | 171 | }; |
| 173 | 172 | ||
| 174 | ClassMapping newClassMapping; | 173 | ClassMapping newClassMapping; |
| @@ -229,7 +228,7 @@ public class MappingsConverter { | |||
| 229 | 228 | ||
| 230 | // non obfuscated classes can be migrated | 229 | // non obfuscated classes can be migrated |
| 231 | ClassEntry classEntry = oldObfType.getClassEntry(); | 230 | ClassEntry classEntry = oldObfType.getClassEntry(); |
| 232 | if (!classEntry.getPackageName().equals(Constants.NonePackage)) { | 231 | if (!classEntry.getPackageName().equals(Constants.NONE_PACKAGE)) { |
| 233 | return true; | 232 | return true; |
| 234 | } | 233 | } |
| 235 | 234 | ||
| @@ -390,7 +389,7 @@ public class MappingsConverter { | |||
| 390 | 389 | ||
| 391 | public static <T extends Entry> MemberMatches<T> computeMemberMatches(Deobfuscator destDeobfuscator, Mappings destMappings, ClassMatches classMatches, Doer<T> doer) { | 390 | public static <T extends Entry> MemberMatches<T> computeMemberMatches(Deobfuscator destDeobfuscator, Mappings destMappings, ClassMatches classMatches, Doer<T> doer) { |
| 392 | 391 | ||
| 393 | MemberMatches<T> memberMatches = new MemberMatches<T>(); | 392 | MemberMatches<T> memberMatches = new MemberMatches<>(); |
| 394 | 393 | ||
| 395 | // unmatched source fields are easy | 394 | // unmatched source fields are easy |
| 396 | MappingsChecker checker = new MappingsChecker(destDeobfuscator.getJarIndex()); | 395 | MappingsChecker checker = new MappingsChecker(destDeobfuscator.getJarIndex()); |
| @@ -481,15 +480,12 @@ public class MappingsConverter { | |||
| 481 | } | 480 | } |
| 482 | 481 | ||
| 483 | private static Type translate(Type type, final BiMap<ClassEntry, ClassEntry> map) { | 482 | private static Type translate(Type type, final BiMap<ClassEntry, ClassEntry> map) { |
| 484 | return new Type(type, new ClassNameReplacer() { | 483 | return new Type(type, inClassName -> { |
| 485 | @Override | 484 | ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); |
| 486 | public String replace(String inClassName) { | 485 | if (outClassEntry == null) { |
| 487 | ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); | 486 | return null; |
| 488 | if (outClassEntry == null) { | ||
| 489 | return null; | ||
| 490 | } | ||
| 491 | return outClassEntry.getName(); | ||
| 492 | } | 487 | } |
| 488 | return outClassEntry.getName(); | ||
| 493 | }); | 489 | }); |
| 494 | } | 490 | } |
| 495 | 491 | ||
| @@ -497,15 +493,12 @@ public class MappingsConverter { | |||
| 497 | if (signature == null) { | 493 | if (signature == null) { |
| 498 | return null; | 494 | return null; |
| 499 | } | 495 | } |
| 500 | return new Signature(signature, new ClassNameReplacer() { | 496 | return new Signature(signature, inClassName -> { |
| 501 | @Override | 497 | ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); |
| 502 | public String replace(String inClassName) { | 498 | if (outClassEntry == null) { |
| 503 | ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); | 499 | return null; |
| 504 | if (outClassEntry == null) { | ||
| 505 | return null; | ||
| 506 | } | ||
| 507 | return outClassEntry.getName(); | ||
| 508 | } | 500 | } |
| 501 | return outClassEntry.getName(); | ||
| 509 | }); | 502 | }); |
| 510 | } | 503 | } |
| 511 | 504 | ||
diff --git a/src/main/java/cuchaz/enigma/convert/MatchesReader.java b/src/main/java/cuchaz/enigma/convert/MatchesReader.java index 773566d..f7853ac 100644 --- a/src/main/java/cuchaz/enigma/convert/MatchesReader.java +++ b/src/main/java/cuchaz/enigma/convert/MatchesReader.java | |||
| @@ -28,7 +28,7 @@ public class MatchesReader { | |||
| 28 | throws IOException { | 28 | throws IOException { |
| 29 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { | 29 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { |
| 30 | ClassMatches matches = new ClassMatches(); | 30 | ClassMatches matches = new ClassMatches(); |
| 31 | String line = null; | 31 | String line; |
| 32 | while ((line = in.readLine()) != null) { | 32 | while ((line = in.readLine()) != null) { |
| 33 | matches.add(readClassMatch(line)); | 33 | matches.add(readClassMatch(line)); |
| 34 | } | 34 | } |
| @@ -56,8 +56,8 @@ public class MatchesReader { | |||
| 56 | public static <T extends Entry> MemberMatches<T> readMembers(File file) | 56 | public static <T extends Entry> MemberMatches<T> readMembers(File file) |
| 57 | throws IOException { | 57 | throws IOException { |
| 58 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { | 58 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { |
| 59 | MemberMatches<T> matches = new MemberMatches<T>(); | 59 | MemberMatches<T> matches = new MemberMatches<>(); |
| 60 | String line = null; | 60 | String line; |
| 61 | while ((line = in.readLine()) != null) { | 61 | while ((line = in.readLine()) != null) { |
| 62 | readMemberMatch(matches, line); | 62 | readMemberMatch(matches, line); |
| 63 | } | 63 | } |
| @@ -90,13 +90,8 @@ public class MatchesReader { | |||
| 90 | } | 90 | } |
| 91 | String[] parts = in.split(" "); | 91 | String[] parts = in.split(" "); |
| 92 | if (parts.length == 3 && parts[2].indexOf('(') < 0) { | 92 | if (parts.length == 3 && parts[2].indexOf('(') < 0) { |
| 93 | return (T) new FieldEntry( | 93 | return (T) new FieldEntry(new ClassEntry(parts[0]), parts[1], new Type(parts[2])); |
| 94 | new ClassEntry(parts[0]), | ||
| 95 | parts[1], | ||
| 96 | new Type(parts[2]) | ||
| 97 | ); | ||
| 98 | } else { | 94 | } else { |
| 99 | assert (parts.length == 2 || parts.length == 3); | ||
| 100 | if (parts.length == 2) { | 95 | if (parts.length == 2) { |
| 101 | return (T) EntryFactory.getBehaviorEntry(parts[0], parts[1]); | 96 | return (T) EntryFactory.getBehaviorEntry(parts[0], parts[1]); |
| 102 | } else if (parts.length == 3) { | 97 | } else if (parts.length == 3) { |