diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/MatchesWriter.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/MatchesWriter.java | 185 |
1 files changed, 94 insertions, 91 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/MatchesWriter.java b/src/main/java/cuchaz/enigma/convert/MatchesWriter.java index dccbf6f..8fe7326 100644 --- a/src/main/java/cuchaz/enigma/convert/MatchesWriter.java +++ b/src/main/java/cuchaz/enigma/convert/MatchesWriter.java | |||
| @@ -8,113 +8,116 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.convert; | ||
| 12 | 11 | ||
| 13 | import java.io.*; | 12 | package cuchaz.enigma.convert; |
| 14 | import java.nio.charset.Charset; | ||
| 15 | import java.util.Map; | ||
| 16 | 13 | ||
| 17 | import cuchaz.enigma.mapping.BehaviorEntry; | 14 | import cuchaz.enigma.mapping.BehaviorEntry; |
| 18 | import cuchaz.enigma.mapping.ClassEntry; | 15 | import cuchaz.enigma.mapping.ClassEntry; |
| 19 | import cuchaz.enigma.mapping.Entry; | 16 | import cuchaz.enigma.mapping.Entry; |
| 20 | import cuchaz.enigma.mapping.FieldEntry; | 17 | import cuchaz.enigma.mapping.FieldEntry; |
| 21 | 18 | ||
| 19 | import java.io.File; | ||
| 20 | import java.io.FileOutputStream; | ||
| 21 | import java.io.IOException; | ||
| 22 | import java.io.OutputStreamWriter; | ||
| 23 | import java.nio.charset.Charset; | ||
| 24 | import java.util.Map; | ||
| 22 | 25 | ||
| 23 | public class MatchesWriter { | 26 | public class MatchesWriter { |
| 24 | 27 | ||
| 25 | public static void writeClasses(ClassMatches matches, File file) | 28 | public static void writeClasses(ClassMatches matches, File file) |
| 26 | throws IOException { | 29 | throws IOException { |
| 27 | try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { | 30 | try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { |
| 28 | for (ClassMatch match : matches) { | 31 | for (ClassMatch match : matches) { |
| 29 | writeClassMatch(out, match); | 32 | writeClassMatch(out, match); |
| 30 | } | 33 | } |
| 31 | } | 34 | } |
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | private static void writeClassMatch(OutputStreamWriter out, ClassMatch match) | 37 | private static void writeClassMatch(OutputStreamWriter out, ClassMatch match) |
| 35 | throws IOException { | 38 | throws IOException { |
| 36 | writeClasses(out, match.sourceClasses); | 39 | writeClasses(out, match.sourceClasses); |
| 37 | out.write(":"); | 40 | out.write(":"); |
| 38 | writeClasses(out, match.destClasses); | 41 | writeClasses(out, match.destClasses); |
| 39 | out.write("\n"); | 42 | out.write("\n"); |
| 40 | } | 43 | } |
| 41 | 44 | ||
| 42 | private static void writeClasses(OutputStreamWriter out, Iterable<ClassEntry> classes) | 45 | private static void writeClasses(OutputStreamWriter out, Iterable<ClassEntry> classes) |
| 43 | throws IOException { | 46 | throws IOException { |
| 44 | boolean isFirst = true; | 47 | boolean isFirst = true; |
| 45 | for (ClassEntry entry : classes) { | 48 | for (ClassEntry entry : classes) { |
| 46 | if (isFirst) { | 49 | if (isFirst) { |
| 47 | isFirst = false; | 50 | isFirst = false; |
| 48 | } else { | 51 | } else { |
| 49 | out.write(","); | 52 | out.write(","); |
| 50 | } | 53 | } |
| 51 | out.write(entry.toString()); | 54 | out.write(entry.toString()); |
| 52 | } | 55 | } |
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | public static <T extends Entry> void writeMembers(MemberMatches<T> matches, File file) | 58 | public static <T extends Entry> void writeMembers(MemberMatches<T> matches, File file) |
| 56 | throws IOException { | 59 | throws IOException { |
| 57 | try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { | 60 | try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))) { |
| 58 | for (Map.Entry<T, T> match : matches.matches().entrySet()) { | 61 | for (Map.Entry<T, T> match : matches.matches().entrySet()) { |
| 59 | writeMemberMatch(out, match.getKey(), match.getValue()); | 62 | writeMemberMatch(out, match.getKey(), match.getValue()); |
| 60 | } | 63 | } |
| 61 | for (T entry : matches.getUnmatchedSourceEntries()) { | 64 | for (T entry : matches.getUnmatchedSourceEntries()) { |
| 62 | writeMemberMatch(out, entry, null); | 65 | writeMemberMatch(out, entry, null); |
| 63 | } | 66 | } |
| 64 | for (T entry : matches.getUnmatchedDestEntries()) { | 67 | for (T entry : matches.getUnmatchedDestEntries()) { |
| 65 | writeMemberMatch(out, null, entry); | 68 | writeMemberMatch(out, null, entry); |
| 66 | } | 69 | } |
| 67 | for (T entry : matches.getUnmatchableSourceEntries()) { | 70 | for (T entry : matches.getUnmatchableSourceEntries()) { |
| 68 | writeUnmatchableEntry(out, entry); | 71 | writeUnmatchableEntry(out, entry); |
| 69 | } | 72 | } |
| 70 | } | 73 | } |
| 71 | } | 74 | } |
| 72 | 75 | ||
| 73 | private static <T extends Entry> void writeMemberMatch(OutputStreamWriter out, T source, T dest) | 76 | private static <T extends Entry> void writeMemberMatch(OutputStreamWriter out, T source, T dest) |
| 74 | throws IOException { | 77 | throws IOException { |
| 75 | if (source != null) { | 78 | if (source != null) { |
| 76 | writeEntry(out, source); | 79 | writeEntry(out, source); |
| 77 | } | 80 | } |
| 78 | out.write(":"); | 81 | out.write(":"); |
| 79 | if (dest != null) { | 82 | if (dest != null) { |
| 80 | writeEntry(out, dest); | 83 | writeEntry(out, dest); |
| 81 | } | 84 | } |
| 82 | out.write("\n"); | 85 | out.write("\n"); |
| 83 | } | 86 | } |
| 84 | 87 | ||
| 85 | private static <T extends Entry> void writeUnmatchableEntry(OutputStreamWriter out, T entry) | 88 | private static <T extends Entry> void writeUnmatchableEntry(OutputStreamWriter out, T entry) |
| 86 | throws IOException { | 89 | throws IOException { |
| 87 | out.write("!"); | 90 | out.write("!"); |
| 88 | writeEntry(out, entry); | 91 | writeEntry(out, entry); |
| 89 | out.write("\n"); | 92 | out.write("\n"); |
| 90 | } | 93 | } |
| 91 | 94 | ||
| 92 | private static <T extends Entry> void writeEntry(OutputStreamWriter out, T entry) | 95 | private static <T extends Entry> void writeEntry(OutputStreamWriter out, T entry) |
| 93 | throws IOException { | 96 | throws IOException { |
| 94 | if (entry instanceof FieldEntry) { | 97 | if (entry instanceof FieldEntry) { |
| 95 | writeField(out, (FieldEntry) entry); | 98 | writeField(out, (FieldEntry) entry); |
| 96 | } else if (entry instanceof BehaviorEntry) { | 99 | } else if (entry instanceof BehaviorEntry) { |
| 97 | writeBehavior(out, (BehaviorEntry) entry); | 100 | writeBehavior(out, (BehaviorEntry) entry); |
| 98 | } | 101 | } |
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | private static void writeField(OutputStreamWriter out, FieldEntry fieldEntry) | 104 | private static void writeField(OutputStreamWriter out, FieldEntry fieldEntry) |
| 102 | throws IOException { | 105 | throws IOException { |
| 103 | out.write(fieldEntry.getClassName()); | 106 | out.write(fieldEntry.getClassName()); |
| 104 | out.write(" "); | 107 | out.write(" "); |
| 105 | out.write(fieldEntry.getName()); | 108 | out.write(fieldEntry.getName()); |
| 106 | out.write(" "); | 109 | out.write(" "); |
| 107 | out.write(fieldEntry.getType().toString()); | 110 | out.write(fieldEntry.getType().toString()); |
| 108 | } | 111 | } |
| 109 | 112 | ||
| 110 | private static void writeBehavior(OutputStreamWriter out, BehaviorEntry behaviorEntry) | 113 | private static void writeBehavior(OutputStreamWriter out, BehaviorEntry behaviorEntry) |
| 111 | throws IOException { | 114 | throws IOException { |
| 112 | out.write(behaviorEntry.getClassName()); | 115 | out.write(behaviorEntry.getClassName()); |
| 113 | out.write(" "); | 116 | out.write(" "); |
| 114 | out.write(behaviorEntry.getName()); | 117 | out.write(behaviorEntry.getName()); |
| 115 | out.write(" "); | 118 | out.write(" "); |
| 116 | if (behaviorEntry.getSignature() != null) { | 119 | if (behaviorEntry.getSignature() != null) { |
| 117 | out.write(behaviorEntry.getSignature().toString()); | 120 | out.write(behaviorEntry.getSignature().toString()); |
| 118 | } | 121 | } |
| 119 | } | 122 | } |
| 120 | } | 123 | } |