diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping')
8 files changed, 43 insertions, 58 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassEntry.java b/src/main/java/cuchaz/enigma/mapping/ClassEntry.java index 2e7711b..c9304d4 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassEntry.java | |||
| @@ -67,10 +67,7 @@ public class ClassEntry implements Entry, Serializable { | |||
| 67 | 67 | ||
| 68 | @Override | 68 | @Override |
| 69 | public boolean equals(Object other) { | 69 | public boolean equals(Object other) { |
| 70 | if (other instanceof ClassEntry) { | 70 | return other instanceof ClassEntry && equals((ClassEntry) other); |
| 71 | return equals((ClassEntry) other); | ||
| 72 | } | ||
| 73 | return false; | ||
| 74 | } | 71 | } |
| 75 | 72 | ||
| 76 | public boolean equals(ClassEntry other) { | 73 | public boolean equals(ClassEntry other) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 9258ec7..84fb6dd 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -403,7 +403,7 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 403 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { | 403 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { |
| 404 | 404 | ||
| 405 | // rename inner classes | 405 | // rename inner classes |
| 406 | for (ClassMapping innerClassMapping : new ArrayList<ClassMapping>(m_innerClassesByObfSimple.values())) { | 406 | for (ClassMapping innerClassMapping : new ArrayList<>(m_innerClassesByObfSimple.values())) { |
| 407 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 407 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 408 | boolean wasRemoved = m_innerClassesByObfSimple.remove(oldObfClassName) != null; | 408 | boolean wasRemoved = m_innerClassesByObfSimple.remove(oldObfClassName) != null; |
| 409 | assert (wasRemoved); | 409 | assert (wasRemoved); |
| @@ -413,7 +413,7 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | // rename field types | 415 | // rename field types |
| 416 | for (FieldMapping fieldMapping : new ArrayList<FieldMapping>(m_fieldsByObf.values())) { | 416 | for (FieldMapping fieldMapping : new ArrayList<>(m_fieldsByObf.values())) { |
| 417 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); | 417 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); |
| 418 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 418 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 419 | boolean wasRemoved = m_fieldsByObf.remove(oldFieldKey) != null; | 419 | boolean wasRemoved = m_fieldsByObf.remove(oldFieldKey) != null; |
| @@ -424,7 +424,7 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | // rename method signatures | 426 | // rename method signatures |
| 427 | for (MethodMapping methodMapping : new ArrayList<MethodMapping>(m_methodsByObf.values())) { | 427 | for (MethodMapping methodMapping : new ArrayList<>(m_methodsByObf.values())) { |
| 428 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); | 428 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 429 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { | 429 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 430 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; | 430 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; |
diff --git a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java index 3de7223..bebc504 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldEntry.java | |||
| @@ -80,10 +80,7 @@ public class FieldEntry implements Entry, Serializable { | |||
| 80 | 80 | ||
| 81 | @Override | 81 | @Override |
| 82 | public boolean equals(Object other) { | 82 | public boolean equals(Object other) { |
| 83 | if (other instanceof FieldEntry) { | 83 | return other instanceof FieldEntry && equals((FieldEntry) other); |
| 84 | return equals((FieldEntry) other); | ||
| 85 | } | ||
| 86 | return false; | ||
| 87 | } | 84 | } |
| 88 | 85 | ||
| 89 | public boolean equals(FieldEntry other) { | 86 | public boolean equals(FieldEntry other) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java index ab68682..5e2b40b 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java | |||
| @@ -90,8 +90,6 @@ public class MappingsChecker { | |||
| 90 | classMapping.removeMethodMapping(methodMapping); | 90 | classMapping.removeMethodMapping(methodMapping); |
| 91 | m_droppedMethodMappings.put(obfBehaviorEntry, methodMapping); | 91 | m_droppedMethodMappings.put(obfBehaviorEntry, methodMapping); |
| 92 | } | 92 | } |
| 93 | |||
| 94 | m_relatedMethodChecker.checkMethod(classEntry, methodMapping); | ||
| 95 | } | 93 | } |
| 96 | 94 | ||
| 97 | // check inner classes | 95 | // check inner classes |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java index 7110d40..b2c3a5c 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java | |||
| @@ -42,14 +42,14 @@ public class MappingsReader { | |||
| 42 | 42 | ||
| 43 | public void readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { | 43 | public void readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { |
| 44 | 44 | ||
| 45 | String builder = ""; | 45 | StringBuffer buf = new StringBuffer(); |
| 46 | String line = null; | 46 | String line = null; |
| 47 | while ((line = in.readLine()) != null) { | 47 | while ((line = in.readLine()) != null) { |
| 48 | builder += line; | 48 | buf.append(line); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | 51 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
| 52 | JsonClass jsonClass = gson.fromJson(builder, JsonClass.class); | 52 | JsonClass jsonClass = gson.fromJson(buf.toString(), JsonClass.class); |
| 53 | load(null, jsonClass, mappings); | 53 | load(null, jsonClass, mappings); |
| 54 | } | 54 | } |
| 55 | 55 | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java index 89fee4e..aaab22f 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java | |||
| @@ -24,7 +24,6 @@ import cuchaz.enigma.json.*; | |||
| 24 | 24 | ||
| 25 | public class MappingsWriter { | 25 | public class MappingsWriter { |
| 26 | 26 | ||
| 27 | |||
| 28 | public void write(File file, Mappings mappings) throws IOException { | 27 | public void write(File file, Mappings mappings) throws IOException { |
| 29 | if (!file.isDirectory()) { | 28 | if (!file.isDirectory()) { |
| 30 | return; | 29 | return; |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java index 301da61..01a5c43 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java | |||
| @@ -85,10 +85,7 @@ public class MethodEntry implements BehaviorEntry, Serializable { | |||
| 85 | 85 | ||
| 86 | @Override | 86 | @Override |
| 87 | public boolean equals(Object other) { | 87 | public boolean equals(Object other) { |
| 88 | if (other instanceof MethodEntry) { | 88 | return other instanceof MethodEntry && equals((MethodEntry) other); |
| 89 | return equals((MethodEntry) other); | ||
| 90 | } | ||
| 91 | return false; | ||
| 92 | } | 89 | } |
| 93 | 90 | ||
| 94 | public boolean equals(MethodEntry other) { | 91 | public boolean equals(MethodEntry other) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java index d1beddd..ff14ccd 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java | |||
| @@ -36,62 +36,62 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 36 | if (obfSignature == null) { | 36 | if (obfSignature == null) { |
| 37 | throw new IllegalArgumentException("obf signature cannot be null!"); | 37 | throw new IllegalArgumentException("obf signature cannot be null!"); |
| 38 | } | 38 | } |
| 39 | m_obfName = obfName; | 39 | this.m_obfName = obfName; |
| 40 | m_deobfName = NameValidator.validateMethodName(deobfName); | 40 | this.m_deobfName = NameValidator.validateMethodName(deobfName); |
| 41 | m_obfSignature = obfSignature; | 41 | this.m_obfSignature = obfSignature; |
| 42 | m_arguments = Maps.newTreeMap(); | 42 | this.m_arguments = Maps.newTreeMap(); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { | 45 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { |
| 46 | m_obfName = other.m_obfName; | 46 | this.m_obfName = other.m_obfName; |
| 47 | m_deobfName = other.m_deobfName; | 47 | this.m_deobfName = other.m_deobfName; |
| 48 | m_obfSignature = new Signature(other.m_obfSignature, obfClassNameReplacer); | 48 | this.m_obfSignature = new Signature(other.m_obfSignature, obfClassNameReplacer); |
| 49 | m_arguments = Maps.newTreeMap(); | 49 | this.m_arguments = Maps.newTreeMap(); |
| 50 | for (Entry<Integer, ArgumentMapping> entry : other.m_arguments.entrySet()) { | 50 | for (Entry<Integer, ArgumentMapping> entry : other.m_arguments.entrySet()) { |
| 51 | m_arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue())); | 51 | this.m_arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue())); |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | @Override | 55 | @Override |
| 56 | public String getObfName() { | 56 | public String getObfName() { |
| 57 | return m_obfName; | 57 | return this.m_obfName; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | public void setObfName(String val) { | 60 | public void setObfName(String val) { |
| 61 | m_obfName = NameValidator.validateMethodName(val); | 61 | this.m_obfName = NameValidator.validateMethodName(val); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | public String getDeobfName() { | 64 | public String getDeobfName() { |
| 65 | return m_deobfName; | 65 | return this.m_deobfName; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | public void setDeobfName(String val) { | 68 | public void setDeobfName(String val) { |
| 69 | m_deobfName = NameValidator.validateMethodName(val); | 69 | this.m_deobfName = NameValidator.validateMethodName(val); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | public Signature getObfSignature() { | 72 | public Signature getObfSignature() { |
| 73 | return m_obfSignature; | 73 | return this.m_obfSignature; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | public void setObfSignature(Signature val) { | 76 | public void setObfSignature(Signature val) { |
| 77 | m_obfSignature = val; | 77 | this.m_obfSignature = val; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | public Iterable<ArgumentMapping> arguments() { | 80 | public Iterable<ArgumentMapping> arguments() { |
| 81 | return m_arguments.values(); | 81 | return this.m_arguments.values(); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | public boolean isConstructor() { | 84 | public boolean isConstructor() { |
| 85 | return m_obfName.startsWith("<"); | 85 | return this.m_obfName.startsWith("<"); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | public void addArgumentMapping(ArgumentMapping argumentMapping) { | 88 | public void addArgumentMapping(ArgumentMapping argumentMapping) { |
| 89 | boolean wasAdded = m_arguments.put(argumentMapping.getIndex(), argumentMapping) == null; | 89 | boolean wasAdded = this.m_arguments.put(argumentMapping.getIndex(), argumentMapping) == null; |
| 90 | assert (wasAdded); | 90 | assert (wasAdded); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | public String getObfArgumentName(int index) { | 93 | public String getObfArgumentName(int index) { |
| 94 | ArgumentMapping argumentMapping = m_arguments.get(index); | 94 | ArgumentMapping argumentMapping = this.m_arguments.get(index); |
| 95 | if (argumentMapping != null) { | 95 | if (argumentMapping != null) { |
| 96 | return argumentMapping.getName(); | 96 | return argumentMapping.getName(); |
| 97 | } | 97 | } |
| @@ -100,7 +100,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | public String getDeobfArgumentName(int index) { | 102 | public String getDeobfArgumentName(int index) { |
| 103 | ArgumentMapping argumentMapping = m_arguments.get(index); | 103 | ArgumentMapping argumentMapping = this.m_arguments.get(index); |
| 104 | if (argumentMapping != null) { | 104 | if (argumentMapping != null) { |
| 105 | return argumentMapping.getName(); | 105 | return argumentMapping.getName(); |
| 106 | } | 106 | } |
| @@ -109,10 +109,10 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | public void setArgumentName(int index, String name) { | 111 | public void setArgumentName(int index, String name) { |
| 112 | ArgumentMapping argumentMapping = m_arguments.get(index); | 112 | ArgumentMapping argumentMapping = this.m_arguments.get(index); |
| 113 | if (argumentMapping == null) { | 113 | if (argumentMapping == null) { |
| 114 | argumentMapping = new ArgumentMapping(index, name); | 114 | argumentMapping = new ArgumentMapping(index, name); |
| 115 | boolean wasAdded = m_arguments.put(index, argumentMapping) == null; | 115 | boolean wasAdded = this.m_arguments.put(index, argumentMapping) == null; |
| 116 | assert (wasAdded); | 116 | assert (wasAdded); |
| 117 | } else { | 117 | } else { |
| 118 | argumentMapping.setName(name); | 118 | argumentMapping.setName(name); |
| @@ -120,7 +120,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | public void removeArgumentName(int index) { | 122 | public void removeArgumentName(int index) { |
| 123 | boolean wasRemoved = m_arguments.remove(index) != null; | 123 | boolean wasRemoved = this.m_arguments.remove(index) != null; |
| 124 | assert (wasRemoved); | 124 | assert (wasRemoved); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| @@ -136,7 +136,7 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 136 | buf.append(m_obfSignature); | 136 | buf.append(m_obfSignature); |
| 137 | buf.append("\n"); | 137 | buf.append("\n"); |
| 138 | buf.append("\tArguments:\n"); | 138 | buf.append("\tArguments:\n"); |
| 139 | for (ArgumentMapping argumentMapping : m_arguments.values()) { | 139 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { |
| 140 | buf.append("\t\t"); | 140 | buf.append("\t\t"); |
| 141 | buf.append(argumentMapping.getIndex()); | 141 | buf.append(argumentMapping.getIndex()); |
| 142 | buf.append(" -> "); | 142 | buf.append(" -> "); |
| @@ -148,31 +148,28 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 148 | 148 | ||
| 149 | @Override | 149 | @Override |
| 150 | public int compareTo(MethodMapping other) { | 150 | public int compareTo(MethodMapping other) { |
| 151 | return (m_obfName + m_obfSignature).compareTo(other.m_obfName + other.m_obfSignature); | 151 | return (this.m_obfName + this.m_obfSignature).compareTo(other.m_obfName + other.m_obfSignature); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { | 154 | public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { |
| 155 | 155 | ||
| 156 | // rename obf classes in the signature | 156 | // rename obf classes in the signature |
| 157 | Signature newSignature = new Signature(m_obfSignature, new ClassNameReplacer() { | 157 | Signature newSignature = new Signature(this.m_obfSignature, className -> { |
| 158 | @Override | 158 | if (className.equals(oldObfClassName)) { |
| 159 | public String replace(String className) { | 159 | return newObfClassName; |
| 160 | if (className.equals(oldObfClassName)) { | ||
| 161 | return newObfClassName; | ||
| 162 | } | ||
| 163 | return null; | ||
| 164 | } | 160 | } |
| 161 | return null; | ||
| 165 | }); | 162 | }); |
| 166 | 163 | ||
| 167 | if (!newSignature.equals(m_obfSignature)) { | 164 | if (!newSignature.equals(this.m_obfSignature)) { |
| 168 | m_obfSignature = newSignature; | 165 | this.m_obfSignature = newSignature; |
| 169 | return true; | 166 | return true; |
| 170 | } | 167 | } |
| 171 | return false; | 168 | return false; |
| 172 | } | 169 | } |
| 173 | 170 | ||
| 174 | public boolean containsArgument(String name) { | 171 | public boolean containsArgument(String name) { |
| 175 | for (ArgumentMapping argumentMapping : m_arguments.values()) { | 172 | for (ArgumentMapping argumentMapping : this.m_arguments.values()) { |
| 176 | if (argumentMapping.getName().equals(name)) { | 173 | if (argumentMapping.getName().equals(name)) { |
| 177 | return true; | 174 | return true; |
| 178 | } | 175 | } |
| @@ -183,9 +180,9 @@ public class MethodMapping implements Serializable, Comparable<MethodMapping>, M | |||
| 183 | @Override | 180 | @Override |
| 184 | public BehaviorEntry getObfEntry(ClassEntry classEntry) { | 181 | public BehaviorEntry getObfEntry(ClassEntry classEntry) { |
| 185 | if (isConstructor()) { | 182 | if (isConstructor()) { |
| 186 | return new ConstructorEntry(classEntry, m_obfSignature); | 183 | return new ConstructorEntry(classEntry, this.m_obfSignature); |
| 187 | } else { | 184 | } else { |
| 188 | return new MethodEntry(classEntry, m_obfName, m_obfSignature); | 185 | return new MethodEntry(classEntry, this.m_obfName, this.m_obfSignature); |
| 189 | } | 186 | } |
| 190 | } | 187 | } |
| 191 | } | 188 | } |