diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/MatchesReader.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/convert/MatchesReader.java | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/MatchesReader.java b/src/main/java/cuchaz/enigma/convert/MatchesReader.java deleted file mode 100644 index f7853ac..0000000 --- a/src/main/java/cuchaz/enigma/convert/MatchesReader.java +++ /dev/null | |||
| @@ -1,104 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.convert; | ||
| 12 | |||
| 13 | import com.google.common.collect.Lists; | ||
| 14 | |||
| 15 | import java.io.BufferedReader; | ||
| 16 | import java.io.File; | ||
| 17 | import java.io.FileReader; | ||
| 18 | import java.io.IOException; | ||
| 19 | import java.util.Collection; | ||
| 20 | import java.util.List; | ||
| 21 | |||
| 22 | import cuchaz.enigma.mapping.*; | ||
| 23 | |||
| 24 | |||
| 25 | public class MatchesReader { | ||
| 26 | |||
| 27 | public static ClassMatches readClasses(File file) | ||
| 28 | throws IOException { | ||
| 29 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { | ||
| 30 | ClassMatches matches = new ClassMatches(); | ||
| 31 | String line; | ||
| 32 | while ((line = in.readLine()) != null) { | ||
| 33 | matches.add(readClassMatch(line)); | ||
| 34 | } | ||
| 35 | return matches; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | private static ClassMatch readClassMatch(String line) | ||
| 40 | throws IOException { | ||
| 41 | String[] sides = line.split(":", 2); | ||
| 42 | return new ClassMatch(readClasses(sides[0]), readClasses(sides[1])); | ||
| 43 | } | ||
| 44 | |||
| 45 | private static Collection<ClassEntry> readClasses(String in) { | ||
| 46 | List<ClassEntry> entries = Lists.newArrayList(); | ||
| 47 | for (String className : in.split(",")) { | ||
| 48 | className = className.trim(); | ||
| 49 | if (className.length() > 0) { | ||
| 50 | entries.add(new ClassEntry(className)); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | return entries; | ||
| 54 | } | ||
| 55 | |||
| 56 | public static <T extends Entry> MemberMatches<T> readMembers(File file) | ||
| 57 | throws IOException { | ||
| 58 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { | ||
| 59 | MemberMatches<T> matches = new MemberMatches<>(); | ||
| 60 | String line; | ||
| 61 | while ((line = in.readLine()) != null) { | ||
| 62 | readMemberMatch(matches, line); | ||
| 63 | } | ||
| 64 | return matches; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | private static <T extends Entry> void readMemberMatch(MemberMatches<T> matches, String line) { | ||
| 69 | if (line.startsWith("!")) { | ||
| 70 | T source = readEntry(line.substring(1)); | ||
| 71 | matches.addUnmatchableSourceEntry(source); | ||
| 72 | } else { | ||
| 73 | String[] parts = line.split(":", 2); | ||
| 74 | T source = readEntry(parts[0]); | ||
| 75 | T dest = readEntry(parts[1]); | ||
| 76 | if (source != null && dest != null) { | ||
| 77 | matches.addMatch(source, dest); | ||
| 78 | } else if (source != null) { | ||
| 79 | matches.addUnmatchedSourceEntry(source); | ||
| 80 | } else if (dest != null) { | ||
| 81 | matches.addUnmatchedDestEntry(dest); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | @SuppressWarnings("unchecked") | ||
| 87 | private static <T extends Entry> T readEntry(String in) { | ||
| 88 | if (in.length() <= 0) { | ||
| 89 | return null; | ||
| 90 | } | ||
| 91 | String[] parts = in.split(" "); | ||
| 92 | if (parts.length == 3 && parts[2].indexOf('(') < 0) { | ||
| 93 | return (T) new FieldEntry(new ClassEntry(parts[0]), parts[1], new Type(parts[2])); | ||
| 94 | } else { | ||
| 95 | if (parts.length == 2) { | ||
| 96 | return (T) EntryFactory.getBehaviorEntry(parts[0], parts[1]); | ||
| 97 | } else if (parts.length == 3) { | ||
| 98 | return (T) EntryFactory.getBehaviorEntry(parts[0], parts[1], parts[2]); | ||
| 99 | } else { | ||
| 100 | throw new Error("Malformed behavior entry: " + in); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||