diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/MatchesWriter.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/MatchesWriter.java | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/cuchaz/enigma/convert/MatchesWriter.java b/src/cuchaz/enigma/convert/MatchesWriter.java index 2118dd0..9e9ead0 100644 --- a/src/cuchaz/enigma/convert/MatchesWriter.java +++ b/src/cuchaz/enigma/convert/MatchesWriter.java | |||
| @@ -5,7 +5,9 @@ import java.io.FileWriter; | |||
| 5 | import java.io.IOException; | 5 | import java.io.IOException; |
| 6 | import java.util.Map; | 6 | import java.util.Map; |
| 7 | 7 | ||
| 8 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 8 | import cuchaz.enigma.mapping.ClassEntry; | 9 | import cuchaz.enigma.mapping.ClassEntry; |
| 10 | import cuchaz.enigma.mapping.Entry; | ||
| 9 | import cuchaz.enigma.mapping.FieldEntry; | 11 | import cuchaz.enigma.mapping.FieldEntry; |
| 10 | 12 | ||
| 11 | 13 | ||
| @@ -41,43 +43,52 @@ public class MatchesWriter { | |||
| 41 | } | 43 | } |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | public static void writeFields(FieldMatches fieldMatches, File file) | 46 | public static <T extends Entry> void writeMembers(MemberMatches<T> matches, File file) |
| 45 | throws IOException { | 47 | throws IOException { |
| 46 | try (FileWriter out = new FileWriter(file)) { | 48 | try (FileWriter out = new FileWriter(file)) { |
| 47 | for (Map.Entry<FieldEntry,FieldEntry> match : fieldMatches.matches().entrySet()) { | 49 | for (Map.Entry<T,T> match : matches.matches().entrySet()) { |
| 48 | writeFieldMatch(out, match.getKey(), match.getValue()); | 50 | writeMemberMatch(out, match.getKey(), match.getValue()); |
| 49 | } | 51 | } |
| 50 | for (FieldEntry fieldEntry : fieldMatches.getUnmatchedSourceFields()) { | 52 | for (T entry : matches.getUnmatchedSourceEntries()) { |
| 51 | writeFieldMatch(out, fieldEntry, null); | 53 | writeMemberMatch(out, entry, null); |
| 52 | } | 54 | } |
| 53 | for (FieldEntry fieldEntry : fieldMatches.getUnmatchedDestFields()) { | 55 | for (T entry : matches.getUnmatchedDestEntries()) { |
| 54 | writeFieldMatch(out, null, fieldEntry); | 56 | writeMemberMatch(out, null, entry); |
| 55 | } | 57 | } |
| 56 | for (FieldEntry fieldEntry : fieldMatches.getUnmatchableSourceFields()) { | 58 | for (T entry : matches.getUnmatchableSourceEntries()) { |
| 57 | writeUnmatchableField(out, fieldEntry); | 59 | writeUnmatchableEntry(out, entry); |
| 58 | } | 60 | } |
| 59 | } | 61 | } |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | private static void writeFieldMatch(FileWriter out, FieldEntry source, FieldEntry dest) | 64 | private static <T extends Entry> void writeMemberMatch(FileWriter out, T source, T dest) |
| 63 | throws IOException { | 65 | throws IOException { |
| 64 | if (source != null) { | 66 | if (source != null) { |
| 65 | writeField(out, source); | 67 | writeEntry(out, source); |
| 66 | } | 68 | } |
| 67 | out.write(":"); | 69 | out.write(":"); |
| 68 | if (dest != null) { | 70 | if (dest != null) { |
| 69 | writeField(out, dest); | 71 | writeEntry(out, dest); |
| 70 | } | 72 | } |
| 71 | out.write("\n"); | 73 | out.write("\n"); |
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | private static void writeUnmatchableField(FileWriter out, FieldEntry fieldEntry) | 76 | private static <T extends Entry> void writeUnmatchableEntry(FileWriter out, T entry) |
| 75 | throws IOException { | 77 | throws IOException { |
| 76 | out.write("!"); | 78 | out.write("!"); |
| 77 | writeField(out, fieldEntry); | 79 | writeEntry(out, entry); |
| 78 | out.write("\n"); | 80 | out.write("\n"); |
| 79 | } | 81 | } |
| 80 | 82 | ||
| 83 | private static <T extends Entry> void writeEntry(FileWriter out, T entry) | ||
| 84 | throws IOException { | ||
| 85 | if (entry instanceof FieldEntry) { | ||
| 86 | writeField(out, (FieldEntry)entry); | ||
| 87 | } else if (entry instanceof BehaviorEntry) { | ||
| 88 | writeBehavior(out, (BehaviorEntry)entry); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 81 | private static void writeField(FileWriter out, FieldEntry fieldEntry) | 92 | private static void writeField(FileWriter out, FieldEntry fieldEntry) |
| 82 | throws IOException { | 93 | throws IOException { |
| 83 | out.write(fieldEntry.getClassName()); | 94 | out.write(fieldEntry.getClassName()); |
| @@ -86,4 +97,15 @@ public class MatchesWriter { | |||
| 86 | out.write(" "); | 97 | out.write(" "); |
| 87 | out.write(fieldEntry.getType().toString()); | 98 | out.write(fieldEntry.getType().toString()); |
| 88 | } | 99 | } |
| 100 | |||
| 101 | private static void writeBehavior(FileWriter out, BehaviorEntry behaviorEntry) | ||
| 102 | throws IOException { | ||
| 103 | out.write(behaviorEntry.getClassName()); | ||
| 104 | out.write(" "); | ||
| 105 | out.write(behaviorEntry.getName()); | ||
| 106 | out.write(" "); | ||
| 107 | if (behaviorEntry.getSignature() != null) { | ||
| 108 | out.write(behaviorEntry.getSignature().toString()); | ||
| 109 | } | ||
| 110 | } | ||
| 89 | } | 111 | } |