summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java112
1 files changed, 55 insertions, 57 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java
index a3f0cc8..b0eb826 100644
--- a/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java
+++ b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java
@@ -13,69 +13,67 @@ import java.util.List;
13 */ 13 */
14public class MappingsSRGWriter { 14public class MappingsSRGWriter {
15 15
16 public void write(File file, Mappings mappings) throws IOException { 16 public void write(File file, Mappings mappings) throws IOException {
17 if(file.exists()){ 17 if (file.exists()) {
18 file.delete(); 18 file.delete();
19 } 19 }
20 file.createNewFile(); 20 file.createNewFile();
21 21
22 TranslationIndex index = new TranslationIndex(); 22 TranslationIndex index = new TranslationIndex();
23 23
24 PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8)); 24 PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8));
25 List<String> fieldMappings = new ArrayList<>(); 25 List<String> fieldMappings = new ArrayList<>();
26 List<String> methodMappings = new ArrayList<>(); 26 List<String> methodMappings = new ArrayList<>();
27 for (ClassMapping classMapping : sorted(mappings.classes())) { 27 for (ClassMapping classMapping : sorted(mappings.classes())) {
28 if(classMapping.getDeobfName() == null || classMapping.getObfSimpleName() == null || classMapping.getDeobfName() == null){ 28 if (classMapping.getDeobfName() == null || classMapping.getObfSimpleName() == null || classMapping.getDeobfName() == null) {
29 continue; 29 continue;
30 } 30 }
31 writer.write("CL: " + classMapping.getObfSimpleName() + " " + classMapping.getDeobfName()); 31 writer.write("CL: " + classMapping.getObfSimpleName() + " " + classMapping.getDeobfName());
32 writer.write(System.lineSeparator()); 32 writer.write(System.lineSeparator());
33 for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { 33 for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) {
34 if(innerClassMapping.getDeobfName() == null || innerClassMapping.getObfSimpleName() == null || innerClassMapping.getDeobfName() == null){ 34 if (innerClassMapping.getDeobfName() == null || innerClassMapping.getObfSimpleName() == null || innerClassMapping.getDeobfName() == null) {
35 continue; 35 continue;
36 } 36 }
37 String innerClassName = classMapping.getObfSimpleName() + "$" + innerClassMapping.getObfSimpleName(); 37 String innerClassName = classMapping.getObfSimpleName() + "$" + innerClassMapping.getObfSimpleName();
38 String innerDeobfClassName = classMapping.getDeobfName() + "$" + innerClassMapping.getDeobfName(); 38 String innerDeobfClassName = classMapping.getDeobfName() + "$" + innerClassMapping.getDeobfName();
39 writer.write("CL: " + innerClassName + " " + classMapping.getDeobfName() + "$" + innerClassMapping.getDeobfName()); 39 writer.write("CL: " + innerClassName + " " + classMapping.getDeobfName() + "$" + innerClassMapping.getDeobfName());
40 writer.write(System.lineSeparator()); 40 writer.write(System.lineSeparator());
41 for (FieldMapping fieldMapping : sorted(innerClassMapping.fields())) { 41 for (FieldMapping fieldMapping : sorted(innerClassMapping.fields())) {
42 fieldMappings.add("FD: " + innerClassName + "/" + fieldMapping.getObfName() + " " + innerDeobfClassName + "/" + fieldMapping.getDeobfName()); 42 fieldMappings.add("FD: " + innerClassName + "/" + fieldMapping.getObfName() + " " + innerDeobfClassName + "/" + fieldMapping.getDeobfName());
43 } 43 }
44 44
45 for (MethodMapping methodMapping : sorted(innerClassMapping.methods())) { 45 for (MethodMapping methodMapping : sorted(innerClassMapping.methods())) {
46 methodMappings.add("MD: " + innerClassName + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString() + " " + innerDeobfClassName + "/" + methodMapping.getDeobfName() + " " + mappings.getTranslator(TranslationDirection.Deobfuscating, index).translateSignature(methodMapping.getObfSignature())); 46 methodMappings.add("MD: " + innerClassName + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature() + " " + innerDeobfClassName + "/" + methodMapping.getDeobfName() + " " + mappings.getTranslator(TranslationDirection.Deobfuscating, index).translateSignature(methodMapping.getObfSignature()));
47 } 47 }
48 } 48 }
49 49
50 for (FieldMapping fieldMapping : sorted(classMapping.fields())) { 50 for (FieldMapping fieldMapping : sorted(classMapping.fields())) {
51 fieldMappings.add("FD: " + classMapping.getObfFullName() + "/" + fieldMapping.getObfName() + " " + classMapping.getDeobfName() + "/" + fieldMapping.getDeobfName()); 51 fieldMappings.add("FD: " + classMapping.getObfFullName() + "/" + fieldMapping.getObfName() + " " + classMapping.getDeobfName() + "/" + fieldMapping.getDeobfName());
52 } 52 }
53 53
54 for (MethodMapping methodMapping : sorted(classMapping.methods())) { 54 for (MethodMapping methodMapping : sorted(classMapping.methods())) {
55 methodMappings.add("MD: " + classMapping.getObfFullName() + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString() + " " + classMapping.getDeobfName() + "/" + methodMapping.getDeobfName() + " " + mappings.getTranslator(TranslationDirection.Deobfuscating, index).translateSignature(methodMapping.getObfSignature())); 55 methodMappings.add("MD: " + classMapping.getObfFullName() + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature() + " " + classMapping.getDeobfName() + "/" + methodMapping.getDeobfName() + " " + mappings.getTranslator(TranslationDirection.Deobfuscating, index).translateSignature(methodMapping.getObfSignature()));
56 } 56 }
57 } 57 }
58 for(String fd : fieldMappings){ 58 for (String fd : fieldMappings) {
59 writer.write(fd); 59 writer.write(fd);
60 writer.write(System.lineSeparator()); 60 writer.write(System.lineSeparator());
61 } 61 }
62 62
63 for(String md : methodMappings){ 63 for (String md : methodMappings) {
64 writer.write(md); 64 writer.write(md);
65 writer.write(System.lineSeparator()); 65 writer.write(System.lineSeparator());
66 } 66 }
67 67
68 writer.close();
69 }
68 70
69 writer.close(); 71 private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) {
70 } 72 List<T> out = new ArrayList<>();
71 73 for (T t : classes) {
72 74 out.add(t);
73 private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { 75 }
74 List<T> out = new ArrayList<>(); 76 Collections.sort(out);
75 for (T t : classes) { 77 return out;
76 out.add(t); 78 }
77 }
78 Collections.sort(out);
79 return out;
80 }
81} 79}