summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert
diff options
context:
space:
mode:
authorGravatar Thog2017-03-07 21:24:39 +0100
committerGravatar Thog2017-03-07 21:30:02 +0100
commitb4aaff683d78ab92b83f3a7257c33b8e27d1affa (patch)
treef23c9bb0927d83cc7302881266b7df8fd37959c7 /src/main/java/cuchaz/enigma/convert
parentAvoid crash of the matcher when the obf name is invalid (set a deob it using ... (diff)
downloadenigma-fork-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.tar.gz
enigma-fork-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.tar.xz
enigma-fork-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.zip
Drop unix case style and implement hashCode when equals is overrided
Also update Guava to version 21
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert')
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassIdentity.java19
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassMatches.java88
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassMatching.java36
-rw-r--r--src/main/java/cuchaz/enigma/convert/FieldMatches.java68
-rw-r--r--src/main/java/cuchaz/enigma/convert/MappingsConverter.java53
-rw-r--r--src/main/java/cuchaz/enigma/convert/MatchesReader.java5
-rw-r--r--src/main/java/cuchaz/enigma/convert/MemberMatches.java70
7 files changed, 164 insertions, 175 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java
index 7360011..f72bf70 100644
--- a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java
+++ b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java
@@ -20,7 +20,6 @@ import java.util.List;
20import java.util.Map; 20import java.util.Map;
21import java.util.Set; 21import java.util.Set;
22 22
23import cuchaz.enigma.Constants;
24import cuchaz.enigma.analysis.ClassImplementationsTreeNode; 23import cuchaz.enigma.analysis.ClassImplementationsTreeNode;
25import cuchaz.enigma.analysis.EntryReference; 24import cuchaz.enigma.analysis.EntryReference;
26import cuchaz.enigma.analysis.JarIndex; 25import cuchaz.enigma.analysis.JarIndex;
@@ -49,9 +48,9 @@ public class ClassIdentity {
49 private Multiset<String> references; 48 private Multiset<String> references;
50 private String outer; 49 private String outer;
51 50
52 private final ClassNameReplacer m_classNameReplacer = new ClassNameReplacer() { 51 private final ClassNameReplacer classNameReplacer = new ClassNameReplacer() {
53 52
54 private Map<String, String> m_classNames = Maps.newHashMap(); 53 private Map<String, String> classNames = Maps.newHashMap();
55 54
56 @Override 55 @Override
57 public String replace(String className) { 56 public String replace(String className) {
@@ -76,14 +75,14 @@ public class ClassIdentity {
76 } 75 }
77 76
78 // otherwise, use local naming 77 // otherwise, use local naming
79 if (!m_classNames.containsKey(className)) { 78 if (!classNames.containsKey(className)) {
80 m_classNames.put(className, getNewClassName()); 79 classNames.put(className, getNewClassName());
81 } 80 }
82 return m_classNames.get(className); 81 return classNames.get(className);
83 } 82 }
84 83
85 private String getNewClassName() { 84 private String getNewClassName() {
86 return String.format("C%03d", m_classNames.size()); 85 return String.format("C%03d", classNames.size());
87 } 86 }
88 }; 87 };
89 88
@@ -229,7 +228,7 @@ public class ClassIdentity {
229 } 228 }
230 229
231 private String scrubClassName(String className) { 230 private String scrubClassName(String className) {
232 return m_classNameReplacer.replace(className); 231 return classNameReplacer.replace(className);
233 } 232 }
234 233
235 private String scrubType(String typeName) { 234 private String scrubType(String typeName) {
@@ -238,7 +237,7 @@ public class ClassIdentity {
238 237
239 private Type scrubType(Type type) { 238 private Type scrubType(Type type) {
240 if (type.hasClass()) { 239 if (type.hasClass()) {
241 return new Type(type, m_classNameReplacer); 240 return new Type(type, classNameReplacer);
242 } else { 241 } else {
243 return type; 242 return type;
244 } 243 }
@@ -249,7 +248,7 @@ public class ClassIdentity {
249 } 248 }
250 249
251 private Signature scrubSignature(Signature signature) { 250 private Signature scrubSignature(Signature signature) {
252 return new Signature(signature, m_classNameReplacer); 251 return new Signature(signature, classNameReplacer);
253 } 252 }
254 253
255 private boolean isClassMatchedUniquely(String className) { 254 private boolean isClassMatchedUniquely(String className) {
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java
index 3a25435..431c4f2 100644
--- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java
+++ b/src/main/java/cuchaz/enigma/convert/ClassMatches.java
@@ -22,28 +22,28 @@ import cuchaz.enigma.mapping.ClassEntry;
22 22
23public class ClassMatches implements Iterable<ClassMatch> { 23public class ClassMatches implements Iterable<ClassMatch> {
24 24
25 Collection<ClassMatch> m_matches; 25 private Collection<ClassMatch> matches;
26 Map<ClassEntry, ClassMatch> m_matchesBySource; 26 private Map<ClassEntry, ClassMatch> matchesBySource;
27 Map<ClassEntry, ClassMatch> m_matchesByDest; 27 private Map<ClassEntry, ClassMatch> matchesByDest;
28 BiMap<ClassEntry, ClassEntry> m_uniqueMatches; 28 private BiMap<ClassEntry, ClassEntry> uniqueMatches;
29 Map<ClassEntry, ClassMatch> m_ambiguousMatchesBySource; 29 private Map<ClassEntry, ClassMatch> ambiguousMatchesBySource;
30 Map<ClassEntry, ClassMatch> m_ambiguousMatchesByDest; 30 private Map<ClassEntry, ClassMatch> ambiguousMatchesByDest;
31 Set<ClassEntry> m_unmatchedSourceClasses; 31 private Set<ClassEntry> unmatchedSourceClasses;
32 Set<ClassEntry> m_unmatchedDestClasses; 32 private Set<ClassEntry> unmatchedDestClasses;
33 33
34 public ClassMatches() { 34 public ClassMatches() {
35 this(new ArrayList<>()); 35 this(new ArrayList<>());
36 } 36 }
37 37
38 public ClassMatches(Collection<ClassMatch> matches) { 38 public ClassMatches(Collection<ClassMatch> matches) {
39 m_matches = matches; 39 this.matches = matches;
40 m_matchesBySource = Maps.newHashMap(); 40 matchesBySource = Maps.newHashMap();
41 m_matchesByDest = Maps.newHashMap(); 41 matchesByDest = Maps.newHashMap();
42 m_uniqueMatches = HashBiMap.create(); 42 uniqueMatches = HashBiMap.create();
43 m_ambiguousMatchesBySource = Maps.newHashMap(); 43 ambiguousMatchesBySource = Maps.newHashMap();
44 m_ambiguousMatchesByDest = Maps.newHashMap(); 44 ambiguousMatchesByDest = Maps.newHashMap();
45 m_unmatchedSourceClasses = Sets.newHashSet(); 45 unmatchedSourceClasses = Sets.newHashSet();
46 m_unmatchedDestClasses = Sets.newHashSet(); 46 unmatchedDestClasses = Sets.newHashSet();
47 47
48 for (ClassMatch match : matches) { 48 for (ClassMatch match : matches) {
49 indexMatch(match); 49 indexMatch(match);
@@ -51,92 +51,92 @@ public class ClassMatches implements Iterable<ClassMatch> {
51 } 51 }
52 52
53 public void add(ClassMatch match) { 53 public void add(ClassMatch match) {
54 m_matches.add(match); 54 matches.add(match);
55 indexMatch(match); 55 indexMatch(match);
56 } 56 }
57 57
58 public void remove(ClassMatch match) { 58 public void remove(ClassMatch match) {
59 for (ClassEntry sourceClass : match.sourceClasses) { 59 for (ClassEntry sourceClass : match.sourceClasses) {
60 m_matchesBySource.remove(sourceClass); 60 matchesBySource.remove(sourceClass);
61 m_uniqueMatches.remove(sourceClass); 61 uniqueMatches.remove(sourceClass);
62 m_ambiguousMatchesBySource.remove(sourceClass); 62 ambiguousMatchesBySource.remove(sourceClass);
63 m_unmatchedSourceClasses.remove(sourceClass); 63 unmatchedSourceClasses.remove(sourceClass);
64 } 64 }
65 for (ClassEntry destClass : match.destClasses) { 65 for (ClassEntry destClass : match.destClasses) {
66 m_matchesByDest.remove(destClass); 66 matchesByDest.remove(destClass);
67 m_uniqueMatches.inverse().remove(destClass); 67 uniqueMatches.inverse().remove(destClass);
68 m_ambiguousMatchesByDest.remove(destClass); 68 ambiguousMatchesByDest.remove(destClass);
69 m_unmatchedDestClasses.remove(destClass); 69 unmatchedDestClasses.remove(destClass);
70 } 70 }
71 m_matches.remove(match); 71 matches.remove(match);
72 } 72 }
73 73
74 public int size() { 74 public int size() {
75 return m_matches.size(); 75 return matches.size();
76 } 76 }
77 77
78 @Override 78 @Override
79 public Iterator<ClassMatch> iterator() { 79 public Iterator<ClassMatch> iterator() {
80 return m_matches.iterator(); 80 return matches.iterator();
81 } 81 }
82 82
83 private void indexMatch(ClassMatch match) { 83 private void indexMatch(ClassMatch match) {
84 if (!match.isMatched()) { 84 if (!match.isMatched()) {
85 // unmatched 85 // unmatched
86 m_unmatchedSourceClasses.addAll(match.sourceClasses); 86 unmatchedSourceClasses.addAll(match.sourceClasses);
87 m_unmatchedDestClasses.addAll(match.destClasses); 87 unmatchedDestClasses.addAll(match.destClasses);
88 } else { 88 } else {
89 if (match.isAmbiguous()) { 89 if (match.isAmbiguous()) {
90 // ambiguously matched 90 // ambiguously matched
91 for (ClassEntry entry : match.sourceClasses) { 91 for (ClassEntry entry : match.sourceClasses) {
92 m_ambiguousMatchesBySource.put(entry, match); 92 ambiguousMatchesBySource.put(entry, match);
93 } 93 }
94 for (ClassEntry entry : match.destClasses) { 94 for (ClassEntry entry : match.destClasses) {
95 m_ambiguousMatchesByDest.put(entry, match); 95 ambiguousMatchesByDest.put(entry, match);
96 } 96 }
97 } else { 97 } else {
98 // uniquely matched 98 // uniquely matched
99 m_uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest()); 99 uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest());
100 } 100 }
101 } 101 }
102 for (ClassEntry entry : match.sourceClasses) { 102 for (ClassEntry entry : match.sourceClasses) {
103 m_matchesBySource.put(entry, match); 103 matchesBySource.put(entry, match);
104 } 104 }
105 for (ClassEntry entry : match.destClasses) { 105 for (ClassEntry entry : match.destClasses) {
106 m_matchesByDest.put(entry, match); 106 matchesByDest.put(entry, match);
107 } 107 }
108 } 108 }
109 109
110 public BiMap<ClassEntry, ClassEntry> getUniqueMatches() { 110 public BiMap<ClassEntry, ClassEntry> getUniqueMatches() {
111 return m_uniqueMatches; 111 return uniqueMatches;
112 } 112 }
113 113
114 public Set<ClassEntry> getUnmatchedSourceClasses() { 114 public Set<ClassEntry> getUnmatchedSourceClasses() {
115 return m_unmatchedSourceClasses; 115 return unmatchedSourceClasses;
116 } 116 }
117 117
118 public Set<ClassEntry> getUnmatchedDestClasses() { 118 public Set<ClassEntry> getUnmatchedDestClasses() {
119 return m_unmatchedDestClasses; 119 return unmatchedDestClasses;
120 } 120 }
121 121
122 public Set<ClassEntry> getAmbiguouslyMatchedSourceClasses() { 122 public Set<ClassEntry> getAmbiguouslyMatchedSourceClasses() {
123 return m_ambiguousMatchesBySource.keySet(); 123 return ambiguousMatchesBySource.keySet();
124 } 124 }
125 125
126 public ClassMatch getAmbiguousMatchBySource(ClassEntry sourceClass) { 126 public ClassMatch getAmbiguousMatchBySource(ClassEntry sourceClass) {
127 return m_ambiguousMatchesBySource.get(sourceClass); 127 return ambiguousMatchesBySource.get(sourceClass);
128 } 128 }
129 129
130 public ClassMatch getMatchBySource(ClassEntry sourceClass) { 130 public ClassMatch getMatchBySource(ClassEntry sourceClass) {
131 return m_matchesBySource.get(sourceClass); 131 return matchesBySource.get(sourceClass);
132 } 132 }
133 133
134 public ClassMatch getMatchByDest(ClassEntry destClass) { 134 public ClassMatch getMatchByDest(ClassEntry destClass) {
135 return m_matchesByDest.get(destClass); 135 return matchesByDest.get(destClass);
136 } 136 }
137 137
138 public void removeSource(ClassEntry sourceClass) { 138 public void removeSource(ClassEntry sourceClass) {
139 ClassMatch match = m_matchesBySource.get(sourceClass); 139 ClassMatch match = matchesBySource.get(sourceClass);
140 if (match != null) { 140 if (match != null) {
141 remove(match); 141 remove(match);
142 match.sourceClasses.remove(sourceClass); 142 match.sourceClasses.remove(sourceClass);
@@ -147,7 +147,7 @@ public class ClassMatches implements Iterable<ClassMatch> {
147 } 147 }
148 148
149 public void removeDest(ClassEntry destClass) { 149 public void removeDest(ClassEntry destClass) {
150 ClassMatch match = m_matchesByDest.get(destClass); 150 ClassMatch match = matchesByDest.get(destClass);
151 if (match != null) { 151 if (match != null) {
152 remove(match); 152 remove(match);
153 match.destClasses.remove(destClass); 153 match.destClasses.remove(destClass);
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatching.java b/src/main/java/cuchaz/enigma/convert/ClassMatching.java
index af9ae01..b05df87 100644
--- a/src/main/java/cuchaz/enigma/convert/ClassMatching.java
+++ b/src/main/java/cuchaz/enigma/convert/ClassMatching.java
@@ -25,52 +25,52 @@ import cuchaz.enigma.mapping.ClassEntry;
25 25
26public class ClassMatching { 26public class ClassMatching {
27 27
28 private ClassForest m_sourceClasses; 28 private ClassForest sourceClasses;
29 private ClassForest m_destClasses; 29 private ClassForest destClasses;
30 private BiMap<ClassEntry, ClassEntry> m_knownMatches; 30 private BiMap<ClassEntry, ClassEntry> knownMatches;
31 31
32 public ClassMatching(ClassIdentifier sourceIdentifier, ClassIdentifier destIdentifier) { 32 public ClassMatching(ClassIdentifier sourceIdentifier, ClassIdentifier destIdentifier) {
33 m_sourceClasses = new ClassForest(sourceIdentifier); 33 sourceClasses = new ClassForest(sourceIdentifier);
34 m_destClasses = new ClassForest(destIdentifier); 34 destClasses = new ClassForest(destIdentifier);
35 m_knownMatches = HashBiMap.create(); 35 knownMatches = HashBiMap.create();
36 } 36 }
37 37
38 public void addKnownMatches(BiMap<ClassEntry, ClassEntry> knownMatches) { 38 public void addKnownMatches(BiMap<ClassEntry, ClassEntry> knownMatches) {
39 m_knownMatches.putAll(knownMatches); 39 this.knownMatches.putAll(knownMatches);
40 } 40 }
41 41
42 public void match(Iterable<ClassEntry> sourceClasses, Iterable<ClassEntry> destClasses) { 42 public void match(Iterable<ClassEntry> sourceClasses, Iterable<ClassEntry> destClasses) {
43 for (ClassEntry sourceClass : sourceClasses) { 43 for (ClassEntry sourceClass : sourceClasses) {
44 if (!m_knownMatches.containsKey(sourceClass)) { 44 if (!knownMatches.containsKey(sourceClass)) {
45 m_sourceClasses.add(sourceClass); 45 this.sourceClasses.add(sourceClass);
46 } 46 }
47 } 47 }
48 for (ClassEntry destClass : destClasses) { 48 for (ClassEntry destClass : destClasses) {
49 if (!m_knownMatches.containsValue(destClass)) { 49 if (!knownMatches.containsValue(destClass)) {
50 m_destClasses.add(destClass); 50 this.destClasses.add(destClass);
51 } 51 }
52 } 52 }
53 } 53 }
54 54
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 : knownMatches.entrySet()) {
58 matches.add(new ClassMatch( 58 matches.add(new ClassMatch(
59 entry.getKey(), 59 entry.getKey(),
60 entry.getValue() 60 entry.getValue()
61 )); 61 ));
62 } 62 }
63 for (ClassIdentity identity : m_sourceClasses.identities()) { 63 for (ClassIdentity identity : sourceClasses.identities()) {
64 matches.add(new ClassMatch( 64 matches.add(new ClassMatch(
65 m_sourceClasses.getClasses(identity), 65 sourceClasses.getClasses(identity),
66 m_destClasses.getClasses(identity) 66 destClasses.getClasses(identity)
67 )); 67 ));
68 } 68 }
69 for (ClassIdentity identity : m_destClasses.identities()) { 69 for (ClassIdentity identity : destClasses.identities()) {
70 if (!m_sourceClasses.containsIdentity(identity)) { 70 if (!sourceClasses.containsIdentity(identity)) {
71 matches.add(new ClassMatch( 71 matches.add(new ClassMatch(
72 new ArrayList<>(), 72 new ArrayList<>(),
73 m_destClasses.getClasses(identity) 73 destClasses.getClasses(identity)
74 )); 74 ));
75 } 75 }
76 } 76 }
diff --git a/src/main/java/cuchaz/enigma/convert/FieldMatches.java b/src/main/java/cuchaz/enigma/convert/FieldMatches.java
index 0899cd2..236cd4d 100644
--- a/src/main/java/cuchaz/enigma/convert/FieldMatches.java
+++ b/src/main/java/cuchaz/enigma/convert/FieldMatches.java
@@ -21,29 +21,29 @@ import cuchaz.enigma.mapping.FieldEntry;
21 21
22public class FieldMatches { 22public class FieldMatches {
23 23
24 private BiMap<FieldEntry, FieldEntry> m_matches; 24 private BiMap<FieldEntry, FieldEntry> matches;
25 private Multimap<ClassEntry, FieldEntry> m_matchedSourceFields; 25 private Multimap<ClassEntry, FieldEntry> matchedSourceFields;
26 private Multimap<ClassEntry, FieldEntry> m_unmatchedSourceFields; 26 private Multimap<ClassEntry, FieldEntry> unmatchedSourceFields;
27 private Multimap<ClassEntry, FieldEntry> m_unmatchedDestFields; 27 private Multimap<ClassEntry, FieldEntry> unmatchedDestFields;
28 private Multimap<ClassEntry, FieldEntry> m_unmatchableSourceFields; 28 private Multimap<ClassEntry, FieldEntry> unmatchableSourceFields;
29 29
30 public FieldMatches() { 30 public FieldMatches() {
31 m_matches = HashBiMap.create(); 31 matches = HashBiMap.create();
32 m_matchedSourceFields = HashMultimap.create(); 32 matchedSourceFields = HashMultimap.create();
33 m_unmatchedSourceFields = HashMultimap.create(); 33 unmatchedSourceFields = HashMultimap.create();
34 m_unmatchedDestFields = HashMultimap.create(); 34 unmatchedDestFields = HashMultimap.create();
35 m_unmatchableSourceFields = HashMultimap.create(); 35 unmatchableSourceFields = HashMultimap.create();
36 } 36 }
37 37
38 public void addMatch(FieldEntry srcField, FieldEntry destField) { 38 public void addMatch(FieldEntry srcField, FieldEntry destField) {
39 boolean wasAdded = m_matches.put(srcField, destField) == null; 39 boolean wasAdded = matches.put(srcField, destField) == null;
40 assert (wasAdded); 40 assert (wasAdded);
41 wasAdded = m_matchedSourceFields.put(srcField.getClassEntry(), srcField); 41 wasAdded = matchedSourceFields.put(srcField.getClassEntry(), srcField);
42 assert (wasAdded); 42 assert (wasAdded);
43 } 43 }
44 44
45 public void addUnmatchedSourceField(FieldEntry fieldEntry) { 45 public void addUnmatchedSourceField(FieldEntry fieldEntry) {
46 boolean wasAdded = m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); 46 boolean wasAdded = unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry);
47 assert (wasAdded); 47 assert (wasAdded);
48 } 48 }
49 49
@@ -54,7 +54,7 @@ public class FieldMatches {
54 } 54 }
55 55
56 public void addUnmatchedDestField(FieldEntry fieldEntry) { 56 public void addUnmatchedDestField(FieldEntry fieldEntry) {
57 boolean wasAdded = m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); 57 boolean wasAdded = unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry);
58 assert (wasAdded); 58 assert (wasAdded);
59 } 59 }
60 60
@@ -65,78 +65,78 @@ public class FieldMatches {
65 } 65 }
66 66
67 public void addUnmatchableSourceField(FieldEntry sourceField) { 67 public void addUnmatchableSourceField(FieldEntry sourceField) {
68 boolean wasAdded = m_unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField); 68 boolean wasAdded = unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField);
69 assert (wasAdded); 69 assert (wasAdded);
70 } 70 }
71 71
72 public Set<ClassEntry> getSourceClassesWithUnmatchedFields() { 72 public Set<ClassEntry> getSourceClassesWithUnmatchedFields() {
73 return m_unmatchedSourceFields.keySet(); 73 return unmatchedSourceFields.keySet();
74 } 74 }
75 75
76 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedFields() { 76 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedFields() {
77 Set<ClassEntry> out = Sets.newHashSet(); 77 Set<ClassEntry> out = Sets.newHashSet();
78 out.addAll(m_matchedSourceFields.keySet()); 78 out.addAll(matchedSourceFields.keySet());
79 out.removeAll(m_unmatchedSourceFields.keySet()); 79 out.removeAll(unmatchedSourceFields.keySet());
80 return out; 80 return out;
81 } 81 }
82 82
83 public Collection<FieldEntry> getUnmatchedSourceFields() { 83 public Collection<FieldEntry> getUnmatchedSourceFields() {
84 return m_unmatchedSourceFields.values(); 84 return unmatchedSourceFields.values();
85 } 85 }
86 86
87 public Collection<FieldEntry> getUnmatchedSourceFields(ClassEntry sourceClass) { 87 public Collection<FieldEntry> getUnmatchedSourceFields(ClassEntry sourceClass) {
88 return m_unmatchedSourceFields.get(sourceClass); 88 return unmatchedSourceFields.get(sourceClass);
89 } 89 }
90 90
91 public Collection<FieldEntry> getUnmatchedDestFields() { 91 public Collection<FieldEntry> getUnmatchedDestFields() {
92 return m_unmatchedDestFields.values(); 92 return unmatchedDestFields.values();
93 } 93 }
94 94
95 public Collection<FieldEntry> getUnmatchedDestFields(ClassEntry destClass) { 95 public Collection<FieldEntry> getUnmatchedDestFields(ClassEntry destClass) {
96 return m_unmatchedDestFields.get(destClass); 96 return unmatchedDestFields.get(destClass);
97 } 97 }
98 98
99 public Collection<FieldEntry> getUnmatchableSourceFields() { 99 public Collection<FieldEntry> getUnmatchableSourceFields() {
100 return m_unmatchableSourceFields.values(); 100 return unmatchableSourceFields.values();
101 } 101 }
102 102
103 public boolean hasSource(FieldEntry fieldEntry) { 103 public boolean hasSource(FieldEntry fieldEntry) {
104 return m_matches.containsKey(fieldEntry) || m_unmatchedSourceFields.containsValue(fieldEntry); 104 return matches.containsKey(fieldEntry) || unmatchedSourceFields.containsValue(fieldEntry);
105 } 105 }
106 106
107 public boolean hasDest(FieldEntry fieldEntry) { 107 public boolean hasDest(FieldEntry fieldEntry) {
108 return m_matches.containsValue(fieldEntry) || m_unmatchedDestFields.containsValue(fieldEntry); 108 return matches.containsValue(fieldEntry) || unmatchedDestFields.containsValue(fieldEntry);
109 } 109 }
110 110
111 public BiMap<FieldEntry, FieldEntry> matches() { 111 public BiMap<FieldEntry, FieldEntry> matches() {
112 return m_matches; 112 return matches;
113 } 113 }
114 114
115 public boolean isMatchedSourceField(FieldEntry sourceField) { 115 public boolean isMatchedSourceField(FieldEntry sourceField) {
116 return m_matches.containsKey(sourceField); 116 return matches.containsKey(sourceField);
117 } 117 }
118 118
119 public boolean isMatchedDestField(FieldEntry destField) { 119 public boolean isMatchedDestField(FieldEntry destField) {
120 return m_matches.containsValue(destField); 120 return matches.containsValue(destField);
121 } 121 }
122 122
123 public void makeMatch(FieldEntry sourceField, FieldEntry destField) { 123 public void makeMatch(FieldEntry sourceField, FieldEntry destField) {
124 boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); 124 boolean wasRemoved = unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField);
125 assert (wasRemoved); 125 assert (wasRemoved);
126 wasRemoved = m_unmatchedDestFields.remove(destField.getClassEntry(), destField); 126 wasRemoved = unmatchedDestFields.remove(destField.getClassEntry(), destField);
127 assert (wasRemoved); 127 assert (wasRemoved);
128 addMatch(sourceField, destField); 128 addMatch(sourceField, destField);
129 } 129 }
130 130
131 public boolean isMatched(FieldEntry sourceField, FieldEntry destField) { 131 public boolean isMatched(FieldEntry sourceField, FieldEntry destField) {
132 FieldEntry match = m_matches.get(sourceField); 132 FieldEntry match = matches.get(sourceField);
133 return match != null && match.equals(destField); 133 return match != null && match.equals(destField);
134 } 134 }
135 135
136 public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) { 136 public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) {
137 boolean wasRemoved = m_matches.remove(sourceField) != null; 137 boolean wasRemoved = matches.remove(sourceField) != null;
138 assert (wasRemoved); 138 assert (wasRemoved);
139 wasRemoved = m_matchedSourceFields.remove(sourceField.getClassEntry(), sourceField); 139 wasRemoved = matchedSourceFields.remove(sourceField.getClassEntry(), sourceField);
140 assert (wasRemoved); 140 assert (wasRemoved);
141 addUnmatchedSourceField(sourceField); 141 addUnmatchedSourceField(sourceField);
142 addUnmatchedDestField(destField); 142 addUnmatchedDestField(destField);
@@ -144,7 +144,7 @@ public class FieldMatches {
144 144
145 public void makeSourceUnmatchable(FieldEntry sourceField) { 145 public void makeSourceUnmatchable(FieldEntry sourceField) {
146 assert (!isMatchedSourceField(sourceField)); 146 assert (!isMatchedSourceField(sourceField));
147 boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); 147 boolean wasRemoved = unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField);
148 assert (wasRemoved); 148 assert (wasRemoved);
149 addUnmatchableSourceField(sourceField); 149 addUnmatchableSourceField(sourceField);
150 } 150 }
diff --git a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java
index 929c89f..a5ded67 100644
--- a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java
+++ b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java
@@ -11,7 +11,6 @@
11package cuchaz.enigma.convert; 11package cuchaz.enigma.convert;
12 12
13import com.google.common.collect.*; 13import com.google.common.collect.*;
14import cuchaz.enigma.Constants;
15import cuchaz.enigma.Deobfuscator; 14import cuchaz.enigma.Deobfuscator;
16import cuchaz.enigma.TranslatingTypeLoader; 15import cuchaz.enigma.TranslatingTypeLoader;
17import cuchaz.enigma.analysis.JarIndex; 16import cuchaz.enigma.analysis.JarIndex;
@@ -24,7 +23,6 @@ import javassist.NotFoundException;
24import javassist.bytecode.BadBytecode; 23import javassist.bytecode.BadBytecode;
25import javassist.bytecode.CodeAttribute; 24import javassist.bytecode.CodeAttribute;
26import javassist.bytecode.CodeIterator; 25import javassist.bytecode.CodeIterator;
27import javassist.bytecode.MethodInfo;
28 26
29import java.util.*; 27import java.util.*;
30import java.util.jar.JarFile; 28import java.util.jar.JarFile;
@@ -174,15 +172,13 @@ public class MappingsConverter {
174 172
175 private static ClassMapping migrateClassMapping(ClassEntry newObfClass, ClassMapping oldClassMapping, final ClassMatches matches, boolean useSimpleName) { 173 private static ClassMapping migrateClassMapping(ClassEntry newObfClass, ClassMapping oldClassMapping, final ClassMatches matches, boolean useSimpleName) {
176 174
177 ClassNameReplacer replacer = new ClassNameReplacer() { 175 ClassNameReplacer replacer = className ->
178 @Override 176 {
179 public String replace(String className) { 177 ClassEntry newClassEntry = matches.getUniqueMatches().get(new ClassEntry(className));
180 ClassEntry newClassEntry = matches.getUniqueMatches().get(new ClassEntry(className)); 178 if (newClassEntry != null) {
181 if (newClassEntry != null) { 179 return newClassEntry.getName();
182 return newClassEntry.getName();
183 }
184 return null;
185 } 180 }
181 return null;
186 }; 182 };
187 183
188 ClassMapping newClassMapping; 184 ClassMapping newClassMapping;
@@ -434,13 +430,12 @@ public class MappingsConverter {
434 // Empty method body, ignore! 430 // Empty method body, ignore!
435 if (sourceAttribute == null) 431 if (sourceAttribute == null)
436 return null; 432 return null;
437 Iterator<BehaviorEntry> it = obfDestEntries.iterator(); 433 for (BehaviorEntry desEntry : obfDestEntries)
438 while (it.hasNext())
439 { 434 {
440 BehaviorEntry desEntry = it.next();
441 try 435 try
442 { 436 {
443 CtMethod destCtClassMethod = destCtClass.getMethod(desEntry.getName(), desEntry.getSignature().toString()); 437 CtMethod destCtClassMethod = destCtClass
438 .getMethod(desEntry.getName(), desEntry.getSignature().toString());
444 CodeAttribute destAttribute = destCtClassMethod.getMethodInfo().getCodeAttribute(); 439 CodeAttribute destAttribute = destCtClassMethod.getMethodInfo().getCodeAttribute();
445 440
446 // Ignore empty body methods 441 // Ignore empty body methods
@@ -533,7 +528,7 @@ public class MappingsConverter {
533 528
534 public static <T extends Entry> MemberMatches<T> computeMemberMatches(Deobfuscator destDeobfuscator, Mappings destMappings, ClassMatches classMatches, Doer<T> doer) { 529 public static <T extends Entry> MemberMatches<T> computeMemberMatches(Deobfuscator destDeobfuscator, Mappings destMappings, ClassMatches classMatches, Doer<T> doer) {
535 530
536 MemberMatches<T> memberMatches = new MemberMatches<T>(); 531 MemberMatches<T> memberMatches = new MemberMatches<>();
537 532
538 // unmatched source fields are easy 533 // unmatched source fields are easy
539 MappingsChecker checker = new MappingsChecker(destDeobfuscator.getJarIndex()); 534 MappingsChecker checker = new MappingsChecker(destDeobfuscator.getJarIndex());
@@ -624,15 +619,13 @@ public class MappingsConverter {
624 } 619 }
625 620
626 private static Type translate(Type type, final BiMap<ClassEntry, ClassEntry> map) { 621 private static Type translate(Type type, final BiMap<ClassEntry, ClassEntry> map) {
627 return new Type(type, new ClassNameReplacer() { 622 return new Type(type, inClassName ->
628 @Override 623 {
629 public String replace(String inClassName) { 624 ClassEntry outClassEntry = map.get(new ClassEntry(inClassName));
630 ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); 625 if (outClassEntry == null) {
631 if (outClassEntry == null) { 626 return null;
632 return null;
633 }
634 return outClassEntry.getName();
635 } 627 }
628 return outClassEntry.getName();
636 }); 629 });
637 } 630 }
638 631
@@ -640,15 +633,13 @@ public class MappingsConverter {
640 if (signature == null) { 633 if (signature == null) {
641 return null; 634 return null;
642 } 635 }
643 return new Signature(signature, new ClassNameReplacer() { 636 return new Signature(signature, inClassName ->
644 @Override 637 {
645 public String replace(String inClassName) { 638 ClassEntry outClassEntry = map.get(new ClassEntry(inClassName));
646 ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); 639 if (outClassEntry == null) {
647 if (outClassEntry == null) { 640 return null;
648 return null;
649 }
650 return outClassEntry.getName();
651 } 641 }
642 return outClassEntry.getName();
652 }); 643 });
653 } 644 }
654 645
diff --git a/src/main/java/cuchaz/enigma/convert/MatchesReader.java b/src/main/java/cuchaz/enigma/convert/MatchesReader.java
index 550da49..d86d6c2 100644
--- a/src/main/java/cuchaz/enigma/convert/MatchesReader.java
+++ b/src/main/java/cuchaz/enigma/convert/MatchesReader.java
@@ -34,8 +34,7 @@ public class MatchesReader {
34 } 34 }
35 } 35 }
36 36
37 private static ClassMatch readClassMatch(String line) 37 private static ClassMatch readClassMatch(String line) {
38 throws IOException {
39 String[] sides = line.split(":", 2); 38 String[] sides = line.split(":", 2);
40 return new ClassMatch(readClasses(sides[0]), readClasses(sides[1])); 39 return new ClassMatch(readClasses(sides[0]), readClasses(sides[1]));
41 } 40 }
@@ -54,7 +53,7 @@ public class MatchesReader {
54 public static <T extends Entry> MemberMatches<T> readMembers(File file) 53 public static <T extends Entry> MemberMatches<T> readMembers(File file)
55 throws IOException { 54 throws IOException {
56 try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")))) { 55 try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8")))) {
57 MemberMatches<T> matches = new MemberMatches<T>(); 56 MemberMatches<T> matches = new MemberMatches<>();
58 String line; 57 String line;
59 while ((line = in.readLine()) != null) { 58 while ((line = in.readLine()) != null) {
60 readMemberMatch(matches, line); 59 readMemberMatch(matches, line);
diff --git a/src/main/java/cuchaz/enigma/convert/MemberMatches.java b/src/main/java/cuchaz/enigma/convert/MemberMatches.java
index 25af2f8..51cee85 100644
--- a/src/main/java/cuchaz/enigma/convert/MemberMatches.java
+++ b/src/main/java/cuchaz/enigma/convert/MemberMatches.java
@@ -21,29 +21,29 @@ import java.util.Set;
21 21
22public class MemberMatches<T extends Entry> { 22public class MemberMatches<T extends Entry> {
23 23
24 private BiMap<T, T> m_matches; 24 private BiMap<T, T> matches;
25 private Multimap<ClassEntry, T> m_matchedSourceEntries; 25 private Multimap<ClassEntry, T> matchedSourceEntries;
26 private Multimap<ClassEntry, T> m_unmatchedSourceEntries; 26 private Multimap<ClassEntry, T> unmatchedSourceEntries;
27 private Multimap<ClassEntry, T> m_unmatchedDestEntries; 27 private Multimap<ClassEntry, T> unmatchedDestEntries;
28 private Multimap<ClassEntry, T> m_unmatchableSourceEntries; 28 private Multimap<ClassEntry, T> unmatchableSourceEntries;
29 29
30 public MemberMatches() { 30 public MemberMatches() {
31 m_matches = HashBiMap.create(); 31 matches = HashBiMap.create();
32 m_matchedSourceEntries = HashMultimap.create(); 32 matchedSourceEntries = HashMultimap.create();
33 m_unmatchedSourceEntries = HashMultimap.create(); 33 unmatchedSourceEntries = HashMultimap.create();
34 m_unmatchedDestEntries = HashMultimap.create(); 34 unmatchedDestEntries = HashMultimap.create();
35 m_unmatchableSourceEntries = HashMultimap.create(); 35 unmatchableSourceEntries = HashMultimap.create();
36 } 36 }
37 37
38 public void addMatch(T srcEntry, T destEntry) { 38 public void addMatch(T srcEntry, T destEntry) {
39 boolean wasAdded = m_matches.put(srcEntry, destEntry) == null; 39 boolean wasAdded = matches.put(srcEntry, destEntry) == null;
40 assert (wasAdded); 40 assert (wasAdded);
41 wasAdded = m_matchedSourceEntries.put(srcEntry.getClassEntry(), srcEntry); 41 wasAdded = matchedSourceEntries.put(srcEntry.getClassEntry(), srcEntry);
42 assert (wasAdded); 42 assert (wasAdded);
43 } 43 }
44 44
45 public void addUnmatchedSourceEntry(T sourceEntry) { 45 public void addUnmatchedSourceEntry(T sourceEntry) {
46 boolean wasAdded = m_unmatchedSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); 46 boolean wasAdded = unmatchedSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry);
47 assert (wasAdded); 47 assert (wasAdded);
48 } 48 }
49 49
@@ -56,7 +56,7 @@ public class MemberMatches<T extends Entry> {
56 public void addUnmatchedDestEntry(T destEntry) { 56 public void addUnmatchedDestEntry(T destEntry) {
57 if (destEntry.getName().equals("<clinit>") || destEntry.getName().equals("<init>")) 57 if (destEntry.getName().equals("<clinit>") || destEntry.getName().equals("<init>"))
58 return; 58 return;
59 boolean wasAdded = m_unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry); 59 boolean wasAdded = unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry);
60 assert (wasAdded); 60 assert (wasAdded);
61 } 61 }
62 62
@@ -67,63 +67,63 @@ public class MemberMatches<T extends Entry> {
67 } 67 }
68 68
69 public void addUnmatchableSourceEntry(T sourceEntry) { 69 public void addUnmatchableSourceEntry(T sourceEntry) {
70 boolean wasAdded = m_unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); 70 boolean wasAdded = unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry);
71 assert (wasAdded); 71 assert (wasAdded);
72 } 72 }
73 73
74 public Set<ClassEntry> getSourceClassesWithUnmatchedEntries() { 74 public Set<ClassEntry> getSourceClassesWithUnmatchedEntries() {
75 return m_unmatchedSourceEntries.keySet(); 75 return unmatchedSourceEntries.keySet();
76 } 76 }
77 77
78 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedEntries() { 78 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedEntries() {
79 Set<ClassEntry> out = Sets.newHashSet(); 79 Set<ClassEntry> out = Sets.newHashSet();
80 out.addAll(m_matchedSourceEntries.keySet()); 80 out.addAll(matchedSourceEntries.keySet());
81 out.removeAll(m_unmatchedSourceEntries.keySet()); 81 out.removeAll(unmatchedSourceEntries.keySet());
82 return out; 82 return out;
83 } 83 }
84 84
85 public Collection<T> getUnmatchedSourceEntries() { 85 public Collection<T> getUnmatchedSourceEntries() {
86 return m_unmatchedSourceEntries.values(); 86 return unmatchedSourceEntries.values();
87 } 87 }
88 88
89 public Collection<T> getUnmatchedSourceEntries(ClassEntry sourceClass) { 89 public Collection<T> getUnmatchedSourceEntries(ClassEntry sourceClass) {
90 return m_unmatchedSourceEntries.get(sourceClass); 90 return unmatchedSourceEntries.get(sourceClass);
91 } 91 }
92 92
93 public Collection<T> getUnmatchedDestEntries() { 93 public Collection<T> getUnmatchedDestEntries() {
94 return m_unmatchedDestEntries.values(); 94 return unmatchedDestEntries.values();
95 } 95 }
96 96
97 public Collection<T> getUnmatchedDestEntries(ClassEntry destClass) { 97 public Collection<T> getUnmatchedDestEntries(ClassEntry destClass) {
98 return m_unmatchedDestEntries.get(destClass); 98 return unmatchedDestEntries.get(destClass);
99 } 99 }
100 100
101 public Collection<T> getUnmatchableSourceEntries() { 101 public Collection<T> getUnmatchableSourceEntries() {
102 return m_unmatchableSourceEntries.values(); 102 return unmatchableSourceEntries.values();
103 } 103 }
104 104
105 public boolean hasSource(T sourceEntry) { 105 public boolean hasSource(T sourceEntry) {
106 return m_matches.containsKey(sourceEntry) || m_unmatchedSourceEntries.containsValue(sourceEntry); 106 return matches.containsKey(sourceEntry) || unmatchedSourceEntries.containsValue(sourceEntry);
107 } 107 }
108 108
109 public boolean hasDest(T destEntry) { 109 public boolean hasDest(T destEntry) {
110 return m_matches.containsValue(destEntry) || m_unmatchedDestEntries.containsValue(destEntry); 110 return matches.containsValue(destEntry) || unmatchedDestEntries.containsValue(destEntry);
111 } 111 }
112 112
113 public BiMap<T, T> matches() { 113 public BiMap<T, T> matches() {
114 return m_matches; 114 return matches;
115 } 115 }
116 116
117 public boolean isMatchedSourceEntry(T sourceEntry) { 117 public boolean isMatchedSourceEntry(T sourceEntry) {
118 return m_matches.containsKey(sourceEntry); 118 return matches.containsKey(sourceEntry);
119 } 119 }
120 120
121 public boolean isMatchedDestEntry(T destEntry) { 121 public boolean isMatchedDestEntry(T destEntry) {
122 return m_matches.containsValue(destEntry); 122 return matches.containsValue(destEntry);
123 } 123 }
124 124
125 public boolean isUnmatchableSourceEntry(T sourceEntry) { 125 public boolean isUnmatchableSourceEntry(T sourceEntry) {
126 return m_unmatchableSourceEntries.containsEntry(sourceEntry.getClassEntry(), sourceEntry); 126 return unmatchableSourceEntries.containsEntry(sourceEntry.getClassEntry(), sourceEntry);
127 } 127 }
128 public void makeMatch(T sourceEntry, T destEntry) { 128 public void makeMatch(T sourceEntry, T destEntry) {
129 makeMatch(sourceEntry, destEntry, null, null); 129 makeMatch(sourceEntry, destEntry, null, null);
@@ -136,15 +136,15 @@ public class MemberMatches<T extends Entry> {
136 sourceEntry = (T) sourceEntry.cloneToNewClass(sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true)); 136 sourceEntry = (T) sourceEntry.cloneToNewClass(sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true));
137 destEntry = (T) destEntry.cloneToNewClass(destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true)); 137 destEntry = (T) destEntry.cloneToNewClass(destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true));
138 } 138 }
139 boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); 139 boolean wasRemoved = unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
140 assert (wasRemoved); 140 assert (wasRemoved);
141 wasRemoved = m_unmatchedDestEntries.remove(destEntry.getClassEntry(), destEntry); 141 wasRemoved = unmatchedDestEntries.remove(destEntry.getClassEntry(), destEntry);
142 assert (wasRemoved); 142 assert (wasRemoved);
143 addMatch(sourceEntry, destEntry); 143 addMatch(sourceEntry, destEntry);
144 } 144 }
145 145
146 public boolean isMatched(T sourceEntry, T destEntry) { 146 public boolean isMatched(T sourceEntry, T destEntry) {
147 T match = m_matches.get(sourceEntry); 147 T match = matches.get(sourceEntry);
148 return match != null && match.equals(destEntry); 148 return match != null && match.equals(destEntry);
149 } 149 }
150 150
@@ -159,9 +159,9 @@ public class MemberMatches<T extends Entry> {
159 destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true)); 159 destDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(destEntry, true));
160 } 160 }
161 161
162 boolean wasRemoved = m_matches.remove(sourceEntry) != null; 162 boolean wasRemoved = matches.remove(sourceEntry) != null;
163 assert (wasRemoved); 163 assert (wasRemoved);
164 wasRemoved = m_matchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); 164 wasRemoved = matchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
165 assert (wasRemoved); 165 assert (wasRemoved);
166 addUnmatchedSourceEntry(sourceEntry); 166 addUnmatchedSourceEntry(sourceEntry);
167 addUnmatchedDestEntry(destEntry); 167 addUnmatchedDestEntry(destEntry);
@@ -175,7 +175,7 @@ public class MemberMatches<T extends Entry> {
175 sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true)); 175 sourceDeobfuscator.getJarIndex().getTranslationIndex().resolveEntryClass(sourceEntry, true));
176 } 176 }
177 assert (!isMatchedSourceEntry(sourceEntry)); 177 assert (!isMatchedSourceEntry(sourceEntry));
178 boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry); 178 boolean wasRemoved = unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
179 assert (wasRemoved); 179 assert (wasRemoved);
180 addUnmatchableSourceEntry(sourceEntry); 180 addUnmatchableSourceEntry(sourceEntry);
181 } 181 }