diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/MatchesReader.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/MatchesReader.java | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/cuchaz/enigma/convert/MatchesReader.java b/src/cuchaz/enigma/convert/MatchesReader.java index 921ab1d..dac2f05 100644 --- a/src/cuchaz/enigma/convert/MatchesReader.java +++ b/src/cuchaz/enigma/convert/MatchesReader.java | |||
| @@ -10,6 +10,8 @@ import java.util.List; | |||
| 10 | import com.beust.jcommander.internal.Lists; | 10 | import com.beust.jcommander.internal.Lists; |
| 11 | 11 | ||
| 12 | import cuchaz.enigma.mapping.ClassEntry; | 12 | import cuchaz.enigma.mapping.ClassEntry; |
| 13 | import cuchaz.enigma.mapping.Entry; | ||
| 14 | import cuchaz.enigma.mapping.EntryFactory; | ||
| 13 | import cuchaz.enigma.mapping.FieldEntry; | 15 | import cuchaz.enigma.mapping.FieldEntry; |
| 14 | import cuchaz.enigma.mapping.Type; | 16 | import cuchaz.enigma.mapping.Type; |
| 15 | 17 | ||
| @@ -45,45 +47,57 @@ public class MatchesReader { | |||
| 45 | return entries; | 47 | return entries; |
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | public static FieldMatches readFields(File file) | 50 | public static <T extends Entry> MemberMatches<T> readMembers(File file) |
| 49 | throws IOException { | 51 | throws IOException { |
| 50 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { | 52 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { |
| 51 | FieldMatches matches = new FieldMatches(); | 53 | MemberMatches<T> matches = new MemberMatches<T>(); |
| 52 | String line = null; | 54 | String line = null; |
| 53 | while ((line = in.readLine()) != null) { | 55 | while ((line = in.readLine()) != null) { |
| 54 | readFieldMatch(matches, line); | 56 | readMemberMatch(matches, line); |
| 55 | } | 57 | } |
| 56 | return matches; | 58 | return matches; |
| 57 | } | 59 | } |
| 58 | } | 60 | } |
| 59 | 61 | ||
| 60 | private static void readFieldMatch(FieldMatches matches, String line) { | 62 | private static <T extends Entry> void readMemberMatch(MemberMatches<T> matches, String line) { |
| 61 | if (line.startsWith("!")) { | 63 | if (line.startsWith("!")) { |
| 62 | matches.addUnmatchableSourceField(readField(line.substring(1))); | 64 | T source = readEntry(line.substring(1)); |
| 65 | matches.addUnmatchableSourceEntry(source); | ||
| 63 | } else { | 66 | } else { |
| 64 | String[] parts = line.split(":", 2); | 67 | String[] parts = line.split(":", 2); |
| 65 | FieldEntry source = readField(parts[0]); | 68 | T source = readEntry(parts[0]); |
| 66 | FieldEntry dest = readField(parts[1]); | 69 | T dest = readEntry(parts[1]); |
| 67 | if (source != null && dest != null) { | 70 | if (source != null && dest != null) { |
| 68 | matches.addMatch(source, dest); | 71 | matches.addMatch(source, dest); |
| 69 | } else if (source != null) { | 72 | } else if (source != null) { |
| 70 | matches.addUnmatchedSourceField(source); | 73 | matches.addUnmatchedSourceEntry(source); |
| 71 | } else if (dest != null) { | 74 | } else if (dest != null) { |
| 72 | matches.addUnmatchedDestField(dest); | 75 | matches.addUnmatchedDestEntry(dest); |
| 73 | } | 76 | } |
| 74 | } | 77 | } |
| 75 | } | 78 | } |
| 76 | 79 | ||
| 77 | private static FieldEntry readField(String in) { | 80 | @SuppressWarnings("unchecked") |
| 81 | private static <T extends Entry> T readEntry(String in) { | ||
| 78 | if (in.length() <= 0) { | 82 | if (in.length() <= 0) { |
| 79 | return null; | 83 | return null; |
| 80 | } | 84 | } |
| 81 | String[] parts = in.split(" "); | 85 | String[] parts = in.split(" "); |
| 82 | assert(parts.length == 3); | 86 | if (parts.length == 3 && parts[2].indexOf('(') < 0) { |
| 83 | return new FieldEntry( | 87 | return (T)new FieldEntry( |
| 84 | new ClassEntry(parts[0]), | 88 | new ClassEntry(parts[0]), |
| 85 | parts[1], | 89 | parts[1], |
| 86 | new Type(parts[2]) | 90 | new Type(parts[2]) |
| 87 | ); | 91 | ); |
| 92 | } else { | ||
| 93 | assert(parts.length == 2 || parts.length == 3); | ||
| 94 | if (parts.length == 2) { | ||
| 95 | return (T)EntryFactory.getBehaviorEntry(parts[0], parts[1]); | ||
| 96 | } else if (parts.length == 3) { | ||
| 97 | return (T)EntryFactory.getBehaviorEntry(parts[0], parts[1], parts[2]); | ||
| 98 | } else { | ||
| 99 | throw new Error("Malformed behavior entry: " + in); | ||
| 100 | } | ||
| 101 | } | ||
| 88 | } | 102 | } |
| 89 | } | 103 | } |